[Mesa-users] Off-Screen Rendering

tom fogal tfogal at alumni.unh.edu
Sat Oct 9 13:25:31 PDT 2010


Tim Gustafson <tjg at tgustafson.com> writes:
> I just successfully compiled the osdemo.c program, which illustrates
> off-screen rendering.  The program is working very well, but as it
> turns out Targa is not really a very helpful format when it comes to
> web media, which is what my project is targeted at.  So far, I've
> been using GD to manipulate 2D image data and I was wondering if the
> data format that is output by off-screen rendering is "XBM" or "XPM"
> format?  Or do I need to go through all the pixels in the memory
> buffer and do a SetPixel instruction in GD for each one of them?

The buffer Mesa uses internally is not specific to any image format.
AFAICT it is not documented other than in the code.  I would not rely
on it.

That said, I don't see how Mesa could work with it, given
OSMesaMakeCurrent's signature, unless it was simply a raw array of
bytes.

> To phrase the question another way: what's the shortest path from the
> data in a Mesa OSMesaCreateContext buffer to a PNG, GIF or JPG file?

Despite what the demo does, I recommend you save the buffer internally
for the sole reason of being able to deallocate.  Otherwise, forget
about it.

When you need to write out an image, allocate an unrelated buffer
and use glReadPixels.  This involves an extra copy, but it won't be
a big deal.  Further, other than context creation, your code is then
"straight" GL code and will work unmodified given any other GL context.

glReadPixels is of course well documented.  You get a raw array of
bytes; if you want a png, look at libpng's docs and write it out.
Likewise for GIF and JPEG.

HTH,

-tom


More information about the mesa-users mailing list