使用未声明的标识符"gl_InstanceID" [英] Use of undeclared identifier 'gl_InstanceID'

查看:468
本文介绍了使用未声明的标识符"gl_InstanceID"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我一直在IOS平台上尝试OpenGLES2.0中的实例化绘图.我的渲染代码

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);

还有我的顶点着色器

attribute vec4 VertPosition;
uniform mat4 mvpMatrix[600];

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

我遇到错误:使用未声明的标识符'gl_InstanceID'

I'm getting ERROR: Use of undeclared identifier 'gl_InstanceID'

我的glsl版本是1.0,如果版本是问题,那么我该如何升级?还有其他在GLSL中使用"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 ?

推荐答案

gl_InstanceID仅从GLSL ES 3.0开始可用,如所述

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

因此,正如您已经怀疑的那样,这是一个版本问题.据我所知,OpenGL ES 2.0中唯一可用的GLSL ES版本是GLSL ES 1.0,如果要使用更高的GLSL ES版本,则必须升级到OpenGL ES 3.0. (更多详情请此处 )

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)

我正在考虑要使用gl_InstanceID实现什么.仅当使用实例绘制命令之一(glDrawArraysInstanced等)时,此变量才有意义,而ES 2.0中也不可用.

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

并使用gl_InstanceIDEXT代替gl_InstanceID.

and use gl_InstanceIDEXT instead of gl_InstanceID.

这篇关于使用未声明的标识符"gl_InstanceID"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆