0

The error I get with the following declaration of a buffer is:

Binding point for uniform block must be equal or greater than 0 and less than: GL_MAX_UNIFORM_BUFFER_BINDINGS.

My GL_MAX_UNIFORM_BUFFER_BINDINGS is 90. I want 128 of the following structs:

layout(binding = 3, std140) uniform lightsBuffer
{
    mat4 viewMatrix;
    vec3 colour;
    float padding;
}lights[128];

It seems I've created 128 of these structs each at different binding points. How do I have the array of 128 structs at binding 2?

Edit: Is it like this:

layout(binding = 3, std140) uniform lightsBuffer
{
    struct Light
    {
        mat4 viewMatrix;
        vec3 colour;
        float padding;
    }lights[128];
};
2
  • 1
    And if you're going to have padding, just use a vec4. Commented Oct 4, 2020 at 16:20
  • @Rabbid76 Can I define the Light struct inside or do I have to define struct Light { } beforehand, and then do what you said? Commented Oct 4, 2020 at 16:23

1 Answer 1

2

That's not a struct; it's a uniform block. You can tell because you didn't use the keyword struct ;) So what you're creating is an array of uniform blocks.

If you want an array within a uniform block, you can create that using standard syntax:

layout(...) uniform lightsBuffer
{
    StructName lights[128];
};

Where StructName is a previously-defined struct.

Can I define the Light struct inside

No. Why would you want to?

Sign up to request clarification or add additional context in comments.

3 Comments

I see, define the struct beforehand. It cannot be inside the block like I did?
@Rabbid76 What I meant was something like uniform lightsBuffer { struct Light { float a; } lights[128]; }; This seems to have worked in my program.
@Zebrafish: Then your compiler has a bug. The grammar technically allows it, but there's a explicit statement in the text forbidding it: "Structure definitions cannot be nested inside a block"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.