From 01ed8b7dc5c073b5dbac667c1b9eb8333f9224ab Mon Sep 17 00:00:00 2001 From: alexei-zebra Date: Fri, 9 Oct 2026 23:50:30 +0300 Subject: [PATCH] Fix 2D batch drawing with a stale texture binding Batch2D cached the bound texture and skipped the bind when the cache matched, but the render pipeline binds textures of its own and leaves a non-zero texture unit active. A rectangle drawn without a texture (the hud hotbar background and slot tiles) was then modulated by whatever texture was left bound, which made the hotbar darken for a single frame on every window resize. The batch now draws from texture unit 0 and compares the cached texture with the actual binding instead of trusting the cache. --- src/graphics/core/Batch2D.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/graphics/core/Batch2D.cpp b/src/graphics/core/Batch2D.cpp index 33265b49f..7d6a7c8fe 100644 --- a/src/graphics/core/Batch2D.cpp +++ b/src/graphics/core/Batch2D.cpp @@ -33,6 +33,7 @@ void Batch2D::setPrimitive(DrawPrimitive primitive) { void Batch2D::begin(){ currentTexture = nullptr; + glActiveTexture(GL_TEXTURE0); blank->bind(); region = blank->getUVRegion(); color = glm::vec4(1.0f); @@ -61,7 +62,16 @@ void Batch2D::vertex( } void Batch2D::texture(const Texture* newTexture){ - if (currentTexture == newTexture) { + // The batch is not the only owner of the texture unit: the render pipeline + // binds textures of its own, so the cached value is only a hint. Compare it + // with the actual binding, otherwise a rectangle without a texture is + // modulated by whatever texture is left bound. + glActiveTexture(GL_TEXTURE0); + const uint expected = + newTexture != nullptr ? newTexture->getId() : blank->getId(); + GLint bound = 0; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); + if (currentTexture == newTexture && static_cast(bound) == expected) { return; } flush();