For details, see section 7.6.2.2 of the OpenGL specification, but basically the std140 layout says that each variable will be laid out immediately after the previous variable with the addition of sufficient padding for alignment needed for the variable type. vec3 and vec4 both require 16-byte alignment and are equal to 12 and 16 bytes, respectively. float requires 4 byte alignment and has a size of 4 bytes. Thus, with the layout std140 LightPosition will get 16-byte alignment, so it will always end at an address equal to 12 mod 16. Since this is 4-byte aligned, the add-on will not be inserted before LightAttenuation .
source share