2010-01-10 12:28:24 -05:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C)2010 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Damien Lespiau <damien.lespiau@intel.com>
|
2010-07-05 11:14:00 -04:00
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
2010-01-10 12:28:24 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
|
|
|
#error "Only <cogl/cogl.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __COGL_BUFFER_H__
|
|
|
|
#define __COGL_BUFFER_H__
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <cogl/cogl-types.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:cogl-buffer
|
2011-06-27 06:16:21 -04:00
|
|
|
* @short_description: Common buffer functions, including data upload APIs
|
2010-01-10 12:28:24 -05:00
|
|
|
* @stability: Unstable
|
|
|
|
*
|
2011-06-27 06:16:21 -04:00
|
|
|
* 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.
|
2010-01-10 12:28:24 -05:00
|
|
|
*/
|
|
|
|
|
2010-06-30 13:06:04 -04:00
|
|
|
/* All of the cogl-buffer API is currently experimental so we suffix
|
|
|
|
* the actual symbols with _EXP so if somone is monitoring for ABI
|
|
|
|
* changes it will hopefully be clearer to them what's going on if any
|
|
|
|
* of the symbols dissapear at a later date.
|
|
|
|
*/
|
|
|
|
#define cogl_is_buffer cogl_is_buffer_EXP
|
|
|
|
#define cogl_buffer_get_size cogl_buffer_get_size_EXP
|
|
|
|
#define cogl_buffer_set_usage_hint cogl_buffer_set_usage_hint_EXP
|
|
|
|
#define cogl_buffer_get_usage_hint cogl_buffer_get_usage_hint_EXP
|
|
|
|
#define cogl_buffer_set_update_hint cogl_buffer_set_update_hint_EXP
|
|
|
|
#define cogl_buffer_get_update_hint cogl_buffer_get_update_hint_EXP
|
|
|
|
#define cogl_buffer_map cogl_buffer_map_EXP
|
|
|
|
#define cogl_buffer_unmap cogl_buffer_unmap_EXP
|
|
|
|
#define cogl_buffer_set_data cogl_buffer_set_data_EXP
|
|
|
|
|
2010-05-27 18:40:40 -04:00
|
|
|
typedef struct _CoglBuffer CoglBuffer;
|
|
|
|
|
2010-01-10 12:28:24 -05:00
|
|
|
/**
|
|
|
|
* cogl_is_buffer:
|
2010-06-30 13:06:04 -04:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
2010-05-27 18:40:40 -04:00
|
|
|
* Checks whether @buffer is a buffer object.
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-06-30 13:06:04 -04:00
|
|
|
cogl_is_buffer (const void *object);
|
2010-01-10 12:28:24 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_get_size:
|
2010-05-27 18:40:40 -04:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
|
|
|
* Retrieves the size of buffer
|
|
|
|
*
|
|
|
|
* Return value: the size of the buffer in bytes
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
unsigned int
|
2010-05-27 18:40:40 -04:00
|
|
|
cogl_buffer_get_size (CoglBuffer *buffer);
|
2010-01-10 12:28:24 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CoglBufferUpdateHint:
|
|
|
|
* @COGL_BUFFER_UPDATE_HINT_STATIC: the buffer will not change over time
|
|
|
|
* @COGL_BUFFER_UPDATE_HINT_DYNAMIC: the buffer will change from time to time
|
|
|
|
* @COGL_BUFFER_UPDATE_HINT_STREAM: the buffer will be used once or a couple of
|
|
|
|
* times
|
|
|
|
*
|
2010-02-09 09:41:37 -05:00
|
|
|
* The update hint on a buffer allows the user to give some detail on how often
|
2010-01-10 12:28:24 -05:00
|
|
|
* the buffer data is going to be updated.
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
|
|
|
|
COGL_BUFFER_UPDATE_HINT_STATIC,
|
|
|
|
COGL_BUFFER_UPDATE_HINT_DYNAMIC,
|
|
|
|
COGL_BUFFER_UPDATE_HINT_STREAM
|
|
|
|
} CoglBufferUpdateHint;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_set_update_hint:
|
2010-05-27 18:40:40 -04:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 12:28:24 -05:00
|
|
|
* @hint: the new hint
|
|
|
|
*
|
2010-02-09 09:41:37 -05:00
|
|
|
* Sets the update hint on a buffer. See #CoglBufferUpdateHint for a description
|
2010-01-10 12:28:24 -05:00
|
|
|
* of the available hints.
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
void
|
2010-05-27 18:40:40 -04:00
|
|
|
cogl_buffer_set_update_hint (CoglBuffer *buffer,
|
2010-01-10 12:28:24 -05:00
|
|
|
CoglBufferUpdateHint hint);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_get_update_hint:
|
2010-05-27 18:40:40 -04:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
2010-02-09 09:41:37 -05:00
|
|
|
* Retrieves the update hints set using cogl_buffer_set_update_hint()
|
|
|
|
*
|
2010-01-10 12:28:24 -05:00
|
|
|
* Return value: the #CoglBufferUpdateHint currently used by the buffer
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
CoglBufferUpdateHint
|
2010-05-27 18:40:40 -04:00
|
|
|
cogl_buffer_get_update_hint (CoglBuffer *buffer);
|
2010-01-10 12:28:24 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CoglBufferAccess:
|
|
|
|
* @COGL_BUFFER_ACCESS_READ: the buffer will be read
|
|
|
|
* @COGL_BUFFER_ACCESS_WRITE: the buffer will written to
|
|
|
|
* @COGL_BUFFER_ACCESS_READ_WRITE: the buffer will be used for both reading and
|
|
|
|
* writing
|
|
|
|
*
|
2010-02-09 09:41:37 -05:00
|
|
|
* The access hints for cogl_buffer_set_update_hint()
|
|
|
|
*
|
2010-01-10 12:28:24 -05:00
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
|
|
|
|
COGL_BUFFER_ACCESS_READ = 1 << 0,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE = 1 << 1,
|
2010-09-15 06:56:59 -04:00
|
|
|
COGL_BUFFER_ACCESS_READ_WRITE = COGL_BUFFER_ACCESS_READ | COGL_BUFFER_ACCESS_WRITE
|
2010-01-10 12:28:24 -05:00
|
|
|
} CoglBufferAccess;
|
|
|
|
|
2010-07-05 11:14:00 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CoglBufferMapHint:
|
2010-12-22 04:42:41 -05:00
|
|
|
* @COGL_BUFFER_MAP_HINT_DISCARD: Tells Cogl that you plan to replace
|
|
|
|
* all the buffer's contents.
|
2010-07-05 11:14:00 -04:00
|
|
|
*
|
|
|
|
* Hints to Cogl about how you are planning to modify the data once it
|
|
|
|
* is mapped.
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
typedef enum { /*< prefix=COGL_BUFFER_MAP_HINT >*/
|
2010-12-22 04:42:41 -05:00
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD = 1 << 0
|
2010-07-05 11:14:00 -04:00
|
|
|
} CoglBufferMapHint;
|
|
|
|
|
2010-01-10 12:28:24 -05:00
|
|
|
/**
|
|
|
|
* cogl_buffer_map:
|
2010-05-27 18:40:40 -04:00
|
|
|
* @buffer: a buffer object
|
2010-07-05 11:14:00 -04:00
|
|
|
* @access: how the mapped buffer will be used by the application
|
|
|
|
* @hints: A mask of #CoglBufferMapHint<!-- -->s that tell Cogl how
|
2010-12-22 04:42:41 -05:00
|
|
|
* the data will be modified once mapped.
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
|
|
|
* Maps the buffer into the application address space for direct access.
|
|
|
|
*
|
2010-07-05 11:14:00 -04:00
|
|
|
* 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
|
2010-07-05 18:32:55 -04:00
|
|
|
* conflicting with the @access mask you pass. It is also an error to
|
|
|
|
* release your last reference while the buffer is mapped.
|
2010-07-05 11:14:00 -04:00
|
|
|
*
|
2010-01-10 12:28:24 -05:00
|
|
|
* Return value: A pointer to the mapped memory or %NULL is the call fails
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
2010-11-04 12:01:23 -04:00
|
|
|
void *
|
2010-07-05 11:14:00 -04:00
|
|
|
cogl_buffer_map (CoglBuffer *buffer,
|
|
|
|
CoglBufferAccess access,
|
|
|
|
CoglBufferMapHint hints);
|
2010-01-10 12:28:24 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_unmap:
|
2010-05-27 18:40:40 -04:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
|
|
|
* Unmaps a buffer previously mapped by cogl_buffer_map().
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
void
|
2010-05-27 18:40:40 -04:00
|
|
|
cogl_buffer_unmap (CoglBuffer *buffer);
|
2010-01-10 12:28:24 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_set_data:
|
2010-05-27 18:40:40 -04:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 12:28:24 -05:00
|
|
|
* @offset: destination offset (in bytes) in the buffer
|
|
|
|
* @data: a pointer to the data to be copied into the buffer
|
|
|
|
* @size: number of bytes to copy
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE is the operation succeeded, %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
|
|
|
* Stability: Unstable
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-05-27 18:40:40 -04:00
|
|
|
cogl_buffer_set_data (CoglBuffer *buffer,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
gsize offset,
|
2010-11-04 12:01:23 -04:00
|
|
|
const void *data,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
gsize size);
|
2010-01-10 12:28:24 -05:00
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __COGL_BUFFER_H__ */
|