Tomasso
Tomasso

Reputation: 711

OpenGL shader language; how to specify precision for vec4?

I'm writing a Qt OpenGL application, just starting out with GLSL, and am trying to compile a "simple" fragment shader I found in an example on the web:

#version 320 es
out vec4 fColor;

void main()
{
    fColor = vec4 (0.0, 0.0, 1.0, 1.0);
}

But when trying to add this shader from source, I get this error message from Qt's addShaderFromSourceFile():

QOpenGLShader::compile(Fragment):
0:3(12): warning: extension GL_ARB_fragment_coord_conventions unsupported in fragment shader
0:1(1): error: No precision specified in this scope for type vec4

What is the proper syntax to declare a precision for type vec4?
I cannot seem to find an example of how to to this for vec4, and trying things like this:

precision mediump vec4;

...results in a syntax error.

Note that I want the shader to run on an embedded system, hence the "#version 320 es" line at the beginning.

Upvotes: 4

Views: 8075

Answers (1)

Rabbid76
Rabbid76

Reputation: 210928

vec4 is not a vaild type for a default precision qualifier.
The type in default Precision Qualifiers has to be either int, float or any opaque type (e.g. a sampler is a opaque type).

The precision statement

precision mediump float;

affects all floating points (e.g. float, vec2, vec3, vec4, mat3, ...)

A precision qualifier can also be set to single variable:

out mediump vec4 fColor;

this will overwrite the default precision qualifier.

For details see OpenGL ES Shading Language 3.20 Specification - 4.7. Precision and Precision Qualifiers.

Upvotes: 7

Related Questions