Open deltanedas opened 3 years ago
This can actually be worked around quite easily. If you want sprites, you make a tilemap and calculate vertexes manually, and then you can draw many different sprites in one batch.
The issue is if you use blend mode and it overlaps.
Everyone has tried to use our good friend
sf::Sprite
for a game, then it gets out of hand when a few hundred/thousand cripple performance. Then you ask around on the forums and try out sf::VertexArray and your cool tilemap draws instantly! Now you want to draw more dynamic things, and you're back to lots of draw calls or manually building VertexArrays which quickly becomes painful. You can't add other drawables to a VertexArray.I think that VertexArray/Buffer are fantastic, but their greatest limitation is that they can only be used to (easily) batch individual vertices. You can't do something like this:
This is where VertexBatch comes in. VertexBatch is a thin wrapper over a VertexArray that when drawn to, simply appends the "drawn" vertices to be actually drawn later. It would be both a Drawable (it has to be drawn somewhere) and a RenderTarget (why bother with it at all if you have to use a special set of drawSprite/drawArray/etc methods, when the RenderTarget::draw(Drawable) relationship already exists?) Example code using it:
Limitations:
RenderStates
can be applied to the batch as a whole (1 texture, 1 shader) but we're used to this withVertexArray
.VertexBuffer
s since the cost of copying them into CPU memory would outweigh the benefit of batched drawing, might upset someone if they don't expect batch.draw(someVertexBuffer) to draw immediately.VertexBuffer
anyways.Currently writing an implementation of this.