I'm having an issue with interface block binding.

Example shader:

const char* vertexShader =      
        "#version 330 core\n"
        "uniform globalMatrices"
        "   mat4 vPMatrix;"
        "layout(location = 0) in vec2 vPosition;"
        "layout(location = 1) in vec4 vColor;"
        "out vec4 color;"
        "void main()"
        "   color = vColor;"
        "   gl_Position = vPMatrix * vec4(vPosition, 1.0, 1.0);"

After creating the shader program i call functions:

    //this is done once per shader
    void BindShaderToMatrixBlock(unsigned int program)
        GLuint globalUniformBlockIndex = glGetUniformBlockIndex(program, "globalMatrices");
        glUniformBlockBinding(program, globalUniformBlockIndex, 0);
    //this is done once 
    void BindUniformBlockMatrix()
        glGenBuffers(1, &uniformBlockMatrix);
        glBindBuffer(GL_UNIFORM_BUFFER, uniformBlockMatrix);
        glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), NULL, GL_DYNAMIC_DRAW);
        glBindBuffer(GL_UNIFORM_BUFFER, 0);
        glBindBufferRange(GL_UNIFORM_BUFFER, 0, uniformBlockMatrix, 0, sizeof(glm::mat4));

And this is how i update the matrix:

inline void SetVPMatrix(const void* data)
    glBindBuffer(GL_UNIFORM_BUFFER, uniformBlockMatrix);
    glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), data);

I tried to debug as much as i could and confirmed that the data gets delivered to the uniform block but for some reason the matrix in the shader stays unchanged.

  • \$\begingroup\$ Please provide your rendering code. Without knowing all related code it is hard to say where the error is. There is also similar question answered on SE, perhaps the answer helps? \$\endgroup\$
    – wondra
    Nov 9, 2015 at 14:10

1 Answer 1


I did several changes to the code and something of the following fixed my problem:

  • changed the order so that all the block binding was done before initializing the uniform buffer
  • added "layout (std140)" to the uniform block in the vertex shader
  • i made sure that i unbound everything after binding and executing series of commands

thanks wondra for the link, it helped.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .