firemiles
firemiles

Reputation: 23

QOpenGLShader Can't Compile GLSL 120 On Android

I have programed OpenGL code on Qt5 for Mac OS 10.10. The GLSL version is 120 and there is no problem to run.

#version 120
attribute highp vec4 vVertex;
attribute vec3 vNormal;

uniform mat4 mvpMatrix;
uniform mat4 mvMatrix;
uniform mat4 normalMatrix;
uniform vec3 vLightPosition;

varying vec3 vVaryingNormal;
varying vec3 vVaryingLightDir;

void main(void)
{
    vVaryingNormal = mat3(normalMatrix) * vNormal;
    vec4 vPosition4 = mvMatrix * vVertex;
    vec3 vPosition3 = vPosition4.xyz / vPosition4.w;

    vVaryingLightDir = normalize(vLightPosition-vPosition3);
    gl_Position = mvpMatrix * vVertex;
}

When I tried to move the code to compile and run for Andriod, I get the flowwing error:

W/Qt      (21457): (null):0 ((null)): QOpenGLShader::compile(Vertex): 0:1:
P0007: Language version '120' unknown, this compiler only supports  up to
version '300 es'

Why QOpenGLShader for Andriod can't support glsl 120? How to solve the problem?

Upvotes: 1

Views: 2124

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54642

Android uses OpenGL ES, and GLSL versions are different between OpenGL ES and full OpenGL.

Valid versions for OpenGL ES are:

  • version 100: ES 2.0.
  • version 300 es: ES 3.0.
  • version 310 es: ES 3.1.

Valid versions for full OpenGL are:

  • version 110: OpenGL 2.0.
  • version 120: OpenGL 2.1.
  • version 130: OpenGL 3.0.
  • version 140: OpenGL 3.1.
  • version 150: OpenGL 3.2.
  • version 330: OpenGL 3.3.
  • version 400: OpenGL 4.0.
  • version 410: OpenGL 4.1.
  • version 420: OpenGL 4.2.
  • version 430: OpenGL 4.3.
  • version 440: OpenGL 4.4.
  • version 450: OpenGL 4.5.

Starting with OpenGL 3.2 (version 150), an optional profile can be specified. Valid version strings for 3.3 are for example:

#version 330
#version 330 core
#version 330 compatibility

In your case, you will probably want to use the lowest ES version that supports the feature set you need. If ES 2.0 is enough, you would use:

#version 100

and if you need ES 3.0:

#version 300 es

You can also use the predefined GL_ES preprocessor symbol to make the version conditional, and use the same shader code for OpenGL ES and OpenGL:

#if GL_ES
#version 300 es
#else
#version 120
#endif

Upvotes: 4

Related Questions