Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The use of column-major format in the spec and blue book

Tags:

opengl

I was just reading an OpenGL FAQ here: http://www.opengl.org/resources/faq/technical/transformations.htm

Look at their section entitled "9.005 Are OpenGL matrices column-major or row-major?" Toward the bottom it says:

"Sadly, the use of column-major format in the spec and blue book has resulted in endless confusion in the OpenGL programming community. Column-major notation suggests that matrices are not laid out in memory as a programmer would expect."

Now, I've been going out of my way to always pass matrix data to OpenGL in column-major order so as not to waste OpenGL's processing time on transpose operations. But does this FAQ's answer imply that I don't need to be doing that?

like image 573
fieldtensor Avatar asked Nov 11 '11 09:11

fieldtensor


1 Answers

The FAQ itself is a bit outdated. Technically with OpenGL-3 it is possible to pass matrices in row-order format, by setting the transpose parameter of glUniformMatrix to true.

However personally I find the column major ordering a huge benefit: It allows one to directly access the base vectors of a coordinate system (transformation) a matrix describes. Look at your typical transformation matrix

X_x Y_x Z_x T_x
X_y Y_y Z_y T_y
X_z Y_z Z_z T_z
W_a W_b W_c W_w

X, Y and Z are the base vectors of the coordinate system you're transforming into, T is the offset.

Now look at the indexing used by OpenGL

0 4 8 c
1 5 9 d
2 6 a e
3 7 b f

So at offset 0 you find the X vector, at offset 4 you find Y, offset 8 gives Z and offset c gives T. You can access them directly, pass them to vector manipulating functions like

float vec4_length3(float v[4]);

in a direct way:

float M[16] = {...};

float T_length = vec4_length3(&M[c]);

instead of first having to scrap those vectors from the matrix piece by piece.

like image 143
datenwolf Avatar answered Sep 23 '22 02:09

datenwolf