QGLShaderProgram GLSL ES 2 shaders not compiling
-
Hi all,
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 ***
#version 100
#define lowp
#define mediump
#define highpvarying highp vec4 outColor;
void main(void)
{
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
Mirx -
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).
-
Hi! I use OpenGL ES too. Try "my example":https://github.com/8Observer8/TexturedTriangle