Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QGLShaderProgram GLSL ES 2 shaders not compiling
mirx last edited by
I'm developing a Qt / Linux x11 application that uses GLSL shaders over openGL ES but I have some issues on the precision identifiers.
When I compile and link my simple QGLShaderProgram I get this error:
QOpenGLShader::compile(Fragment): 0:6(16): error: no precision specified this scope for type `vec4'
*** Problematic Fragment shader source code ***
varying highp vec4 outColor;
gl_FragColor = outColor;
The problem is that the definitions of lowp, mediump and highp are automatically added to my shader source code as described in the documentation "documentation":https://qt-project.org/doc/qt-5/qglshaderprogram.html#details and the effect is that the precision identifiers are ignored.
With the first line I'm forcing the GLSL version to be the ES 2 standard where the precision identifiers are mandatory but the definitions are generated anyhow.
If I explicitly undefine those definitions the shader works well but I'm sure that's not the right way to do.
Why these definitions are added?
What's the right way to write a portable shader code?
Thank you very much
pippox last edited by
I've also seen this problem in the wild.
Is anybody willing to explain why those three defines are autogenerated??
agocs last edited by
Because when Qt is configured for desktop (non-ES) OpenGL, it will add those dummy defines to make sure a shader targeted for ES still compiles.
The portable way is to omit the #version and write ES2 shaders. These will then work both on ES and desktop (where Qt will insert the dummy defines).
8Observer8 last edited by
Hi! I use OpenGL ES too. Try "my example":https://github.com/8Observer8/TexturedTriangle