2009-11-27 18:45:36 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-11-27 18:45:36 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2009-11-27 18:45:36 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2009-11-27 18:45:36 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 12:56:10 +00:00
|
|
|
*
|
|
|
|
*
|
2009-11-27 18:45:36 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2016-05-05 14:21:51 +00:00
|
|
|
#include "cogl-config.h"
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2012-02-13 23:02:04 +00:00
|
|
|
#include "cogl-private.h"
|
2009-11-27 18:45:36 +00:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-texture-2d-private.h"
|
|
|
|
#include "cogl-texture-driver.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 13:14:10 +00:00
|
|
|
#include "cogl-object-private.h"
|
2010-02-10 18:18:30 +00:00
|
|
|
#include "cogl-journal-private.h"
|
2011-02-10 18:22:27 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2018-05-21 19:57:38 +00:00
|
|
|
#include "cogl-gtype-private.h"
|
|
|
|
#include "driver/gl/cogl-texture-2d-gl-private.h"
|
2011-11-28 22:55:58 +00:00
|
|
|
#ifdef COGL_HAS_EGL_SUPPORT
|
2018-05-21 19:57:38 +00:00
|
|
|
#include "winsys/cogl-winsys-egl-private.h"
|
2011-11-28 22:55:58 +00:00
|
|
|
#endif
|
2009-11-27 18:45:36 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
static void _cogl_texture_2d_free (CoglTexture2D *tex_2d);
|
|
|
|
|
2011-05-16 23:05:54 +00:00
|
|
|
COGL_TEXTURE_DEFINE (Texture2D, texture_2d);
|
2013-09-02 15:02:42 +00:00
|
|
|
COGL_GTYPE_DEFINE_CLASS (Texture2D, texture_2d,
|
|
|
|
COGL_GTYPE_IMPLEMENT_INTERFACE (texture));
|
2009-11-27 18:45:36 +00:00
|
|
|
|
|
|
|
static const CoglTextureVtable cogl_texture_2d_vtable;
|
|
|
|
|
|
|
|
typedef struct _CoglTexture2DManualRepeatData
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d;
|
2011-10-08 13:13:03 +00:00
|
|
|
CoglMetaTextureCallback callback;
|
2009-11-27 18:45:36 +00:00
|
|
|
void *user_data;
|
|
|
|
} CoglTexture2DManualRepeatData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_2d_free (CoglTexture2D *tex_2d)
|
|
|
|
{
|
2012-09-10 20:45:33 +00:00
|
|
|
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
|
|
|
|
|
|
|
|
ctx->driver_vtable->texture_2d_free (tex_2d);
|
2010-04-26 09:01:43 +00:00
|
|
|
|
|
|
|
/* Chain up */
|
|
|
|
_cogl_texture_free (COGL_TEXTURE (tex_2d));
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
void
|
2012-04-04 14:09:43 +00:00
|
|
|
_cogl_texture_2d_set_auto_mipmap (CoglTexture *tex,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean value)
|
2012-04-04 14:09:43 +00:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
|
|
|
|
tex_2d->auto_mipmap = value;
|
|
|
|
}
|
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
CoglTexture2D *
|
2012-09-07 14:26:34 +00:00
|
|
|
_cogl_texture_2d_create_base (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
CoglTextureLoader *loader)
|
2009-11-27 18:45:36 +00:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = g_new (CoglTexture2D, 1);
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
_cogl_texture_init (tex, ctx, width, height, internal_format, loader,
|
|
|
|
&cogl_texture_2d_vtable);
|
2009-11-27 18:45:36 +00:00
|
|
|
|
|
|
|
tex_2d->mipmaps_dirty = TRUE;
|
2012-04-04 14:09:43 +00:00
|
|
|
tex_2d->auto_mipmap = TRUE;
|
2019-07-16 16:27:38 +00:00
|
|
|
tex_2d->is_get_data_supported = TRUE;
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2016-10-20 07:52:57 +00:00
|
|
|
tex_2d->gl_target = GL_TEXTURE_2D;
|
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
ctx->driver_vtable->texture_2d_init (tex_2d);
|
|
|
|
|
|
|
|
return _cogl_texture_2d_object_new (tex_2d);
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 13:19:11 +00:00
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_with_format (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format)
|
|
|
|
{
|
|
|
|
CoglTextureLoader *loader;
|
|
|
|
|
|
|
|
g_return_val_if_fail (width >= 1, NULL);
|
|
|
|
g_return_val_if_fail (height >= 1, NULL);
|
|
|
|
|
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
|
|
|
|
loader->src.sized.width = width;
|
|
|
|
loader->src.sized.height = height;
|
|
|
|
loader->src.sized.format = format;
|
|
|
|
|
|
|
|
return _cogl_texture_2d_create_base (ctx, width, height, format, loader);
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:05:54 +00:00
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
2013-07-02 00:48:54 +00:00
|
|
|
int height)
|
2009-11-27 18:45:36 +00:00
|
|
|
{
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglTextureLoader *loader;
|
|
|
|
|
2020-04-02 18:30:14 +00:00
|
|
|
g_return_val_if_fail (width >= 1, NULL);
|
|
|
|
g_return_val_if_fail (height >= 1, NULL);
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
loader = _cogl_texture_create_loader ();
|
2022-06-06 13:19:11 +00:00
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
|
2013-06-23 15:18:18 +00:00
|
|
|
loader->src.sized.width = width;
|
|
|
|
loader->src.sized.height = height;
|
2022-06-06 13:19:11 +00:00
|
|
|
loader->src.sized.format = COGL_PIXEL_FORMAT_ANY;
|
2013-06-23 15:18:18 +00:00
|
|
|
|
|
|
|
return _cogl_texture_2d_create_base (ctx, width, height,
|
2013-07-02 00:48:54 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE, loader);
|
2012-11-22 23:01:08 +00:00
|
|
|
}
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2012-11-22 23:01:08 +00:00
|
|
|
_cogl_texture_2d_allocate (CoglTexture *tex,
|
2019-06-18 06:02:10 +00:00
|
|
|
GError **error)
|
2012-11-22 23:01:08 +00:00
|
|
|
{
|
|
|
|
CoglContext *ctx = tex->context;
|
2013-06-23 15:18:18 +00:00
|
|
|
|
2012-11-22 23:01:08 +00:00
|
|
|
return ctx->driver_vtable->texture_2d_allocate (tex, error);
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-04 14:10:04 +00:00
|
|
|
CoglTexture2D *
|
2013-06-07 23:28:14 +00:00
|
|
|
_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean can_convert_in_place)
|
2009-11-27 18:45:36 +00:00
|
|
|
{
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglTextureLoader *loader;
|
2011-07-07 11:48:24 +00:00
|
|
|
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (bmp != NULL, NULL);
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_BITMAP;
|
|
|
|
loader->src.bitmap.bitmap = cogl_object_ref (bmp);
|
|
|
|
loader->src.bitmap.can_convert_in_place = can_convert_in_place;
|
2010-03-01 18:54:03 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
return _cogl_texture_2d_create_base (_cogl_bitmap_get_context (bmp),
|
|
|
|
cogl_bitmap_get_width (bmp),
|
|
|
|
cogl_bitmap_get_height (bmp),
|
2013-07-02 00:48:54 +00:00
|
|
|
cogl_bitmap_get_format (bmp),
|
2013-06-23 15:18:18 +00:00
|
|
|
loader);
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 23:28:14 +00:00
|
|
|
CoglTexture2D *
|
2013-07-02 00:48:54 +00:00
|
|
|
cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp)
|
2013-06-07 23:28:14 +00:00
|
|
|
{
|
2013-07-02 00:48:54 +00:00
|
|
|
return _cogl_texture_2d_new_from_bitmap (bmp,
|
|
|
|
FALSE); /* can't convert in place */
|
2013-06-07 23:28:14 +00:00
|
|
|
}
|
|
|
|
|
2013-06-08 01:10:15 +00:00
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_from_file (CoglContext *ctx,
|
|
|
|
const char *filename,
|
2019-06-18 06:02:10 +00:00
|
|
|
GError **error)
|
2013-06-08 01:10:15 +00:00
|
|
|
{
|
|
|
|
CoglBitmap *bmp;
|
|
|
|
CoglTexture2D *tex_2d = NULL;
|
|
|
|
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2013-06-08 01:10:15 +00:00
|
|
|
|
|
|
|
bmp = _cogl_bitmap_from_file (ctx, filename, error);
|
|
|
|
if (bmp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tex_2d = _cogl_texture_2d_new_from_bitmap (bmp,
|
2013-07-02 00:48:54 +00:00
|
|
|
TRUE); /* can convert in-place */
|
2013-06-08 01:10:15 +00:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
|
|
|
return tex_2d;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:05:54 +00:00
|
|
|
CoglTexture2D *
|
|
|
|
cogl_texture_2d_new_from_data (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat 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 20:56:40 +00:00
|
|
|
const uint8_t *data,
|
2019-06-18 06:02:10 +00:00
|
|
|
GError **error)
|
2011-05-16 23:05:54 +00:00
|
|
|
{
|
|
|
|
CoglBitmap *bmp;
|
2012-04-16 13:14:10 +00:00
|
|
|
CoglTexture2D *tex_2d;
|
2011-05-16 23:05:54 +00:00
|
|
|
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, NULL);
|
2019-10-14 16:56:25 +00:00
|
|
|
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, NULL);
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (data != NULL, NULL);
|
2011-05-16 23:05:54 +00:00
|
|
|
|
|
|
|
/* Rowstride from width if not given */
|
|
|
|
if (rowstride == 0)
|
2019-10-14 16:56:25 +00:00
|
|
|
rowstride = width * cogl_pixel_format_get_bytes_per_pixel (format, 0);
|
2011-05-16 23:05:54 +00:00
|
|
|
|
|
|
|
/* Wrap the data into a bitmap */
|
2012-03-13 14:46:18 +00: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 20:56:40 +00:00
|
|
|
(uint8_t *) data);
|
2011-05-16 23:05:54 +00:00
|
|
|
|
2013-07-02 00:48:54 +00:00
|
|
|
tex_2d = cogl_texture_2d_new_from_bitmap (bmp);
|
2011-05-16 23:05:54 +00:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
if (tex_2d &&
|
|
|
|
!cogl_texture_allocate (COGL_TEXTURE (tex_2d), error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (tex_2d);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-16 13:14:10 +00:00
|
|
|
return tex_2d;
|
2011-05-16 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 21:34:10 +00: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 *
|
2016-10-20 06:14:14 +00:00
|
|
|
cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
EGLImageKHR image,
|
2019-07-16 16:29:29 +00:00
|
|
|
CoglEglImageFlags flags,
|
2019-06-18 06:02:10 +00:00
|
|
|
GError **error)
|
2011-05-24 21:34:10 +00:00
|
|
|
{
|
2013-06-23 15:18:18 +00:00
|
|
|
CoglTextureLoader *loader;
|
2014-02-19 17:26:02 +00:00
|
|
|
CoglTexture2D *tex;
|
2013-06-23 15:18:18 +00:00
|
|
|
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (_cogl_context_get_winsys (ctx)->constraints &
|
|
|
|
COGL_RENDERER_CONSTRAINT_USES_EGL,
|
|
|
|
NULL);
|
2011-05-24 21:34:10 +00:00
|
|
|
|
2019-06-17 21:42:01 +00:00
|
|
|
g_return_val_if_fail (_cogl_has_private_feature
|
|
|
|
(ctx,
|
|
|
|
COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE),
|
|
|
|
NULL);
|
2011-05-24 21:34:10 +00:00
|
|
|
|
2013-06-23 15:18:18 +00:00
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE;
|
|
|
|
loader->src.egl_image.image = image;
|
|
|
|
loader->src.egl_image.width = width;
|
|
|
|
loader->src.egl_image.height = height;
|
|
|
|
loader->src.egl_image.format = format;
|
2019-07-16 16:29:29 +00:00
|
|
|
loader->src.egl_image.flags = flags;
|
2013-06-23 15:18:18 +00:00
|
|
|
|
2014-02-19 17:26:02 +00:00
|
|
|
tex = _cogl_texture_2d_create_base (ctx, width, height, format, loader);
|
|
|
|
|
|
|
|
if (!cogl_texture_allocate (COGL_TEXTURE (tex), error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (tex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tex;
|
2011-05-24 21:34:10 +00:00
|
|
|
}
|
|
|
|
#endif /* defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base) */
|
|
|
|
|
2010-06-03 14:06:47 +00:00
|
|
|
void
|
2012-04-16 13:14:10 +00:00
|
|
|
_cogl_texture_2d_externally_modified (CoglTexture *texture)
|
2010-06-03 14:06:47 +00:00
|
|
|
{
|
2012-04-16 13:14:10 +00:00
|
|
|
if (!cogl_is_texture_2d (texture))
|
2010-06-03 14:06:47 +00:00
|
|
|
return;
|
|
|
|
|
2012-04-16 13:14:10 +00:00
|
|
|
COGL_TEXTURE_2D (texture)->mipmaps_dirty = TRUE;
|
2010-06-03 14:06:47 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 18:22:27 +00:00
|
|
|
void
|
2012-04-16 13:14:10 +00:00
|
|
|
_cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d,
|
2011-02-10 18:22:27 +00:00
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int width,
|
2012-11-09 17:55:54 +00:00
|
|
|
int height,
|
|
|
|
CoglFramebuffer *src_fb,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int level)
|
2011-02-10 18:22:27 +00:00
|
|
|
{
|
2012-11-22 23:01:08 +00:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2d);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
|
|
|
|
/* Assert that the storage for this texture has been allocated */
|
|
|
|
cogl_texture_allocate (tex, NULL); /* (abort on error) */
|
2012-09-07 14:26:34 +00:00
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
ctx->driver_vtable->texture_2d_copy_from_framebuffer (tex_2d,
|
|
|
|
src_x,
|
|
|
|
src_y,
|
|
|
|
width,
|
2012-11-09 17:55:54 +00:00
|
|
|
height,
|
|
|
|
src_fb,
|
|
|
|
dst_x,
|
|
|
|
dst_y,
|
|
|
|
level);
|
2011-02-10 18:22:27 +00: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-10 01:57:32 +00:00
|
|
|
static int
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_get_max_waste (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_is_sliced (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_can_hardware_repeat (CoglTexture *tex)
|
|
|
|
{
|
2019-03-28 19:03:44 +00:00
|
|
|
return TRUE;
|
2009-11-27 18:45:36 +00: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 21:49:04 +00:00
|
|
|
static CoglTransformResult
|
2010-01-18 09:22:04 +00: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 21:49:04 +00: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 16:44:38 +00:00
|
|
|
{
|
|
|
|
/* Repeat is needed */
|
|
|
|
return (_cogl_texture_2d_can_hardware_repeat (tex) ?
|
|
|
|
COGL_TRANSFORM_HARDWARE_REPEAT :
|
|
|
|
COGL_TRANSFORM_SOFTWARE_REPEAT);
|
|
|
|
}
|
2010-03-01 21:49:04 +00:00
|
|
|
|
2012-04-24 16:44:38 +00:00
|
|
|
/* No repeat is needed */
|
|
|
|
return COGL_TRANSFORM_NO_REPEAT;
|
2010-01-18 09:22:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_get_gl_texture (CoglTexture *tex,
|
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
2012-09-10 20:45:33 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
2009-11-27 18:45:36 +00:00
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
if (ctx->driver_vtable->texture_2d_get_gl_handle)
|
|
|
|
{
|
|
|
|
GLuint handle;
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
if (out_gl_target)
|
2016-10-20 07:52:57 +00:00
|
|
|
*out_gl_target = tex_2d->gl_target;
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
handle = ctx->driver_vtable->texture_2d_get_gl_handle (tex_2d);
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
if (out_gl_handle)
|
|
|
|
*out_gl_handle = handle;
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
return handle ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 16:39:59 +00:00
|
|
|
_cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
2009-11-27 18:45:36 +00:00
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
|
|
|
|
/* Only update if the mipmaps are dirty */
|
2010-06-09 16:39:59 +00:00
|
|
|
if ((flags & COGL_TEXTURE_NEEDS_MIPMAP) &&
|
|
|
|
tex_2d->auto_mipmap && tex_2d->mipmaps_dirty)
|
|
|
|
{
|
2012-09-10 20:45:33 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
|
2020-07-02 09:58:30 +00:00
|
|
|
/* Since we are about to ask the GPU to generate mipmaps of tex, we
|
|
|
|
* better make sure tex is up-to-date.
|
|
|
|
*/
|
|
|
|
_cogl_texture_flush_journal_rendering (tex);
|
|
|
|
|
2022-09-06 09:29:26 +00:00
|
|
|
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_QUIRK_GENERATE_MIPMAP_NEEDS_FLUSH) &&
|
|
|
|
_cogl_texture_get_associated_framebuffers (tex))
|
|
|
|
ctx->glFlush ();
|
|
|
|
|
2012-09-10 20:45:33 +00:00
|
|
|
ctx->driver_vtable->texture_2d_generate_mipmap (tex_2d);
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2010-06-09 16:39:59 +00:00
|
|
|
tex_2d->mipmaps_dirty = FALSE;
|
|
|
|
}
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 09:22:04 +00:00
|
|
|
static void
|
|
|
|
_cogl_texture_2d_ensure_non_quad_rendering (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
/* Nothing needs to be done */
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2012-11-08 17:54:10 +00:00
|
|
|
_cogl_texture_2d_set_region (CoglTexture *tex,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height,
|
2012-11-09 17:55:54 +00:00
|
|
|
int level,
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBitmap *bmp,
|
2019-06-18 06:02:10 +00:00
|
|
|
GError **error)
|
2009-11-27 18:45:36 +00:00
|
|
|
{
|
2012-09-07 14:26:34 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
2012-09-10 20:45:33 +00:00
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
2010-07-13 17:41:01 +00:00
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
if (!ctx->driver_vtable->texture_2d_copy_from_bitmap (tex_2d,
|
|
|
|
src_x,
|
|
|
|
src_y,
|
|
|
|
width,
|
|
|
|
height,
|
2012-11-09 17:55:54 +00:00
|
|
|
bmp,
|
|
|
|
dst_x,
|
|
|
|
dst_y,
|
|
|
|
level,
|
2012-11-08 17:54:10 +00:00
|
|
|
error))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-11-27 18:45:36 +00:00
|
|
|
|
2010-05-28 17:12:53 +00:00
|
|
|
tex_2d->mipmaps_dirty = TRUE;
|
|
|
|
|
2009-11-27 18:45:36 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2018-12-19 10:46:45 +00:00
|
|
|
_cogl_texture_2d_is_get_data_supported (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
|
|
|
|
return ctx->driver_vtable->texture_2d_is_get_data_supported (tex_2d);
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
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 20:56:40 +00:00
|
|
|
_cogl_texture_2d_get_data (CoglTexture *tex,
|
|
|
|
CoglPixelFormat format,
|
2012-09-26 16:05:01 +00:00
|
|
|
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 20:56:40 +00:00
|
|
|
uint8_t *data)
|
2009-11-27 18:45:36 +00:00
|
|
|
{
|
2012-09-07 14:26:34 +00:00
|
|
|
CoglContext *ctx = tex->context;
|
2012-09-10 20:45:33 +00:00
|
|
|
|
|
|
|
if (ctx->driver_vtable->texture_2d_get_data)
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
|
|
|
|
ctx->driver_vtable->texture_2d_get_data (tex_2d, format, rowstride, data);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_texture_2d_get_format (CoglTexture *tex)
|
|
|
|
{
|
2012-11-22 23:01:08 +00:00
|
|
|
return COGL_TEXTURE_2D (tex)->internal_format;
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
_cogl_texture_2d_get_gl_format (CoglTexture *tex)
|
|
|
|
{
|
2012-11-09 17:55:54 +00:00
|
|
|
return COGL_TEXTURE_2D (tex)->gl_internal_format;
|
2009-11-27 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const CoglTextureVtable
|
|
|
|
cogl_texture_2d_vtable =
|
|
|
|
{
|
2012-04-04 14:09:43 +00:00
|
|
|
TRUE, /* primitive */
|
2012-11-22 23:01:08 +00:00
|
|
|
_cogl_texture_2d_allocate,
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_set_region,
|
2018-12-19 10:46:45 +00:00
|
|
|
_cogl_texture_2d_is_get_data_supported,
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_get_data,
|
2011-10-08 13:13:03 +00:00
|
|
|
NULL, /* foreach_sub_texture_in_region */
|
2009-11-27 18:45:36 +00: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 09:22:04 +00:00
|
|
|
_cogl_texture_2d_transform_quad_coords_to_gl,
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_get_gl_texture,
|
2012-09-10 19:35:39 +00:00
|
|
|
_cogl_texture_2d_gl_flush_legacy_texobj_filters,
|
2010-06-09 16:39:59 +00:00
|
|
|
_cogl_texture_2d_pre_paint,
|
2010-01-18 09:22:04 +00:00
|
|
|
_cogl_texture_2d_ensure_non_quad_rendering,
|
2012-09-10 19:35:39 +00:00
|
|
|
_cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes,
|
2009-11-27 18:45:36 +00:00
|
|
|
_cogl_texture_2d_get_format,
|
|
|
|
_cogl_texture_2d_get_gl_format,
|
2012-04-04 14:09:43 +00:00
|
|
|
_cogl_texture_2d_set_auto_mipmap
|
2009-11-27 18:45:36 +00:00
|
|
|
};
|