尝试调用 glUseProgram
时出现“无效操作”错误针对下面的片段着色器。该错误仅在我尝试添加 int
时发生块定义的成员。请注意,我在顶点和片段着色器中保持块定义相同。我什至不必访问它!仅仅将该字段添加到块定义的顶点和片段着色器副本会导致程序失败。
#version 450
...
in VSOutput // and of course "out" in the vertex shader
{
vec4 color;
vec4 normal;
vec2 texCoord;
//int foo; // uncommenting this line causes "invalid operation"
} vs_output;
在尝试使用相同类型的独立输入/输出变量时,我也遇到了同样的问题,尽管在这些情况下,我只有在直接访问这些变量时才会遇到问题;如果我忽略它们,我认为编译器会优化它们,因此不会发生错误。这几乎就像我只被允许传递向量和矩阵......
我在这里缺少什么?我在文档中找不到任何表明这应该是一个问题的内容。
编辑 : 用
float[2]
填充它强制 int 成员进入下一个 16 字节边界也不起作用。编辑 : 解决了,按照下面的答案。事实证明,如果我检查了着色器程序的信息日志,我可以更快地弄清楚这一点。这是我的代码:
bool checkProgramLinkStatus(GLuint programId)
{
auto log = logger("Shaders");
GLint status;
glGetProgramiv(programId, GL_LINK_STATUS, &status);
if(status == GL_TRUE)
{
log << "Program link successful." << endlog;
return true;
}
return false;
}
bool checkProgramInfoLog(GLuint programId)
{
auto log = logger("Shaders");
GLint infoLogLength;
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar* strInfoLog = new GLchar[infoLogLength + 1];
glGetProgramInfoLog(programId, infoLogLength, NULL, strInfoLog);
if(infoLogLength == 0)
{
log << "No error message was provided" << endlog;
}
else
{
log << "Program link error: " << std::string(strInfoLog) << endlog;
}
return false;
}
最佳答案
(正如评论中已经指出的那样):GL 永远不会插入整数类型。引用 GLSL spec (Version 4.5)第 4.3.4 节“输入变量”:
Fragment shader inputs that are signed or unsigned integers, integer vectors, or any double-precision floating-point type must be qualified with the interpolation qualifier
flat
.
这当然也适用于前一阶段的相应输出。
关于opengl - 为什么我不能将 int 成员添加到我的 GLSL 着色器输入/输出 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28514892/