2

I just tried to do this

C++

struct PointLight
{
    glm::vec4 position;
    glm::vec4 colour;
};

std::vector <PointLight> lights_array;

GLSL 320 ES:

layout (std140) struct PointLight
{
    vec4 position;
    vec4 colour;
};

layout (std140) buffer Lights 
{
    int        count;
    PointLight data [];
}
b_lights;

The compile error surprised me:

error C7600: no value specified for layout qualifier 'std140'

I can't find a straight answer but I get the impression that I can't specify std140 for struct definitions. Is this so? Or how can I spell it?

If not, then how am I able to guarantee that I can send lights_array to glBufferData so that it has the correct layout in the shader's b_lights.data array?

In other words, why is std140 required for the buffer but not for the struct?

genpfault
  • 51,148
  • 11
  • 85
  • 139
spraff
  • 32,570
  • 22
  • 121
  • 229

1 Answers1

4

Interface blocks have layouts, not structs. The layout applies to how the block lays out its elements, recursively, through their entire contents.

So you don't need to apply an interface block layout to a random struct.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • So if I use my `PointLight` struct in two different interface blocks, it can end up with a different layout in each?! – spraff Sep 03 '19 at 17:51
  • @spraff: Sure. What's the problem? A `mat4` might have row-major layout in one block and column-major layout in another. But when you *read it*, it will be correct (assuming you put the data in correctly). Memory layout is about *memory* layout. – Nicol Bolas Sep 03 '19 at 18:08