I'amI am designing a Spritebatch class
Spritebatch class, for static and dynamic objects with WebGL
WebGL.
A problem I'amI'm facing is that I have read several different opinions on sprite batching
sprite batching but with one goal.
- Put all vertices in one buffer and render them
So in WebGL
WebGL I'amI'm using gl.bufferData(....,new Float32Array(size), gl.STEAM_DRAW)
.
And
And here is my first problem,: when the spritebatch
should be dynamic then size
is not fixed and will increase, which leads to recreating the Float32Array
which I found out is very expensive for n >= 10000
n ≥ 10000 (at least on my machine).
Second Problem, let's say iI give the Float32Array(maxElements)
a maximum size, and iI add 4 Sprites
4 Sprites then I have allocated much more than I actually need.
Other way : I create Spritebatch
Spritebatch when I know how many Sprites
sprites I have. So basically I put4 Sprites
4 Sprites into my scene, then before rendering I create a Spritebatch
Spritebatch with size 4*numVerticesPerSprite4 * numVerticesPerSprite
. However letslet's say I want to update Sprite 2
Sprite 2, I need some kind of index structure in my Spritebatch class
Spritebatch class to identify at which position the vertices
vertices of Sprite 2
Sprite 2 are stored inside the SpriteBatch
SpriteBatch (inside Float32Array()
).
So my question is :
How is a dynamic Spritebatch
Spritebatch supposed to work and can you think of an indexing method to identify Sprites X
Sprite X's vertices inside the Float32Array
to update/remove them? (Additionally: Do particle systems
particle systems solve what i am looking for? I assume they are also some kind of sprite batching
sprite batching)