规范和蓝皮书中列主格式的使用
我刚刚在这里阅读 OpenGL 常见问题解答: http://www.opengl.org/ resources/faq/technical/transformations.htm
查看标题为“9.005 OpenGL 矩阵是列优先还是行优先?”的部分。底部写道:
“可悲的是,规范和蓝皮书中使用列主格式导致了 OpenGL 编程社区的无尽混乱。列主表示法表明矩阵并不像程序员那样在内存中布局预计。”
现在,我一直在不遗余力地始终按列优先顺序将矩阵数据传递给 OpenGL,以免在转置操作上浪费 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
常见问题解答本身有点过时了。从技术上讲,使用 OpenGL-3 可以通过将 glUniformMatrix 的 transpose 参数设置为 true,以行顺序格式传递矩阵。
然而,我个人发现列主排序有一个巨大的好处:它允许直接访问矩阵描述的坐标系(变换)的基向量。看看典型的变换矩阵
X、Y 和 Z 是要变换到的坐标系的基向量,T 是偏移量。
现在看看 OpenGL 使用的索引
因此,在偏移量 0 处您可以找到 X 向量,在偏移量 4 处您可以找到 Y,偏移量 8 给出 Z,偏移量 c 给出 T。您可以直接访问它们,将它们传递给向量操作函数,例如
在直接方式:
不必首先从矩阵中逐段废弃这些向量。
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, 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
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
in a direct way:
instead of first having to scrap those vectors from the matrix piece by piece.