Re: Accessing a locked surface
- From: "[Jongware]" <sorry@xxxxxxxxxxx>
- Date: Tue, 22 Aug 2006 17:26:02 +0200
"Mark Morrisson" <mark4@xxxxxxxxxxxxxxx> wrote in message
news:44eb14cd$0$21149$7a628cd7@xxxxxxxxxxxxxxxxxxxxxxxx
Thanks for your reply. In the x-loop, I compute a new value for *ptr,
pixel
by pixel. If I write all calculation in a whole scanline, how can I fastly
copy it to *ptr ? It would make another loop. The only optimization I can
do
is copy 32-blocks at once (I work in 16-bit colors), but I don't think
that
would speed things up.
It would be an extra operation, but since it is from and to known addresses
and with a known size you can use memcpy.
I do need to read the backbuffer surface each time I apply the effect, it
cannot be precomputed, it's a real time effect (fog with
semi-transparency).
Indeed, it's not a problem of optimization of the loop, since removing the
surface writing code (in this very case, *ptr++ = Color16(r, g, b);) makes
this process very fast.
But it's enough to copy a raw color to *ptr without
calculation (for instance, plotting a red pixel everywhere on the surface)
to make it VERY slow.
A guess: Color16 (r,g,b) is a function which converts (red,green,blue) byte
values into a single short. Is that correct?
Okay... Don't use a *function*-per-pixel! That's slooooo. Try replacing this
with a macro -- it'll be hardcoded to your specific video mode, but
theoretically it should improve the speed. For 16-bit color, try this one:
#define Color16(r,g,b) (unsigned short)((r & 0xf8)<<8) | ((g & 0xfc)<<2) |
((b & 0xf8) >> 3))
[from memory -- I hope you can see what I'm doing here]
If this works, copy the entire function a few times, and adjust this rgb
calculation for every possible DX mode you want your program to run in. Make
the call to the original function a pointer to this function, so you can let
the program select the routine to use at startup. Do not forget to include
your original routine as a "catch-all" -- it'll be slow, but it'll do at
least *something*.
It is not uncommon to see this kind of routines copied several times, with
minor adjustments in the code. It is far faster than bloating each drawing
routine with "if {..} else {..}" for every possible DX configuration.
Thinking some more about it...
[Jw]
.
- Follow-Ups:
- Re: Accessing a locked surface
- From: Mark Morrisson
- Re: Accessing a locked surface
- References:
- Accessing a locked surface
- From: Mark Morrisson
- Re: Accessing a locked surface
- From: [jongware]
- Re: Accessing a locked surface
- From: Mark Morrisson
- Accessing a locked surface
- Prev by Date: Re: Accessing a locked surface
- Next by Date: Re: Convert Matrix to String
- Previous by thread: Re: Accessing a locked surface
- Next by thread: Re: Accessing a locked surface
- Index(es):
Relevant Pages
|