OpenGL ES3 android:内置变量 gl_InstanceID
OpenGL ES3 android: built in variable gl_InstanceID
我正在尝试在我的 android 游戏中实现实例化 - 即在一次绘制调用中绘制 64 个精灵。
我正在学习基于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 变量?我已经在自定义的 GLSurfaceview 中将 GLcontextClientVersion 设置为 3。
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。
我正在尝试在我的 android 游戏中实现实例化 - 即在一次绘制调用中绘制 64 个精灵。
我正在学习基于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 变量?我已经在自定义的 GLSurfaceview 中将 GLcontextClientVersion 设置为 3。
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。