简体   繁体   中英

“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. 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:

  1. Divide the list of shader programs in two parts. The first one for all rendering shaders and the second one, for all compute shaders. After that, just iterate over the rendering ones.
  2. Ask for each shader if it's a compute shader and just do the binding for the rendering shaders. But I don't know if there is the possibility to access the information if it is a rendering or compute shader.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM