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

Author Topic: Drawing efficency concern  (Read 1953 times)

0 Members and 1 Guest are viewing this topic.

xXGeriXx

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Drawing efficency concern
« on: December 09, 2015, 07:37:03 pm »
So I just created a game that would read from a matrix of sprites which will be the background. Each element of the matrix corresponds to a tile(an image) of the background.

My concern is that this looks way too inefficent, since i have to read+draw all the elements of the matrix every single frame(iteration of the game loop) when this background doesn't even get modified at all.

Is this fine? Should i photoshop every background into a single image? Is there a way to partialy clear the window instead of completely clearing it? Any other solutions?

Thanks in advance. I've been using sfml for a week, please bare with me :P

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Drawing efficency concern
« Reply #1 on: December 09, 2015, 07:51:44 pm »
Modern graphics cards/drivers optimize for the case of "clear/draw/display" every frame. That's not a problem and it's what you are expected to do with SFML. See the big red box in the Drawing 2D Stuff tutorial.

As far as minimizing draw calls; yeah, sure, you could make a single large image for your background. Either by drawing it once in a graphics program and then using that as your background texture that you draw. Or you could keep your current 'tiles' but draw them to a sf::RenderTexture once and then use said RenderTexture from then on to draw the background. Or you could use a sf::VertexArray to cut down on the number of draw calls for your tiles.
Documentation for all of the above can be found at  http://www.sfml-dev.org/documentation/2.3.2/ and  http://www.sfml-dev.org/tutorials/2.3/
Check out  http://www.sfml-dev.org/learn.php and the wiki:  https://github.com/SFML/SFML/wiki

Ohh and by the way: unless you have an actual real performance problem, don't worry too much about it - focus instead on what keeps your code simple and maintainable (a couple hundred draws every frame is nothing)  ;)
« Last Edit: December 09, 2015, 08:46:30 pm by Jesper Juhl »

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: Drawing efficency concern
« Reply #2 on: December 11, 2015, 09:48:52 pm »
How complex or cluttered are the visuals on screen at any one time? Could we see a screenshot? :)