From f5c5a344f05364b912c6aefef15383bb00edd326 Mon Sep 17 00:00:00 2001 From: dtatarnikov Date: Thu, 6 Jul 2023 13:55:56 +0700 Subject: [PATCH] Fix #481 --- src/Veldrid/OpenGL/OpenGLCommandExecutor.cs | 51 ++++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs b/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs index 789b2833e..e86051231 100644 --- a/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs +++ b/src/Veldrid/OpenGL/OpenGLCommandExecutor.cs @@ -94,28 +94,55 @@ public void ClearColorTarget(uint index, RgbaFloat clearColor) public void ClearDepthStencil(float depth, byte stencil) { - glClearDepth_Compat(depth); - CheckLastError(); + if (_graphicsPipeline != null) + { + if (!_graphicsPipeline.DepthStencilState.DepthWriteEnabled) + { + glDepthMask(true); + CheckLastError(); + } + + if (_graphicsPipeline.DepthStencilState.StencilWriteMask != 0xFF) + { + glStencilMask(0xFF); + CheckLastError(); + } - glStencilMask(~0u); + if (_graphicsPipeline.RasterizerState.ScissorTestEnabled) + { + glDisable(EnableCap.ScissorTest); + CheckLastError(); + } + } + + glClearDepth_Compat(depth); CheckLastError(); glClearStencil(stencil); CheckLastError(); - if (_graphicsPipeline != null && _graphicsPipeline.RasterizerState.ScissorTestEnabled) - { - glDisable(EnableCap.ScissorTest); - CheckLastError(); - } - - glDepthMask(true); glClear(ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); CheckLastError(); - if (_graphicsPipeline != null && _graphicsPipeline.RasterizerState.ScissorTestEnabled) + if (_graphicsPipeline != null) { - glEnable(EnableCap.ScissorTest); + if (!_graphicsPipeline.DepthStencilState.DepthWriteEnabled) + { + glDepthMask(false); + CheckLastError(); + } + + if (_graphicsPipeline.DepthStencilState.StencilWriteMask != 0xFF) + { + glStencilMask(_graphicsPipeline.DepthStencilState.StencilWriteMask); + CheckLastError(); + } + + if (_graphicsPipeline.RasterizerState.ScissorTestEnabled) + { + glEnable(EnableCap.ScissorTest); + CheckLastError(); + } } }