diff --git a/CHANGELOG.md b/CHANGELOG.md
index a497667..90c3afa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,10 @@ Jump to version:
## 6.3.0 (In Development)
+### MLEM
+Additions
+- Added GraphicsExtensions.WithRenderTargets, a multi-target version of WithRenderTarget
+
## 6.2.0
### MLEM
diff --git a/MLEM/Extensions/GraphicsExtensions.cs b/MLEM/Extensions/GraphicsExtensions.cs
index 4c1b230..57dd9b8 100644
--- a/MLEM/Extensions/GraphicsExtensions.cs
+++ b/MLEM/Extensions/GraphicsExtensions.cs
@@ -69,11 +69,22 @@ namespace MLEM.Extensions {
///
/// The graphics device
/// The render target to apply
- ///
+ /// The render target context, to be used in a using statement
public static TargetContext WithRenderTarget(this GraphicsDevice device, RenderTarget2D target) {
return new TargetContext(device, target);
}
+ ///
+ /// Starts a new using the specified render target bindings.
+ /// The returned context automatically disposes when used in a using statement, which causes any previously applied render targets to be reapplied automatically.
+ ///
+ /// The graphics device
+ /// The render targets to apply
+ /// The render target context, to be used in a using statement
+ public static TargetContext WithRenderTargets(this GraphicsDevice device, params RenderTargetBinding[] targets) {
+ return new TargetContext(device, targets);
+ }
+
///
/// Represents a context in which a is applied.
/// This class should be used with .
@@ -88,7 +99,20 @@ namespace MLEM.Extensions {
///
/// The graphics device to apply the target on
/// The target to apply
- public TargetContext(GraphicsDevice device, RenderTarget2D target) {
+ public TargetContext(GraphicsDevice device, RenderTarget2D target) : this(device) {
+ device.SetRenderTarget(target);
+ }
+
+ ///
+ /// Creates a new target context with the given settings.
+ ///
+ /// The graphics device to apply the target on
+ /// The targets to apply
+ public TargetContext(GraphicsDevice device, RenderTargetBinding[] targets) : this(device) {
+ device.SetRenderTargets(targets);
+ }
+
+ private TargetContext(GraphicsDevice device) {
this.device = device;
#if FNA
// RenderTargetCount doesn't exist in FNA but we still want the optimization in MG
@@ -96,7 +120,6 @@ namespace MLEM.Extensions {
#else
this.lastTargets = device.RenderTargetCount <= 0 ? null : device.GetRenderTargets();
#endif
- device.SetRenderTarget(target);
}
///