简体   繁体   English

通过仅绑定一个统一块来生成“ GL_INVALID_VALUE错误。”

[英]“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: 我认为有两种可能的解决方案:

  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. 编辑:有可能获得与着色器程序相关的所有着色器的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.

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