在OpenGL中,矩阵是以列优先的方式(column-major order)存储的,而一般的数学书上是以行优先的方式(row-major order)存储的。
列优先:
m0 m4 m8 m12
m1 m5 m9 m13
m2 m6 m10 m14
m3 m7 m11 m15
行优先:
m0 m1 m2 m3
m4 m5 m6 m7
m8 m9 m10 m11
m12 m13 m14 m15
在OpenGL中,矩阵是用一维数组来保存的:m[16]。
可以用ARB_transpose_matrix来实现2者的转换:
New functions and tokens are added allowing application matrices
stored in row major order rather than column major order to be
transferred to the OpenGL implementation. This allows an application
to use standard C-language 2-dimensional arrays (m[row][col]) and
have the array indices match the expected matrix row and column indexes.
These arrays are referred to as transpose matrices since they are
the transpose of the standard matrices passed to OpenGL.
This extension adds an interface for transfering data to and from the
OpenGL pipeline, it does not change any OpenGL processing or imply any
changes in state representation.
提供的函数:
void LoadTransposeMatrix{fd}ARB(T m[16]);
void MultTransposeMatrix{fd}ARB(T m[16]);
提供的标记(对GetBooleanv, GetIntegerv, GetFloatv, GetDoublev函数):
TRANSPOSE_MODELVIEW_MATRIX_ARB
TRANSPOSE_PROJECTION_MATRIX_ARB
TRANSPOSE_TEXTURE_MATRIX_ARB
TRANSPOSE_COLOR_MATRIX_ARB
LoadTransposeMatrixARB(m)相当于:
float n[16];
transpose(m,n)
LoadMatrix(n);
MultTransposeMatrixARB(m)相当于:
float n[16];
transpose(m,n);
MultMatrix(n);
GetFloatv(TRANSPOSE_MODELVIEW_MATRIX_ARB,m)相当于:
float n[16];
GetFloatv(MODELVIEW_MATRIX_ARB,n);
transpose(n,m);
TRANSPOSE_PROJECTION_MATRIX_ARB,TRANSPOSE_TEXTURE_MATRIX_ARB和 TRANSPOSE_COLOR_MATRIX_ARB类似。