Skip to main content
deleted 46 characters in body
Source Link
Kromster
  • 10.7k
  • 4
  • 54
  • 67
layout(std140) uniform TransformBlock
{
      //Member                        base alignment    offset  aligned offset
      float scale ;                   // 4              0       0
      vec3 translation;               // 16             4       16
      float rotation[3];              // 16             28      32 (rotation[0])
                                      //                        48 (rotation[1])
                                      //                        64 (rotation[2])
      mat4 projection_matrix;         // 16             80      80 (column 0)
                                      //                        96 (column 1)       
                                      //                        112 (column 2)   
                                      //                        128 (column 3)                                    
}
layout(std140) uniform TransformBlock
{
      //Member                        base alignment    offset  aligned offset
      float scale ;                   // 4              0       0
      vec3 translation;               // 16             4       16
      float rotation[3];              // 16             28      32 (rotation[0])
                                      //                        48 (rotation[1])
                                      //                        64 (rotation[2])
      mat4 projection_matrix;         // 16             80      80 (column 0)
                                      //                        96 (column 1)       
                                      //                        112 (column 2)   
                                      //                        128 (column 3)                                    
}
layout(std140) uniform TransformBlock
{
      //Member                        base alignment    offset  aligned offset
      float scale ;                   // 4              0       0
      vec3 translation;               // 16             4       16
      float rotation[3];              // 16             28      32 (rotation[0])
                                      //                        48 (rotation[1])
                                      //                        64 (rotation[2])
      mat4 projection_matrix;         // 16             80      80 (column 0)
                                      //                        96 (column 1)
                                      //                        112 (column 2)
                                      //                        128 (column 3)
}
Source Link
aaa111
  • 175
  • 1
  • 6

OpenGL Uniform Standard Buffer Alignment confusion

Although i asked the same question over StackOverflow, i thought i can get more info from here too.

I have been reading about std140 Uniform block in OpenGL Superbible 6th edition, where in page 111 the following example is given :

layout(std140) uniform TransformBlock
{
      //Member                        base alignment    offset  aligned offset
      float scale ;                   // 4              0       0
      vec3 translation;               // 16             4       16
      float rotation[3];              // 16             28      32 (rotation[0])
                                      //                        48 (rotation[1])
                                      //                        64 (rotation[2])
      mat4 projection_matrix;         // 16             80      80 (column 0)
                                      //                        96 (column 1)       
                                      //                        112 (column 2)   
                                      //                        128 (column 3)                                    
}

I am having hard time understanding the alignments, even using the rules that have described earlier in that page, it still don't make sense.To be specific thing that confuses me is :

  1. What is the Offset and what is aligned offset, why 2 different offset?

  2. Why is the rotation[0] offset starts at 28, and why aligned offset is 32?

Hopefully someone can clear my confusions.I would highly appreciate. Thanks