Board index » delphi » Very fast putpixel
Mikko Tammela
![]() Delphi Developer |
Mikko Tammela
![]() Delphi Developer |
Very fast putpixel2004-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; |
Jens Gruschel
![]() Delphi Developer |
2004-01-10 09:15:23 PM
Re:Very fast putpixelQuoteIs there some way to speed up this putpixel procedure (for example asm 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). QuoteHow can DirectX and OpenGL make it so fast? I know they don't use GDI but 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 |
Jens Gruschel
![]() Delphi Developer |
2004-01-10 09:26:18 PM
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 |