Skip to content

Commit

Permalink
Fix invalid UseShader() uses
Browse files Browse the repository at this point in the history
Apparently you can't set the shader outside `RenderInRenderTarget()`. A little saddening, but not a huge hit to allocation rate.
  • Loading branch information
wixoaGit committed Jan 17, 2024
1 parent 32698d6 commit 77f9af0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 0 additions & 2 deletions OpenDreamClient/Rendering/DreamPlane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public void Draw(DreamViewOverlay overlay, DrawingHandleWorld handle, Box2 world
handle.UseShader(overlay.GetBlendAndColorShader(Master, useOverlayMode: true));
handle.SetTransform(DreamViewOverlay.CreateRenderTargetFlipMatrix(_temporaryRenderTarget.Size, Vector2.Zero));
handle.DrawTextureRect(mainRenderTarget.Texture, new Box2(Vector2.Zero, mainRenderTarget.Size));
handle.SetTransform(Matrix3.Identity);
handle.UseShader(null);
}, new Color());
}
}
Expand Down
26 changes: 14 additions & 12 deletions OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,27 +802,29 @@ private void DrawIconSlow(DrawingHandleWorld handle, Texture frame, RendererMeta
IRenderTexture ping = RentRenderTarget(frame.Size * 2);
IRenderTexture pong = RentRenderTarget(ping.Size);

//we can use the color matrix shader here, since we don't need to blend
//also because blend mode is none, we don't need to clear
var colorMatrix = iconMetaData.ColorMatrixToApply.Equals(ColorMatrix.Identity)
? new ColorMatrix(iconMetaData.ColorToApply.WithAlpha(iconMetaData.AlphaToApply))
: iconMetaData.ColorMatrixToApply;

ShaderInstance colorShader = _colorInstance.Duplicate();
colorShader.SetParameter("colorMatrix", colorMatrix.GetMatrix4());
colorShader.SetParameter("offsetVector", colorMatrix.GetOffsetVector());
colorShader.SetParameter("isPlaneMaster",iconMetaData.IsPlaneMaster);
handle.UseShader(colorShader);
handle.RenderInRenderTarget(pong, () => {
//we can use the color matrix shader here, since we don't need to blend
//also because blend mode is none, we don't need to clear
var colorMatrix = iconMetaData.ColorMatrixToApply.Equals(ColorMatrix.Identity)
? new ColorMatrix(iconMetaData.ColorToApply.WithAlpha(iconMetaData.AlphaToApply))
: iconMetaData.ColorMatrixToApply;

ShaderInstance colorShader = _colorInstance.Duplicate();
colorShader.SetParameter("colorMatrix", colorMatrix.GetMatrix4());
colorShader.SetParameter("offsetVector", colorMatrix.GetOffsetVector());
colorShader.SetParameter("isPlaneMaster",iconMetaData.IsPlaneMaster);
handle.UseShader(colorShader);

handle.SetTransform(CreateRenderTargetFlipMatrix(pong.Size, frame.Size / 2));
handle.DrawTextureRect(frame, new Box2(Vector2.Zero, frame.Size));
}, Color.Black.WithAlpha(0));

foreach (DreamFilter filterId in iconMetaData.MainIcon!.Appearance!.Filters) {
ShaderInstance s = _appearanceSystem.GetFilterShader(filterId, RenderSourceLookup);

handle.UseShader(s); // Set the shader out here to avoid a closure alloc
handle.RenderInRenderTarget(ping, () => {
handle.UseShader(s);

// Technically this should be ping.Size, but they are the same size so avoid the extra closure alloc
var transform = CreateRenderTargetFlipMatrix(pong.Size, Vector2.Zero);

Expand Down

0 comments on commit 77f9af0

Please sign in to comment.