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. 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.
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.
EDIT: Because 4294967295 is the value of 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. 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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.