在OpenGL中存储和加载矩阵 [英] Storing and loading matrices in OpenGL

查看:145
本文介绍了在OpenGL中存储和加载矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能告诉OpenGL将当前转换矩阵存储在特定位置(而不是将其推送到堆栈上)并从特定位置加载矩阵?

我更喜欢一种解决方案,它不涉及视频设备和主存储器之间的附加数据传输(即最好将矩阵存储在视频存储器的某处)。

解决方案

在旧的固定功能流水线上,矩阵按需加载到一些特殊的GPU寄存器中,但从未存在于VRAM中,计算发生在CPU上。在现代,OpenGL矩阵计算仍然发生在CPU上(以及如此),并且在需求时再次被加载到称为Uniforms的寄存器中。然而现代的OpenGL也有一个叫做Uniform Buffer Objects的特性,允许从VRAM加载统一(寄存器)值。 http://www.opengl.org/wiki/Uniform_Buffer_Object



但它们对存储变换矩阵没有多大用处。首先,你会不断改变它们做动画。其次,管理UBO仅仅是一个简单矩阵的开销就比从CPU中设置更多的性能。一个矩阵只有16个标量,或者与具有位置,法线,纹理坐标和切线属性的单个顶点相当。


Is it possible to tell OpenGL to store the current transformation matrix in a specific location (instead of pushing it on a stack) and to load a matrix from a specific location?

I prefer a solution that does not involve additional data transfer between the video device and main memory (i.e. it's better to store the matrix somewhere in video memory).

解决方案

On old fixed function pipeline the matrices were loaded into some special GPU registers on demand, but never were in VRAM, all matrix calculations happened on the CPU. In modern day OpenGL matrix calculations still happen on CPU (and right so), and are loaded into registers called "Uniforms" on demand again. However modern OpenGL also has a feature called "Uniform Buffer Objects" that allow to load Uniform (register) values from VRAM. http://www.opengl.org/wiki/Uniform_Buffer_Object

But they make little use for storing transform matrices. First, you'll change them constantly for doing animations. Second, the overhead of managing the UBOs for just a simple matrix eats much more performance, than setting it from the CPU. A matrix is just 16 scalars, or the equivalent of one single vertex with a position, normal, texture coordinate and tangent attribute.

这篇关于在OpenGL中存储和加载矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆