Browse Source

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.
Sasha Szpakowski 2 years ago
parent
commit
94d05e319b
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/modules/graphics/Graphics.cpp

+ 9 - 3
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()