SFML community forums

Help => Graphics => Topic started by: zakkor on June 02, 2014, 07:47:42 pm

Title: Vertex Array using individual textures?
Post by: zakkor on June 02, 2014, 07:47:42 pm
I implemented a small top-down tilebased game using individual textures and sprites to draw the map, and now I'm experiencing poor performance due to the large amount of draw calls (I'm guessing that's what it is.)
Looking at the vertex array tutorial (http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php) I can see that it uses a tileset. If I were to implement a tileset, I think i would need to rewrite a lot of code, so what I'm asking is: is it possible to just add(convert) the sprites that have textures and positions already assigned to them to the vertex array and then just draw that?
I know this is not the most optimized way, but I'm thinking the sprite creation and handling is negligible performance-wise (correct me if I'm wrong). Would this grant me a noticeable performance boost?
How do I do it?

If you need me to post some code, don't hesitate to ask, please!
Title: Re: Vertex Array using individual textures?
Post by: Nexus on June 02, 2014, 07:56:13 pm
and now I'm experiencing poor performance due to the large amount of draw calls (I'm guessing that's what it is.)
Don't guess. Measure.

is it possible to just add(convert) the sprites that have textures and positions already assigned to them to the vertex array and then just draw that?
I know this is not the most optimized way, but I'm thinking the sprite creation and handling is negligible performance-wise (correct me if I'm wrong). Would this grant me a noticeable performance boost?
Vertex arrays are not magically faster, they're faster because a lot of objects can be drawn at once. Therefore, you still need the logic to find out which sprites need the same texture. You can try to create vertex arrays in addition, but why not directly?

If this adaption comes with a huge effort, that's a sign that rendering is not modular or encapsulated enough. Ideally, not the whole game uses sprites directly, but rather a few central classes related to rendering.

How do I do it?
This is explained in the tutorial and API documentation of sf::VertexArray.