Board index » delphi » Very fast putpixel

Very fast putpixel


2004-01-10 08:06:52 PM
delphi261
Is there some way to speed up this putpixel procedure (for example asm
optimization)?
How can DirectX and OpenGL make it so fast? I know they don't use GDI but
what?
procedure PutPixel640(x, y: integer; Color: word); // pf15Bit
begin
// Screen = scanline of bitmap
Screen[y shl 9 + y shl 7 + x] := Color;
end;
 
 

Re:Very fast putpixel

Quote
Is there some way to speed up this putpixel procedure (for example asm
optimization)?
PutPixel is slow because each time it is called a lot of addional things are
done (checking wether the pixel coordinates are valid, using different
methods depending on the pixel format and much more). it is much faster if
you access the memory directly, but also more difficult, because now it's
your turn to do it the right way. If you want to modify the pixels of a
bitmap, use TBitmap's ScanLine property, which returns a pointer to the
pixel data. Use this pointer to modify the single bytes (or words, dwords).
You need different code for different pixel formats (except if you know for
sure that you use your routine only for some certain pixel format).
Quote
How can DirectX and OpenGL make it so fast? I know they don't use GDI but
what?
Pixels on your screen can be access this way, too, but you need DirectX.
Using DirectDraw you can get a pointer to your screen pixel data similar to
TBitmap.ScanLine (take a look at DirectDraw surfaces). To display 3D objects
Direct3D and OpenGL are using the hardware even more directly (if possible),
without the need to modify single pixels.
Jens
 

Re:Very fast putpixel

P.S. For fast pixel manipulation using MMX can also speed up things, but you
should have some assembler experience. With MMX you can manipulate several
bytes (for example the red, green and blue color channel of one pixel) at
the same time with only one command. Another advantage is that there are MMX
commands which combine two or more "normal" (8086) commands (like adding
with saturation).
Jens