mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-23 10:59:45 +00:00
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:
parent
543cab9579
commit
01ed8b7dc5
1 changed files with 11 additions and 1 deletions
|
|
@ -33,6 +33,7 @@ void Batch2D::setPrimitive(DrawPrimitive primitive) {
|
||||||
|
|
||||||
void Batch2D::begin(){
|
void Batch2D::begin(){
|
||||||
currentTexture = nullptr;
|
currentTexture = nullptr;
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
blank->bind();
|
blank->bind();
|
||||||
region = blank->getUVRegion();
|
region = blank->getUVRegion();
|
||||||
color = glm::vec4(1.0f);
|
color = glm::vec4(1.0f);
|
||||||
|
|
@ -61,7 +62,16 @@ void Batch2D::vertex(
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch2D::texture(const Texture* newTexture){
|
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;
|
return;
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue