From ea227fb9152759bcb425c44565651a5032aba134 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 7 Oct 2020 14:52:58 +0200 Subject: [PATCH] rhi: gl: Fix missing texture bindings The block to update the cached state needs to be run also when the texture parameters have changed. Change-Id: Ifa80c142c6ff31c95a718a1a900ff3db0bbfe4bc Reviewed-by: Andy Nichols --- src/gui/rhi/qrhigles2.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index c9d92b4d71..bf473deefb 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -3093,8 +3093,9 @@ void QRhiGles2::bindShaderResources(QGles2CommandBuffer *cbD, for (const QGles2SamplerDescription &shaderSampler : samplers) { if (shaderSampler.binding == b->binding) { const bool samplerStateValid = texD->samplerState == samplerD->d; + const bool cachedStateInRange = texUnit < 16; bool updateTextureBinding = true; - if (samplerStateValid && texUnit < 16) { + if (samplerStateValid && cachedStateInRange) { // If we already encountered the same texture with // the same pipeline for this texture unit in the // current pass, then the shader program already @@ -3107,10 +3108,6 @@ void QRhiGles2::bindShaderResources(QGles2CommandBuffer *cbD, && cbD->textureUnitState[texUnit].texture == texD->texture) { updateTextureBinding = false; - } else { - cbD->textureUnitState[texUnit].ps = ps; - cbD->textureUnitState[texUnit].psGeneration = psGeneration; - cbD->textureUnitState[texUnit].texture = texD->texture; } } if (updateTextureBinding) { @@ -3118,6 +3115,11 @@ void QRhiGles2::bindShaderResources(QGles2CommandBuffer *cbD, activeTexUnitAltered = true; f->glBindTexture(texD->target, texD->texture); f->glUniform1i(shaderSampler.glslLocation + elem, texUnit); + if (cachedStateInRange) { + cbD->textureUnitState[texUnit].ps = ps; + cbD->textureUnitState[texUnit].psGeneration = psGeneration; + cbD->textureUnitState[texUnit].texture = texD->texture; + } } ++texUnit; if (!samplerStateValid) {