Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: vector<sf::Sprite> VS sf::VertexArray for Tilemaps  (Read 2761 times)

0 Members and 1 Guest are viewing this topic.

ghzmdr

  • Newbie
  • *
  • Posts: 11
    • View Profile
vector<sf::Sprite> VS sf::VertexArray for Tilemaps
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: vector<sf::Sprite> VS sf::VertexArray for Tilemaps
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ghzmdr

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: vector<sf::Sprite> VS sf::VertexArray for Tilemaps
« Reply #2 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.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: vector<sf::Sprite> VS sf::VertexArray for Tilemaps
« Reply #3 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 ;)
Current project: Racod's Lair - Rogue-inspired Coop Action RPG