gl_PointCoord 在 Mac 上不可用?
我想为点精灵制作一个着色器 - 到目前为止一切都在 iOS 上运行。但在 Mac OS X 上不行。 我的顶点着色器:
attribute vec4 position;
attribute vec4 color;
attribute vec2 texcoord;
varying vec4 colorVarying;
uniform mat4 modelViewProjectionMatrix;
uniform float pointSize;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
colorVarying = color;
gl_PointSize = pointSize;
}
我的片段着色器:
varying lowp vec4 colorVarying;
uniform lowp float textureFlag;
uniform sampler2D texture;
void main()
{
gl_FragColor = textureFlag * texture2D(texture, gl_PointCoord) * colorVarying +
(1.0 - textureFlag) * colorVarying;
}
由于“gl_PointCoord”,片段着色器无法在 Mac 上编译。在 Mac 上,我在着色器中添加了一个“#define lowp”作为预处理器。
如果我在着色器顶部添加“#version 120\n”,它在 Mac 上可以正常编译,但不会显示任何内容(但是在 iOS 上,如果我在着色器顶部使用 #version 标记,则它不起作用)着色器 - 也许,因为 1.2 版本会错过“lowp”)。
那么,原因可能是什么?我的 Mac 说,它使用 GLSL 1.2(我认为添加了 gl_PointCoord)。 有什么想法吗?!?
I want to make an shader for point sprites - everthing is working on iOS so far. But not on Mac OS X.
My vertex shader:
attribute vec4 position;
attribute vec4 color;
attribute vec2 texcoord;
varying vec4 colorVarying;
uniform mat4 modelViewProjectionMatrix;
uniform float pointSize;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
colorVarying = color;
gl_PointSize = pointSize;
}
My Fragment shader:
varying lowp vec4 colorVarying;
uniform lowp float textureFlag;
uniform sampler2D texture;
void main()
{
gl_FragColor = textureFlag * texture2D(texture, gl_PointCoord) * colorVarying +
(1.0 - textureFlag) * colorVarying;
}
The fragment shader doesn't compile on mac, because of "gl_PointCoord". On Mac I've added an "#define lowp" as preprocessor in the shader.
If I add an "#version 120\n" on top of the shader, it compiles fine on Mac, but doesn't show anything (however on iOS it doesn't work if I'm using an #version tag on top of the shader - maybe, because version 1.2 would miss "lowp").
So, what can the reason be? My Mac says, it uses GLSL 1.2 (I think there was gl_PointCoord added).
Any ideas?!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
顶部没有
#version
指令的 GLSL 着色器假定为 1.10。这可能永远不是您真正想要的,因此始终使用#version
指令。桌面 OpenGL 和 OpenGL ES 不是一回事。尝试通过桌面 GL 实现提供 ES 着色器并不能保证一定有效。所以你必须相应地修改着色器。
A GLSL shader that does not have a
#version
directive at the top is assumed to be 1.10. That's probably never what you really want, so always use a#version
directive.Desktop OpenGL and OpenGL ES are not the same thing. Attempting to feed a ES shader through a desktop GL implementation is not guaranteed to work. So you have to modify the shader accordingly.
有点线程死灵,但我在移植一些 GLES20 代码时遇到了同样的问题。
gl_PointCoord手册明确指出1.10版本支持gl_PointCoord,但 GLSL 1.10 规范甚至没有提到该功能。
此外,1.20 规范的§1.2 明确指出添加了 gl_PointCoord 支持。
所以,是的,看起来 glsl 手册在这方面是错误的,对 gl_PointCoord 的支持从版本 1.2 开始。
令人麻烦的是,一些显示驱动程序会愉快地编译和运行带有
#version 110
的 GLSL 着色器并调用gl_PointCoord
,而其他显示驱动程序(最近的 NVidia)会吐出一个漂亮的 <代码>错误C7532:全局变量gl_PointCoord需要“#version 120”或更高版本。A bit of thread necromancy, but i faced the same problem porting some GLES20 code.
The gl_PointCoord manual clearly states that gl_PointCoord is supported in version 1.10, but the GLSL 1.10 spec doesn't even mention that function.
Furthermore, §1.2 of the 1.20 spec clearly states that gl_PointCoord support has been added.
So yeah, it looks like the the glsl manual is wrong on this one and support for gl_PointCoord starts at version 1.2.
The troubling part is that some display drivers will happily compile and run a GLSL shader with
#version 110
and calls togl_PointCoord
, while others (recent NVidia) will barf a niceerror C7532: global variable gl_PointCoord requires "#version 120" or later
.