PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Fastest way to set a specific pixel in screen memory

Hi, Im still getting to grips with GAPI programming!

Assume I want to set the pixel (u,v) to the color c. What is the quickest way to do this? Is the following code reasonable?

============================

unsigned short * pusLine = (unsigned short *)GXBeginDraw();
if (pusLine == NULL) return false;
y = 0;
while(y<v)
{
pusLine += g_gxdp.cbyPitch >> 1;
++y;
}

unsigned short *pusDest = pusLine;
x = 0;
while(x < u)
{
pusDest += g_gxdp.cbxPitch >> 1;
++x;
}
*pusDest = c;
Why not use multiplication? ;)

Code:
unsigned short * pusLine = (unsigned short *)GXBeginDraw();
if (pusLine == NULL) return false;

pusLine += (g_gxdp.cbyPitch >> 1) * v;
pusLine += (g_gxdp.cbxPitch >> 1) * u;

*pusLine=c;


It will also be faster to pass the pusLine to the function rather than call GXBeginDraw for every pixel.
thanks, so obvious eh?
Don't forget, while there is a slight overhead with calling GXBeginDraw() / GXEndDraw() every frame, if you don't, it will not work on MIPS or SH-3 devices if you wish to support them.
You don't have to call on ARM (and presuamably X-SCALE too) devices.
If you are writing to the memory addressed by the value returned by GXBeginDraw AND GXIsDisplayDRAMBuffer returns a non-zero value, then you must call GXEndDraw each frame, regardless of the platform.