我尝试编译这个着色器:
varying vec2 TexCoords;
varying vec4 color;
uniform sampler2D text;
uniform vec3 textColor;
void main()
{
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
color = vec4(textColor, 1.0) * sampled;
}
这适用于 OpenGL es。我得到的错误:
ERROR: 0:2: 'vec2' : No precision defined for this type
ERROR: 0:3: 'vec4' : No precision defined for this type
ERROR: 0:6: 'vec3' : No precision defined for this type
ERROR: 0:10: 'texture' : undeclared identifier
ERROR: 0:10: invalid function call
请注意,它在 OpenGL 3.3 上编译,但在 es 上失败。
请参阅OpenGL ES 着色语言 1.00 规范 - 4.5.3 默认精度限定符:
片段语言没有浮点类型的默认精度限定符。因此,对于浮点、浮点向量和矩阵变量声明,要么声明必须包含精度限定符,要么必须事先声明默认的浮点精度。
因此,您必须添加精度限定符。例如:
precision mediump float;
重载函数texture
是在 GLSL ES 3.00 中引入的,但在 GLSL ES 1.00 中不受支持。您必须使用该功能texture2D
:
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
vec4 sampled = vec4(1.0, 1.0, 1.0, texture2D(text, TexCoords).r);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句