I am writing a game using Qt and I have implemented some post processing shaders to make it look more interesting. It worked ok until I upgraded to linux mint 16, now I always get an error requiring a precision specifier, this only happens when compiling fragment shaders. Because the code compiles and works ok on an android build, I think this happens because QGLShaderProgram adds mediump, highp and lowp as defines to the beginning of the shader when it's compiled in a desktop build.
So my question is: Is there any way to make the glsl compiler to stop requiring precision specifiers, or should I look into how to disable those defines from being added ?
Code:
isOk = m_displaceShader.addShaderFromSourceCode(QGLShader::Vertex,
"#version 100 \n"
"attribute mediump vec4 in_verts; \n"
"varying mediump vec2 out_tex; \n"
"void main(void) \n"
"{ \n"
" gl_Position = in_verts; \n"
" out_tex = (in_verts.xy + vec2(1.0)) * 0.5; \n"
"} \n");
qDebug() << m_displaceShader.log();
isOk &= m_displaceShader.addShaderFromSourceCode( QGLShader::Fragment,
"#version 100 \n"
"uniform sampler2D inCol; \n"
"uniform sampler2D inDisplace; \n"
"varying mediump vec2 out_tex; \n"
"void main(void) \n"
"{ \n"
" mediump vec4 displaceCol = texture2D(inDisplace, out_tex); \n"
" mediump float dispX = (displaceCol.r - 0.5) * 0.2; \n"
" mediump float dispY = (displaceCol.g - 0.5) * 0.2; \n"
" mediump vec2 texPlace = out_tex + vec2(dispX, dispY); \n"
" gl_FragColor = texture2D(inCol, texPlace); \n"
#ifdef DEBUG_SHADERS
" gl_FragColor = 0.5 * pow(texture2D(inCol, texPlace), vec4(1.0/2.2)) + 0.5 * displaceCol; \n"
#endif
"} \n"
);
Errors:
QGLShader::compile(Fragment): 0:7(16): error: no precision specified this scope for type `vec2'
0:10(9): error: no precision specified this scope for type `vec4'
0:11(10): error: no precision specified this scope for type `float'
0:12(10): error: no precision specified this scope for type `float'
0:13(9): error: no precision specified this scope for type `vec2'
#undef mediump; ugh.