问题描述
何时将STD140用于OpenGL中的统一块?
When do I use the STD140 for uniform blocks in OpenGL?
尽管我不确定100%,但是我相信有另一种方法可以实现相同的目标,称为共享".
Although I am not a 100% sure, I believe there is an alternative to it which can achieve the same thing, called "Shared".
这仅仅是对编码者的偏爱吗?还是有理由在一个之上使用另一个?
Is it just preference for the coder? Or are there reasons to use one over the other?
推荐答案
统一缓冲区对象在 http://www.opengl.org/registry/specs/ARB/uniform_buffer_object.txt
可以声明统一块的数据存储使用内存中的三种布局之一: packed
, shared
或 std140
.
The data storage for a uniform block can be declared to use one of three layouts in memory: packed
, shared
, or std140
.
-
打包的
统一块具有与实现相关的数据布局,以提高效率,并且编译器可以消除未使用的统一块以节省空间.
packed
uniform blocks have an implementation-dependent data layout for efficiency, and unused uniforms may be eliminated by the compiler to save space.
shared
统一块(默认布局)具有与实现相关的数据布局,以提高效率,但是该布局将由块的结构唯一确定,从而可以进行数据存储跨程序共享.
shared
uniform blocks, the default layout, have an implementation-dependent data layout for efficiency, but the layout will be uniquely determined by the structure of the block, allowing data storage to be shared across programs.
std140
统一块具有标准的跨平台跨供应商布局.未使用的制服将不会被淘汰.
std140
uniform blocks have a standard cross-platform cross-vendor layout. Unused uniforms will not be eliminated.
std140
统一的块布局,可以保证特定的打包行为,并且不需要应用程序查询偏移量和步幅.在这种情况下,即使仅基于统一块声明预先确定了最小大小,仍然可以查询最小大小.通过应用OpenGL规范中描述的规则集,可以从统一块的定义中得出统一块中每个统一的偏移量.
The std140
uniform block layout, which guarantees specific packing behavior and does not require the application to query for offsets and strides. In this case, the minimum size may still be queried, even though it is determined in advance based only on the uniform block declaration. The offset of each uniform in a uniform block can be derived from the definition of the uniform block by applying the set of rules described in the OpenGL specification.
这篇关于什么时候应该在OpenGL中使用STD140?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!