Add an internal _cogl_bitmap_new_from_buffer

This function creates a CoglBitmap which internally references a
CoglBuffer. The map and unmap functions will divert to mapping the
buffer. There are also now bind and unbind functions which should be
used instead of map and unmap whenever the data doesn't need to be
read from the CPU but will instead be passed to GL for packing or
unpacking. For bitmaps created from buffers this just binds the
bitmap.

cogl_texture_new_from_buffer now just uses this function to wrap the
buffer in a bitmap rather than trying to bind the buffer
immediately. This means that the buffer will be bound only at the
point right before the texture data is uploaded.

This approach means that using a pixel array will take the fastest
upload route if possible, but can still fallback to copying the data
by mapping the buffer if some conversion is needed. Previously it
would just crash in this case because the texture functions were all
passed a NULL pointer.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2112
This commit is contained in:
Neil Roberts
2010-07-15 13:05:55 +01:00
parent e5dc645753
commit 4eca571a32
5 changed files with 256 additions and 130 deletions

View File

@ -82,6 +82,17 @@ _cogl_bitmap_new_shared (CoglBitmap *shared_bmp,
int height,
int rowstride);
/* This creates a cogl bitmap that internally references a pixel
array. The data is not copied. _cogl_bitmap_map will divert to
mapping the pixel array */
CoglBitmap *
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
CoglPixelFormat format,
int width,
int height,
int rowstride,
int offset);
gboolean
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
@ -173,4 +184,18 @@ _cogl_bitmap_map (CoglBitmap *bitmap,
void
_cogl_bitmap_unmap (CoglBitmap *bitmap);
/* These two are replacements for map and unmap that should used when
the pointer is going to be passed to GL for pixel packing or
unpacking. The address might not be valid for reading if the bitmap
was created with new_from_buffer but it will however be good to
pass to glTexImage2D for example. The access should be READ for
unpacking and WRITE for packing. It can not be both */
guint8 *
_cogl_bitmap_bind (CoglBitmap *bitmap,
CoglBufferAccess access,
CoglBufferMapHint hints);
void
_cogl_bitmap_unbind (CoglBitmap *bitmap);
#endif /* __COGL_BITMAP_H */