4 * An object oriented GL/GLES Abstraction/Utility Layer
6 * Copyright (C)2010 Intel Corporation.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 * Damien Lespiau <damien.lespiau@intel.com>
25 * Robert Bragg <robert@linux.intel.com>
28 #if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
29 #error "Only <cogl/cogl.h> can be included directly."
32 #ifndef __COGL_BUFFER_H__
33 #define __COGL_BUFFER_H__
36 #include <cogl/cogl-types.h>
42 * @short_description: Common buffer functions, including data upload APIs
43 * @stability: unstable
45 * The CoglBuffer API provides a common interface to manipulate
46 * buffers that have been allocated either via cogl_pixel_buffer_new()
47 * or cogl_attribute_buffer_new(). The API allows you to upload data
48 * to these buffers and define usage hints that help Cogl manage your
51 * Data can either be uploaded by supplying a pointer and size so Cogl
52 * can copy your data, or you can mmap() a CoglBuffer and then you can
53 * copy data to the buffer directly.
55 * One of the most common uses for CoglBuffers is to upload texture
56 * data asynchronously since the ability to mmap the buffers into
57 * the CPU makes it possible for another thread to handle the IO
58 * of loading an image file and unpacking it into the mapped buffer
59 * without blocking other Cogl operations.
62 #define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer))
64 typedef struct _CoglBuffer CoglBuffer;
68 * @object: a buffer object
70 * Checks whether @buffer is a buffer object.
72 * Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise
78 cogl_is_buffer (void *object);
81 * cogl_buffer_get_size:
82 * @buffer: a buffer object
84 * Retrieves the size of buffer
86 * Return value: the size of the buffer in bytes
92 cogl_buffer_get_size (CoglBuffer *buffer);
95 * CoglBufferUpdateHint:
96 * @COGL_BUFFER_UPDATE_HINT_STATIC: the buffer will not change over time
97 * @COGL_BUFFER_UPDATE_HINT_DYNAMIC: the buffer will change from time to time
98 * @COGL_BUFFER_UPDATE_HINT_STREAM: the buffer will be used once or a couple of
101 * The update hint on a buffer allows the user to give some detail on how often
102 * the buffer data is going to be updated.
105 * Stability: unstable
107 typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
108 COGL_BUFFER_UPDATE_HINT_STATIC,
109 COGL_BUFFER_UPDATE_HINT_DYNAMIC,
110 COGL_BUFFER_UPDATE_HINT_STREAM
111 } CoglBufferUpdateHint;
114 * cogl_buffer_set_update_hint:
115 * @buffer: a buffer object
116 * @hint: the new hint
118 * Sets the update hint on a buffer. See #CoglBufferUpdateHint for a description
119 * of the available hints.
122 * Stability: unstable
125 cogl_buffer_set_update_hint (CoglBuffer *buffer,
126 CoglBufferUpdateHint hint);
129 * cogl_buffer_get_update_hint:
130 * @buffer: a buffer object
132 * Retrieves the update hints set using cogl_buffer_set_update_hint()
134 * Return value: the #CoglBufferUpdateHint currently used by the buffer
137 * Stability: unstable
140 cogl_buffer_get_update_hint (CoglBuffer *buffer);
144 * @COGL_BUFFER_ACCESS_READ: the buffer will be read
145 * @COGL_BUFFER_ACCESS_WRITE: the buffer will written to
146 * @COGL_BUFFER_ACCESS_READ_WRITE: the buffer will be used for both reading and
149 * The access hints for cogl_buffer_set_update_hint()
152 * Stability: unstable
154 typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
155 COGL_BUFFER_ACCESS_READ = 1 << 0,
156 COGL_BUFFER_ACCESS_WRITE = 1 << 1,
157 COGL_BUFFER_ACCESS_READ_WRITE = COGL_BUFFER_ACCESS_READ | COGL_BUFFER_ACCESS_WRITE
163 * @COGL_BUFFER_MAP_HINT_DISCARD: Tells Cogl that you plan to replace
164 * all the buffer's contents.
166 * Hints to Cogl about how you are planning to modify the data once it
170 * Stability: unstable
172 typedef enum { /*< prefix=COGL_BUFFER_MAP_HINT >*/
173 COGL_BUFFER_MAP_HINT_DISCARD = 1 << 0
178 * @buffer: a buffer object
179 * @access: how the mapped buffer will be used by the application
180 * @hints: A mask of #CoglBufferMapHint<!-- -->s that tell Cogl how
181 * the data will be modified once mapped.
183 * Maps the buffer into the application address space for direct access.
185 * It is strongly recommended that you pass
186 * %COGL_BUFFER_MAP_HINT_DISCARD as a hint if you are going to replace
187 * all the buffer's data. This way if the buffer is currently being
188 * used by the GPU then the driver won't have to stall the CPU and
189 * wait for the hardware to finish because it can instead allocate a
192 * The behaviour is undefined if you access the buffer in a way
193 * conflicting with the @access mask you pass. It is also an error to
194 * release your last reference while the buffer is mapped.
196 * Return value: A pointer to the mapped memory or %NULL is the call fails
199 * Stability: unstable
202 cogl_buffer_map (CoglBuffer *buffer,
203 CoglBufferAccess access,
204 CoglBufferMapHint hints);
208 * @buffer: a buffer object
210 * Unmaps a buffer previously mapped by cogl_buffer_map().
213 * Stability: unstable
216 cogl_buffer_unmap (CoglBuffer *buffer);
219 * cogl_buffer_set_data:
220 * @buffer: a buffer object
221 * @offset: destination offset (in bytes) in the buffer
222 * @data: a pointer to the data to be copied into the buffer
223 * @size: number of bytes to copy
225 * Updates part of the buffer with new data from @data. Where to put this new
226 * data is controlled by @offset and @offset + @data should be less than the
229 * Return value: %TRUE is the operation succeeded, %FALSE otherwise
232 * Stability: unstable
235 cogl_buffer_set_data (CoglBuffer *buffer,
242 #endif /* __COGL_BUFFER_H__ */