Re: Accessing a locked surface

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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]


.



Relevant Pages

  • Re: Accessing a locked surface
    ... In the x-loop, I compute a new value for *ptr, pixel ... If I write all calculation in a whole scanline, ... It would make another loop. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Induction experiment part 2
    ... Except your calculation for B above is wrong. ... Amp/meter matches 4.36 amps. ... amps in the primary via the loop calculation. ... That is not the primary voltage. ...
    (sci.physics.electromag)
  • Re: Induction Experiment Part 5
    ... output voltage is 42.3 VAC RMS. ... measurement is 9.22 mV AC RMS so double the 60Hz measurement. ... The emf via E_k calculation is now 14.2 mV AC RMS for this ... field is current divided by the diameter of the circle loop. ...
    (sci.physics.electromag)
  • Re: Induction experiment part 2
    ... Except your calculation for B above is wrong. ... amps in the primary via the loop calculation. ... That is not the primary voltage. ... secondary measured voltage and got the magnetic flux. ...
    (sci.physics.electromag)
  • Re: Induction Experiment Part 5
    ... We have the same 7.62 meter parallel wire 18 gauge zip ... measurement is 9.22 mV AC RMS so double the 60Hz measurement. ... The emf via E_k calculation is now 14.2 mV AC RMS for this ... field is current divided by the diameter of the circle loop. ...
    (sci.physics.electromag)