GLSL ES 1.0中没有基于整数的属性
当然,您可以传入浮点(并以无符号字节的形式提供)。传入
false
用于调用时规范化标志
gl.vertexAttribPointer
另一方面,GLSL ES 1.0和GLSL ES 3.00都不允许索引采样器阵列。
spec
12.30动态索引
GLSL ES 1.00支持通过常数索引表达式对采样器阵列进行索引。常数索引表达式
是由常量表达式和某些循环索引组成的表达式,定义为
循环构造的子集。GLSL ES 3.00中是否应包含此功能?
分辨率:否。取样器阵列只能由常数积分表达式索引。
“GLSL ES 3.00中是否应包含此功能?”
手段应该
动态索引
GLES ES 3.00中包括的采样器数量
我引用了GLSL ES 3.00规范,因为它也引用了GLSL ES 1.0规范。
所以,你必须编写代码,使你的独立变量是常数索引表达式。
attribute float TexUnitNdx;
...
uniform sampler2D TextureUnit[6];
vec4 getValueFromSamplerArray(float ndx, vec2 uv) {
if (ndx < .5) {
return texture2D(TextureUnit[0], uv);
} else if (ndx < 1.5) {
return texture2D(TextureUnit[1], uv);
} else if (ndx < 2.5) {
return texture2D(TextureUnit[2], uv);
} else if (ndx < 3.5) {
return texture2D(TextureUnit[3], uv);
} else if (ndx < 4.5) {
return texture2D(TextureUnit[4], uv);
} else {
return texture2D(TextureUnit[5], uv);
}
}
vec4 color = getValueFromSamplerArray(TexUnitNdx, someTexCoord);
或者类似的。将ifs整理成二进制搜索可能会更快。