![]() |
![]() |
![]() |
Cogl 2.0 Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
CoglBuffer: The Buffer InterfaceCoglBuffer: The Buffer Interface — Common buffer functions, including data upload APIs |
CoglBool cogl_is_buffer (void *object
); unsigned int cogl_buffer_get_size (CoglBuffer *buffer
); enum CoglBufferUpdateHint; void cogl_buffer_set_update_hint (CoglBuffer *buffer
,CoglBufferUpdateHint hint
); CoglBufferUpdateHint cogl_buffer_get_update_hint (CoglBuffer *buffer
); enum CoglBufferAccess; void * cogl_buffer_map (CoglBuffer *buffer
,CoglBufferAccess access
,CoglBufferMapHint hints
); void cogl_buffer_unmap (CoglBuffer *buffer
); CoglBool cogl_buffer_set_data (CoglBuffer *buffer
,size_t offset
,const void *data
,size_t size
); #define cogl_pixel_buffer_new #define cogl_is_pixel_buffer
The CoglBuffer API provides a common interface to manipulate
buffers that have been allocated either via cogl_pixel_buffer_new()
or cogl_attribute_buffer_new()
. The API allows you to upload data
to these buffers and define usage hints that help Cogl manage your
buffer optimally.
Data can either be uploaded by supplying a pointer and size so Cogl
can copy your data, or you can mmap()
a CoglBuffer and then you can
copy data to the buffer directly.
One of the most common uses for CoglBuffers is to upload texture data asynchronously since the ability to mmap the buffers into the CPU makes it possible for another thread to handle the IO of loading an image file and unpacking it into the mapped buffer without blocking other Cogl operations.
CoglBool cogl_is_buffer (void *object
);
Checks whether buffer
is a buffer object.
Since 1.2
Stability Level: Unstable
unsigned int cogl_buffer_get_size (CoglBuffer *buffer
);
Retrieves the size of buffer
|
a buffer object |
Returns : |
the size of the buffer in bytes |
Since 1.2
Stability Level: Unstable
typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/ COGL_BUFFER_UPDATE_HINT_STATIC, COGL_BUFFER_UPDATE_HINT_DYNAMIC, COGL_BUFFER_UPDATE_HINT_STREAM } CoglBufferUpdateHint;
The update hint on a buffer allows the user to give some detail on how often the buffer data is going to be updated.
the buffer will not change over time | |
the buffer will change from time to time | |
the buffer will be used once or a couple of times |
Since 1.2
Stability Level: Unstable
void cogl_buffer_set_update_hint (CoglBuffer *buffer
,CoglBufferUpdateHint hint
);
Sets the update hint on a buffer. See CoglBufferUpdateHint for a description of the available hints.
|
a buffer object |
|
the new hint |
Since 1.2
Stability Level: Unstable
CoglBufferUpdateHint cogl_buffer_get_update_hint (CoglBuffer *buffer
);
Retrieves the update hints set using cogl_buffer_set_update_hint()
|
a buffer object |
Returns : |
the CoglBufferUpdateHint currently used by the buffer |
Since 1.2
Stability Level: Unstable
typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/ COGL_BUFFER_ACCESS_READ = 1 << 0, COGL_BUFFER_ACCESS_WRITE = 1 << 1, COGL_BUFFER_ACCESS_READ_WRITE = COGL_BUFFER_ACCESS_READ | COGL_BUFFER_ACCESS_WRITE } CoglBufferAccess;
The access hints for cogl_buffer_set_update_hint()
the buffer will be read | |
the buffer will written to | |
the buffer will be used for both reading and writing |
Since 1.2
Stability Level: Unstable
void * cogl_buffer_map (CoglBuffer *buffer
,CoglBufferAccess access
,CoglBufferMapHint hints
);
Maps the buffer into the application address space for direct access.
It is strongly recommended that you pass
COGL_BUFFER_MAP_HINT_DISCARD
as a hint if you are going to replace
all the buffer's data. This way if the buffer is currently being
used by the GPU then the driver won't have to stall the CPU and
wait for the hardware to finish because it can instead allocate a
new buffer to map.
The behaviour is undefined if you access the buffer in a way
conflicting with the access
mask you pass. It is also an error to
release your last reference while the buffer is mapped.
|
a buffer object |
|
how the mapped buffer will be used by the application |
|
A mask of CoglBufferMapHints that tell Cogl how the data will be modified once mapped. |
Returns : |
A pointer to the mapped memory or NULL is the call fails |
Since 1.2
Stability Level: Unstable
void cogl_buffer_unmap (CoglBuffer *buffer
);
Unmaps a buffer previously mapped by cogl_buffer_map()
.
|
a buffer object |
Since 1.2
Stability Level: Unstable
CoglBool cogl_buffer_set_data (CoglBuffer *buffer
,size_t offset
,const void *data
,size_t size
);
Updates part of the buffer with new data from data
. Where to put this new
data is controlled by offset
and offset
+ data
should be less than the
buffer size.
|
a buffer object |
|
destination offset (in bytes) in the buffer |
|
a pointer to the data to be copied into the buffer |
|
number of bytes to copy |
Returns : |
TRUE is the operation succeeded, FALSE otherwise |
Since 1.2
Stability Level: Unstable
#define cogl_pixel_buffer_new cogl_pixel_buffer_new_EXP
Declares a new CoglPixelBuffer of size
bytes to contain arrays of
pixels. Once declared, data can be set using cogl_buffer_set_data()
or by mapping it into the application's address space using
cogl_buffer_map()
.
If data
isn't NULL
then size
bytes will be read from data
and
immediately copied into the new buffer.
|
A CoglContext |
|
The number of bytes to allocate for the pixel data. |
|
An optional pointer to vertex data to upload immediately |
Since 1.10
Stability Level: Unstable
#define cogl_is_pixel_buffer cogl_is_pixel_buffer_EXP
Checks whether object
is a pixel buffer.
|
a CoglObject to test |
Returns : |
TRUE if the object is a pixel buffer, and FALSE
otherwise |
Since 1.2
Stability Level: Unstable