A strange issue with OpenGL 3.0 under Mesa 9.2.1 on Ubuntu 13.10 (64-bit) is observed. Variable definition with explicit precision (like this: highp vec2 v;
) produces an error:
syntax error, unexpected VEC2, expecting ',' or ';'
It seems like precision qualifier is disabled there for some reasons. Mesa Release Notes doesn't clear the situation -- not bugs, nor notifications are relative to the topic.
P.S. with OpenGL ES 3.0 precision qualifier works correctly.
Make sure you specify
#version 130
.Without a
#version
directive OpenGL will default to#version 110
where precision qualifiers are most certainly not valid.Unsurprising. Precision qualifiers work in both OpenGL ES GLSL
#version
s.highp
is actually undefined in fragment shaders by default, so it really comes as no surprise that this generates a parse error.I feel like a broken record, but the proper way to use
highp
in a fragment shader is to first check for the pre-processor definition:GL_FRAGMENT_PRECISION_HIGH
. This pre-processor definition is defined in all stages since you need to know when outputting something in a vertex shader whether the fragment shader will supporthighp
.Consider the following GLSL snippet:
Since you need to match precision between vertex and fragment shaders for I/O, you might use something like this (for both the fragment and vertex shader):
Vertex shaders always support
highp
, by the way. This only applies to fragment shaders.With that out of the way, you should be aware that in desktop GLSL, while version 1.30 defines precision qualifiers they do not actually do anything. They are there simply to make porting shaders from GLSL ES easier.
The OpenGL Shading Language (Version 1.3) - 4.5 Precision Qualifiers - pp. 35
The only types of precision desktop GLSL deals with are single- and double-precision (GL 4.0+ /
ARB_gpu_shader_fp64
) floating-point. And these variables are distinguished using different data types (e.g.dvec2
vs.vec2
) rather than a precision qualifier.