diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 8eaf02f817..33f3e0342c 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -3986,6 +3986,29 @@ void QRhiGles2::gatherSamplers(GLuint program, } } +void QRhiGles2::sanityCheckVertexFragmentInterface(const QShaderDescription &vsDesc, const QShaderDescription &fsDesc) +{ + if (!vsDesc.isValid() || !fsDesc.isValid()) + return; + + // Print a warning if the fragment shader input for a given location uses a + // name that does not match the vertex shader output at the same location. + // This is not an error with any other API and not with GLSL >= 330 either, + // but matters for older GLSL code that has no location qualifiers. + for (const QShaderDescription::InOutVariable &outVar : vsDesc.outputVariables()) { + for (const QShaderDescription::InOutVariable &inVar : fsDesc.inputVariables()) { + if (inVar.location == outVar.location) { + if (inVar.name != outVar.name) { + qWarning("Vertex output name '%s' does not match fragment input '%s'. " + "This should be avoided because it causes problems with older GLSL versions.", + outVar.name.constData(), inVar.name.constData()); + } + break; + } + } + } +} + bool QRhiGles2::isProgramBinaryDiskCacheEnabled() const { static QOpenGLProgramBinarySupportCheckWrapper checker; @@ -4886,6 +4909,8 @@ bool QGles2GraphicsPipeline::create() for (const QShaderDescription::InOutVariable &inVar : vsDesc.inputVariables()) rhiD->f->glBindAttribLocation(program, GLuint(inVar.location), inVar.name); + rhiD->sanityCheckVertexFragmentInterface(vsDesc, fsDesc); + if (!rhiD->linkProgram(program)) return false; diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h index 67a21f3053..3d9fba80dc 100644 --- a/src/gui/rhi/qrhigles2_p_p.h +++ b/src/gui/rhi/qrhigles2_p_p.h @@ -862,6 +862,7 @@ public: QSet *activeUniformLocations, QGles2UniformDescriptionVector *dst); void gatherSamplers(GLuint program, const QShaderDescription::InOutVariable &v, QGles2SamplerDescriptionVector *dst); + void sanityCheckVertexFragmentInterface(const QShaderDescription &vsDesc, const QShaderDescription &fsDesc); bool isProgramBinaryDiskCacheEnabled() const; enum ProgramCacheResult {