开发者

Dynamic number of uniform blocks

Running openGL 3.1, the question is simple.

From GLSL site, h开发者_如何转开发ere 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 ;)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜