2010-01-10 17:28:24 +00: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 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
#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
|
|
|
|
|
|
|
|
gboolean
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_is_buffer (const void *object)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
CoglObject *obj = (CoglObject *)object;
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
if (obj == NULL)
|
2010-01-10 17:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return obj->klass->type == _cogl_handle_pixel_buffer_get_type ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_buffer_initialize (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-10 01:57:32 +00:00
|
|
|
unsigned int size,
|
2010-01-10 17:28:24 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-02-02 16:44:16 +00:00
|
|
|
/* OpenGL ES 1.1 and 2 have a GL_OES_mapbuffer extension that is able to map
|
|
|
|
* VBOs for write only, we don't support that in CoglBuffer */
|
|
|
|
#if defined (COGL_HAS_GLES)
|
|
|
|
GLenum
|
|
|
|
_cogl_buffer_access_to_gl_enum (CoglBufferAccess access)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2010-01-10 17:28:24 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-02-02 16:44:16 +00:00
|
|
|
#endif
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-02-02 16:44:16 +00:00
|
|
|
/* OpenGL ES 1.1 and 2 only know about STATIC_DRAW and DYNAMIC_DRAW */
|
|
|
|
#if defined (COGL_HAS_GLES)
|
|
|
|
GLenum
|
2010-02-12 17:24:15 +00:00
|
|
|
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
|
|
|
CoglBufferUpdateHint update_hint)
|
2010-02-02 16:44:16 +00:00
|
|
|
{
|
2010-02-12 17:24:15 +00:00
|
|
|
/* usage hint is always TEXTURE for now */
|
|
|
|
if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
|
2010-02-02 16:44:16 +00:00
|
|
|
return GL_STATIC_DRAW;
|
2010-02-12 17:24:15 +00:00
|
|
|
return GL_DYNAMIC_DRAW;
|
2010-02-02 16:44:16 +00:00
|
|
|
}
|
|
|
|
#else
|
2010-01-10 17:28:24 +00:00
|
|
|
GLenum
|
|
|
|
_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint usage_hint,
|
|
|
|
CoglBufferUpdateHint update_hint)
|
|
|
|
{
|
2010-02-08 17:11:43 +00:00
|
|
|
/* usage hint is always TEXTURE for now */
|
|
|
|
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;
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
return GL_STATIC_DRAW;
|
|
|
|
}
|
2010-02-02 16:44:16 +00:00
|
|
|
#endif
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-10 01:57:32 +00:00
|
|
|
unsigned int
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_get_size (CoglBuffer *buffer)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
return COGL_BUFFER (buffer)->size;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_set_usage_hint (CoglBuffer *buffer,
|
|
|
|
CoglBufferUsageHint hint)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return;
|
|
|
|
|
2010-02-08 17:11:43 +00:00
|
|
|
if (G_UNLIKELY (hint > COGL_BUFFER_USAGE_HINT_TEXTURE))
|
|
|
|
hint = COGL_BUFFER_USAGE_HINT_TEXTURE;
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
buffer->usage_hint = hint;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglBufferUsageHint
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_get_usage_hint (CoglBuffer *buffer)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
return buffer->usage_hint;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_set_update_hint (CoglBuffer *buffer,
|
|
|
|
CoglBufferUpdateHint hint)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM))
|
|
|
|
hint = COGL_BUFFER_UPDATE_HINT_STATIC;
|
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
buffer->update_hint = hint;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglBufferUpdateHint
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_get_update_hint (CoglBuffer *buffer)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
return buffer->update_hint;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
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-10 01:57:32 +00:00
|
|
|
guint8 *
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_map (CoglBuffer *buffer,
|
|
|
|
CoglBufferAccess access)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-05-27 07:28:29 +00:00
|
|
|
return NULL;
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
|
|
|
|
return buffer->data;
|
|
|
|
|
|
|
|
buffer->data = buffer->vtable->map (buffer, access);
|
|
|
|
return buffer->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_unmap (CoglBuffer *buffer)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
|
|
|
|
return;
|
|
|
|
|
2010-02-09 10:21:37 +00:00
|
|
|
buffer->vtable->unmap (buffer);
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_set_data (CoglBuffer *buffer,
|
|
|
|
gsize offset,
|
|
|
|
const guint8 *data,
|
|
|
|
gsize size)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (G_UNLIKELY((offset + size) > buffer->size))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return buffer->vtable->set_data (buffer, offset, data, size);
|
|
|
|
}
|