Skip to content

Commit

Permalink
[2D] - Added convenience methods to enable/disable passes in the effe…
Browse files Browse the repository at this point in the history
…cts compositor.
  • Loading branch information
Tape-Worm committed Aug 11, 2021
1 parent 78ef5b8 commit 48c6ace
Showing 1 changed file with 80 additions and 6 deletions.
86 changes: 80 additions & 6 deletions Gorgon/Gorgon.Renderers/Gorgon2D/Effects/Gorgon2DCompositor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@ private void CreateResources(GorgonRenderTargetView outputTarget)
/// <param name="final">The final output render target.</param>
private void CopyToFinal(GorgonTexture2DView lastTargetTexture, GorgonRenderTargetView final)
{
// We cannot copy a texture to itself, and it's pointless to do so, so just leave.
if (lastTargetTexture.Resource == final.Resource)
{
return;
}

Graphics.SetRenderTarget(final);

if (_finalClear is not null)
Expand Down Expand Up @@ -460,6 +454,80 @@ public Gorgon2DCompositor MovePass(int passIndex, int newPassIndex)
return this;
}

/// <summary>
/// Function to disable a pass by index.
/// </summary>
/// <param name="index">The index of the pass to disable or disable.</param>
/// <returns>The fluent interface for the effects processor.</returns>
public Gorgon2DCompositor DisablePass(int index)
{
if ((index < 0) || (index >= _passes.Count))
{
return this;
}

_passes[index].Enabled = false;
return this;
}

/// <summary>
/// Function to disable a pass by name.
/// </summary>
/// <param name="passName">The name of the pass to disable or disable.</param>
/// <returns>The fluent interface for the effects processor.</returns>
public Gorgon2DCompositor DisablePass(string passName)
{
if (string.IsNullOrWhiteSpace(passName))
{
return this;
}

if (!_passLookup.TryGetValue(passName, out int index))
{
return this;
}

_passes[index].Enabled = false;
return this;
}

/// <summary>
/// Function to enable a pass by index.
/// </summary>
/// <param name="index">The index of the pass to enable or disable.</param>
/// <returns>The fluent interface for the effects processor.</returns>
public Gorgon2DCompositor EnablePass(int index)
{
if ((index < 0) || (index >= _passes.Count))
{
return this;
}

_passes[index].Enabled = true;
return this;
}

/// <summary>
/// Function to enable a pass by name.
/// </summary>
/// <param name="passName">The name of the pass to enable or disable.</param>
/// <returns>The fluent interface for the effects processor.</returns>
public Gorgon2DCompositor EnablePass(string passName)
{
if (string.IsNullOrWhiteSpace(passName))
{
return this;
}

if (!_passLookup.TryGetValue(passName, out int index))
{
return this;
}

_passes[index].Enabled = true;
return this;
}

/// <summary>
/// Function to render the scene for the compositor effects.
/// </summary>
Expand All @@ -471,6 +539,12 @@ public Gorgon2DCompositor Render(GorgonTexture2DView source, GorgonRenderTargetV
source.ValidateObject(nameof(source));
output.ValidateObject(nameof(output));

// We cannot copy a texture to itself, and it's pointless to do so, so just leave.
if (source.Resource == output.Resource)
{
return this;
}

// Create or update our resources
CreateResources(output);

Expand Down

0 comments on commit 48c6ace

Please sign in to comment.