Luc*_*uca 4 opengl preprocessor glsl
我试图弄清楚为什么以下GLSL代码不起作用:
#ifndef VertexPositionType
#define VertexPositionType vec3
#endif
in StandardVertexShaderInputs {
VertexPositionType ds_VertexPosition;
};
vec4 ProjectVertexPosition(in vec4 v);
vec4 ProjectVertexPosition(in vec3 v);
void main() {
gl_Position = ProjectVertexPosition(ds_VertexPosition);
}
Run Code Online (Sandbox Code Playgroud)
着色器拒绝编译.信息日志状态:
错误C1008:未定义变量"ProjectVertexPosition"
即使它没有警告预处理器,我得到的是预处理器符号VertexPositionType没有被替换.如果我删除预处理器定义,一切都很好.
现在,规范说:
#define和#undef功能被定义为具有和不具有宏参数的宏定义的C++预处理器的标准.
也许以下行不是有效的预处理器行?
#define VertexPositionType vec3
Run Code Online (Sandbox Code Playgroud)
你的着色器是非法的.NVIDIA的编译器可能没有吐出正确的错误,但你的着色器做错了(好吧,除了你没有提供#version声明的事实.我认为#version 330,但明确GLSL版本总是好的).
我只能假设这是一个顶点着色器,因为你正在写gl_Position.输入接口块在顶点着色器中是非法的,就像输出接口块在片段着色器中是非法的一样.AMD的编译器对此更明确:
ERROR: 0:5: error(#328) interface block should not apply in 'Vertex Shader in'.
ERROR: 0:14: error(#143) Undeclared identifier ds_VertexPosition
ERROR: 0:14: error(#202) No matching overloaded function found ProjectVertexPosition
ERROR: 0:14: error(#160) Cannot convert from 'const float' to 'Position 4-component vector of float'
ERROR: error(#273) 4 compilation errors. No code generated
Run Code Online (Sandbox Code Playgroud)
当我删除接口块定义,将其保留为正确时in VertexPositionType ds_VertexPosition;,它编译得很好.
如果我删除预处理器定义,一切都很好.
那么恭喜你:你发现了一个NVIDIA驱动程序错误.您应该向它们报告,因为顶点着色器中不允许输入接口块.
您已经声明了一个名为 ProjectVertexPosition 的重载函数,但从未定义过它,因此当您链接程序时,您会收到未定义的错误。对于错误来说,说“未定义的函数”而不是“未定义的变量”可能更有意义(因为您将其声明为函数。),但我猜测链接器没有保留足够的信息来了解 a 之间的区别函数符号和变量符号。
此错误可能来自 LinkProgram 调用,而不是 CompileShader 调用,并且与预处理器或 VertexPositionType 无关