Row-major vs Column-major confusion

后端 未结 9 1411
离开以前
离开以前 2021-01-31 19:27

I\'ve been reading a lot about this, the more I read the more confused I get.

My understanding: In row-major rows are stored contiguously in memory, in column-major colu

9条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 20:00

    It's easy:row-major and column-major are from the glUniformMatrix*()'s perspective. actually, matrix never changed, it is alwarys:

    What is difference is matrix class realization. It deterimins how 16 floats stored as parameter passing to glUniformMatrix*()

    If you use row-major matrix, memory of 4x4 matrix is: (a11, a12, a13, a14, a21, a22, a23, a24, a31, a32, a33, a34, a41, a42, a43, a44), else for column-major is: (a11, a21, a31, a41, a12, a22, a32, a42, a13, a23, a33, a43, a41, a42, a43, a44).

    Because glsl is column-major matrix, so it will read the 16 float data (b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16) as

    Since in row-major, a11=b1, a12=b2, a13=b3, a14=b4, a21=b5, a22=b6,...so in glsl matrix is changed to

    while in column-major: a11=b1, a21=b2, a31=b3, a41=b4, a12=b5, a22=b6,...so in glsl matrix is changed to

    which is the same as the orign. So row-major needing a transpose while column-major not.

    Hoping this can solve your confusion.

提交回复
热议问题