关于OpenGL中的布局std140统一块中的数组 [英] Regarding arrays in layout std140 uniform block for OpenGL

查看:444
本文介绍了关于OpenGL中的布局std140统一块中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据规范:

如果成员是标量或向量的数组,则基本比对 + *和数组步幅设置为匹配单个的基本对齐方式 + *数组元素,根据规则(1),(2)和(3),并四舍五入 + *为vec4的基本对齐方式.该数组可能在 + *结束;数组后的成员的基本偏移量被四舍五入 + *至基本比对的下一个倍数.

If the member is an array of scalars or vectors, the base alignment + * and array stride are set to match the base alignment of a single + * array element, according to rules (1), (2), and (3), and rounded up + * to the base alignment of a vec4. The array may have padding at the + * end; the base offset of the member following the array is rounded up + * to the next multiple of the base alignment.

这是否意味着如果我有一个(float)vec3大小为3的数组,那会是

Does this mean that if I had an array of size 3 of a (float)vec3, would it be

vec3,vec3,vec3,(12个空字节达到vec4的倍数),(由于最后一个句子,所以有16个空字节)

vec3,vec3,vec3, (12 empty bytes to reach a vec4 multiple), (16 empty bytes because of the last sentence)

vec3,(4个空字节),vec3,(4个空字节)vec3,(4个空字节),(由于最后一个句子,所以有16个空字节)

vec3, (4 empty bytes),vec3,(4 empty bytes)vec3,(4 empty bytes), (16 empty bytes because of the last sentence)

推荐答案

来自 actual

3:如果成员是三分量向量,且分量消耗N 基本机器单元,基本对齐方式为4N.

3: If the member is a three-component vector with components consuming N basic machine units, the base alignment is 4N.

4:如果成员是标量或向量的数组,则基本比对和数组 跨度设置为匹配单个数组元素的基本对齐方式 遵循规则(1),(2)和(3),并四舍五入到vec4的基本对齐方式.这 数组的末尾可能会有填充;成员的基本偏移量 数组会四舍五入到基本比对的下一个倍数.

4: If the member is an array of scalars or vectors, the base alignment and array stride are set tomatch the base alignment of a single array element, according to rules (1), (2), and (3), and rounded up to the base alignment of a vec4. The array may have padding at the end; the base offset of the member following the array is rounded up to the next multiple of the base alignment.

因此,vec3的基本对齐方式为4 * 4.因此,vec3的数组的基本对齐方式和数组跨度为4 * 4.跨度是从一个元素到下一个元素的字节数.因此,每个元素的大小为16个字节,前12个是实际的vec3数据.

So a vec3 has a base alignment of 4*4. The base alignment and array stride of an array of vec3's is therefore 4*4. The stride is the number of bytes from one element to the next. So each element is 16 bytes in size, with the first 12 being the actual vec3 data.

最后,末尾的填充等于基本对齐方式,因此该填充有空白.

Finally, there is padding equal to the base alignment at the end, so there is empty space from that.

或者以图表形式,vec3[3]看起来像这样:

Or, in diagram form, a vec3[3] looks like this:

|#|#|#|0|#|#|#|0|#|#|#|0| 

每个单元格为4个字节,#是实际数据,而0是未使用数据.

Where each cell is 4 bytes, # is actual data, and 0 is unused data.

这篇关于关于OpenGL中的布局std140统一块中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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