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.
This commit is contained in:
alexei-zebra 2026-10-09 23:50:30 +03:00
parent 543cab9579
commit 01ed8b7dc5
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E

View file

@ -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<uint>(bound) == expected) {
return;
}
flush();