Using undeclared identifier 'gl_InstanceID'

Hello everyone, I tried to use the instance in OpenSLL2.0, on the IOS platform. My rendering code

 glEnableVertexAttribArray(...);
 glVertexAttribPointer(...)
 glDrawElementsInstancedEXT(GL_TRIANGLES,IndicesCount, GL_UNSIGNED_SHORT, 0, 5);

      

And my Vertex Shader

attribute vec4 VertPosition;
uniform mat4 mvpMatrix[600];

void main()
{
    gl_Position = (mvpMatrix[gl_InstanceID]) * VertPosition;
}

      

I am getting ERROR: using undeclared identifier 'gl_InstanceID'

my glsl version is 1.0, if the version is the problem then how can i upgrade? Any other way to use "gl_InstanceID" in GLSL?

+1


source to share


1 answer


gl_InstanceID is only available since GLSL ES 3.0 as mentioned here .

So, as you suspected, there is a version issue. As far as I know, the only GLSL ES version available in OpenGL ES 2.0 is GLSL ES 1.0, and if you want to use a higher version of GLSL ES you need to upgrade to OpenGL ES 3.0. (more details here )

Edit: I was thinking about what you want to achieve using gl_InstanceID. This variable is only meaningful when using one of the instantiated drawing commands (glDrawArraysInstanced, etc.), which are also not available in ES 2.0.



Apparently it is possible to use instantiated rendering in OpenGL ES 2.0 using the GL_EXT_draw_instanced extension . This extension provides two additional drawing commands for the instantiated drawing (glDrawElementsInstancedEXT and glDrawArraysInstancedEXT). When using an extension, you must enable it in the shader

#extension GL_EXT_draw_instanced : enable

      

and use gl_InstanceIDEXT instead of gl_InstanceID.

+4


source







All Articles