2017-09-19 80 views
0

我试图在我的android游戏中实现实例 - 即在一次绘制调用中绘制64个精灵。OpenGL ES3 android:内置变量gl_InstanceID

我基于C语言下面的教程

https://learnopengl.com/#!Advanced-OpenGL/Instancing

程序崩溃时,我用下面的语法在顶点着色器代码

vec2 offset = offsets[gl_InstanceID]; 

例外

09-19 17:28:18.315 3635-3674/? E/ShaderHelper: Error compiling shader: 0:47: L0002: Undeclared variable 'gl_InstanceID' 

那么为什么我不能访问instanceID vari能够?我已经在自定义的GLSurfaceview中将GLcontextClientVersion设置为3。

回答

2

gl_InstanceID是一个ES 3.0功能。从GLSL ES 3.00规范第3.4节,我们读到:

The directive “#version 300 es” is required in any shader that uses version 3.00 of the language. Any number representing a version of the language a compiler does not support will cause an error to be generated. Version 1.00 of the language does not require shaders to include this directive, and shaders that do not include a #version directive will be treated as targeting version 1.00.

我卑微的猜测是你错过了在着色器输入“的#Version 300个ES”作为一线所以编译器假定版本1.00。

+0

谢谢我认为这应该解决我的问题,因为我错过了在着色器中输入它,但我得到以下错误:**错误编译着色器:0:7:L0003:关键字'属性'保留** – java

+0

@java http ://www.shaderific.com/blog/2014/3/13/tutorial-how-to-update-a-shader-for-opengl-es-30关键字'属性'与关键字'in'交换。其他一些关键字也会改变。 – Andreas