[英]“GL_INVALID_VALUE error generated.” by binding just one Uniform Block
I have some problems with the binding of an uniform buffer object to several shaders. 将统一缓冲区对象绑定到多个着色器时遇到一些问题。
The execution of the following code: 执行以下代码:
for(auto& shaderIter : shaderHandler.getShaderPrograms()){
shaderIter.second->bind();
GLuint programID = shaderIter.second->programId();
GLuint index = glFuncs->glGetUniformBlockIndex(programID, "MatrixUBO");
glFuncs->glUniformBlockBinding(programID, index, UBO_MATRICES_BINDING_POINT);
shaderIter.second->release();
}
causes the error message 导致错误信息
QOpenGLDebugMessage("APISource", 1281, "GL_INVALID_VALUE error generated. Uniform block index exceeds the maximum supported uniform buffers.", "HighSeverity", "ErrorType")
The type of the shader programs is QOpenGLShaderProgram. 着色器程序的类型为QOpenGLShaderProgram。 I use vertex, geometry, fragment and compute shaders with these shader programs. 我在这些着色器程序中使用了顶点,几何,片段和计算着色器。
The value of GL_MAX_{VERTEX, FRAGMENT, GEOMETRY}_UNIFORM_BLOCKS
is 14. The output of index
is for each program 0 except for one where it is 4294967295. GL_MAX_{VERTEX, FRAGMENT, GEOMETRY}_UNIFORM_BLOCKS
值为14。对于每个程序0, index
的输出是0,但其中一个是4294967295。
It is not possible to bind a uniform block buffer to a compute shader. 不可能将统一块缓冲区绑定到计算着色器。 That's why the output of index is 4294967295 for the shader program with the compute shader. 这就是为什么使用计算着色器的着色器程序的索引输出为4294967295的原因。
EDIT: Because 4294967295 is the value of GL_INVALID_INDEX. 编辑:因为4294967295是GL_INVALID_INDEX的值。
There are two possible solutions in my oppinion: 我认为有两种可能的解决方案:
EDIT: There is the possibility to get a QList of all shaders related to a shader program and the type of each shader can be checked. 编辑:有可能获得与着色器程序相关的所有着色器的QList,并且可以检查每个着色器的类型。 So i changed the code to the following, which works for me. 所以我将代码更改为以下代码,这对我有用。
for(auto& shaderProgramIter : shaderHandler.getShaderPrograms()){
bool isComputeShader = false;
for(auto& shaderIter : shaderProgramIter.second->shaders())
{
if(shaderIter->shaderType() == QOpenGLShader::Compute)
isComputeShader = true;
}
if(!isComputeShader)
{
shaderProgramIter.second->bind();
GLuint programID = shaderProgramIter.second->programId();
GLuint index = glFuncs->glGetUniformBlockIndex(programID, "MatrixUBO");
glFuncs->glUniformBlockBinding(programID, index, UBO_MATRICES_BINDING_POINT);
shaderProgramIter.second->release();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.