Zebrafish
Zebrafish

Reputation: 13886

How can I have an array uniform buffer block in glsl?

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];
};

Upvotes: 0

Views: 901

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473252

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?

Upvotes: 2

Related Questions