OpenGL ES Shader 纹理数组
一、使用方法
1、在Fragment Shader中定义
uniform sampler2D vTexSampler[8]
2、代码中绑定纹理单元
GLint vTexIndex[] = {0,1,2,3,4,5,6,7};
glUniform1iv(glGetUniformLocation(program, "vTexSampler"), 8, vTexIndex);
3、Fragment Shader函数中直接使用下标
main()
{
int index = 0;
vec4 color = texture2D (vTexSampler[index], xy);
}
二、错误分析
提示:profile requires index expression to be compile-time constant
profile requires index expression to be compile-time constant
配置文件要求索引表达式为编译时常量.
当出现以上问题,表示GPU驱动版本低,不支持动态索引,需要将数组下标修改为常量,可采用if else,不支持swith语句。
if (index == 0)
{
color = texture2D (vTexSampler[0], xy);
}