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

Author Topic: [Solved] Is the refreshing optimized?  (Read 3038 times)

0 Members and 1 Guest are viewing this topic.

vlad

  • Newbie
  • *
  • Posts: 9
    • View Profile
[Solved] Is the refreshing optimized?
« on: July 24, 2011, 02:10:41 pm »
Hi,

I come from an SDL background and there, a certain method is used when, say, a character's moved on a certain area of a map but nothing else on the map has moved:
instead of refreshing the entire screen at the end of each iteration of the main loop, you just refresh a specific rectangle where changes have been made (i.e. the rectangle in which the character's moved).

I was wondering if SFML used this technique natively or if I had to design a refresh() function by myself like it's the case with SDL.

If you didn't understand what this was about, feel free to mention it and I will try to explain it a little better.

And sorry if this question has been answered 'cause I've sure been looking for it on the forum but since I can't put a name on this technique...

Edit: as said below, this technique is called the Dirty Rectangle Method

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
[Solved] Is the refreshing optimized?
« Reply #1 on: July 24, 2011, 02:16:55 pm »
In SFML, you draw the whole scene again and again. So you don't have to find out which part of the screen has changed, code becomes easier (and still faster than SDL :P).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
[Solved] Is the refreshing optimized?
« Reply #2 on: July 24, 2011, 03:58:55 pm »
For reference, this technique is called "Dirty Rectangles" or something like that. The idea is that you only re-draw 'Dirty'(rectangles that have changed) regions of the screen.

It's probably not worth the effort with todays hardware. Especially when you take Nexus' comment into account.

I wouldn't worry about this technique until you have a finished game, odds are you wont need it. I wonder if video cards implicitly perform this optimisation already...

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
[Solved] Is the refreshing optimized?
« Reply #3 on: July 24, 2011, 04:27:50 pm »
Hi Vlad

I was a long term SDL user too, but since I switched to SFML, I have not looked back. It is so much better than SDL in many ways, not just from a code point of view, but the community here is great and really helpful.

Anyway, I used the dirty rectangles method in SDL as this was the only way to get good performance on DirectX. Since switching to SFML and re-writing my codebase, I get the same or better performance even though I have to re-draw all my sprites every frame.

It also results in MUCH cleaner (and less buggy) code.

Hope that was helpful.

Regards
Ed
SFML 2.1

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
[Solved] Is the refreshing optimized?
« Reply #4 on: July 24, 2011, 06:07:10 pm »
+1 to everyone else.

Dirty Rects is an antiquated concept.  Today's machines are designed to redraw the full screen every frame because that is what is expected/required of most programs (it's all 3D hardware now, and dirty rects simply don't apply to a 3D environment)


So yeah, don't worry about it.  Just redraw the whole thing every frame.

vlad

  • Newbie
  • *
  • Posts: 9
    • View Profile
[Solved] Is the refreshing optimized?
« Reply #5 on: July 24, 2011, 09:30:10 pm »
Alright, my main question's been answered: I don't need to handle them dirty rectangles anymore :D

I too noticed that even though I didn't use the dirty rectangles method (damn, such a hassle, btw) my CPU was running at a very fair pace.

But I was wondering if it was because SFML handled the rectangles by itself or if it was a hardware matter (said hardware being either powerful enough to redraw the scene each time or smart enough to detect by itself which zones in the screen needed refreshing)

This is just to fulfill my curiosity, though; I'll ask Laurent some time in the future if I get the opportunity.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Is the refreshing optimized?
« Reply #6 on: July 24, 2011, 11:03:57 pm »
There's no more concept of dirty rectangles with today's hardware, there's even no more concept of 2D drawing -- everything's 3D. The graphics card is powerful enough to draw thousands of sprites at very high framerates (see how it can render very complex 3D scenes; a bunch of 2D sprites is nothing compared to this).
Laurent Gomila - SFML developer

 

anything