2009-11-27 13:45:36 -05:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 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/>.
|
|
|
|
*
|
|
|
|
*
|
2009-11-27 13:45:36 -05:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-13 18:02:04 -05:00
|
|
|
#include "cogl-private.h"
|
2009-11-27 13:45:36 -05:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-texture-2d-private.h"
|
|
|
|
#include "cogl-texture-driver.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 09:14:10 -04:00
|
|
|
#include "cogl-object-private.h"
|
2010-02-10 13:18:30 -05:00
|
|
|
#include "cogl-journal-private.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline-opengl-private.h"
|
2011-02-10 13:22:27 -05:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2012-08-31 14:28:27 -04:00
|
|
|
#include "cogl-error-private.h"
|
2011-11-28 17:55:58 -05:00
|
|
|
#ifdef COGL_HAS_EGL_SUPPORT
|
2011-05-24 17:34:10 -04:00
|
|
|
#include "cogl-winsys-egl-private.h"
|
2011-11-28 17:55:58 -05:00
|
|
|
#endif
|
2009-11-27 13:45:36 -05:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2011-05-24 20:37:56 -04:00
|
|
|
#ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT
|
2012-03-20 09:21:18 -04:00
|
|
|
#include "cogl-wayland-server.h"
|
2011-05-24 20:37:56 -04:00
|
|
|
#endif
|
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
static void _cogl_texture_2d_free (CoglTexture2D *tex_2d);
|
|
|
|
|
2011-05-16 19:05:54 -04:00
|
|
|
COGL_TEXTURE_DEFINE (Texture2D, texture_2d);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
|
|
|
static const CoglTextureVtable cogl_texture_2d_vtable;
|
|
|
|
|
|
|
|
typedef struct _CoglTexture2DManualRepeatData
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d;
|
2011-10-08 09:13:03 -04:00
|
|
|
CoglMetaTextureCallback callback;
|
2009-11-27 13:45:36 -05:00
|
|
|
void *user_data;
|
|
|
|
} CoglTexture2DManualRepeatData;
|
|
|
|
|
|
|
|
static void
|
2010-03-25 13:29:22 -04:00
|
|
|
_cogl_texture_2d_set_wrap_mode_parameters (CoglTexture *tex,
|
|
|
|
GLenum wrap_mode_s,
|
|
|
|
GLenum wrap_mode_t,
|
2010-07-12 12:01:32 -04:00
|
|
|
GLenum wrap_mode_p)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2010-03-25 13:29:22 -04:00
|
|
|
/* Only set the wrap mode if it's different from the current value
|
|
|
|
to avoid too many GL calls. Texture 2D doesn't make use of the r
|
|
|
|
coordinate so we can ignore its wrap mode */
|
|
|
|
if (tex_2d->wrap_mode_s != wrap_mode_s ||
|
|
|
|
tex_2d->wrap_mode_t != wrap_mode_t)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
|
|
tex_2d->gl_texture,
|
2010-10-04 10:27:38 -04:00
|
|
|
tex_2d->is_foreign);
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_2D,
|
|
|
|
GL_TEXTURE_WRAP_S,
|
|
|
|
wrap_mode_s) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_2D,
|
|
|
|
GL_TEXTURE_WRAP_T,
|
|
|
|
wrap_mode_t) );
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-03-25 13:29:22 -04:00
|
|
|
tex_2d->wrap_mode_s = wrap_mode_s;
|
|
|
|
tex_2d->wrap_mode_t = wrap_mode_t;
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_2d_free (CoglTexture2D *tex_2d)
|
|
|
|
{
|
2010-10-04 10:27:38 -04:00
|
|
|
if (!tex_2d->is_foreign)
|
|
|
|
_cogl_delete_gl_texture (tex_2d->gl_texture);
|
2010-04-26 05:01:43 -04:00
|
|
|
|
|
|
|
/* Chain up */
|
|
|
|
_cogl_texture_free (COGL_TEXTURE (tex_2d));
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-09-07 10:26:34 -04:00
|
|
|
_cogl_texture_2d_can_create (CoglContext *ctx,
|
|
|
|
unsigned int width,
|
2009-11-27 13:45:36 -05:00
|
|
|
unsigned int height,
|
|
|
|
CoglPixelFormat internal_format)
|
|
|
|
{
|
|
|
|
GLenum gl_intformat;
|
2012-05-23 09:47:57 -04:00
|
|
|
GLenum gl_format;
|
2009-11-27 13:45:36 -05:00
|
|
|
GLenum gl_type;
|
|
|
|
|
|
|
|
/* If NPOT textures aren't supported then the size must be a power
|
|
|
|
of two */
|
2012-04-24 12:44:38 -04:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
|
2010-07-01 06:07:03 -04:00
|
|
|
(!_cogl_util_is_pot (width) ||
|
|
|
|
!_cogl_util_is_pot (height)))
|
2009-11-27 13:45:36 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
2012-05-23 09:47:57 -04:00
|
|
|
&gl_format,
|
2012-03-22 12:32:56 -04:00
|
|
|
&gl_type);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
|
|
|
/* Check that the driver can create a texture with that size */
|
2012-03-22 13:04:47 -04:00
|
|
|
if (!ctx->texture_driver->size_supported (ctx,
|
|
|
|
GL_TEXTURE_2D,
|
2009-11-27 13:45:36 -05:00
|
|
|
gl_intformat,
|
2012-05-23 09:47:57 -04:00
|
|
|
gl_format,
|
2009-11-27 13:45:36 -05:00
|
|
|
gl_type,
|
|
|
|
width,
|
|
|
|
height))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-04 10:09:43 -04:00
|
|
|
static void
|
|
|
|
_cogl_texture_2d_set_auto_mipmap (CoglTexture *tex,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool value)
|
2012-04-04 10:09:43 -04:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
|
|
|
|
tex_2d->auto_mipmap = value;
|
|
|
|
}
|
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
static CoglTexture2D *
|
2012-09-07 10:26:34 -04:00
|
|
|
_cogl_texture_2d_create_base (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat internal_format)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = g_new (CoglTexture2D, 1);
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
_cogl_texture_init (tex, ctx, &cogl_texture_2d_vtable);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
|
|
|
tex_2d->width = width;
|
|
|
|
tex_2d->height = height;
|
|
|
|
tex_2d->mipmaps_dirty = TRUE;
|
2012-04-04 10:09:43 -04:00
|
|
|
tex_2d->auto_mipmap = TRUE;
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-01-25 06:21:05 -05:00
|
|
|
/* We default to GL_LINEAR for both filters */
|
|
|
|
tex_2d->min_filter = GL_LINEAR;
|
|
|
|
tex_2d->mag_filter = GL_LINEAR;
|
2009-11-27 13:45:36 -05:00
|
|
|
|
|
|
|
/* Wrap mode not yet set */
|
2010-03-25 13:29:22 -04:00
|
|
|
tex_2d->wrap_mode_s = GL_FALSE;
|
|
|
|
tex_2d->wrap_mode_t = GL_FALSE;
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-10-04 10:27:38 -04:00
|
|
|
tex_2d->is_foreign = FALSE;
|
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
tex_2d->format = internal_format;
|
|
|
|
|
|
|
|
return tex_2d;
|
|
|
|
}
|
|
|
|
|
2011-05-16 19:05:54 -04:00
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
|
|
|
|
/* Since no data, we need some internal format */
|
|
|
|
if (internal_format == COGL_PIXEL_FORMAT_ANY)
|
|
|
|
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
|
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
if (!_cogl_texture_2d_can_create (ctx, width, height, internal_format))
|
2011-05-16 19:05:54 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_SIZE,
|
|
|
|
"Failed to create texture 2d due to size/format"
|
|
|
|
" constraints");
|
2011-05-16 19:05:54 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
internal_format = ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
internal_format,
|
|
|
|
&gl_intformat,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
tex_2d = _cogl_texture_2d_create_base (ctx,
|
|
|
|
width, height,
|
2011-05-16 19:05:54 -04:00
|
|
|
internal_format);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-03-22 13:04:47 -04:00
|
|
|
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
|
|
tex_2d->gl_texture,
|
2010-10-04 10:27:38 -04:00
|
|
|
tex_2d->is_foreign);
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexImage2D (GL_TEXTURE_2D, 0, gl_intformat,
|
|
|
|
width, height, 0, gl_format, gl_type, NULL) );
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
return _cogl_texture_2d_object_new (tex_2d);
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
|
2012-04-04 10:10:04 -04:00
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
|
|
|
|
CoglPixelFormat internal_format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
2010-02-01 07:11:58 -05:00
|
|
|
CoglTexture2D *tex_2d;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBitmap *dst_bmp;
|
|
|
|
GLenum gl_intformat;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
uint8_t *data;
|
|
|
|
CoglContext *ctx;
|
2011-07-07 07:48:24 -04:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (bmp != NULL, NULL);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-04-04 08:57:42 -04:00
|
|
|
ctx = _cogl_bitmap_get_context (bmp);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
internal_format =
|
2012-02-25 15:18:05 -05:00
|
|
|
_cogl_texture_determine_internal_format (cogl_bitmap_get_format (bmp),
|
2010-07-07 13:44:16 -04:00
|
|
|
internal_format);
|
2010-03-09 19:37:52 -05:00
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
if (!_cogl_texture_2d_can_create (ctx,
|
|
|
|
cogl_bitmap_get_width (bmp),
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_height (bmp),
|
2010-07-07 13:44:16 -04:00
|
|
|
internal_format))
|
2011-05-16 19:05:54 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_SIZE,
|
|
|
|
"Failed to create texture 2d due to size/format"
|
|
|
|
" constraints");
|
2011-05-16 19:05:54 -04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
2010-03-01 13:54:03 -05:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
if ((dst_bmp = _cogl_texture_prepare_for_upload (bmp,
|
|
|
|
internal_format,
|
|
|
|
&internal_format,
|
|
|
|
&gl_intformat,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type)) == NULL)
|
2011-05-16 19:05:54 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error, COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_FORMAT,
|
|
|
|
"Failed to prepare texture upload due to format");
|
2011-05-16 19:05:54 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
tex_2d = _cogl_texture_2d_create_base (ctx,
|
|
|
|
cogl_bitmap_get_width (bmp),
|
2012-02-25 15:18:05 -05:00
|
|
|
cogl_bitmap_get_height (bmp),
|
2010-02-01 07:11:58 -05:00
|
|
|
internal_format);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-07-13 13:41:01 -04:00
|
|
|
/* Keep a copy of the first pixel so that if glGenerateMipmap isn't
|
|
|
|
supported we can fallback to using GL_GENERATE_MIPMAP */
|
2011-10-12 17:31:12 -04:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN) &&
|
2010-07-07 13:44:16 -04:00
|
|
|
(data = _cogl_bitmap_map (dst_bmp,
|
|
|
|
COGL_BUFFER_ACCESS_READ, 0)))
|
|
|
|
{
|
2012-02-25 15:18:05 -05:00
|
|
|
CoglPixelFormat format = cogl_bitmap_get_format (dst_bmp);
|
2010-07-07 13:44:16 -04:00
|
|
|
tex_2d->first_pixel.gl_format = gl_format;
|
|
|
|
tex_2d->first_pixel.gl_type = gl_type;
|
|
|
|
memcpy (tex_2d->first_pixel.data, data,
|
2012-02-13 18:02:04 -05:00
|
|
|
_cogl_pixel_format_get_bytes_per_pixel (format));
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
_cogl_bitmap_unmap (dst_bmp);
|
|
|
|
}
|
2010-07-13 13:41:01 -04:00
|
|
|
|
2012-03-22 13:04:47 -04:00
|
|
|
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
|
|
|
ctx->texture_driver->upload_to_gl (ctx,
|
|
|
|
GL_TEXTURE_2D,
|
2009-11-27 13:45:36 -05:00
|
|
|
tex_2d->gl_texture,
|
2010-04-26 05:01:43 -04:00
|
|
|
FALSE,
|
2010-07-07 13:44:16 -04:00
|
|
|
dst_bmp,
|
2010-02-01 07:11:58 -05:00
|
|
|
gl_intformat,
|
|
|
|
gl_format,
|
|
|
|
gl_type);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-02-01 07:11:58 -05:00
|
|
|
tex_2d->gl_format = gl_intformat;
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (dst_bmp);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
return _cogl_texture_2d_object_new (tex_2d);
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
|
2011-05-16 19:05:54 -04:00
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_from_data (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
int rowstride,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
const uint8_t *data,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2011-05-16 19:05:54 -04:00
|
|
|
{
|
|
|
|
CoglBitmap *bmp;
|
2012-04-16 09:14:10 -04:00
|
|
|
CoglTexture2D *tex_2d;
|
2011-05-16 19:05:54 -04:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (format != COGL_PIXEL_FORMAT_ANY, NULL);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (data != NULL, NULL);
|
2011-05-16 19:05:54 -04:00
|
|
|
|
|
|
|
/* Rowstride from width if not given */
|
|
|
|
if (rowstride == 0)
|
2012-02-13 18:02:04 -05:00
|
|
|
rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format);
|
2011-05-16 19:05:54 -04:00
|
|
|
|
|
|
|
/* Wrap the data into a bitmap */
|
2012-03-13 10:46:18 -04:00
|
|
|
bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
(uint8_t *) data);
|
2011-05-16 19:05:54 -04:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
tex_2d = cogl_texture_2d_new_from_bitmap (bmp,
|
|
|
|
internal_format,
|
|
|
|
error);
|
2011-05-16 19:05:54 -04:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
return tex_2d;
|
2011-05-16 19:05:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_from_foreign (CoglContext *ctx,
|
2012-08-31 21:13:32 -04:00
|
|
|
unsigned int gl_handle,
|
2011-05-16 19:05:54 -04:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2010-10-04 10:27:38 -04:00
|
|
|
{
|
|
|
|
/* NOTE: width, height and internal format are not queriable
|
|
|
|
* in GLES, hence such a function prototype.
|
|
|
|
*/
|
|
|
|
|
2012-08-31 21:13:32 -04:00
|
|
|
GLenum gl_error = 0;
|
|
|
|
GLint gl_compressed = GL_FALSE;
|
|
|
|
GLenum gl_int_format = 0;
|
2010-10-04 10:27:38 -04:00
|
|
|
CoglTexture2D *tex_2d;
|
|
|
|
|
2012-08-31 21:13:32 -04:00
|
|
|
/* Assert it is a valid GL texture object */
|
|
|
|
g_return_val_if_fail (ctx->glIsTexture (gl_handle), NULL);
|
|
|
|
|
2012-03-22 13:04:47 -04:00
|
|
|
if (!ctx->texture_driver->allows_foreign_gl_target (ctx, GL_TEXTURE_2D))
|
2012-08-31 21:13:32 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
2012-08-31 21:13:32 -04:00
|
|
|
"Foreign GL_TEXTURE_2D textures are not "
|
|
|
|
"supported by your system");
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* Make sure binding succeeds */
|
2011-07-06 16:51:00 -04:00
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
2010-10-04 10:27:38 -04:00
|
|
|
;
|
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D, gl_handle, TRUE);
|
2011-07-06 16:51:00 -04:00
|
|
|
if (ctx->glGetError () != GL_NO_ERROR)
|
2012-08-31 21:13:32 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Failed to bind foreign GL_TEXTURE_2D texture");
|
2012-08-31 21:13:32 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Obtain texture parameters
|
|
|
|
(only level 0 we are interested in) */
|
|
|
|
|
|
|
|
#if HAVE_COGL_GL
|
2011-07-07 15:44:56 -04:00
|
|
|
if (ctx->driver == COGL_DRIVER_GL)
|
|
|
|
{
|
|
|
|
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_2D, 0,
|
|
|
|
GL_TEXTURE_COMPRESSED,
|
|
|
|
&gl_compressed) );
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
{
|
|
|
|
GLint val;
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_2D, 0,
|
|
|
|
GL_TEXTURE_INTERNAL_FORMAT,
|
|
|
|
&val) );
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
gl_int_format = val;
|
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
/* If we can query GL for the actual pixel format then we'll ignore
|
|
|
|
the passed in format and use that. */
|
2012-03-22 12:32:56 -04:00
|
|
|
if (!ctx->driver_vtable->pixel_format_from_gl_internal (ctx,
|
|
|
|
gl_int_format,
|
|
|
|
&format))
|
2012-08-31 21:13:32 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Unsupported internal format for foreign texture");
|
2012-08-31 21:13:32 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-07 15:44:56 -04:00
|
|
|
}
|
|
|
|
else
|
2010-10-04 10:27:38 -04:00
|
|
|
#endif
|
2011-07-07 15:44:56 -04:00
|
|
|
{
|
|
|
|
/* Otherwise we'll assume we can derive the GL format from the
|
|
|
|
passed in format */
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
format,
|
|
|
|
&gl_int_format,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2011-07-07 15:44:56 -04:00
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Note: We always trust the given width and height without querying
|
|
|
|
* the texture object because the user may be creating a Cogl
|
|
|
|
* texture for a texture_from_pixmap object where glTexImage2D may
|
|
|
|
* not have been called and the texture_from_pixmap spec doesn't
|
|
|
|
* clarify that it is reliable to query back the size from OpenGL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Validate width and height */
|
2012-08-31 21:13:32 -04:00
|
|
|
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Compressed texture images not supported */
|
|
|
|
if (gl_compressed == GL_TRUE)
|
2012-08-31 21:13:32 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_SYSTEM_ERROR,
|
|
|
|
COGL_SYSTEM_ERROR_UNSUPPORTED,
|
|
|
|
"Compressed foreign textures aren't currently supported");
|
2012-08-31 21:13:32 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Note: previously this code would query the texture object for
|
|
|
|
whether it has GL_GENERATE_MIPMAP enabled to determine whether to
|
|
|
|
auto-generate the mipmap. This doesn't make much sense any more
|
|
|
|
since Cogl switch to using glGenerateMipmap. Ideally I think
|
2012-08-31 21:13:32 -04:00
|
|
|
cogl_texture_2d_new_from_foreign should take a flags parameter so
|
2010-10-04 10:27:38 -04:00
|
|
|
that the application can decide whether it wants
|
|
|
|
auto-mipmapping. To be compatible with existing code, Cogl now
|
|
|
|
disables its own auto-mipmapping but leaves the value of
|
|
|
|
GL_GENERATE_MIPMAP alone so that it would still work but without
|
|
|
|
the dirtiness tracking that Cogl would do. */
|
|
|
|
|
|
|
|
/* Create new texture */
|
2012-09-07 10:26:34 -04:00
|
|
|
tex_2d = _cogl_texture_2d_create_base (ctx,
|
|
|
|
width, height,
|
2010-10-04 10:27:38 -04:00
|
|
|
format);
|
2012-04-04 10:09:43 -04:00
|
|
|
_cogl_texture_2d_set_auto_mipmap (COGL_TEXTURE (tex_2d), FALSE);
|
2010-10-04 10:27:38 -04:00
|
|
|
|
|
|
|
/* Setup bitmap info */
|
|
|
|
tex_2d->is_foreign = TRUE;
|
|
|
|
tex_2d->mipmaps_dirty = TRUE;
|
|
|
|
|
|
|
|
tex_2d->format = format;
|
|
|
|
|
|
|
|
tex_2d->gl_texture = gl_handle;
|
|
|
|
tex_2d->gl_format = gl_int_format;
|
|
|
|
|
|
|
|
/* Unknown filter */
|
|
|
|
tex_2d->min_filter = GL_FALSE;
|
|
|
|
tex_2d->mag_filter = GL_FALSE;
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
return _cogl_texture_2d_object_new (tex_2d);
|
2010-10-04 10:27:38 -04:00
|
|
|
}
|
|
|
|
|
2011-05-24 17:34:10 -04:00
|
|
|
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
|
|
|
|
/* NB: The reason we require the width, height and format to be passed
|
|
|
|
* even though they may seem redundant is because GLES 1/2 don't
|
|
|
|
* provide a way to query these properties. */
|
|
|
|
CoglTexture2D *
|
|
|
|
_cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
EGLImageKHR image,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2011-05-24 17:34:10 -04:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d;
|
|
|
|
GLenum gl_error;
|
|
|
|
|
2012-01-13 11:48:26 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->constraints &
|
|
|
|
COGL_RENDERER_CONSTRAINT_USES_EGL,
|
2011-12-13 13:57:53 -05:00
|
|
|
NULL);
|
2011-05-24 17:34:10 -04:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (ctx->private_feature_flags &
|
2011-05-24 17:34:10 -04:00
|
|
|
COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE,
|
|
|
|
NULL);
|
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
tex_2d = _cogl_texture_2d_create_base (ctx,
|
|
|
|
width, height,
|
2011-05-24 17:34:10 -04:00
|
|
|
format);
|
|
|
|
|
2012-03-22 13:04:47 -04:00
|
|
|
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, 1, &tex_2d->gl_texture);
|
2011-05-24 17:34:10 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
|
|
tex_2d->gl_texture,
|
|
|
|
FALSE);
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
|
2011-05-24 17:34:10 -04:00
|
|
|
;
|
2011-07-06 13:59:20 -04:00
|
|
|
ctx->glEGLImageTargetTexture2D (GL_TEXTURE_2D, image);
|
2011-07-06 16:51:00 -04:00
|
|
|
if (ctx->glGetError () != GL_NO_ERROR)
|
2011-05-24 17:34:10 -04:00
|
|
|
{
|
2012-08-31 14:28:27 -04:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_BAD_PARAMETER,
|
|
|
|
"Could not create a CoglTexture2D from a given "
|
|
|
|
"EGLImage");
|
2011-05-24 17:34:10 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
return _cogl_texture_2d_object_new (tex_2d);
|
2011-05-24 17:34:10 -04:00
|
|
|
}
|
|
|
|
#endif /* defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base) */
|
|
|
|
|
2011-05-24 20:37:56 -04:00
|
|
|
#ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT
|
|
|
|
CoglTexture2D *
|
|
|
|
cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
|
|
|
|
struct wl_buffer *buffer,
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError **error)
|
2011-05-24 20:37:56 -04:00
|
|
|
{
|
|
|
|
if (wl_buffer_is_shm (buffer))
|
|
|
|
{
|
|
|
|
int stride = wl_shm_buffer_get_stride (buffer);
|
2011-12-01 17:52:59 -05:00
|
|
|
CoglPixelFormat format;
|
|
|
|
CoglPixelFormat internal_format = COGL_PIXEL_FORMAT_ANY;
|
|
|
|
|
|
|
|
switch (wl_shm_buffer_get_format (buffer))
|
|
|
|
{
|
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
2012-01-12 15:24:48 -05:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
2011-12-01 17:52:59 -05:00
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888_PRE;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB32:
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
internal_format = COGL_PIXEL_FORMAT_RGB_888;
|
|
|
|
break;
|
|
|
|
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2012-01-12 15:24:48 -05:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
2011-12-01 17:52:59 -05:00
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888_PRE;
|
|
|
|
break;
|
2012-01-12 15:24:48 -05:00
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
2011-12-01 17:52:59 -05:00
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888;
|
|
|
|
internal_format = COGL_PIXEL_FORMAT_BGR_888;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
}
|
|
|
|
|
2011-05-24 20:37:56 -04:00
|
|
|
return cogl_texture_2d_new_from_data (ctx,
|
|
|
|
buffer->width,
|
|
|
|
buffer->height,
|
|
|
|
format,
|
2011-12-01 17:52:59 -05:00
|
|
|
internal_format,
|
2011-05-24 20:37:56 -04:00
|
|
|
stride,
|
|
|
|
wl_shm_buffer_get_data (buffer),
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EGLImageKHR image;
|
2012-01-11 11:05:53 -05:00
|
|
|
CoglTexture2D *tex;
|
2011-05-24 20:37:56 -04:00
|
|
|
|
2012-01-13 11:48:26 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->constraints &
|
|
|
|
COGL_RENDERER_CONSTRAINT_USES_EGL,
|
2011-12-01 17:52:59 -05:00
|
|
|
NULL);
|
2011-05-24 20:37:56 -04:00
|
|
|
image = _cogl_egl_create_image (ctx,
|
|
|
|
EGL_WAYLAND_BUFFER_WL,
|
|
|
|
buffer,
|
|
|
|
NULL);
|
2012-01-11 11:05:53 -05:00
|
|
|
tex = _cogl_egl_texture_2d_new_from_image (ctx,
|
|
|
|
buffer->width,
|
|
|
|
buffer->height,
|
|
|
|
COGL_PIXEL_FORMAT_ARGB_8888_PRE,
|
|
|
|
image,
|
|
|
|
error);
|
|
|
|
_cogl_egl_destroy_image (ctx, image);
|
|
|
|
return tex;
|
2011-05-24 20:37:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT */
|
|
|
|
|
2010-06-03 10:06:47 -04:00
|
|
|
void
|
2012-04-16 09:14:10 -04:00
|
|
|
_cogl_texture_2d_externally_modified (CoglTexture *texture)
|
2010-06-03 10:06:47 -04:00
|
|
|
{
|
2012-04-16 09:14:10 -04:00
|
|
|
if (!cogl_is_texture_2d (texture))
|
2010-06-03 10:06:47 -04:00
|
|
|
return;
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
COGL_TEXTURE_2D (texture)->mipmaps_dirty = TRUE;
|
2010-06-03 10:06:47 -04:00
|
|
|
}
|
|
|
|
|
2011-02-10 13:22:27 -05:00
|
|
|
void
|
2012-04-16 09:14:10 -04:00
|
|
|
_cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
2011-02-10 13:22:27 -05:00
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_texture_2d (tex_2d));
|
2011-02-10 13:22:27 -05:00
|
|
|
|
2012-09-07 10:26:34 -04:00
|
|
|
ctx = COGL_TEXTURE (tex_2d)->context;
|
|
|
|
|
2011-11-03 09:12:47 -04:00
|
|
|
/* Make sure the current framebuffers are bound, though we don't need to
|
|
|
|
* flush the clip state here since we aren't going to draw to the
|
|
|
|
* framebuffer. */
|
2011-03-10 16:33:31 -05:00
|
|
|
_cogl_framebuffer_flush_state (cogl_get_draw_framebuffer (),
|
|
|
|
_cogl_get_read_framebuffer (),
|
2011-11-21 10:53:40 -05:00
|
|
|
COGL_FRAMEBUFFER_STATE_ALL &
|
|
|
|
~COGL_FRAMEBUFFER_STATE_CLIP);
|
2011-02-10 13:22:27 -05:00
|
|
|
|
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
|
|
tex_2d->gl_texture,
|
|
|
|
tex_2d->is_foreign);
|
|
|
|
|
2011-07-06 16:51:00 -04:00
|
|
|
ctx->glCopyTexSubImage2D (GL_TEXTURE_2D,
|
|
|
|
0, /* level */
|
|
|
|
dst_x, dst_y,
|
|
|
|
src_x, src_y,
|
|
|
|
width, height);
|
2011-02-10 13:22:27 -05:00
|
|
|
|
|
|
|
tex_2d->mipmaps_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static int
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_get_max_waste (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_is_sliced (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_can_hardware_repeat (CoglTexture *tex)
|
|
|
|
{
|
2012-04-24 12:44:38 -04:00
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2012-04-24 12:44:38 -04:00
|
|
|
|
|
|
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_REPEAT) ||
|
|
|
|
(_cogl_util_is_pot (tex_2d->width) &&
|
|
|
|
_cogl_util_is_pot (tex_2d->height)))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_2d_transform_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *s,
|
|
|
|
float *t)
|
|
|
|
{
|
|
|
|
/* The texture coordinates map directly so we don't need to do
|
|
|
|
anything */
|
|
|
|
}
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
static CoglTransformResult
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_texture_2d_transform_quad_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *coords)
|
|
|
|
{
|
|
|
|
/* The texture coordinates map directly so we don't need to do
|
2010-03-01 16:49:04 -05:00
|
|
|
anything other than check for repeats */
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
if (coords[i] < 0.0f || coords[i] > 1.0f)
|
2012-04-24 12:44:38 -04:00
|
|
|
{
|
|
|
|
/* Repeat is needed */
|
|
|
|
return (_cogl_texture_2d_can_hardware_repeat (tex) ?
|
|
|
|
COGL_TRANSFORM_HARDWARE_REPEAT :
|
|
|
|
COGL_TRANSFORM_SOFTWARE_REPEAT);
|
|
|
|
}
|
2010-03-01 16:49:04 -05:00
|
|
|
|
2012-04-24 12:44:38 -04:00
|
|
|
/* No repeat is needed */
|
|
|
|
return COGL_TRANSFORM_NO_REPEAT;
|
2010-01-18 04:22:04 -05:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_get_gl_texture (CoglTexture *tex,
|
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
|
|
|
|
if (out_gl_handle)
|
|
|
|
*out_gl_handle = tex_2d->gl_texture;
|
|
|
|
|
|
|
|
if (out_gl_target)
|
|
|
|
*out_gl_target = GL_TEXTURE_2D;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_2d_set_filters (CoglTexture *tex,
|
|
|
|
GLenum min_filter,
|
|
|
|
GLenum mag_filter)
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2011-07-06 16:51:00 -04:00
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
if (min_filter == tex_2d->min_filter
|
|
|
|
&& mag_filter == tex_2d->mag_filter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Store new values */
|
|
|
|
tex_2d->min_filter = min_filter;
|
|
|
|
tex_2d->mag_filter = mag_filter;
|
|
|
|
|
|
|
|
/* Apply new filters to the texture */
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
|
|
tex_2d->gl_texture,
|
2010-10-04 10:27:38 -04:00
|
|
|
tex_2d->is_foreign);
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter) );
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
2009-11-27 13:45:36 -05:00
|
|
|
|
|
|
|
/* Only update if the mipmaps are dirty */
|
2010-06-09 12:39:59 -04:00
|
|
|
if ((flags & COGL_TEXTURE_NEEDS_MIPMAP) &&
|
|
|
|
tex_2d->auto_mipmap && tex_2d->mipmaps_dirty)
|
|
|
|
{
|
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
|
|
tex_2d->gl_texture,
|
2010-10-04 10:27:38 -04:00
|
|
|
tex_2d->is_foreign);
|
2010-07-13 13:41:01 -04:00
|
|
|
|
|
|
|
/* glGenerateMipmap is defined in the FBO extension. If it's not
|
|
|
|
available we'll fallback to temporarily enabling
|
|
|
|
GL_GENERATE_MIPMAP and reuploading the first pixel */
|
2011-10-12 17:31:12 -04:00
|
|
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
2012-03-22 13:04:47 -04:00
|
|
|
ctx->texture_driver->gl_generate_mipmaps (ctx, GL_TEXTURE_2D);
|
2011-07-07 15:44:56 -04:00
|
|
|
#if defined(HAVE_COGL_GLES) || defined(HAVE_COGL_GL)
|
2010-07-13 13:41:01 -04:00
|
|
|
else
|
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_2D,
|
|
|
|
GL_GENERATE_MIPMAP,
|
|
|
|
GL_TRUE) );
|
|
|
|
GE( ctx, glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 1, 1,
|
|
|
|
tex_2d->first_pixel.gl_format,
|
|
|
|
tex_2d->first_pixel.gl_type,
|
|
|
|
tex_2d->first_pixel.data) );
|
|
|
|
GE( ctx, glTexParameteri (GL_TEXTURE_2D,
|
|
|
|
GL_GENERATE_MIPMAP,
|
|
|
|
GL_FALSE) );
|
2010-07-13 13:41:01 -04:00
|
|
|
}
|
2010-12-05 13:02:05 -05:00
|
|
|
#endif
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-06-09 12:39:59 -04:00
|
|
|
tex_2d->mipmaps_dirty = FALSE;
|
|
|
|
}
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
static void
|
|
|
|
_cogl_texture_2d_ensure_non_quad_rendering (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
/* Nothing needs to be done */
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_set_region (CoglTexture *tex,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
unsigned int dst_width,
|
|
|
|
unsigned int dst_height,
|
2010-07-08 10:15:22 -04:00
|
|
|
CoglBitmap *bmp)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
2010-07-08 10:15:22 -04:00
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = tex->context;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
uint8_t *data;
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2011-08-31 12:22:20 -04:00
|
|
|
bmp = _cogl_texture_prepare_for_upload (bmp,
|
|
|
|
cogl_texture_get_format (tex),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-07-13 13:41:01 -04:00
|
|
|
/* If this touches the first pixel then we'll update our copy */
|
2010-07-07 13:44:16 -04:00
|
|
|
if (dst_x == 0 && dst_y == 0 &&
|
2011-10-12 17:31:12 -04:00
|
|
|
!cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN) &&
|
2010-07-07 13:44:16 -04:00
|
|
|
(data = _cogl_bitmap_map (bmp, COGL_BUFFER_ACCESS_READ, 0)))
|
2010-07-13 13:41:01 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglPixelFormat bpp =
|
2012-02-25 15:18:05 -05:00
|
|
|
_cogl_pixel_format_get_bytes_per_pixel (cogl_bitmap_get_format (bmp));
|
2010-07-13 13:41:01 -04:00
|
|
|
tex_2d->first_pixel.gl_format = gl_format;
|
|
|
|
tex_2d->first_pixel.gl_type = gl_type;
|
|
|
|
memcpy (tex_2d->first_pixel.data,
|
2012-02-25 15:18:05 -05:00
|
|
|
data + cogl_bitmap_get_rowstride (bmp) * src_y + bpp * src_x,
|
2010-07-13 13:41:01 -04:00
|
|
|
bpp);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
_cogl_bitmap_unmap (bmp);
|
2010-07-13 13:41:01 -04:00
|
|
|
}
|
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
/* Send data to GL */
|
2012-03-22 13:04:47 -04:00
|
|
|
ctx->texture_driver->upload_subregion_to_gl (ctx,
|
|
|
|
GL_TEXTURE_2D,
|
2009-11-27 13:45:36 -05:00
|
|
|
tex_2d->gl_texture,
|
2010-04-26 05:01:43 -04:00
|
|
|
FALSE,
|
2009-11-27 13:45:36 -05:00
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_width, dst_height,
|
2010-07-08 10:15:22 -04:00
|
|
|
bmp,
|
|
|
|
gl_format,
|
|
|
|
gl_type);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2010-05-28 13:12:53 -04:00
|
|
|
tex_2d->mipmaps_dirty = TRUE;
|
|
|
|
|
2011-08-31 12:22:20 -04:00
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
|
|
|
_cogl_texture_2d_get_data (CoglTexture *tex,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
unsigned int rowstride,
|
|
|
|
uint8_t *data)
|
2009-11-27 13:45:36 -05:00
|
|
|
{
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
int bpp;
|
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
2011-07-07 07:48:24 -04:00
|
|
|
|
2012-02-13 18:02:04 -05:00
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
format,
|
|
|
|
NULL, /* internal format */
|
|
|
|
&gl_format,
|
|
|
|
&gl_type);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
2012-03-22 07:40:16 -04:00
|
|
|
ctx->texture_driver->prep_gl_for_pixels_download (ctx,
|
|
|
|
rowstride,
|
|
|
|
tex_2d->width,
|
|
|
|
bpp);
|
2010-03-17 15:39:55 -04:00
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
|
|
|
|
tex_2d->gl_texture,
|
2010-10-04 10:27:38 -04:00
|
|
|
tex_2d->is_foreign);
|
2012-03-22 13:04:47 -04:00
|
|
|
return ctx->texture_driver->gl_get_tex_image (ctx,
|
|
|
|
GL_TEXTURE_2D,
|
2010-07-08 08:54:37 -04:00
|
|
|
gl_format,
|
|
|
|
gl_type,
|
|
|
|
data);
|
2009-11-27 13:45:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_texture_2d_get_format (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_2D (tex)->format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
_cogl_texture_2d_get_gl_format (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_2D (tex)->gl_format;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static int
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_get_width (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_2D (tex)->width;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static int
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_get_height (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_2D (tex)->height;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2010-10-04 10:27:38 -04:00
|
|
|
_cogl_texture_2d_is_foreign (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_2D (tex)->is_foreign;
|
|
|
|
}
|
|
|
|
|
2012-02-09 06:19:04 -05:00
|
|
|
static CoglTextureType
|
|
|
|
_cogl_texture_2d_get_type (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_TYPE_2D;
|
|
|
|
}
|
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
static const CoglTextureVtable
|
|
|
|
cogl_texture_2d_vtable =
|
|
|
|
{
|
2012-04-04 10:09:43 -04:00
|
|
|
TRUE, /* primitive */
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_set_region,
|
|
|
|
_cogl_texture_2d_get_data,
|
2011-10-08 09:13:03 -04:00
|
|
|
NULL, /* foreach_sub_texture_in_region */
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_get_max_waste,
|
|
|
|
_cogl_texture_2d_is_sliced,
|
|
|
|
_cogl_texture_2d_can_hardware_repeat,
|
|
|
|
_cogl_texture_2d_transform_coords_to_gl,
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_texture_2d_transform_quad_coords_to_gl,
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_get_gl_texture,
|
|
|
|
_cogl_texture_2d_set_filters,
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_texture_2d_pre_paint,
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_texture_2d_ensure_non_quad_rendering,
|
2010-03-25 13:29:22 -04:00
|
|
|
_cogl_texture_2d_set_wrap_mode_parameters,
|
2009-11-27 13:45:36 -05:00
|
|
|
_cogl_texture_2d_get_format,
|
|
|
|
_cogl_texture_2d_get_gl_format,
|
|
|
|
_cogl_texture_2d_get_width,
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_texture_2d_get_height,
|
2012-02-09 06:19:04 -05:00
|
|
|
_cogl_texture_2d_get_type,
|
2012-04-04 10:09:43 -04:00
|
|
|
_cogl_texture_2d_is_foreign,
|
|
|
|
_cogl_texture_2d_set_auto_mipmap
|
2009-11-27 13:45:36 -05:00
|
|
|
};
|