mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
Added WithRenderTargets, a multi-target version of WithRenderTarget
This commit is contained in:
parent
840c528f06
commit
50da081be9
2 changed files with 30 additions and 3 deletions
|
@ -13,6 +13,10 @@ Jump to version:
|
||||||
|
|
||||||
## 6.3.0 (In Development)
|
## 6.3.0 (In Development)
|
||||||
|
|
||||||
|
### MLEM
|
||||||
|
Additions
|
||||||
|
- Added GraphicsExtensions.WithRenderTargets, a multi-target version of WithRenderTarget
|
||||||
|
|
||||||
## 6.2.0
|
## 6.2.0
|
||||||
|
|
||||||
### MLEM
|
### MLEM
|
||||||
|
|
|
@ -69,11 +69,22 @@ namespace MLEM.Extensions {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="device">The graphics device</param>
|
/// <param name="device">The graphics device</param>
|
||||||
/// <param name="target">The render target to apply</param>
|
/// <param name="target">The render target to apply</param>
|
||||||
/// <returns></returns>
|
/// <returns>The render target context, to be used in a <c>using</c> statement</returns>
|
||||||
public static TargetContext WithRenderTarget(this GraphicsDevice device, RenderTarget2D target) {
|
public static TargetContext WithRenderTarget(this GraphicsDevice device, RenderTarget2D target) {
|
||||||
return new TargetContext(device, target);
|
return new TargetContext(device, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts a new <see cref="TargetContext"/> using the specified render target bindings.
|
||||||
|
/// The returned context automatically disposes when used in a <c>using</c> statement, which causes any previously applied render targets to be reapplied automatically.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device">The graphics device</param>
|
||||||
|
/// <param name="targets">The render targets to apply</param>
|
||||||
|
/// <returns>The render target context, to be used in a <c>using</c> statement</returns>
|
||||||
|
public static TargetContext WithRenderTargets(this GraphicsDevice device, params RenderTargetBinding[] targets) {
|
||||||
|
return new TargetContext(device, targets);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a context in which a <see cref="RenderTarget2D"/> is applied.
|
/// Represents a context in which a <see cref="RenderTarget2D"/> is applied.
|
||||||
/// This class should be used with <see cref="GraphicsExtensions.WithRenderTarget"/>.
|
/// This class should be used with <see cref="GraphicsExtensions.WithRenderTarget"/>.
|
||||||
|
@ -88,7 +99,20 @@ namespace MLEM.Extensions {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="device">The graphics device to apply the target on</param>
|
/// <param name="device">The graphics device to apply the target on</param>
|
||||||
/// <param name="target">The target to apply</param>
|
/// <param name="target">The target to apply</param>
|
||||||
public TargetContext(GraphicsDevice device, RenderTarget2D target) {
|
public TargetContext(GraphicsDevice device, RenderTarget2D target) : this(device) {
|
||||||
|
device.SetRenderTarget(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new target context with the given settings.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="device">The graphics device to apply the target on</param>
|
||||||
|
/// <param name="targets">The targets to apply</param>
|
||||||
|
public TargetContext(GraphicsDevice device, RenderTargetBinding[] targets) : this(device) {
|
||||||
|
device.SetRenderTargets(targets);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TargetContext(GraphicsDevice device) {
|
||||||
this.device = device;
|
this.device = device;
|
||||||
#if FNA
|
#if FNA
|
||||||
// RenderTargetCount doesn't exist in FNA but we still want the optimization in MG
|
// RenderTargetCount doesn't exist in FNA but we still want the optimization in MG
|
||||||
|
@ -96,7 +120,6 @@ namespace MLEM.Extensions {
|
||||||
#else
|
#else
|
||||||
this.lastTargets = device.RenderTargetCount <= 0 ? null : device.GetRenderTargets();
|
this.lastTargets = device.RenderTargetCount <= 0 ? null : device.GetRenderTargets();
|
||||||
#endif
|
#endif
|
||||||
device.SetRenderTarget(target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue