OpenGL的Uniform Buffer Object “std140” storage layout内容理解

呃呃,看到高级GLSL语言了,但是在看Uniform块布局的时候有点云里雾里的,基本对齐量和对齐偏移量概念不清楚,上网找了找大佬的文章,下面贴上,做个小记录。

基本定义

When using the “std140” storage layout, structures will be laid out in
buffer storage with its members stored in monotonically increasing order
based on their location in the declaration. A structure and each
structure member have a base offset and a base alignment, from which an
aligned offset is computed by rounding the base offset up to a multiple of
the base alignment. The base offset of the first member of a structure is
taken from the aligned offset of the structure itself. The base offset of
all other structure members is derived by taking the offset of the last
basic machine unit consumed by the previous member and adding one.
Each structure member is stored in memory at its aligned offset. The members
of a top-level uniform block are laid out in buffer storage by treating
the uniform block as a structure with a base offset of zero.

  • 一个ubo结构的"std140"存储布局
  • 一个ubo结构和其中的结构成员存在一个基本偏移量(Base Offset)和一个基本对齐量(Base Alignment)。
    • 结构成员的对齐偏移量 = 【基本偏移量的值四舍五入,变为基本对齐量的倍数(0,1,2…)】
  • 一个ubo结构的第一个成员的基本偏移量 = 这个ubo结构相对于起始ubo结构的对齐偏移量
  • 一个ubo结构的非第一个成员的基本偏移量=上一个成员的对齐偏移量 + 上一个成员的真正占用量
  • 一个ubo结构的占用量按照下述规则计算出来后,还需要约束成vec4占用量的倍数

详见下图:
在这里插入图片描述

GLSL中各种变量的布局规则:
在这里插入图片描述

引用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值