Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RenderInRenderTarget #5478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Robust.Client/Graphics/Clyde/Clyde.HLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ private void RenderInRenderTarget(RenderTargetBase rt, Action a, Color? clearCol

var oldTransform = _currentMatrixModel;
var oldScissor = _currentScissorState;
var oldMatrixProj = _currentMatrixProj;
var oldMatrixView = _currentMatrixView;
var oldBoundTarget = _currentBoundRenderTarget;
var oldRenderTarget = _currentRenderTarget;
var oldShader = _queuedShaderInstance;

// Have to flush the render queue so that all commands finish rendering to the previous framebuffer.
FlushRenderQueue();
Expand All @@ -447,11 +452,20 @@ private void RenderInRenderTarget(RenderTargetBase rt, Action a, Color? clearCol

FenceRenderTarget(rt);

_currentRenderTarget = oldRenderTarget;
PopRenderStateFull(state);
_updateUniformConstants(_currentRenderTarget.Size);

SetScissorFull(oldScissor);
_currentMatrixModel = oldTransform;

DebugTools.Assert(_currentMatrixModel.Equals(oldTransform));
DebugTools.Assert(_currentScissorState.Equals(oldScissor));
DebugTools.Assert(_currentMatrixProj.Equals(oldMatrixProj));
DebugTools.Assert(oldMatrixView.Equals(_currentMatrixView));
DebugTools.Assert(oldRenderTarget.Equals(_currentRenderTarget));
DebugTools.Assert(oldBoundTarget.Equals(_currentBoundRenderTarget));
DebugTools.Assert(oldShader.Equals(_queuedShaderInstance));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OD breaks on this assert. Idk if that means we're doing it wrong.

}

private void RenderViewport(Viewport viewport)
Expand Down
4 changes: 2 additions & 2 deletions Robust.Client/Graphics/Clyde/Clyde.Rendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,13 +859,13 @@ private void BreakBatch()

private FullStoredRendererState PushRenderStateFull()
{
return new FullStoredRendererState(_currentMatrixProj, _currentMatrixView, _currentRenderTarget);
return new FullStoredRendererState(_currentMatrixProj, _currentMatrixView, _currentBoundRenderTarget);
}

private void PopRenderStateFull(in FullStoredRendererState state)
{
SetProjViewFull(state.ProjMatrix, state.ViewMatrix);
BindRenderTargetFull(state.RenderTarget);
BindRenderTargetImmediate(state.RenderTarget);

var (width, height) = state.RenderTarget.Size;
GL.Viewport(0, 0, width, height);
Expand Down
Loading