— Julien Pauty wrote:
Another point is alpha. If you use alpha, you must
know that if your
surfaces are in video memory blitting will be dog
slow, because the
blitting is done by the CPU. If you don’t need an
alpha channel, and if
your surfaces are in video memory the blitting is
done by the GPU and is
very fast.
He meant in system memory, the CPU blits very
expensively,
On the contrary, the CPU works very fast in system memory - compared
to the CPU working in VRAM, that is…
and in video memory, the GPU very
inexpensively.
Yeah, except that you can’t rely on the GPU doing anything much at all
when using the SDL 2D API. (Unless you use glSDL, which uses the
OpenGL API, which is more likely to be accelerated on most
platforms.)
Now, if you use alpha blending, you can pretty much forget about
acceleration (only glSDL and DirectFB support that AFAIK) - and
what’s worse, if you do alpha blending with the CPU in VRAM, you’ll
effectively downgrade the CPU to something like a 286, due to the
slow VRAM reads.
In short, if you want the best performance on more than one platform,
there’s no simple answer. Sometimes you should use h/w surfaces for
everything. Sometimes you should definitely not use h/w surfaces
for anything but the display surface. In some cases, a some kind of
hybrid may be faster. (For example, if everything but alpha is
accelerated, your best bet may be to use that, and do s/w alpha in
small areas only.)
A tip for composing each layer (that will PROBABLY be
helpful, but depending on your program, might be
irrelevant, you really didn’t provide much
information,) you could use a strategy called “Dirty
Rectangles.”
When you do this, each instance of a sprite copies the
space it is to be drawn to before you draw it, once
all sprites have been drawn, you flip your screen
(assuming you’re double buffering,) and then each
sprite can restore the piece of the screen they
copied.
I would recommend against copying dirty rectangles, unless rendering
the background is extremely expensive and/or you know that blitting
from the screen is accelerated. (If it isn’t, you’ll be doing CPU
reads from VRAM, which - for the 13,546,572nd time - is insanely slow
on pretty much any computer you can find today.)
Instead, just rerender the dirty areas from the map to remove sprites.
Either way, note that you need to do some extra work to make dirty
rects work properly on page flipping double buffered displays. With
plain dirty rects, moving sprites will leave flickering trails.
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
— http://olofson.net — http://www.reologica.se —On Thursday 08 July 2004 05.43, Donny Viszneki wrote: