From 5eba9a64342397001bad13466fc2d7b8eef27043 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 6 Aug 2025 15:29:03 +0100 Subject: [PATCH] OpenGL: Clear bound texture after rendering transparency layer A change introduced in 00836d1e94dcd45949da5be7f9266258c5d0dfe5 meant that GL renderers could sometimes assert in StateHelpers::ActiveTextures::bindTexture() when ending a transparency layer. Specifically, the issue was provoked by adding the ScopedTextureBinding in the constructor of OpenGLFrameBuffer. This reset the bound texture after creating a new transparency layer. I think the previous implementation worked by accident, not by design. It so happens that when rendering multiple transparency layers within the same frame (i.e. calling begin/end several times in that order, *not* nesting the calls), the same texture ID will generally get reused. From the graphics context's (GC's) perspective, we create a texture with ID "2", then call bindTexture() to bind it, and the GC remembers that this ID is bound. We draw the frame, and the texture gets destroyed. The call to glDeleteTextures() will cause the default texture, "0", to be bound if the texture being destroyed is bound at the point of destruction. So, after the texture is destroyed, the GC's stored binding no longer reflects reality, since texture "0" is now bound. The next time we create a texture, that texture also gets created with ID "2". Previously, we would leave this texture bound after construction, but now we re-bind the previously-bound texture, "0". This causes the assertion in bindTexture() to fire when we next attempt to bind texture "2", since the actual bound texture is "0". The solution added in this patch will bind texture "0" when the transparency layer image is destroyed, in order to keep the GC's view of the GL context consistent with the real state. --- modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index 30a33c191c..9289f8acdc 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -1834,6 +1834,8 @@ struct SavedState final : public RenderingHelpers::SavedStateBase clip->renderImageUntransformed (*this, finishedLayerState.transparencyLayer, (int) (finishedLayerState.transparencyLayerAlpha * 255.0f), clipBounds.getX(), clipBounds.getY(), false); + + state->activeTextures.bindTexture (0); } }