为什么我不能将 int 成员添加到我的 GLSL 着色器 input/output 块中?
Why can't I add an int member to my GLSL shader input/output block?
尝试针对下面的片段着色器调用 glUseProgram
时出现 "invalid operation" 错误。该错误仅在我尝试将 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;
我在尝试使用相同类型的独立 in/out 变量时也遇到了同样的问题,尽管在那些情况下,我只有在直接访问这些变量时才会遇到问题;如果我忽略它们,我假设编译器将它们优化掉,因此不会发生错误。这几乎就像我只被允许传递向量和矩阵...
我在这里错过了什么?我无法在文档中找到任何表明这应该是个问题的内容。
编辑:用float[2]
填充它以强制将 int 成员放到下一个 16 字节边界上也不起作用。
EDIT:已解决,根据以下答案。事实证明,如果我检查了着色器程序的信息日志,我本可以更快地解决这个问题。这是我的代码:
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 节 "input variables":
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
.
这当然也适用于前一阶段的相应输出。
尝试针对下面的片段着色器调用 glUseProgram
时出现 "invalid operation" 错误。该错误仅在我尝试将 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;
我在尝试使用相同类型的独立 in/out 变量时也遇到了同样的问题,尽管在那些情况下,我只有在直接访问这些变量时才会遇到问题;如果我忽略它们,我假设编译器将它们优化掉,因此不会发生错误。这几乎就像我只被允许传递向量和矩阵...
我在这里错过了什么?我无法在文档中找到任何表明这应该是个问题的内容。
编辑:用float[2]
填充它以强制将 int 成员放到下一个 16 字节边界上也不起作用。
EDIT:已解决,根据以下答案。事实证明,如果我检查了着色器程序的信息日志,我本可以更快地解决这个问题。这是我的代码:
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 节 "input variables":
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
.
这当然也适用于前一阶段的相应输出。