From 94d05e319b8b672683e735ef3126950abdd0d607 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Wed, 11 Jan 2023 18:17:22 -0400 Subject: [PATCH] Clear auto-generated temporary depth/stencil buffers in setCanvas. Previously it would discard them, which needed the user to call love.graphics.clear afterward to get them into a valid state. The current code has suboptimal performance if the user still calls clear after setCanvas (a common situation), so more optimizations will probably be needed. Fixes #1843. --- src/modules/graphics/Graphics.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 895cc7dab..85733e0be 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -963,10 +963,16 @@ void Graphics::setRenderTargets(const RenderTargets &rts) resetProjection(); - // Invalidate temporary depth/stencil. This could be a clear, but if the - // user also clears a double-clear may be slow... + // Clear/reset the temporary depth/stencil buffers. + // TODO: make this deferred somehow to avoid double clearing if the user + // also calls love.graphics.clear after setCanvas. if (rts.depthStencil.texture == nullptr && rts.temporaryRTFlags != 0) - discard({}, true); + { + OptionalColorD clearcolor; + OptionalInt clearstencil(0); + OptionalDouble cleardepth(1.0); + clear(clearcolor, clearstencil, cleardepth); + } } void Graphics::setRenderTarget()