Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Uniform block binding

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2012

    Uniform block binding

    Hello, I'm trying to set some data to a shader through uniform blocks. But I don't get what I wanted. Here's the code:
    Code :
    const GLfloat pColor[] =
    		1.0f, 1.0f, 1.0f, 1.0f,
    		1.0f, 1.0f, 1.0f, 1.0f
    GLuint nUniformBuffer;
    glGenBuffers(1, &nUniformBuffer);
    glBindBuffer(GL_UNIFORM_BUFFER, nUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, sizeof(pColor), pColor, GL_STATIC_DRAW);
    glBindBuffer(GL_UNIFORM_BUFFER, 0);
    GLuint nBlockIndex0 = Shader.GetUniformBlockLocation("ColorsBlock[0]"); // glGetUniformBlockIndex(...)
    GLuint nBlockIndex1 = Shader.GetUniformBlockLocation("ColorsBlock[1]");
    glBindBufferRange(GL_UNIFORM_BUFFER, 0, nUniformBuffer, 0,                   4 * sizeof(GLfloat));
    glBindBufferRange(GL_UNIFORM_BUFFER, 1, nUniformBuffer, 4 * sizeof(GLfloat), 4 * sizeof(GLfloat));
    glUniformBlockBinding(Shader, nBlockIndex0, 0);
    glUniformBlockBinding(Shader, nBlockIndex1, 1);

    Code :
    uniform ColorsBlock
    	vec4 uColor;
    } ColorInput[2];
    // ...
    teColor = (ColorInput[0].uColor.rgb + ColorInput[1].uColor.rgb) / 2.0f;
    // ...

    But I instead of getting white I get gray. So I think it's because I don't set ColorInput[1]. What am I doing wrong?

  2. #2
    Intern Newbie
    Join Date
    Dec 2013
    Although I don't believe this is the cause of your problem, it looks like you are relying on the std140 block layout in your program, and so you should declare your block in your shader like this instead:
    Code :
    layout(std140) uniform ColorsBlock
        // ...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts