Use of undeclared identifier 'gl_InstanceID'

一个人想着一个人 提交于 2019-12-08 07:35:41

问题


Hi everyone, i have been trying Instanced drawing in OpenGLES2.0, in 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'm getting ERROR: Use of undeclared identifier 'gl_InstanceID'

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


回答1:


gl_InstanceID is only available starting from GLSL ES 3.0 as stated here.

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

Edit: I was thinking about what you want to achieve with the usage of gl_InstanceID. This variable does only make sense when using one of the instanced draw commands (glDrawArraysInstanced etc.), which are also not available in ES 2.0.

Apparently, there is a possibility to use instanced rendering in OpenGL ES 2.0 by using the GL_EXT_draw_instanced extension. This extension provides one with two additional draw commands for instanced drawing (glDrawElementsInstancedEXT and glDrawArraysInstancedEXT). When using the extension, one has to enable it in the shader

#extension GL_EXT_draw_instanced : enable

and use gl_InstanceIDEXT instead of gl_InstanceID.



来源:https://stackoverflow.com/questions/28041936/use-of-undeclared-identifier-gl-instanceid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!