Con*_*tin 2 opengl-es glsl opengl-es-2.0
为什么以下着色器,而不是在OpenGL(桌面)上编译 - 但在OpenGL ES 2.0(iPhone)上它运行良好(我使用相同的c/c ++代码来加载,编译和链接两个平台上的着色器).我的FragmentShader:
varying lowp vec4 colorVarying;
void main()
{
gl_FragColor = colorVarying;
}
Run Code Online (Sandbox Code Playgroud)
顶点着色器:
attribute vec4 position;
attribute vec4 color;
varying vec4 colorVarying;
uniform float translate;
void main()
{
gl_Position = position;
gl_Position.y += sin(translate) / 2.0;
colorVarying = color;
}
Run Code Online (Sandbox Code Playgroud)
编译日志如下所示:
Shader compile log:
ERROR: 0:9: 'lowp' : syntax error syntax error
ERROR: Parser found no code to compile in source strings.
Failed to compile fragment shaderProgram validate log:
Validation Failed: Program is not successfully linked.
Failed to validate program: 1
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
通过GLSL 1.1,lowpGLSL规范中没有提到.在GLSL 1.2中(与OpenGL 2.1一起使用)lowp保留用于实现.在GLSL 1.3中(lowp开始允许使用OpenGL (但没有意义).
因此,您在桌面上使用的任何内容似乎都只识别旧版本的GLSL.明显的解决方法是删除它,或者为桌面添加一个宏,如:
#ifdef DESKTOP
#define lowp
#endif
Run Code Online (Sandbox Code Playgroud)
以DESKTOP取代由在您使用的是桌面上的任何环境中定义的,但不是任何环境中,您正在使用的iPhone的一些标识.
编辑:将其纳入源代码本身并非易事.一种方法是这样的:
char const *shader =
#ifdef DESKTOP
"#define lowp\n"
#endif
"varying lowp vec4 colorVarying;\n"
/* ... */
;
Run Code Online (Sandbox Code Playgroud)
这样,当且仅当在主机环境中设置了DESKTOP时,"lowp"才会在着色器中定义为空.
| 归档时间: |
|
| 查看次数: |
4709 次 |
| 最近记录: |