1

我尝试在 Win10 PC 上使用 RenderMonkey 1.82,显卡是 NVIDIA Geforce 405 v342.01。我不能使用它附带的 OpenGL ES 示例。我记得有一次我可以在另一台机器上做到这一点。这是兼容性问题吗?

顶点着色器:

uniform mat4 view_proj_matrix;
uniform vec4 view_position;

attribute vec4 rm_Vertex;
attribute vec3 rm_Normal;

varying vec3 vNormal;
varying vec3 vViewVec;

void main(void)
{
   gl_Position = view_proj_matrix * rm_Vertex;

   // World-space lighting
   vNormal = rm_Normal;
   vViewVec = view_position.xyz - rm_Vertex.xyz;


}

片段着色器:

precision mediump float;
uniform vec4 color;

varying vec3 vNormal;
varying vec3 vViewVec;

void main(void)
{
   float v = 0.5 * (1.0 + dot(normalize(vViewVec), vNormal));
   gl_FragColor = v * color;

}

错误信息是:

OpenGL ES Preview Window: Compiling vertex shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Vertex Program/ ... failure 

0(8) :
error C0118: macros prefixed with 'GL_' are reserved 

OpenGL ES Preview
Window: Compiling fragment shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Fragment Program/ ... failure 

0(3) :
error C0118: macros prefixed with 'GL_' are reserved 

RENDERING
ERROR(s):  Vertex program 'Vertex Program' failed to compile in pass
'Single Pass'.  See Output window for details Fragment program

'Fragment Program' failed to compile in pass 'Single Pass'.  See
Output window for details
4

1 回答 1

0

RenderMonkey 在将它们发送到 GLSL 编译器之前将一堆定义添加到着色器中。您可以通过CodeXL运行它,然后检查着色器的文本来验证这一点。对于我的机器,这似乎是标准(对于顶点着色器,片段着色器是类似的):

#version 120
attribute float _J_K_;
void _VSh();void main()
{
   _VSh();   gl_Position += (vec4(_J_K_) - vec4(_J_K_));
}
#define main _VSh
#define GL_ES
#define highp
#define mediump
#define lowp
#define invariant
#define gl_MaxVertexAttribs 15
#define gl_MaxVertexUniformVectors 224
#define gl_MaxVaryingVectors 8
#define gl_MaxVertexTextureImageUnits 0
#define gl_MaxCombinedTextureImageUnits 8
#define gl_MaxTextureImageUnits 8
#define gl_MaxFragmentUniformVectors 256
#define gl_MaxDrawBuffers 1

如您所见,第 8 行#define GL_ES是您遇到的错误(对于片段着色器,这发生在第 3 行)。

GLSL ES 规范中,它指出:

所有以“GL_”(“GL”后跟一个下划线)为前缀的宏名称也是保留的,定义这样的名称会导致编译时错误。

因此,您的驱动程序正在做正确的事情,并拒绝此着色器,因为它实际上违反了规范。可能在非常旧的 Nvidia 驱动程序中,未报告此错误。您需要重新编译 RenderMonkey 才能解决此问题,并且源不是公开的。

但是,您可以破解 RenderMonkey 来编译这些着色器。这些附加的字符串包含在libGLESv2.dll纯文本中,您可以使用十六进制编辑器将它们更改为不以GL_. 它们出现在偏移量 0x16052E 和 0x1606A0 处。

或者,只需使用 GL2 工作区来开发着色器,因为 GLSL 和 GLSL ES 非常相似。

于 2017-09-28T19:50:12.440 回答