Archived

This topic is now archived and is closed to further replies.

Vulcan

DirectX pixel plotting

Recommended Posts

Is there a faster way that this: inline PutPixel(int x, int y, unsigned short color, unsigned short *buffer, int lpitch) { buffer[x+(y*(lpitch>>1))] = color; return 0;} inline unsigned short ReturnPixel(int x, int y, unsigned short *buffer, int lpitch) { return (buffer[x+(y*(lpitch>>1))]);} to put and return pixels on a 16 bit surface? -Vulcan

Share this post


Link to post
Share on other sites
I can't think of a faster method conceptually...but maybe a little assembly could outperform your compiler???
            
asm
{
mov eax, lpitch
mov ebx, buffer
mov cx, color

shr eax, 1 // eax = lpitch/2

mul y // eax *= y

add eax, x // eax += x

add ebx, eax // ebx += eax


mov [ebx], WORD PTR cx // dest pixel = color

}


...Hope this helps a little, maybe???
OOPS, had to modify to move *16* bits to pixel
(I'm used to 32 bit color).


Edited by - asmLOCK on October 30, 2000 1:14:05 PM

Share this post


Link to post
Share on other sites
To make it a bit faster you should store all your lpitches in words rather than in bytes, this will eliminate the >> 1. It may not seem like much of an improvement but when you''re plotting several thousand pixels per frame they add up.



Please state the nature of the debugging emergency.


sharewaregames.20m.com

Share this post


Link to post
Share on other sites
I dont actually think there is a faster way of doing this. I certainly dont think that you can outperform you compiler by write a buffer-access in asm, the compiler will do this just as fast for you.

What you can do, is to actually remove the putpixel function.
The compiler will not guarantie that it will make it inline,
and you do not want 1 functioncall per pixel, promise
Write to the buffer directly instead, this can make a big difference if the compiler choose to not inline you putpixel.

Also, follow furbie100''s tip ,if you know that you are using 16 bit surfaces, and store your pitches in words instead of bytes.

/ Tooon


Share this post


Link to post
Share on other sites
Actually, as far as Assembly vs. Compiler, I compiled the C/C++ method...
    
pSurface[((Pitch>>1)*Y)+X] = Color;


It created 9 lines of asm code, only 1 more than my 8 lines...fine, good enough.
However, 8 of these 9 had a memory reference(as opposed to my 4).
That can''t be good.


When life hands you lemons, throw them at God's head.

Share this post


Link to post
Share on other sites
wow...another guy that knows asm...

and take care it should be x*2 there i think...(if in 16bits)

However 8 reads from memory form the C compiler as opposed to 4 reads in above example makes C code 100% slower (1/2 speed) i think...

Not a very good compiler i think...

Bogdan

Share this post


Link to post
Share on other sites
You're right, it should be (2*x) instead of just (x)...I'm used to calculating the logical offset first, then adjusting the whole thing by the pixel depth. I don't really use pitch:

    pSurface[((y*width)+x) * BPPscale] = Color;    

...where BPPscale is the scale factor of the pixel depth/size.

1 = 8-bit
2 = 16-bit
4 = 32-bit

Anyway, this thread is way too long.


When life hands you lemons, throw them at God's head.

Edited by - asmLOCK on November 1, 2000 1:03:25 PM

Share this post


Link to post
Share on other sites