PocketMatrix forums

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

What exactly does GetBuffer() do?

Hi, I'm a newbie here and I've been trying to learn and understand GapiDraw a bit more. What exactly does GetBuffer() and ReleaseBuffer() do? Will it make my app run faster instead of just using the backbuffer that was used in most of the sample codes in GapiDraw?

Also, what does Lock and Unlock do? I'm really sorry for these questions, I just want to know why do I exactly need to use these (if ever). I didn't quite understand what was explained in the docs.

Many thanks! :-)
GetBuffer returns pointer to actual memory.
It is useful only if you need to manipulate pixels using your own code.
The problem with GetBuffer returned memory is that the layout of this memory is device dependant (rotated) which makes things much more complicated.
You can use Lock/Unlock calls to get a generic memory buffer but these calls translate the buffer back and forth which can be slow.
So , as always, you got to make some choices ....

To summarize: unless you need to manipulate pixels ( memory ) directly, you will never make any use of Lock/GetBuffer calls.
Thanks! I thought there was something in there that can improve my game's performance. :-)
<img src="http://cellosoft.com/marcello/pocketpc/pocketww05.gif" width="240" height="320" align="right">
Ok, so I'm working on this little game with GapiDraw, Pocket WaterWorks. (http://cellosoft.com/marcello/pocketpc/)

So I started out using get and setpixel functions in the surface class, it worked, people liked it, etc.

After realizing that Set/get pixel seem to do weird scary stuff with converting color formats behind my back, I decided to access the memory buffer directly by using the GetBuffer routine and my own pixel accessing.

The problem is, although it works fine on my 16bit color PocketPC2002 device, I'm not getting error reports from people with 12bit devices, with apparent alignment problems.

One person complained that pixels move diagonally, and parts being displayed as dotted lines.

My question, then, is how do I handle non 16bit devices. Although these screens are 12bit, am I correct in understanding the display itself can only handle 8bit colors. In which case, how do I use these things with GapiDraw---since it obviously handles it when I use the built in set/get pixel routines.

Also, is there any particular reason GapiDraw isn't open-source? I would much like to look at how the different things work, so my code will be cleaner. The library is somewhat non-descript on the inner workings...which makes it extremely difficult to program with/for. I like GapiDraw, but the lack of source makes it very difficult to use.

So I guess my question is, how can I access pixels with set/get routines, but using native colors instead of COLORREF's. How do I handle screens that aren't 16bit.

Here is my code for get/set:

Code:

bool CProject::setPixel(DWORD x, DWORD y, WORD color) {
if (x>=dwWidth || y>=dwHeight) return false;
*pBuffer + (x * xPitch + y * yPitch)) = color;
return true;
}
bool CProject::getPixel(DWORD x, DWORD y, WORD *color) {
if (x>=dwWidth || y>=dwHeight) return false;
*color = *(pBuffer + (x * xPitch + y * yPitch));
return true;
}


Right now I'm just using the GapiDrawExtension.h converters to translate from 24bit to 16bit color, but how do I translate to lower depths?

Thanks,

Marcello
I was under the impression that get buffer in GapiDraw would give you the standard orientation you specify(device independent). Otherwise you could just use the Gapi calls to grab direct access to the buffer. I am currently checkin this out since I need it for a new game I'm writing. Sbl, please correct me if I'm wrong.
Marcello:

(1) 12 bit displays are accessed as 16-bit displays. There is no difference. The only difference is that the DAC only use 4 bits for each RGB color value.

(2) In your code sample, how is pBuffer declared?

Please note that xPitch and yPitch returned from GapiDraw are returned as BYTES. If pBuffer is declared as WORD* pBuffer you should divide xPitch and yPitch by 2. Otherwise the code seems like it should work out ok.

Efortier: GetBuffer always returns the GAPI-compatible buffer. It will be aligned differently on different PDAs.
The problem was that of alignment, my old code didn't take the pitch's into account. The code I pasted does work. (Somehow I figured this would happen, after I posted...)

Everything works fine now, thanks.

Marcello