统一块的动态数量

发布于 2024-10-12 10:53:03 字数 332 浏览 6 评论 0原文

运行openGL 3.1,问题很简单。

在 GLSL 站点上,以下是如何定义统一缓冲区块数组的方法:

uniform BlockName
{
  vec3 blockMember1, blockMember2;
  float blockMember3;
} multiBlocks[3];

现在,是否可以拥有这些多块的动态数量? GLSL 中没有指针,因此没有“新”语句等。

如果没有,是否有其他方法来发送动态数量的元素? 我的块当前正在包装 4 个浮点数和 1 个 vec2。

我还没有写过着色器,所以你可以提出任何建议,谢谢;)

Running openGL 3.1, the question is simple.

From GLSL site, here is how one can define array of uniform buffer blocks:

uniform BlockName
{
  vec3 blockMember1, blockMember2;
  float blockMember3;
} multiBlocks[3];

Now, is it possible to have dynamic number of these multiBlocks? There are no pointers in GLSL so no "new" statement etc.

If not, is there other approach to send dynamic number of elements?
My block is currently packing four floats and one vec2.

I haven't wrote shader yet so you can suggest anything, thanks ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慈悲佛祖 2024-10-19 10:53:03

您无法拥有它们的动态数量,也无法拥有它们的动态索引。这意味着即使您可以动态更改计数,它也没什么用,因为您仍然需要更改着色器代码才能访问新元素。

一种可能的替代方法是创建块成员数组:

#define BLOCK_COUNT %d

uniform BlockName
{
    vec3 blockMember1[BLOCK_COUNT];
    vec3 blockMember2[BLOCK_COUNT];
    float blockMember3[BLOCK_COUNT];
}
multiBlocks;

然后您可以更改 BLOCK_COUNT 来更改成员数量,并且可以使用动态索引就好:

multiBlocks.blockMember2[i];

它仍然不允许您在不重新编译着色器的情况下更改元素数量, 尽管。

You can't have a dynamic number of them, and you can't have a dynamic index into them. That means that even if you could change the count dynamically, it would be of little use since you'd still have to change the shader code to access the new elements.

One possible alternative would be to make the block members arrays:

#define BLOCK_COUNT %d

uniform BlockName
{
    vec3 blockMember1[BLOCK_COUNT];
    vec3 blockMember2[BLOCK_COUNT];
    float blockMember3[BLOCK_COUNT];
}
multiBlocks;

Then you can alter BLOCK_COUNT to change the number of members, and you can use dynamic indexes just fine:

multiBlocks.blockMember2[i];

It still doesn't allow you to alter the number of elements without recompiling the shader, though.

橘亓 2024-10-19 10:53:03

好的,所以我也写信给 openGL 论坛,这出来了< /a>

所以基本上你有 3 个解决方案:
统一缓冲区对象或纹理缓冲区或具有大量准备元素的静态数组,并使用另一个统一来指定实际大小。

最后一个可以使用 OneSadCookie 在编译时定义的最大大小进行升级。

Ok so i wrote also to openGL forum and this came out

So basicaly you have 3 solutions:
Uniform buffer objects or Texture buffers or static array with some high number of prepared elements and use another uniform for specifying actual size.

The last one could be upgraded with OneSadCookie's definition of max size in compile time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文