cogl-buffer: add an abstract class around openGL's buffer objects
Buffer objects are cool! This abstracts the buffer API first introduced by GL_ARB_vertex_buffer_object and then extended to other objects. The coglBuffer abstract class is intended to be the base class of all the buffer objects, letting the user map() buffers. If the underlying implementation does not support buffer objects (or only support VBO but not FBO for instance), fallback paths should be provided.
This commit is contained in:
parent
de8a6314f1
commit
b5e9710cdf
@ -54,6 +54,7 @@ DISTCLEANFILES += cogl-defines.h
|
||||
# public headers
|
||||
cogl_public_h = \
|
||||
$(srcdir)/cogl-bitmap.h \
|
||||
$(srcdir)/cogl-buffer.h \
|
||||
$(srcdir)/cogl-color.h \
|
||||
$(srcdir)/cogl-debug.h \
|
||||
$(srcdir)/cogl-fixed.h \
|
||||
@ -101,6 +102,8 @@ cogl_sources_c = \
|
||||
$(srcdir)/cogl-feature-private.c \
|
||||
$(srcdir)/cogl-fixed.c \
|
||||
$(srcdir)/cogl-color.c \
|
||||
$(srcdir)/cogl-buffer-private.h \
|
||||
$(srcdir)/cogl-buffer.c \
|
||||
$(srcdir)/cogl-vertex-buffer-private.h \
|
||||
$(srcdir)/cogl-vertex-buffer.c \
|
||||
$(srcdir)/cogl-matrix.c \
|
||||
|
102
clutter/cogl/cogl/cogl-buffer-private.h
Normal file
102
clutter/cogl/cogl/cogl-buffer-private.h
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Damien Lespiau <damien.lespiau@intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __COGL_BUFFER_PRIVATE_H__
|
||||
#define __COGL_BUFFER_PRIVATE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-buffer.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer))
|
||||
|
||||
#define COGL_BUFFER_SET_FLAG(buffer, flag) \
|
||||
((buffer)->flags |= (COGL_BUFFER_FLAG_ ## flag))
|
||||
|
||||
#define COGL_BUFFER_CLEAR_FLAG(buffer, flag) \
|
||||
((buffer)->flags &= ~(COGL_BUFFER_FLAG_ ## flag))
|
||||
|
||||
#define COGL_BUFFER_FLAG_IS_SET(buffer, flag) \
|
||||
((buffer)->flags & (COGL_BUFFER_FLAG_ ## flag))
|
||||
|
||||
typedef struct _CoglBuffer CoglBuffer;
|
||||
typedef struct _CoglBufferVtable CoglBufferVtable;
|
||||
|
||||
struct _CoglBufferVtable
|
||||
{
|
||||
guchar * (* map) (CoglBuffer *buffer,
|
||||
CoglBufferAccess access);
|
||||
|
||||
void (* unmap) (CoglBuffer *buffer);
|
||||
|
||||
gboolean (* set_data) (CoglBuffer *buffer,
|
||||
guint offset,
|
||||
const guchar *data,
|
||||
guint size);
|
||||
};
|
||||
|
||||
typedef enum _CoglBufferFlags
|
||||
{
|
||||
COGL_BUFFER_FLAG_NONE = 0,
|
||||
COGL_BUFFER_FLAG_BUFFER_OBJECT = 1UL << 0, /* real openGL buffer object */
|
||||
COGL_BUFFER_FLAG_MAPPED = 1UL << 1
|
||||
} CoglBufferFlags;
|
||||
|
||||
struct _CoglBuffer
|
||||
{
|
||||
CoglHandleObject _parent;
|
||||
const CoglBufferVtable *vtable;
|
||||
|
||||
CoglBufferFlags flags;
|
||||
|
||||
GLuint gl_handle; /* OpenGL handle */
|
||||
guint size; /* size of the buffer, in bytes */
|
||||
CoglBufferUsageHint usage_hint;
|
||||
CoglBufferUpdateHint update_hint;
|
||||
|
||||
guchar *data; /* points to the mapped memory when
|
||||
* the CoglBuffer is a VBO, PBO, ... or
|
||||
* points to allocated memory in the
|
||||
* fallback paths */
|
||||
};
|
||||
|
||||
void _cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
guint size,
|
||||
CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint);
|
||||
void _cogl_buffer_fini (CoglBuffer *buffer);
|
||||
void _cogl_buffer_bind (CoglBuffer *buffer,
|
||||
GLenum target);
|
||||
GLenum _cogl_buffer_access_to_gl_enum (CoglBufferAccess access);
|
||||
GLenum _cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_BUFFER_PRIVATE_H__ */
|
282
clutter/cogl/cogl/cogl-buffer.c
Normal file
282
clutter/cogl/cogl/cogl-buffer.c
Normal file
@ -0,0 +1,282 @@
|
||||
/*
|
||||
* 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
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Damien Lespiau <damien.lespiau@intel.com>
|
||||
*/
|
||||
|
||||
/* For an overview of the functionality implemented here, please see
|
||||
* cogl-buffer.h, which contains the gtk-doc section overview for the
|
||||
* Pixel Buffers API.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "cogl.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-util.h"
|
||||
#include "cogl-context.h"
|
||||
#include "cogl-handle.h"
|
||||
#include "cogl-pixel-buffer-private.h"
|
||||
|
||||
/*
|
||||
* GL/GLES compatibility defines for the buffer API:
|
||||
*/
|
||||
|
||||
#if defined (HAVE_COGL_GL)
|
||||
|
||||
#define glGenBuffers ctx->drv.pf_glGenBuffers
|
||||
#define glBindBuffer ctx->drv.pf_glBindBuffer
|
||||
#define glBufferData ctx->drv.pf_glBufferData
|
||||
#define glBufferSubData ctx->drv.pf_glBufferSubData
|
||||
#define glGetBufferSubData ctx->drv.pf_glGetBufferSubData
|
||||
#define glDeleteBuffers ctx->drv.pf_glDeleteBuffers
|
||||
#define glMapBuffer ctx->drv.pf_glMapBuffer
|
||||
#define glUnmapBuffer ctx->drv.pf_glUnmapBuffer
|
||||
#define glActiveTexture ctx->drv.pf_glActiveTexture
|
||||
#define glClientActiveTexture ctx->drv.pf_glClientActiveTexture
|
||||
#ifndef GL_ARRAY_BUFFER
|
||||
#define GL_ARRAY_BUFFER GL_ARRAY_BUFFER_ARB
|
||||
#endif
|
||||
|
||||
#elif defined (HAVE_COGL_GLES2)
|
||||
|
||||
#include "../gles/cogl-gles2-wrapper.h"
|
||||
|
||||
#endif
|
||||
|
||||
void cogl_buffer_unmap_EXP (CoglHandle handle);
|
||||
|
||||
gboolean
|
||||
cogl_is_buffer_EXP (CoglHandle handle)
|
||||
{
|
||||
CoglHandleObject *obj = (CoglHandleObject *) handle;
|
||||
|
||||
if (handle == COGL_INVALID_HANDLE)
|
||||
return FALSE;
|
||||
|
||||
return obj->klass->type == _cogl_handle_pixel_buffer_get_type ();
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
guint size,
|
||||
CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
buffer->flags = COGL_BUFFER_FLAG_NONE;
|
||||
buffer->size = size;
|
||||
buffer->usage_hint = usage_hint;
|
||||
buffer->update_hint = update_hint;
|
||||
buffer->data = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_fini (CoglBuffer *buffer)
|
||||
{
|
||||
if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
|
||||
cogl_buffer_unmap (buffer);
|
||||
}
|
||||
|
||||
GLenum
|
||||
_cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
|
||||
{
|
||||
if ((access & COGL_BUFFER_ACCESS_READ_WRITE) == COGL_BUFFER_ACCESS_READ_WRITE)
|
||||
return GL_READ_WRITE;
|
||||
else if (access & COGL_BUFFER_ACCESS_WRITE)
|
||||
return GL_WRITE_ONLY;
|
||||
else
|
||||
return GL_READ_ONLY;
|
||||
}
|
||||
|
||||
GLenum
|
||||
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint)
|
||||
{
|
||||
if (usage_hint == COGL_BUFFER_USAGE_HINT_DRAW)
|
||||
{
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
|
||||
return GL_STATIC_DRAW;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_DYNAMIC)
|
||||
return GL_DYNAMIC_DRAW;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STREAM)
|
||||
return GL_STREAM_DRAW;
|
||||
}
|
||||
if (usage_hint == COGL_BUFFER_USAGE_HINT_READ)
|
||||
{
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
|
||||
return GL_STATIC_READ;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_DYNAMIC)
|
||||
return GL_DYNAMIC_READ;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STREAM)
|
||||
return GL_STREAM_READ;
|
||||
}
|
||||
if (usage_hint == COGL_BUFFER_USAGE_HINT_COPY)
|
||||
{
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
|
||||
return GL_STATIC_COPY;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_DYNAMIC)
|
||||
return GL_DYNAMIC_COPY;
|
||||
if (update_hint == COGL_BUFFER_UPDATE_HINT_STREAM)
|
||||
return GL_STREAM_COPY;
|
||||
}
|
||||
|
||||
return GL_STATIC_DRAW;
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_buffer_bind (CoglBuffer *buffer,
|
||||
GLenum target)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
/* Don't bind again an already bound pbo */
|
||||
if (ctx->current_pbo == buffer)
|
||||
return;
|
||||
|
||||
if (buffer && COGL_BUFFER_FLAG_IS_SET (buffer, BUFFER_OBJECT))
|
||||
{
|
||||
GE( glBindBuffer (target, buffer->gl_handle) );
|
||||
}
|
||||
else if (buffer == NULL &&
|
||||
ctx->current_pbo &&
|
||||
COGL_BUFFER_FLAG_IS_SET (ctx->current_pbo, BUFFER_OBJECT))
|
||||
{
|
||||
GE( glBindBuffer (target, 0) );
|
||||
}
|
||||
|
||||
ctx->current_pbo = buffer;
|
||||
}
|
||||
|
||||
guint
|
||||
cogl_buffer_get_size_EXP (CoglHandle handle)
|
||||
{
|
||||
if (!cogl_is_buffer (handle))
|
||||
return 0;
|
||||
|
||||
return COGL_BUFFER (handle)->size;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_buffer_set_usage_hint_EXP (CoglHandle handle,
|
||||
CoglBufferUsageHint hint)
|
||||
{
|
||||
if (!cogl_is_buffer (handle))
|
||||
return;
|
||||
|
||||
if (G_UNLIKELY (hint > COGL_BUFFER_USAGE_HINT_COPY))
|
||||
hint = COGL_BUFFER_USAGE_HINT_DRAW;
|
||||
|
||||
COGL_BUFFER (handle)->usage_hint = hint;
|
||||
}
|
||||
|
||||
CoglBufferUsageHint
|
||||
cogl_buffer_get_usage_hint_EXP (CoglHandle handle)
|
||||
{
|
||||
if (!cogl_is_buffer (handle))
|
||||
return FALSE;
|
||||
|
||||
return COGL_BUFFER (handle)->usage_hint;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_buffer_set_update_hint_EXP (CoglHandle handle,
|
||||
CoglBufferUpdateHint hint)
|
||||
{
|
||||
if (!cogl_is_buffer (handle))
|
||||
return;
|
||||
|
||||
if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM))
|
||||
hint = COGL_BUFFER_UPDATE_HINT_STATIC;
|
||||
|
||||
COGL_BUFFER (handle)->update_hint = hint;
|
||||
}
|
||||
|
||||
CoglBufferUpdateHint
|
||||
cogl_buffer_get_update_hint_EXP (CoglHandle handle)
|
||||
{
|
||||
if (!cogl_is_buffer (handle))
|
||||
return FALSE;
|
||||
|
||||
return COGL_BUFFER (handle)->update_hint;
|
||||
}
|
||||
|
||||
guchar *
|
||||
cogl_buffer_map_EXP (CoglHandle handle,
|
||||
CoglBufferAccess access)
|
||||
{
|
||||
CoglBuffer *buffer;
|
||||
|
||||
if (!cogl_is_buffer (handle))
|
||||
return FALSE;
|
||||
|
||||
buffer = COGL_BUFFER (handle);
|
||||
|
||||
if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
|
||||
return buffer->data;
|
||||
|
||||
buffer->data = buffer->vtable->map (buffer, access);
|
||||
return buffer->data;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_buffer_unmap_EXP (CoglHandle handle)
|
||||
{
|
||||
CoglBuffer *buffer;
|
||||
|
||||
if (!cogl_is_buffer (handle))
|
||||
return;
|
||||
|
||||
buffer = COGL_BUFFER (handle);
|
||||
|
||||
if (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
|
||||
return;
|
||||
|
||||
return buffer->vtable->unmap (buffer);
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_buffer_set_data_EXP (CoglHandle handle,
|
||||
guint offset,
|
||||
const guchar *data,
|
||||
guint size)
|
||||
{
|
||||
CoglBuffer *buffer;
|
||||
|
||||
if (!cogl_is_buffer (handle))
|
||||
return FALSE;
|
||||
|
||||
buffer = COGL_BUFFER (handle);
|
||||
|
||||
if (G_UNLIKELY((offset + size) > buffer->size))
|
||||
return FALSE;
|
||||
|
||||
return buffer->vtable->set_data (buffer, offset, data, size);
|
||||
}
|
287
clutter/cogl/cogl/cogl-buffer.h
Normal file
287
clutter/cogl/cogl/cogl-buffer.h
Normal file
@ -0,0 +1,287 @@
|
||||
/*
|
||||
* 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
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors:
|
||||
* Damien Lespiau <damien.lespiau@intel.com>
|
||||
*/
|
||||
|
||||
#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
|
||||
* @short_description: Buffer creation and manipulation
|
||||
* @stability: Unstable
|
||||
*
|
||||
* COGL allows the creation and the manipulation of buffers. If the underlying
|
||||
* OpenGL implementation allows it, COGL will use Pixel Buffer Objects.
|
||||
*/
|
||||
|
||||
/**
|
||||
* cogl_is_buffer:
|
||||
* @handle: a #CoglHandle to test
|
||||
*
|
||||
* Checks whether @handle is a buffer handle.
|
||||
*
|
||||
* Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
gboolean
|
||||
cogl_is_buffer (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* cogl_buffer_get_size:
|
||||
* @handle: a buffer handle
|
||||
*
|
||||
* Retrieves the size of buffer
|
||||
*
|
||||
* Return value: the size of the buffer in bytes
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
guint
|
||||
cogl_buffer_get_size (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* CoglBufferUsageHint:
|
||||
* @COGL_BUFFER_USAGE_HINT_DRAW: the buffer will be used as a source for
|
||||
* drawing commands (e.g. texture), the data coming from the application
|
||||
* @COGL_BUFFER_USAGE_HINT_READ: the buffer will be read by the application,
|
||||
* the data store being modified by the GPU
|
||||
* @COGL_BUFFER_USAGE_HINT_COPY: the buffer will be used as a source for
|
||||
* drawing commands, the data coming from the GPU
|
||||
*
|
||||
* The usage hint on a buffer allows the user to give some clue on how the
|
||||
* buffer will be used.
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
typedef enum { /*< prefix=COGL_BUFFER_USAGE_HINT >*/
|
||||
COGL_BUFFER_USAGE_HINT_DRAW,
|
||||
COGL_BUFFER_USAGE_HINT_READ,
|
||||
COGL_BUFFER_USAGE_HINT_COPY,
|
||||
} CoglBufferUsageHint;
|
||||
|
||||
/**
|
||||
* cogl_buffer_set_usage_hint:
|
||||
* @handle: a buffer handle
|
||||
* @hint: the new hint
|
||||
*
|
||||
* Set the usage hint on a buffer. See #CoglBufferUsageHint for a description
|
||||
* of the available hints.
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_buffer_set_usage_hint (CoglHandle handle,
|
||||
CoglBufferUsageHint hint);
|
||||
|
||||
/**
|
||||
* cogl_buffer_get_usage_hint:
|
||||
* @handle: a buffer handle
|
||||
*
|
||||
* Return value: the #CoglBufferUsageHint currently used by the buffer
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
CoglBufferUsageHint
|
||||
cogl_buffer_get_usage_hint (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* The update hint on a buffer allows the user to give some clue on how often
|
||||
* 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:
|
||||
* @handle: a buffer handle
|
||||
* @hint: the new hint
|
||||
*
|
||||
* Set the update hint on a buffer. See #CoglBufferUpdateHint for a description
|
||||
* of the available hints.
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_buffer_set_update_hint (CoglHandle handle,
|
||||
CoglBufferUpdateHint hint);
|
||||
|
||||
/**
|
||||
* cogl_buffer_get_update_hint:
|
||||
* @handle: a buffer handle
|
||||
*
|
||||
* Return value: the #CoglBufferUpdateHint currently used by the buffer
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
CoglBufferUpdateHint
|
||||
cogl_buffer_get_update_hint (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: 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;
|
||||
|
||||
/**
|
||||
* cogl_buffer_map:
|
||||
* @handle: a buffer handle
|
||||
* @access: how the mapped buffer will by use by the application
|
||||
*
|
||||
* Maps the buffer into the application address space for direct access.
|
||||
*
|
||||
* Return value: A pointer to the mapped memory or %NULL is the call fails
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
guchar *
|
||||
cogl_buffer_map (CoglHandle handle,
|
||||
CoglBufferAccess access);
|
||||
|
||||
/**
|
||||
* cogl_buffer_unmap:
|
||||
* @handle: a buffer handle
|
||||
*
|
||||
* Unmaps a buffer previously mapped by cogl_buffer_map().
|
||||
*
|
||||
* Since: 1.2
|
||||
* Stability: Unstable
|
||||
*/
|
||||
void
|
||||
cogl_buffer_unmap (CoglHandle handle);
|
||||
|
||||
/**
|
||||
* cogl_buffer_set_data:
|
||||
* @handle: a buffer handle
|
||||
* @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
|
||||
cogl_buffer_set_data (CoglHandle handle,
|
||||
gsize offset,
|
||||
const guchar *data,
|
||||
gsize size);
|
||||
|
||||
/* the functions above are experimental, the actual symbols are suffixed by
|
||||
* _EXP so we can ensure ABI compatibility and leave the cogl_buffer namespace
|
||||
* free for future use. A bunch of defines translates the symbols documented
|
||||
* above into the real symbols */
|
||||
|
||||
gboolean
|
||||
cogl_is_buffer_EXP (CoglHandle handle);
|
||||
|
||||
guint
|
||||
cogl_buffer_get_size_EXP (CoglHandle handle);
|
||||
|
||||
void
|
||||
cogl_buffer_set_usage_hint_EXP (CoglHandle handle,
|
||||
CoglBufferUsageHint hint);
|
||||
|
||||
CoglBufferUsageHint
|
||||
cogl_buffer_get_usage_hint_EXP (CoglHandle handle);
|
||||
|
||||
void
|
||||
cogl_buffer_set_update_hint_EXP (CoglHandle handle,
|
||||
CoglBufferUpdateHint hint);
|
||||
|
||||
CoglBufferUpdateHint
|
||||
cogl_buffer_get_update_hint_EXP (CoglHandle handle);
|
||||
|
||||
guchar *
|
||||
cogl_buffer_map_EXP (CoglHandle handle,
|
||||
CoglBufferAccess access);
|
||||
|
||||
void
|
||||
cogl_buffer_unmap_EXP (CoglHandle handle);
|
||||
|
||||
gboolean
|
||||
cogl_buffer_set_data_EXP (CoglHandle handle,
|
||||
gsize offset,
|
||||
const guchar *data,
|
||||
gsize size);
|
||||
|
||||
#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
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_BUFFER_H__ */
|
@ -150,6 +150,8 @@ cogl_create_context (void)
|
||||
_context->atlas = NULL;
|
||||
_context->atlas_texture = COGL_INVALID_HANDLE;
|
||||
|
||||
_context->current_pbo = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "cogl-matrix-stack.h"
|
||||
#include "cogl-material-private.h"
|
||||
#include "cogl-atlas.h"
|
||||
#include "cogl-buffer-private.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -87,6 +88,10 @@ typedef struct
|
||||
GArray *current_layers;
|
||||
guint n_texcoord_arrays_enabled;
|
||||
|
||||
/* PBOs */
|
||||
/* This can be used to check if a pbo is bound */
|
||||
CoglBuffer *current_pbo;
|
||||
|
||||
/* Framebuffers */
|
||||
GSList *framebuffer_stack;
|
||||
CoglHandle window_buffer;
|
||||
|
@ -48,6 +48,10 @@
|
||||
|
||||
#include <cogl/cogl-deprecated.h>
|
||||
|
||||
#if defined (COGL_ENABLE_EXPERIMENTAL_API)
|
||||
#include <cogl/cogl-buffer.h>
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
|
@ -71,6 +71,27 @@
|
||||
|
||||
</chapter>
|
||||
|
||||
<chapter>
|
||||
<title>COGL experimental API</title>
|
||||
|
||||
<section id="cogl-experimental">
|
||||
<title>About the experimental API</title>
|
||||
|
||||
<para>COGL has some experimental API developers are welcomed to play
|
||||
with. The main drawback when using those is that there is no API
|
||||
stability guarantee, functions flagged as experimental could be changed
|
||||
or removed in future versions of the library. To use this experimental
|
||||
API you will need to define
|
||||
<literal>COGL_ENABLE_EXPERIMENTAL_API</literal> before including
|
||||
<filename class="headerfile"><clutter/clutter.h></filename> or
|
||||
<filename class="headerfile"><cogl/cogl.h></filename>.</para>
|
||||
|
||||
</section>
|
||||
|
||||
<xi:include href="xml/cogl-buffer.xml"/>
|
||||
|
||||
</chapter>
|
||||
|
||||
<index>
|
||||
<title>Index of all symbols</title>
|
||||
<xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
|
||||
|
@ -472,3 +472,20 @@ CoglMaterialLayerType
|
||||
cogl_material_layer_get_type
|
||||
cogl_material_layer_get_texture
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>cogl-buffer</FILE>
|
||||
<TITLE>Buffers</TITLE>
|
||||
cogl_is_buffer
|
||||
cogl_buffer_get_size
|
||||
CoglBufferUsageHint
|
||||
cogl_buffer_set_usage_hint
|
||||
cogl_buffer_get_usage_hint
|
||||
CoglBufferUpdateHint
|
||||
cogl_buffer_set_update_hint
|
||||
cogl_buffer_get_update_hint
|
||||
CoglBufferAccess
|
||||
cogl_buffer_map
|
||||
cogl_buffer_unmap
|
||||
cogl_buffer_set_data
|
||||
</SECTION>
|
||||
|
Loading…
Reference in New Issue
Block a user