2009-11-27 11:39:16 -05:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-11-27 11:39:16 -05:00
|
|
|
*
|
2011-10-21 06:36:25 -04:00
|
|
|
* Copyright (C) 2009,2010,2011 Intel Corporation.
|
2009-11-27 11:39:16 -05:00
|
|
|
*
|
2014-02-21 20:28:54 -05: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:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* 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 07:56:10 -05:00
|
|
|
*
|
|
|
|
*
|
2009-11-27 11:39:16 -05:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
2016-05-05 10:21:51 -04:00
|
|
|
#include "cogl-config.h"
|
2009-11-27 11:39:16 -05:00
|
|
|
|
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-texture-private.h"
|
|
|
|
#include "cogl-sub-texture-private.h"
|
2012-02-17 20:19:17 -05:00
|
|
|
#include "cogl-sub-texture.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2011-10-21 06:36:25 -04:00
|
|
|
#include "cogl-object.h"
|
2009-11-27 11:39:16 -05:00
|
|
|
#include "cogl-texture-driver.h"
|
2012-02-17 20:19:17 -05:00
|
|
|
#include "cogl-texture-2d.h"
|
2013-09-02 11:02:42 -04:00
|
|
|
#include "cogl-gtype-private.h"
|
2018-05-21 15:57:38 -04:00
|
|
|
#include "driver/gl/cogl-texture-gl-private.h"
|
2009-11-27 11:39:16 -05:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
static void _cogl_sub_texture_free (CoglSubTexture *sub_tex);
|
|
|
|
|
2011-10-21 06:36:25 -04:00
|
|
|
COGL_TEXTURE_DEFINE (SubTexture, sub_texture);
|
2013-09-02 11:02:42 -04:00
|
|
|
COGL_GTYPE_DEFINE_CLASS (SubTexture, sub_texture);
|
2009-11-27 11:39:16 -05:00
|
|
|
|
|
|
|
static const CoglTextureVtable cogl_sub_texture_vtable;
|
|
|
|
|
|
|
|
static void
|
2011-10-08 09:13:03 -04:00
|
|
|
_cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
|
|
|
|
float *coords)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
2012-11-22 16:46:54 -05:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (sub_tex);
|
2019-03-08 12:16:44 -05:00
|
|
|
float width = cogl_texture_get_width (sub_tex->full_texture);
|
|
|
|
float height = cogl_texture_get_height (sub_tex->full_texture);
|
2012-11-22 16:46:54 -05:00
|
|
|
|
2019-03-08 12:16:44 -05:00
|
|
|
coords[0] = (coords[0] * width - sub_tex->sub_x) / tex->width;
|
|
|
|
coords[1] = (coords[1] * height - sub_tex->sub_y) / tex->height;
|
|
|
|
coords[2] = (coords[2] * width - sub_tex->sub_x) / tex->width;
|
|
|
|
coords[3] = (coords[3] * height - sub_tex->sub_y) / tex->height;
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
|
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
|
|
|
float *coords)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
2012-11-22 16:46:54 -05:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (sub_tex);
|
2019-03-08 12:16:44 -05:00
|
|
|
float width = cogl_texture_get_width (sub_tex->full_texture);
|
|
|
|
float height = cogl_texture_get_height (sub_tex->full_texture);
|
2012-11-22 16:46:54 -05:00
|
|
|
|
2019-03-08 12:16:44 -05:00
|
|
|
coords[0] = (coords[0] * tex->width + sub_tex->sub_x) / width;
|
|
|
|
coords[1] = (coords[1] * tex->height + sub_tex->sub_y) / height;
|
|
|
|
coords[2] = (coords[2] * tex->width + sub_tex->sub_x) / width;
|
|
|
|
coords[3] = (coords[3] * tex->height + sub_tex->sub_y) / height;
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _CoglSubTextureForeachData
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex;
|
2011-10-08 09:13:03 -04:00
|
|
|
CoglMetaTextureCallback callback;
|
2009-11-27 11:39:16 -05:00
|
|
|
void *user_data;
|
|
|
|
} CoglSubTextureForeachData;
|
|
|
|
|
|
|
|
static void
|
2011-10-08 09:13:03 -04:00
|
|
|
unmap_coords_cb (CoglTexture *slice_texture,
|
|
|
|
const float *slice_texture_coords,
|
|
|
|
const float *meta_coords,
|
|
|
|
void *user_data)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
|
|
|
CoglSubTextureForeachData *data = user_data;
|
2011-10-08 09:13:03 -04:00
|
|
|
float unmapped_coords[4];
|
2009-11-27 11:39:16 -05:00
|
|
|
|
2011-10-08 09:13:03 -04:00
|
|
|
memcpy (unmapped_coords, meta_coords, sizeof (unmapped_coords));
|
2009-11-27 11:39:16 -05:00
|
|
|
|
2011-10-08 09:13:03 -04:00
|
|
|
_cogl_sub_texture_unmap_quad (data->sub_tex, unmapped_coords);
|
2009-11-27 11:39:16 -05:00
|
|
|
|
2011-10-08 09:13:03 -04:00
|
|
|
data->callback (slice_texture,
|
|
|
|
slice_texture_coords,
|
|
|
|
unmapped_coords,
|
|
|
|
data->user_data);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_sub_texture_foreach_sub_texture_in_region (
|
|
|
|
CoglTexture *tex,
|
|
|
|
float virtual_tx_1,
|
|
|
|
float virtual_ty_1,
|
|
|
|
float virtual_tx_2,
|
|
|
|
float virtual_ty_2,
|
2011-10-08 09:13:03 -04:00
|
|
|
CoglMetaTextureCallback callback,
|
2009-11-27 11:39:16 -05:00
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
2011-10-08 09:13:03 -04:00
|
|
|
CoglTexture *full_texture = sub_tex->full_texture;
|
|
|
|
float mapped_coords[4] =
|
|
|
|
{ virtual_tx_1, virtual_ty_1, virtual_tx_2, virtual_ty_2};
|
|
|
|
float virtual_coords[4] =
|
|
|
|
{ virtual_tx_1, virtual_ty_1, virtual_tx_2, virtual_ty_2};
|
|
|
|
|
|
|
|
/* map the virtual coordinates to ->full_texture coordinates */
|
|
|
|
_cogl_sub_texture_map_quad (sub_tex, mapped_coords);
|
|
|
|
|
|
|
|
/* TODO: Add something like cogl_is_low_level_texture() */
|
2019-03-08 12:16:44 -05:00
|
|
|
if (cogl_is_texture_2d (full_texture))
|
2011-10-08 09:13:03 -04:00
|
|
|
{
|
|
|
|
callback (sub_tex->full_texture,
|
|
|
|
mapped_coords,
|
|
|
|
virtual_coords,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglSubTextureForeachData data;
|
|
|
|
|
|
|
|
data.sub_tex = sub_tex;
|
|
|
|
data.callback = callback;
|
|
|
|
data.user_data = user_data;
|
|
|
|
|
|
|
|
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (full_texture),
|
|
|
|
mapped_coords[0],
|
|
|
|
mapped_coords[1],
|
|
|
|
mapped_coords[2],
|
|
|
|
mapped_coords[3],
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
unmap_coords_cb,
|
|
|
|
&data);
|
|
|
|
}
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
|
|
|
|
GLenum wrap_mode_s,
|
2020-01-21 14:05:20 -05:00
|
|
|
GLenum wrap_mode_t)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_gl_flush_legacy_texobj_wrap_modes (sub_tex->full_texture,
|
|
|
|
wrap_mode_s,
|
2020-01-21 14:05:20 -05:00
|
|
|
wrap_mode_t);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_sub_texture_free (CoglSubTexture *sub_tex)
|
|
|
|
{
|
2011-10-21 06:36:25 -04:00
|
|
|
cogl_object_unref (sub_tex->next_texture);
|
|
|
|
cogl_object_unref (sub_tex->full_texture);
|
2009-11-27 11:39:16 -05:00
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
/* Chain up */
|
|
|
|
_cogl_texture_free (COGL_TEXTURE (sub_tex));
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
2011-10-21 06:36:25 -04:00
|
|
|
CoglSubTexture *
|
|
|
|
cogl_sub_texture_new (CoglContext *ctx,
|
|
|
|
CoglTexture *next_texture,
|
|
|
|
int sub_x, int sub_y,
|
|
|
|
int sub_width, int sub_height)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
2011-10-21 06:36:25 -04:00
|
|
|
CoglTexture *full_texture;
|
2009-11-27 11:39:16 -05:00
|
|
|
CoglSubTexture *sub_tex;
|
|
|
|
CoglTexture *tex;
|
2010-02-12 05:08:51 -05:00
|
|
|
unsigned int next_width, next_height;
|
2010-01-18 04:22:04 -05:00
|
|
|
|
2010-02-12 05:08:51 -05:00
|
|
|
next_width = cogl_texture_get_width (next_texture);
|
|
|
|
next_height = cogl_texture_get_height (next_texture);
|
2010-01-18 04:22:04 -05:00
|
|
|
|
|
|
|
/* The region must specify a non-zero subset of the full texture */
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (sub_x >= 0 && sub_y >= 0, NULL);
|
|
|
|
g_return_val_if_fail (sub_width > 0 && sub_height > 0, NULL);
|
|
|
|
g_return_val_if_fail (sub_x + sub_width <= next_width, NULL);
|
|
|
|
g_return_val_if_fail (sub_y + sub_height <= next_height, NULL);
|
2009-11-27 11:39:16 -05:00
|
|
|
|
|
|
|
sub_tex = g_new (CoglSubTexture, 1);
|
|
|
|
|
|
|
|
tex = COGL_TEXTURE (sub_tex);
|
2011-01-06 08:25:45 -05:00
|
|
|
|
2012-11-22 16:46:54 -05:00
|
|
|
_cogl_texture_init (tex, ctx, sub_width, sub_height,
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_get_format (next_texture),
|
|
|
|
NULL, /* no loader */
|
2012-11-22 16:46:54 -05:00
|
|
|
&cogl_sub_texture_vtable);
|
2009-11-27 11:39:16 -05:00
|
|
|
|
2010-02-12 05:08:51 -05:00
|
|
|
/* If the next texture is also a sub texture we can avoid one level
|
|
|
|
of indirection by referencing the full texture of that texture
|
|
|
|
instead. */
|
2011-10-21 06:36:25 -04:00
|
|
|
if (cogl_is_sub_texture (next_texture))
|
2010-02-12 05:08:51 -05:00
|
|
|
{
|
2012-03-06 13:21:28 -05:00
|
|
|
CoglSubTexture *other_sub_tex = COGL_SUB_TEXTURE (next_texture);
|
2010-02-12 05:08:51 -05:00
|
|
|
full_texture = other_sub_tex->full_texture;
|
|
|
|
sub_x += other_sub_tex->sub_x;
|
|
|
|
sub_y += other_sub_tex->sub_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
full_texture = next_texture;
|
|
|
|
|
2011-10-21 06:36:25 -04:00
|
|
|
sub_tex->next_texture = cogl_object_ref (next_texture);
|
|
|
|
sub_tex->full_texture = cogl_object_ref (full_texture);
|
2009-11-27 11:39:16 -05:00
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
sub_tex->sub_x = sub_x;
|
|
|
|
sub_tex->sub_y = sub_y;
|
2009-11-27 11:39:16 -05:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
return _cogl_sub_texture_object_new (sub_tex);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_sub_texture_allocate (CoglTexture *tex,
|
2019-06-18 02:02:10 -04:00
|
|
|
GError **error)
|
2012-11-22 18:01:08 -05:00
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean status = cogl_texture_allocate (sub_tex->full_texture, error);
|
2012-11-22 18:01:08 -05:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_set_allocated (tex,
|
|
|
|
_cogl_texture_get_format (sub_tex->full_texture),
|
|
|
|
tex->width, tex->height);
|
|
|
|
|
|
|
|
return status;
|
2012-11-22 18:01:08 -05:00
|
|
|
}
|
|
|
|
|
2011-12-12 13:20:00 -05:00
|
|
|
CoglTexture *
|
|
|
|
cogl_sub_texture_get_parent (CoglSubTexture *sub_texture)
|
|
|
|
{
|
|
|
|
return sub_texture->next_texture;
|
|
|
|
}
|
|
|
|
|
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 11:39:16 -05:00
|
|
|
_cogl_sub_texture_get_max_waste (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
|
|
|
return cogl_texture_get_max_waste (sub_tex->full_texture);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_sub_texture_is_sliced (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
|
|
|
return cogl_texture_is_sliced (sub_tex->full_texture);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_sub_texture_can_hardware_repeat (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
/* We can hardware repeat if the subtexture actually represents all of the
|
|
|
|
of the full texture */
|
2012-11-22 16:46:54 -05:00
|
|
|
return (tex->width ==
|
2010-01-18 04:22:04 -05:00
|
|
|
cogl_texture_get_width (sub_tex->full_texture) &&
|
2012-11-22 16:46:54 -05:00
|
|
|
tex->height ==
|
2010-01-18 04:22:04 -05:00
|
|
|
cogl_texture_get_height (sub_tex->full_texture) &&
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_texture_can_hardware_repeat (sub_tex->full_texture));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_sub_texture_transform_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *s,
|
|
|
|
float *t)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
/* This won't work if the sub texture is not the size of the full
|
|
|
|
texture and the coordinates are outside the range [0,1] */
|
2012-11-22 16:46:54 -05:00
|
|
|
*s = ((*s * tex->width + sub_tex->sub_x) /
|
2010-01-18 04:22:04 -05:00
|
|
|
cogl_texture_get_width (sub_tex->full_texture));
|
2012-11-22 16:46:54 -05:00
|
|
|
*t = ((*t * tex->height + sub_tex->sub_y) /
|
2010-01-18 04:22:04 -05:00
|
|
|
cogl_texture_get_height (sub_tex->full_texture));
|
|
|
|
|
2010-02-09 05:21:37 -05:00
|
|
|
_cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t);
|
2010-01-18 04:22:04 -05:00
|
|
|
}
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
static CoglTransformResult
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_sub_texture_transform_quad_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *coords)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* We can't support repeating with this method. In this case
|
|
|
|
cogl-primitives will resort to manual repeating */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
if (coords[i] < 0.0f || coords[i] > 1.0f)
|
2010-03-01 16:49:04 -05:00
|
|
|
return COGL_TRANSFORM_SOFTWARE_REPEAT;
|
2010-01-18 04:22:04 -05:00
|
|
|
|
|
|
|
_cogl_sub_texture_map_quad (sub_tex, coords);
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
return _cogl_texture_transform_quad_coords_to_gl (sub_tex->full_texture,
|
|
|
|
coords);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_sub_texture_get_gl_texture (CoglTexture *tex,
|
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
|
|
|
return cogl_texture_get_gl_texture (sub_tex->full_texture,
|
|
|
|
out_gl_handle,
|
|
|
|
out_gl_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_sub_texture_gl_flush_legacy_texobj_filters (CoglTexture *tex,
|
|
|
|
GLenum min_filter,
|
|
|
|
GLenum mag_filter)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_gl_flush_legacy_texobj_filters (sub_tex->full_texture,
|
|
|
|
min_filter, mag_filter);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_sub_texture_pre_paint (CoglTexture *tex,
|
|
|
|
CoglTexturePrePaintFlags flags)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_texture_pre_paint (sub_tex->full_texture, flags);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_sub_texture_ensure_non_quad_rendering (CoglTexture *tex)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_sub_texture_set_region (CoglTexture *tex,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int dst_width,
|
|
|
|
int dst_height,
|
2012-11-09 12:55:54 -05:00
|
|
|
int level,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBitmap *bmp,
|
2019-06-18 02:02:10 -04:00
|
|
|
GError **error)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
2010-01-18 04:22:04 -05:00
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2012-11-09 12:55:54 -05:00
|
|
|
if (level != 0)
|
|
|
|
{
|
|
|
|
int full_width = cogl_texture_get_width (sub_tex->full_texture);
|
|
|
|
int full_height = cogl_texture_get_width (sub_tex->full_texture);
|
|
|
|
|
2019-06-17 17:42:01 -04:00
|
|
|
g_return_val_if_fail (sub_tex->sub_x == 0 &&
|
|
|
|
cogl_texture_get_width (tex) == full_width,
|
|
|
|
FALSE);
|
|
|
|
g_return_val_if_fail (sub_tex->sub_y == 0 &&
|
|
|
|
cogl_texture_get_height (tex) == full_height,
|
|
|
|
FALSE);
|
2012-11-09 12:55:54 -05:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return _cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_width, dst_height,
|
|
|
|
bmp,
|
2012-11-09 12:55:54 -05:00
|
|
|
dst_x + sub_tex->sub_x,
|
|
|
|
dst_y + sub_tex->sub_y,
|
|
|
|
level,
|
2012-11-08 12:54:10 -05:00
|
|
|
error);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2018-12-19 05:46:45 -05:00
|
|
|
_cogl_sub_texture_is_get_data_supported (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
|
|
|
return cogl_texture_is_get_data_supported (sub_tex->full_texture);
|
|
|
|
}
|
|
|
|
|
2009-11-27 11:39:16 -05:00
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_sub_texture_get_format (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2013-06-27 13:33:04 -04:00
|
|
|
return _cogl_texture_get_format (sub_tex->full_texture);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
_cogl_sub_texture_get_gl_format (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
|
|
|
|
2012-11-22 16:31:25 -05:00
|
|
|
return _cogl_texture_gl_get_format (sub_tex->full_texture);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static const CoglTextureVtable
|
|
|
|
cogl_sub_texture_vtable =
|
|
|
|
{
|
2012-04-04 10:09:43 -04:00
|
|
|
FALSE, /* not primitive */
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_sub_texture_allocate,
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_sub_texture_set_region,
|
2018-12-19 05:46:45 -05:00
|
|
|
_cogl_sub_texture_is_get_data_supported,
|
2010-11-12 11:02:13 -05:00
|
|
|
NULL, /* get_data */
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_sub_texture_foreach_sub_texture_in_region,
|
|
|
|
_cogl_sub_texture_get_max_waste,
|
|
|
|
_cogl_sub_texture_is_sliced,
|
|
|
|
_cogl_sub_texture_can_hardware_repeat,
|
|
|
|
_cogl_sub_texture_transform_coords_to_gl,
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_sub_texture_transform_quad_coords_to_gl,
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_sub_texture_get_gl_texture,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_sub_texture_gl_flush_legacy_texobj_filters,
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_sub_texture_pre_paint,
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_sub_texture_ensure_non_quad_rendering,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes,
|
2009-11-27 11:39:16 -05:00
|
|
|
_cogl_sub_texture_get_format,
|
|
|
|
_cogl_sub_texture_get_gl_format,
|
2012-04-04 10:09:43 -04:00
|
|
|
NULL /* set_auto_mipmap */
|
2009-11-27 11:39:16 -05:00
|
|
|
};
|