统一块的动态数量
运行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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法拥有它们的动态数量,也无法拥有它们的动态索引。这意味着即使您可以动态更改计数,它也没什么用,因为您仍然需要更改着色器代码才能访问新元素。
一种可能的替代方法是创建块成员数组:
然后您可以更改 BLOCK_COUNT 来更改成员数量,并且可以使用动态索引就好:
它仍然不允许您在不重新编译着色器的情况下更改元素数量, 尽管。
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:
Then you can alter BLOCK_COUNT to change the number of members, and you can use dynamic indexes just fine:
It still doesn't allow you to alter the number of elements without recompiling the shader, though.
好的,所以我也写信给 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.