Torsten Giebl <wizard syntheticsw.com> writes:
Hello !
My question to you is, don’t you think that from a certain
number of dirty rectangles,
it’s quicker to use SDL_Flip() than using SDL_UpdateRects() ?
Yes it is.
But I can’t almost find an SDL engine that is made in this way.
Everyone just say “I have accelerated hardware or opengl so I don’t
care”.
Well, if you have some 2D backend with actual page flipping,
SDL_Flip() is the way to go, as that’s basically a no cost operation,
involving no copying of VRAM data.
Now, OpenGL isn’t really an excuse, as it may well be using
back-to-front copy blits for “swapping”. You’ll see this in windowed
mode on most platforms, and in some cases (xf86, xorg, …) even in
fullscreen mode. Even though it’s hardware accelerated, it’s not
free, and will actually bring less powerful video cards to their
knees in high resolution.
Basically, always consider “smart” refresh methods if your application
normally only animates part of the display area - especially if it
can run in high resolutions. Even with full acceleration, a slower
video card may not even be able to do full screen/full window "flips"
by copying without dropping to annoyingly low frame rates.
Also, it’s generally bad manners wasting CPU and/or GPU power doing
essentially nothing. It generates heat (my quad core dual video card
monster keeps my room warm quite well as it is, thank you!) and
consumes power, which is particularly annoying if you’re using some
mobile device on battery power.
It is, but it is hard to guess at what Nr. the first is better
than
the second. It depends a lot on what machine you are using, what
gfx card
and so on.
Also if your app or game is scrolling for example SDL_Flip is
most of the time quicker and easier to use.
I agree about easier… but most of time quicker?
I don’t think so!
As you said before… it depends!
On old machines and without full screen mode SDL_Flip is a mess for
performance.
Well… I was going to say that if you’re actually scrolling the
whole screen at all times, SDL_Flip() is the way to go - but it’s not
quite that simple!
Say you have a scrolling shooter; ie a constantly scrolling background
with some sprites over it. You could just do the na?ve thing and
repaint the whole screen and then calling SDL_Flip() every frame.
That’s optimal if you have hardware page flipping, and allows you to
take advantage of retrace sync where available.
However, if you don’t have hardware page flipping, you’ll end up
blitting more than two full screen’s worth of data for every frame!
First you render the background, then the sprites… and then you
copy it all to the frame buffer.
Obviously, you can’t (usually) avoid that by simply rendering directly
to the display buffer, as that would result in flickering sprites and
whatnot. (Well, you can avoid that by doing “halv buffering”, but I
wouldn’t recommend that on any normal operating system.)
So, what you do is emulate hardware scrolling. That is, drop the SDL
shadow surface (ie use a single buffered display surface) and replace
it with some constellation of custom back buffers, arranged so that
you can get away with only moving the sprites and rendering a small
fraction of new background graphics every frame. This way, a
quiescent scene takes only ever so sligthly more than one full screen
blit (the “flip” blit) per frame, whereas the na?ve “repaint all,
then flip” method would take two full screen blits per frame.
Of course, if you don’t mind rolling your own blitters, you could come
up with some sort of method of rendering the screen progressively as
a one step blit with no intermediate buffers. S-buffering springs to
mind… This may also have the advantage of eliminating overdraw,
which can matter a great deal if you have lots of sprites, parallax
layers or other things that would impact “painter’s algorithm” a lot.
The is an old (never finished) Ultima Online client based on SDL
called “Aracnide” that don’t use Flip and implements a lot of code
in order to redraw only what is needed (with updaterects, bitmasks
etc) and is a lot of faster than Flip.
Obviously it has its limits: no alpha and only 16 bit depth.
Well, that’s the downside of custom blitters, I suppose…
//David Olofson - Programmer, Composer, Open Source Advocate
.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Friday 11 July 2008, Guido wrote: