SFML community forums

Help => Graphics => Topic started by: ghzmdr on March 19, 2015, 07:09:27 pm

Title: vector<sf::Sprite> VS sf::VertexArray for Tilemaps
Post by: ghzmdr on March 19, 2015, 07:09:27 pm
Hi there! I happen to be developing a game which is tile-based and even tough it shouldn't have enormous requirements I'm as always concerned about performance.

I had my background tiles in a vector of Sprites but today found out that when running on linux with nvidia drivers there was some tearing due to floating point view moving.

So after some searching I switched to a VertexArray, altought the problem isn't gone away (if you have any input on this that would be awesome, for now I'm just subtracting a little -- 0.0075 -- offset from the top of the tile and everythig is smooth, but that's only a workaround not a solution).

Anyway before that I was drawing tiles in a loop, only drawing those that were currently in view, plus a 2 tile offset in every direction for smoothness. Now I'm drawing the whole tilemap in a single call, but isn't there any looping involved in VertexArray drawing? If so, isn't cheaper to loop through every tile and just draw the ones I need? How can be faster to draw the whole array (even if treated as a single texture) VS drawing just the necessary tiles?
Title: AW: vector<sf::Sprite> VS sf::VertexArray for Tilemaps
Post by: eXpl0it3r on March 19, 2015, 07:17:50 pm
As you noted yourself the performance for your scope is not important.

As for vertex array, there's no "real" looping going on. The vertices are uploaded at once and then drawn. The performance gain for a big number of tiles with vertex array is that you get one OpenGL draw call as opposed to x draw callw.
Title: Re: vector<sf::Sprite> VS sf::VertexArray for Tilemaps
Post by: ghzmdr on March 19, 2015, 11:10:31 pm
Thanks for the explanation! I think I'll use a VertexArray for the map and a vector for custom objects then.
Title: Re: vector<sf::Sprite> VS sf::VertexArray for Tilemaps
Post by: Glocke on March 21, 2015, 06:00:34 pm
Thanks for the explanation! I think I'll use a VertexArray for the map and a vector for custom objects then.

That's exactly the approach I'm using ... and it works just great ;)