user1051003
user1051003

Reputation: 1231

Opengl shader compatibility with opengl es 2.0

I created an application with sdl 2.0 and initialized opengl with version 2.0 like this:

SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MINOR_VERSION, 0 );

Then I found some simple diffuse shader on internet:

attribute highp   vec3  inVertex;
attribute mediump vec3  inNormal;
attribute mediump vec2  inTexCoord;

uniform highp   mat4  MVPMatrix;
uniform mediump vec3  LightDirection;

varying lowp    float  LightIntensity;
varying mediump vec2   TexCoord;



void main()
{
    //Transform position
    gl_Position = MVPMatrix * vec4(inVertex, 1.0);

    //Pass through texcoords
    TexCoord = inTexCoord;

    //Simple diffuse lighting in model space
    LightIntensity = dot(inNormal, -LightDirection);
}

it failed to compile with error like this:

error: syntax error, unexpected NEW_IDENTIFIER

Then I found after I remove

highp mediump lowp

it compiles fine and runs ok, 1.what was the reason for that? another question: 2.Can I still run this shader both on linux and android? I am using linux now everything runs good. thanks

Upvotes: 1

Views: 1236

Answers (1)

Tara
Tara

Reputation: 1796

What was the reason for that?

Precision qualifiers are only supported in OpenGL ES, not in desktop OpenGL.

Can I still run this shader both on linux and android?

No (at least not directly), because of the reason explained above. You'll have to make two shaders. One for desktop OpenGL and one for OpenGL ES.

OpenGL ES 2.0 is not the same thing as OpenGL 2.0.

See here for more information:
https://stackoverflow.com/a/10390965/1907004

Edit:
As pointed out by other people: You can use precision qualifiers in desktop OpenGL, but they will be ignored by the compiler. See here:
https://stackoverflow.com/a/20131165/1907004
For that to work, you need to specify a GLSL version for your shader using #version XXX, which you seem to lack. Regardless of what you do, you should always specify the GLSL version of your shader.

Upvotes: 2

Related Questions