2009-08-30 06:36:11 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-08-30 06:36:11 -04:00
|
|
|
*
|
2010-10-04 09:34:24 -04:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
2009-08-30 06:36:11 -04: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-08-30 06:36:11 -04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-07-25 16:36:41 -04:00
|
|
|
#include "cogl-debug.h"
|
2012-02-13 18:02:04 -05:00
|
|
|
#include "cogl-private.h"
|
2009-08-30 06:36:11 -04:00
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-bitmap.h"
|
|
|
|
#include "cogl-bitmap-private.h"
|
|
|
|
#include "cogl-texture-private.h"
|
2012-09-10 16:45:33 -04:00
|
|
|
#include "cogl-texture-2d-gl.h"
|
2010-10-04 09:34:24 -04:00
|
|
|
#include "cogl-texture-2d-private.h"
|
2009-08-30 06:36:11 -04:00
|
|
|
#include "cogl-texture-2d-sliced-private.h"
|
2012-11-08 18:00:49 -05:00
|
|
|
#include "cogl-texture-gl-private.h"
|
2009-08-30 06:36:11 -04:00
|
|
|
#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"
|
2009-09-23 10:11:55 -04:00
|
|
|
#include "cogl-spans.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"
|
2012-04-04 11:25:25 -04:00
|
|
|
#include "cogl-primitive-texture.h"
|
2012-08-31 14:28:27 -04:00
|
|
|
#include "cogl-error-private.h"
|
2012-11-09 12:55:54 -05:00
|
|
|
#include "cogl-texture-gl-private.h"
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
static void _cogl_texture_2d_sliced_free (CoglTexture2DSliced *tex_2ds);
|
|
|
|
|
2011-10-08 06:53:20 -04:00
|
|
|
COGL_TEXTURE_DEFINE (Texture2DSliced, texture_2d_sliced);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
static const CoglTextureVtable cogl_texture_2d_sliced_vtable;
|
|
|
|
|
2011-10-08 09:13:03 -04:00
|
|
|
typedef struct _ForeachData
|
|
|
|
{
|
|
|
|
CoglMetaTextureCallback callback;
|
|
|
|
void *user_data;
|
|
|
|
float x_normalize_factor;
|
|
|
|
float y_normalize_factor;
|
|
|
|
} ForeachData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
re_normalize_sub_texture_coords_cb (CoglTexture *sub_texture,
|
|
|
|
const float *sub_texture_coords,
|
|
|
|
const float *meta_coords,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
ForeachData *data = user_data;
|
2012-12-10 10:47:45 -05:00
|
|
|
/* The coordinates passed to the span iterating code were
|
|
|
|
* un-normalized so we need to renormalize them before passing them
|
|
|
|
* on */
|
2011-10-08 09:13:03 -04:00
|
|
|
float re_normalized_coords[4] =
|
|
|
|
{
|
2012-12-10 10:47:45 -05:00
|
|
|
meta_coords[0] * data->x_normalize_factor,
|
|
|
|
meta_coords[1] * data->y_normalize_factor,
|
|
|
|
meta_coords[2] * data->x_normalize_factor,
|
|
|
|
meta_coords[3] * data->y_normalize_factor
|
2011-10-08 09:13:03 -04:00
|
|
|
};
|
|
|
|
|
2012-12-10 10:47:45 -05:00
|
|
|
data->callback (sub_texture, sub_texture_coords, re_normalized_coords,
|
2011-10-08 09:13:03 -04:00
|
|
|
data->user_data);
|
|
|
|
}
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
static void
|
2009-08-30 06:36:11 -04:00
|
|
|
_cogl_texture_2d_sliced_foreach_sub_texture_in_region (
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture *tex,
|
2009-08-30 06:36:11 -04:00
|
|
|
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-08-30 06:36:11 -04:00
|
|
|
void *user_data)
|
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2011-10-08 09:13:03 -04:00
|
|
|
CoglSpan *x_spans = (CoglSpan *)tex_2ds->slice_x_spans->data;
|
|
|
|
CoglSpan *y_spans = (CoglSpan *)tex_2ds->slice_y_spans->data;
|
|
|
|
CoglTexture **textures = (CoglTexture **)tex_2ds->slice_textures->data;
|
|
|
|
float un_normalized_coords[4];
|
|
|
|
ForeachData data;
|
|
|
|
|
|
|
|
/* NB: its convenient for us to store non-normalized coordinates in
|
|
|
|
* our CoglSpans but that means we need to un-normalize the incoming
|
|
|
|
* virtual coordinates and make sure we re-normalize the coordinates
|
|
|
|
* before calling the given callback.
|
2009-08-30 06:36:11 -04:00
|
|
|
*/
|
|
|
|
|
2011-10-08 09:13:03 -04:00
|
|
|
data.callback = callback;
|
|
|
|
data.user_data = user_data;
|
2012-11-22 16:46:54 -05:00
|
|
|
data.x_normalize_factor = 1.0f / tex->width;
|
|
|
|
data.y_normalize_factor = 1.0f / tex->height;
|
2011-10-08 09:13:03 -04:00
|
|
|
|
2012-12-10 10:47:45 -05:00
|
|
|
un_normalized_coords[0] = virtual_tx_1 * tex->width;
|
|
|
|
un_normalized_coords[1] = virtual_ty_1 * tex->height;
|
|
|
|
un_normalized_coords[2] = virtual_tx_2 * tex->width;
|
|
|
|
un_normalized_coords[3] = virtual_ty_2 * tex->height;
|
2011-10-08 09:13:03 -04:00
|
|
|
|
2012-12-10 10:47:45 -05:00
|
|
|
/* Note that the normalize factors passed here are the reciprocal of
|
|
|
|
* the factors calculated above because the span iterating code
|
|
|
|
* normalizes by dividing by the factor instead of multiplying */
|
2011-10-08 09:13:03 -04:00
|
|
|
_cogl_texture_spans_foreach_in_region (x_spans,
|
|
|
|
tex_2ds->slice_x_spans->len,
|
|
|
|
y_spans,
|
|
|
|
tex_2ds->slice_y_spans->len,
|
|
|
|
textures,
|
|
|
|
un_normalized_coords,
|
2012-12-10 10:47:45 -05:00
|
|
|
tex->width,
|
|
|
|
tex->height,
|
2011-10-08 09:13:03 -04:00
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
re_normalize_sub_texture_coords_cb,
|
|
|
|
&data);
|
2009-08-30 06:36:11 -04: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 uint8_t *
|
2009-11-26 12:32:52 -05:00
|
|
|
_cogl_texture_2d_sliced_allocate_waste_buffer (CoglTexture2DSliced *tex_2ds,
|
|
|
|
CoglPixelFormat format)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan *last_x_span;
|
|
|
|
CoglSpan *last_y_span;
|
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 *waste_buf = NULL;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* If the texture has any waste then allocate a buffer big enough to
|
|
|
|
fill the gaps */
|
2009-09-23 10:11:55 -04:00
|
|
|
last_x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan,
|
2009-08-30 06:36:11 -04:00
|
|
|
tex_2ds->slice_x_spans->len - 1);
|
2009-09-23 10:11:55 -04:00
|
|
|
last_y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan,
|
2009-08-30 06:36:11 -04:00
|
|
|
tex_2ds->slice_y_spans->len - 1);
|
|
|
|
if (last_x_span->waste > 0 || last_y_span->waste > 0)
|
|
|
|
{
|
2012-02-13 18:02:04 -05:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan *first_x_span
|
|
|
|
= &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0);
|
|
|
|
CoglSpan *first_y_span
|
|
|
|
= &g_array_index (tex_2ds->slice_y_spans, CoglSpan, 0);
|
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
|
|
|
unsigned int right_size = first_y_span->size * last_x_span->waste;
|
|
|
|
unsigned int bottom_size = first_x_span->size * last_y_span->waste;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
waste_buf = g_malloc (MAX (right_size, bottom_size) * bpp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return waste_buf;
|
|
|
|
}
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
static CoglBool
|
2010-10-04 09:34:24 -04:00
|
|
|
_cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
|
|
|
|
CoglBitmap *source_bmp,
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_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
|
|
|
uint8_t *waste_buf,
|
2010-10-04 09:34:24 -04:00
|
|
|
CoglSpan *x_span,
|
|
|
|
CoglSpan *y_span,
|
|
|
|
CoglSpanIter *x_iter,
|
|
|
|
CoglSpanIter *y_iter,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
2012-11-08 12:54:10 -05:00
|
|
|
int dst_y,
|
|
|
|
CoglError **error)
|
2010-10-04 09:34:24 -04: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
|
|
|
CoglBool need_x, need_y;
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = COGL_TEXTURE (tex_2ds)->context;
|
2012-03-13 10:46:18 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* If the x_span is sliced and the upload touches the
|
|
|
|
rightmost pixels then fill the waste with copies of the
|
|
|
|
pixels */
|
|
|
|
need_x = x_span->waste > 0 &&
|
|
|
|
x_iter->intersect_end - x_iter->pos >= x_span->size - x_span->waste;
|
|
|
|
|
|
|
|
/* same for the bottom-most pixels */
|
|
|
|
need_y = y_span->waste > 0 &&
|
|
|
|
y_iter->intersect_end - y_iter->pos >= y_span->size - y_span->waste;
|
|
|
|
|
|
|
|
if (need_x || need_y)
|
|
|
|
{
|
2012-02-25 15:18:05 -05:00
|
|
|
int bmp_rowstride = cogl_bitmap_get_rowstride (source_bmp);
|
|
|
|
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
|
2012-02-13 18:02:04 -05:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
|
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 *bmp_data;
|
|
|
|
const uint8_t *src;
|
|
|
|
uint8_t *dst;
|
2010-10-04 09:34:24 -04:00
|
|
|
unsigned int wy, wx;
|
|
|
|
CoglBitmap *waste_bmp;
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
bmp_data = _cogl_bitmap_map (source_bmp, COGL_BUFFER_ACCESS_READ, 0, error);
|
2010-10-04 09:34:24 -04:00
|
|
|
if (bmp_data == NULL)
|
2012-11-08 12:54:10 -05:00
|
|
|
return FALSE;
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
if (need_x)
|
|
|
|
{
|
|
|
|
src = (bmp_data + ((src_y + (int) y_iter->intersect_start - dst_y) *
|
|
|
|
bmp_rowstride) +
|
2011-10-23 15:20:49 -04:00
|
|
|
(src_x + (int)x_span->start + (int)x_span->size -
|
|
|
|
(int)x_span->waste - dst_x - 1) * bpp);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
dst = waste_buf;
|
|
|
|
|
|
|
|
for (wy = 0;
|
|
|
|
wy < y_iter->intersect_end - y_iter->intersect_start;
|
|
|
|
wy++)
|
|
|
|
{
|
|
|
|
for (wx = 0; wx < x_span->waste; wx++)
|
|
|
|
{
|
|
|
|
memcpy (dst, src, bpp);
|
|
|
|
dst += bpp;
|
|
|
|
}
|
|
|
|
src += bmp_rowstride;
|
|
|
|
}
|
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
waste_bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
x_span->waste,
|
|
|
|
y_iter->intersect_end -
|
|
|
|
y_iter->intersect_start,
|
|
|
|
source_format,
|
|
|
|
x_span->waste * bpp,
|
|
|
|
waste_buf);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
|
|
|
0, /* src_x */
|
|
|
|
0, /* src_y */
|
2012-11-09 12:55:54 -05:00
|
|
|
x_span->waste, /* width */
|
|
|
|
/* height */
|
|
|
|
y_iter->intersect_end -
|
|
|
|
y_iter->intersect_start,
|
|
|
|
waste_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
/* dst_x */
|
|
|
|
x_span->size - x_span->waste,
|
|
|
|
y_iter->intersect_start -
|
|
|
|
y_span->start, /* dst_y */
|
2012-11-09 12:55:54 -05:00
|
|
|
0, /* level */
|
2012-11-08 12:54:10 -05:00
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (waste_bmp);
|
|
|
|
_cogl_bitmap_unmap (source_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
cogl_object_unref (waste_bmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_y)
|
|
|
|
{
|
|
|
|
unsigned int copy_width, intersect_width;
|
|
|
|
|
|
|
|
src = (bmp_data + ((src_x + (int) x_iter->intersect_start - dst_x) *
|
|
|
|
bpp) +
|
2011-10-23 15:20:49 -04:00
|
|
|
(src_y + (int)y_span->start + (int)y_span->size -
|
|
|
|
(int)y_span->waste - dst_y - 1) * bmp_rowstride);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
dst = waste_buf;
|
|
|
|
|
|
|
|
if (x_iter->intersect_end - x_iter->pos
|
|
|
|
>= x_span->size - x_span->waste)
|
|
|
|
copy_width = x_span->size + x_iter->pos - x_iter->intersect_start;
|
|
|
|
else
|
|
|
|
copy_width = x_iter->intersect_end - x_iter->intersect_start;
|
|
|
|
|
|
|
|
intersect_width = x_iter->intersect_end - x_iter->intersect_start;
|
|
|
|
|
|
|
|
for (wy = 0; wy < y_span->waste; wy++)
|
|
|
|
{
|
|
|
|
memcpy (dst, src, intersect_width * bpp);
|
|
|
|
dst += intersect_width * bpp;
|
|
|
|
|
|
|
|
for (wx = intersect_width; wx < copy_width; wx++)
|
|
|
|
{
|
|
|
|
memcpy (dst, dst - bpp, bpp);
|
|
|
|
dst += bpp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
waste_bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
copy_width,
|
|
|
|
y_span->waste,
|
|
|
|
source_format,
|
|
|
|
copy_width * bpp,
|
|
|
|
waste_buf);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
|
|
|
0, /* src_x */
|
|
|
|
0, /* src_y */
|
2012-11-09 12:55:54 -05:00
|
|
|
copy_width, /* width */
|
|
|
|
y_span->waste, /* height */
|
|
|
|
waste_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
/* dst_x */
|
|
|
|
x_iter->intersect_start -
|
|
|
|
x_iter->pos,
|
|
|
|
/* dst_y */
|
|
|
|
y_span->size - y_span->waste,
|
2012-11-09 12:55:54 -05:00
|
|
|
0, /* level */
|
2012-11-08 12:54:10 -05:00
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (waste_bmp);
|
|
|
|
_cogl_bitmap_unmap (source_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
cogl_object_unref (waste_bmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_bitmap_unmap (source_bmp);
|
|
|
|
}
|
2012-11-08 12:54:10 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2010-10-04 09:34:24 -04: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
|
2013-06-07 19:28:14 -04:00
|
|
|
_cogl_texture_2d_sliced_upload_bitmap (CoglTexture2DSliced *tex_2ds,
|
|
|
|
CoglBitmap *bmp,
|
|
|
|
CoglError **error)
|
2009-08-30 06:36:11 -04: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
|
|
|
CoglSpan *x_span;
|
|
|
|
CoglSpan *y_span;
|
|
|
|
CoglTexture2D *slice_tex;
|
|
|
|
int x, y;
|
|
|
|
uint8_t *waste_buf;
|
|
|
|
CoglPixelFormat bmp_format;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-02-25 15:18:05 -05:00
|
|
|
bmp_format = cogl_bitmap_get_format (bmp);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-02-01 07:11:58 -05:00
|
|
|
waste_buf = _cogl_texture_2d_sliced_allocate_waste_buffer (tex_2ds,
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp_format);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Iterate vertical slices */
|
|
|
|
for (y = 0; y < tex_2ds->slice_y_spans->len; ++y)
|
|
|
|
{
|
2009-09-23 10:11:55 -04:00
|
|
|
y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, y);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Iterate horizontal slices */
|
|
|
|
for (x = 0; x < tex_2ds->slice_x_spans->len; ++x)
|
|
|
|
{
|
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
|
|
|
int slice_num = y * tex_2ds->slice_x_spans->len + x;
|
2010-10-04 09:34:24 -04:00
|
|
|
CoglSpanIter x_iter, y_iter;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2009-09-23 10:11:55 -04:00
|
|
|
x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, x);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Pick the gl texture object handle */
|
2010-10-04 09:34:24 -04:00
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures,
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *, slice_num);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
|
|
|
x_span->start, /* src x */
|
|
|
|
y_span->start, /* src y */
|
|
|
|
x_span->size -
|
|
|
|
x_span->waste, /* width */
|
|
|
|
y_span->size -
|
|
|
|
y_span->waste, /* height */
|
|
|
|
bmp,
|
2012-11-09 12:55:54 -05:00
|
|
|
0, /* dst x */
|
|
|
|
0, /* dst y */
|
|
|
|
0, /* level */
|
2012-11-08 12:54:10 -05:00
|
|
|
error))
|
|
|
|
{
|
|
|
|
if (waste_buf)
|
|
|
|
g_free (waste_buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
/* Set up a fake iterator that covers the whole slice */
|
|
|
|
x_iter.intersect_start = x_span->start;
|
|
|
|
x_iter.intersect_end = (x_span->start +
|
|
|
|
x_span->size -
|
|
|
|
x_span->waste);
|
|
|
|
x_iter.pos = x_span->start;
|
|
|
|
|
|
|
|
y_iter.intersect_start = y_span->start;
|
|
|
|
y_iter.intersect_end = (y_span->start +
|
|
|
|
y_span->size -
|
|
|
|
y_span->waste);
|
|
|
|
y_iter.pos = y_span->start;
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_texture_2d_sliced_set_waste (tex_2ds,
|
|
|
|
bmp,
|
|
|
|
slice_tex,
|
|
|
|
waste_buf,
|
|
|
|
x_span, y_span,
|
|
|
|
&x_iter, &y_iter,
|
|
|
|
0, /* src_x */
|
|
|
|
0, /* src_y */
|
|
|
|
0, /* dst_x */
|
|
|
|
0,
|
|
|
|
error)) /* dst_y */
|
|
|
|
{
|
|
|
|
if (waste_buf)
|
|
|
|
g_free (waste_buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (waste_buf)
|
|
|
|
g_free (waste_buf);
|
|
|
|
|
|
|
|
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
|
2013-06-07 19:28:14 -04:00
|
|
|
_cogl_texture_2d_sliced_upload_subregion (CoglTexture2DSliced *tex_2ds,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglBitmap *source_bmp,
|
|
|
|
CoglError **error)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2012-11-22 16:46:54 -05:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2ds);
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan *x_span;
|
|
|
|
CoglSpan *y_span;
|
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
|
|
|
CoglSpanIter x_iter;
|
|
|
|
CoglSpanIter y_iter;
|
|
|
|
CoglTexture2D *slice_tex;
|
|
|
|
int source_x = 0, source_y = 0;
|
|
|
|
int inter_w = 0, inter_h = 0;
|
|
|
|
int local_x = 0, local_y = 0;
|
|
|
|
uint8_t *waste_buf;
|
|
|
|
CoglPixelFormat source_format;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-02-25 15:18:05 -05:00
|
|
|
source_format = cogl_bitmap_get_format (source_bmp);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2009-11-26 12:32:52 -05:00
|
|
|
waste_buf =
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_2d_sliced_allocate_waste_buffer (tex_2ds, source_format);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Iterate vertical spans */
|
|
|
|
for (source_y = src_y,
|
|
|
|
_cogl_span_iter_begin (&y_iter,
|
2011-10-08 09:13:03 -04:00
|
|
|
(CoglSpan *)tex_2ds->slice_y_spans->data,
|
|
|
|
tex_2ds->slice_y_spans->len,
|
2012-11-22 16:46:54 -05:00
|
|
|
tex->height,
|
2009-08-30 06:36:11 -04:00
|
|
|
dst_y,
|
2011-10-08 09:13:03 -04:00
|
|
|
dst_y + height,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
!_cogl_span_iter_end (&y_iter);
|
|
|
|
|
|
|
|
_cogl_span_iter_next (&y_iter),
|
|
|
|
source_y += inter_h )
|
|
|
|
{
|
2009-09-23 10:11:55 -04:00
|
|
|
y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan,
|
2009-08-30 06:36:11 -04:00
|
|
|
y_iter.index);
|
|
|
|
|
|
|
|
/* Iterate horizontal spans */
|
|
|
|
for (source_x = src_x,
|
|
|
|
_cogl_span_iter_begin (&x_iter,
|
2011-10-08 09:13:03 -04:00
|
|
|
(CoglSpan *)tex_2ds->slice_x_spans->data,
|
|
|
|
tex_2ds->slice_x_spans->len,
|
2012-11-22 16:46:54 -05:00
|
|
|
tex->width,
|
2009-08-30 06:36:11 -04:00
|
|
|
dst_x,
|
2011-10-08 09:13:03 -04:00
|
|
|
dst_x + width,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
!_cogl_span_iter_end (&x_iter);
|
|
|
|
|
|
|
|
_cogl_span_iter_next (&x_iter),
|
|
|
|
source_x += inter_w )
|
|
|
|
{
|
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
|
|
|
int slice_num;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2009-09-23 10:11:55 -04:00
|
|
|
x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan,
|
2009-08-30 06:36:11 -04:00
|
|
|
x_iter.index);
|
|
|
|
|
|
|
|
/* Pick intersection width and height */
|
|
|
|
inter_w = (x_iter.intersect_end - x_iter.intersect_start);
|
|
|
|
inter_h = (y_iter.intersect_end - y_iter.intersect_start);
|
|
|
|
|
|
|
|
/* Localize intersection top-left corner to slice*/
|
|
|
|
local_x = (x_iter.intersect_start - x_iter.pos);
|
|
|
|
local_y = (y_iter.intersect_start - y_iter.pos);
|
|
|
|
|
|
|
|
slice_num = y_iter.index * tex_2ds->slice_x_spans->len + x_iter.index;
|
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* Pick slice texture */
|
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures,
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *, slice_num);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex),
|
|
|
|
source_x,
|
|
|
|
source_y,
|
|
|
|
inter_w, /* width */
|
|
|
|
inter_h, /* height */
|
|
|
|
source_bmp,
|
2012-11-09 12:55:54 -05:00
|
|
|
local_x, /* dst x */
|
|
|
|
local_y, /* dst y */
|
|
|
|
0, /* level */
|
2012-11-08 12:54:10 -05:00
|
|
|
error))
|
|
|
|
{
|
|
|
|
if (waste_buf)
|
|
|
|
g_free (waste_buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_cogl_texture_2d_sliced_set_waste (tex_2ds,
|
|
|
|
source_bmp,
|
|
|
|
slice_tex,
|
|
|
|
waste_buf,
|
|
|
|
x_span, y_span,
|
|
|
|
&x_iter, &y_iter,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
if (waste_buf)
|
|
|
|
g_free (waste_buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (waste_buf)
|
|
|
|
g_free (waste_buf);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
return 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-08-30 06:36:11 -04:00
|
|
|
_cogl_rect_slices_for_size (int size_to_fill,
|
|
|
|
int max_span_size,
|
|
|
|
int max_waste,
|
|
|
|
GArray *out_spans)
|
|
|
|
{
|
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
|
|
|
int n_spans = 0;
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan span;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Init first slice span */
|
|
|
|
span.start = 0;
|
|
|
|
span.size = max_span_size;
|
|
|
|
span.waste = 0;
|
|
|
|
|
|
|
|
/* Repeat until whole area covered */
|
|
|
|
while (size_to_fill >= span.size)
|
|
|
|
{
|
|
|
|
/* Add another slice span of same size */
|
|
|
|
if (out_spans)
|
|
|
|
g_array_append_val (out_spans, span);
|
|
|
|
span.start += span.size;
|
|
|
|
size_to_fill -= span.size;
|
|
|
|
n_spans++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add one last smaller slice span */
|
|
|
|
if (size_to_fill > 0)
|
|
|
|
{
|
|
|
|
span.size = size_to_fill;
|
|
|
|
if (out_spans)
|
|
|
|
g_array_append_val (out_spans, span);
|
|
|
|
n_spans++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_spans;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
_cogl_pot_slices_for_size (int size_to_fill,
|
|
|
|
int max_span_size,
|
|
|
|
int max_waste,
|
2009-08-30 06:36:11 -04:00
|
|
|
GArray *out_spans)
|
|
|
|
{
|
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
|
|
|
int n_spans = 0;
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan span;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Init first slice span */
|
|
|
|
span.start = 0;
|
|
|
|
span.size = max_span_size;
|
|
|
|
span.waste = 0;
|
|
|
|
|
|
|
|
/* Fix invalid max_waste */
|
|
|
|
if (max_waste < 0)
|
|
|
|
max_waste = 0;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Is the whole area covered? */
|
|
|
|
if (size_to_fill > span.size)
|
|
|
|
{
|
|
|
|
/* Not yet - add a span of this size */
|
|
|
|
if (out_spans)
|
|
|
|
g_array_append_val (out_spans, span);
|
|
|
|
|
|
|
|
span.start += span.size;
|
|
|
|
size_to_fill -= span.size;
|
|
|
|
n_spans++;
|
|
|
|
}
|
|
|
|
else if (span.size - size_to_fill <= max_waste)
|
|
|
|
{
|
|
|
|
/* Yes and waste is small enough */
|
2010-10-05 12:17:53 -04:00
|
|
|
/* Pick the next power of two up from size_to_fill. This can
|
|
|
|
sometimes be less than the span.size that would be chosen
|
|
|
|
otherwise */
|
|
|
|
span.size = _cogl_util_next_p2 (size_to_fill);
|
2009-08-30 06:36:11 -04:00
|
|
|
span.waste = span.size - size_to_fill;
|
|
|
|
if (out_spans)
|
|
|
|
g_array_append_val (out_spans, span);
|
|
|
|
|
|
|
|
return ++n_spans;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Yes but waste is too large */
|
|
|
|
while (span.size - size_to_fill > max_waste)
|
|
|
|
{
|
|
|
|
span.size /= 2;
|
|
|
|
g_assert (span.size > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can't get here */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
|
|
|
|
GLenum wrap_mode_s,
|
|
|
|
GLenum wrap_mode_t,
|
|
|
|
GLenum wrap_mode_p)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2010-10-04 09:34:24 -04:00
|
|
|
int i;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* Pass the set wrap mode on to all of the child textures */
|
|
|
|
for (i = 0; i < tex_2ds->slice_textures->len; i++)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex = g_array_index (tex_2ds->slice_textures,
|
|
|
|
CoglTexture2D *,
|
|
|
|
i);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_gl_flush_legacy_texobj_wrap_modes (COGL_TEXTURE (slice_tex),
|
|
|
|
wrap_mode_s,
|
|
|
|
wrap_mode_t,
|
|
|
|
wrap_mode_p);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static void
|
|
|
|
free_spans (CoglTexture2DSliced *tex_2ds)
|
|
|
|
{
|
|
|
|
if (tex_2ds->slice_x_spans != NULL)
|
|
|
|
{
|
|
|
|
g_array_free (tex_2ds->slice_x_spans, TRUE);
|
|
|
|
tex_2ds->slice_x_spans = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex_2ds->slice_y_spans != NULL)
|
|
|
|
{
|
|
|
|
g_array_free (tex_2ds->slice_y_spans, TRUE);
|
|
|
|
tex_2ds->slice_y_spans = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2013-06-23 11:18:18 -04:00
|
|
|
setup_spans (CoglContext *ctx,
|
|
|
|
CoglTexture2DSliced *tex_2ds,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int max_waste,
|
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
CoglError **error)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2011-10-08 06:53:20 -04:00
|
|
|
int max_width;
|
|
|
|
int max_height;
|
|
|
|
int n_x_slices;
|
|
|
|
int n_y_slices;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
int (*slices_for_size) (int, int, int, GArray*);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Initialize size of largest slice according to supported features */
|
2011-10-12 17:31:12 -04:00
|
|
|
if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT))
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2010-02-01 07:11:58 -05:00
|
|
|
max_width = width;
|
|
|
|
max_height = height;
|
2009-08-30 06:36:11 -04:00
|
|
|
slices_for_size = _cogl_rect_slices_for_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-15 09:39:05 -04:00
|
|
|
max_width = _cogl_util_next_p2 (width);
|
|
|
|
max_height = _cogl_util_next_p2 (height);
|
2009-08-30 06:36:11 -04:00
|
|
|
slices_for_size = _cogl_pot_slices_for_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Negative number means no slicing forced by the user */
|
2012-11-22 18:01:08 -05:00
|
|
|
if (max_waste <= -1)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan span;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Check if size supported else bail out */
|
2013-06-07 19:28:14 -04:00
|
|
|
if (!ctx->driver_vtable->texture_2d_can_create (ctx,
|
|
|
|
max_width,
|
|
|
|
max_height,
|
|
|
|
internal_format))
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_SIZE,
|
|
|
|
"Sliced texture size of %d x %d not possible "
|
|
|
|
"with max waste set to -1",
|
|
|
|
width,
|
|
|
|
height);
|
2009-08-30 06:36:11 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
n_x_slices = 1;
|
|
|
|
n_y_slices = 1;
|
|
|
|
|
|
|
|
/* Init span arrays */
|
|
|
|
tex_2ds->slice_x_spans = g_array_sized_new (FALSE, FALSE,
|
2009-09-23 10:11:55 -04:00
|
|
|
sizeof (CoglSpan),
|
2009-08-30 06:36:11 -04:00
|
|
|
1);
|
|
|
|
|
|
|
|
tex_2ds->slice_y_spans = g_array_sized_new (FALSE, FALSE,
|
2009-09-23 10:11:55 -04:00
|
|
|
sizeof (CoglSpan),
|
2009-08-30 06:36:11 -04:00
|
|
|
1);
|
|
|
|
|
|
|
|
/* Add a single span for width and height */
|
|
|
|
span.start = 0;
|
|
|
|
span.size = max_width;
|
2010-02-01 07:11:58 -05:00
|
|
|
span.waste = max_width - width;
|
2009-08-30 06:36:11 -04:00
|
|
|
g_array_append_val (tex_2ds->slice_x_spans, span);
|
|
|
|
|
|
|
|
span.size = max_height;
|
2010-02-01 07:11:58 -05:00
|
|
|
span.waste = max_height - height;
|
2009-08-30 06:36:11 -04:00
|
|
|
g_array_append_val (tex_2ds->slice_y_spans, span);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Decrease the size of largest slice until supported by GL */
|
2013-06-07 19:28:14 -04:00
|
|
|
while (!ctx->driver_vtable->texture_2d_can_create (ctx,
|
|
|
|
max_width,
|
|
|
|
max_height,
|
|
|
|
internal_format))
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
|
|
|
/* Alternate between width and height */
|
|
|
|
if (max_width > max_height)
|
|
|
|
max_width /= 2;
|
|
|
|
else
|
|
|
|
max_height /= 2;
|
|
|
|
|
|
|
|
if (max_width == 0 || max_height == 0)
|
2012-11-22 18:01:08 -05:00
|
|
|
{
|
|
|
|
/* Maybe it would be ok to just g_warn_if_reached() for this
|
|
|
|
* codepath */
|
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_SIZE,
|
|
|
|
"No suitable slice geometry found");
|
2013-06-23 11:18:18 -04:00
|
|
|
free_spans (tex_2ds);
|
2012-11-22 18:01:08 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the slices required to cover the bitmap area */
|
2010-02-01 07:11:58 -05:00
|
|
|
n_x_slices = slices_for_size (width,
|
2012-11-22 18:01:08 -05:00
|
|
|
max_width, max_waste,
|
2009-08-30 06:36:11 -04:00
|
|
|
NULL);
|
|
|
|
|
2010-02-01 07:11:58 -05:00
|
|
|
n_y_slices = slices_for_size (height,
|
2012-11-22 18:01:08 -05:00
|
|
|
max_height, max_waste,
|
2009-08-30 06:36:11 -04:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Init span arrays with reserved size */
|
|
|
|
tex_2ds->slice_x_spans = g_array_sized_new (FALSE, FALSE,
|
2009-09-23 10:11:55 -04:00
|
|
|
sizeof (CoglSpan),
|
2009-08-30 06:36:11 -04:00
|
|
|
n_x_slices);
|
|
|
|
|
|
|
|
tex_2ds->slice_y_spans = g_array_sized_new (FALSE, FALSE,
|
2009-09-23 10:11:55 -04:00
|
|
|
sizeof (CoglSpan),
|
2009-08-30 06:36:11 -04:00
|
|
|
n_y_slices);
|
|
|
|
|
|
|
|
/* Fill span arrays with info */
|
2010-02-01 07:11:58 -05:00
|
|
|
slices_for_size (width,
|
2012-11-22 18:01:08 -05:00
|
|
|
max_width, max_waste,
|
2009-08-30 06:36:11 -04:00
|
|
|
tex_2ds->slice_x_spans);
|
|
|
|
|
2010-02-01 07:11:58 -05:00
|
|
|
slices_for_size (height,
|
2012-11-22 18:01:08 -05:00
|
|
|
max_height, max_waste,
|
2009-08-30 06:36:11 -04:00
|
|
|
tex_2ds->slice_y_spans);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-23 11:18:18 -04:00
|
|
|
free_slices (CoglTexture2DSliced *tex_2ds)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2010-10-04 09:34:24 -04:00
|
|
|
if (tex_2ds->slice_textures != NULL)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2010-04-26 05:01:43 -04:00
|
|
|
int i;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
for (i = 0; i < tex_2ds->slice_textures->len; i++)
|
|
|
|
{
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex =
|
|
|
|
g_array_index (tex_2ds->slice_textures, CoglTexture2D *, i);
|
2012-04-16 09:14:10 -04:00
|
|
|
cogl_object_unref (slice_tex);
|
2010-10-04 09:34:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_array_free (tex_2ds->slice_textures, TRUE);
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
free_spans (tex_2ds);
|
2009-08-30 06:36:11 -04: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
|
2013-06-23 11:18:18 -04:00
|
|
|
allocate_slices (CoglTexture2DSliced *tex_2ds,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int max_waste,
|
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
CoglError **error)
|
2009-11-26 12:32:52 -05:00
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2ds);
|
2012-11-22 18:01:08 -05:00
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
int n_x_slices;
|
|
|
|
int n_y_slices;
|
|
|
|
int n_slices;
|
|
|
|
int x, y;
|
|
|
|
CoglSpan *x_span;
|
|
|
|
CoglSpan *y_span;
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_2ds->internal_format = internal_format;
|
|
|
|
|
|
|
|
if (!setup_spans (ctx, tex_2ds,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
max_waste,
|
|
|
|
internal_format,
|
|
|
|
error))
|
2012-11-22 18:01:08 -05:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
n_x_slices = tex_2ds->slice_x_spans->len;
|
|
|
|
n_y_slices = tex_2ds->slice_y_spans->len;
|
|
|
|
n_slices = n_x_slices * n_y_slices;
|
|
|
|
|
|
|
|
tex_2ds->slice_textures = g_array_sized_new (FALSE, FALSE,
|
|
|
|
sizeof (CoglTexture2D *),
|
|
|
|
n_slices);
|
|
|
|
|
|
|
|
/* Allocate each slice */
|
|
|
|
for (y = 0; y < n_y_slices; ++y)
|
|
|
|
{
|
|
|
|
y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, y);
|
|
|
|
|
|
|
|
for (x = 0; x < n_x_slices; ++x)
|
|
|
|
{
|
|
|
|
CoglTexture *slice;
|
|
|
|
|
|
|
|
x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, x);
|
|
|
|
|
|
|
|
COGL_NOTE (SLICING, "CREATE SLICE (%d,%d)\tsize (%d,%d)",
|
|
|
|
x, y,
|
|
|
|
(int)(x_span->size - x_span->waste),
|
|
|
|
(int)(y_span->size - y_span->waste));
|
|
|
|
|
|
|
|
slice = COGL_TEXTURE (
|
|
|
|
cogl_texture_2d_new_with_size (ctx,
|
2013-07-01 20:48:54 -04:00
|
|
|
x_span->size, y_span->size));
|
|
|
|
|
|
|
|
_cogl_texture_copy_internal_format (tex, slice);
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
g_array_append_val (tex_2ds->slice_textures, slice);
|
|
|
|
if (!cogl_texture_allocate (slice, error))
|
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
free_slices (tex_2ds);
|
2012-11-22 18:01:08 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static void
|
|
|
|
_cogl_texture_2d_sliced_free (CoglTexture2DSliced *tex_2ds)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
free_slices (tex_2ds);
|
2011-10-08 06:53:20 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
/* Chain up */
|
|
|
|
_cogl_texture_free (COGL_TEXTURE (tex_2ds));
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static CoglTexture2DSliced *
|
|
|
|
_cogl_texture_2d_sliced_create_base (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int max_waste,
|
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
CoglTextureLoader *loader)
|
|
|
|
{
|
|
|
|
CoglTexture2DSliced *tex_2ds = g_new0 (CoglTexture2DSliced, 1);
|
2012-04-04 08:57:42 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_init (COGL_TEXTURE (tex_2ds), ctx, width, height,
|
|
|
|
internal_format, loader,
|
|
|
|
&cogl_texture_2d_sliced_vtable);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
tex_2ds->max_waste = max_waste;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
return _cogl_texture_2d_sliced_object_new (tex_2ds);
|
|
|
|
}
|
2013-06-07 19:28:14 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTexture2DSliced *
|
|
|
|
cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
2013-07-01 20:48:54 -04:00
|
|
|
int max_waste)
|
2013-06-23 11:18:18 -04:00
|
|
|
{
|
2013-07-01 20:48:54 -04:00
|
|
|
CoglTextureLoader *loader = _cogl_texture_create_loader ();
|
2013-06-23 11:18:18 -04:00
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
|
|
|
|
loader->src.sized.width = width;
|
|
|
|
loader->src.sized.height = height;
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
return _cogl_texture_2d_sliced_create_base (ctx,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
max_waste,
|
2013-07-01 20:48:54 -04:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2013-06-23 11:18:18 -04:00
|
|
|
loader);
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTexture2DSliced *
|
|
|
|
_cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
|
|
|
|
int max_waste,
|
2013-07-01 20:48:54 -04:00
|
|
|
CoglBool can_convert_in_place)
|
2013-06-23 11:18:18 -04:00
|
|
|
{
|
|
|
|
CoglTextureLoader *loader;
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_bitmap (bmp), NULL);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2013-06-23 11:18:18 -04: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;
|
|
|
|
|
|
|
|
return _cogl_texture_2d_sliced_create_base (_cogl_bitmap_get_context (bmp),
|
|
|
|
cogl_bitmap_get_width (bmp),
|
|
|
|
cogl_bitmap_get_height (bmp),
|
|
|
|
max_waste,
|
2013-07-01 20:48:54 -04:00
|
|
|
cogl_bitmap_get_format (bmp),
|
2013-06-23 11:18:18 -04:00
|
|
|
loader);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2013-06-08 13:52:20 -04:00
|
|
|
CoglTexture2DSliced *
|
|
|
|
cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
|
2013-07-01 20:48:54 -04:00
|
|
|
int max_waste)
|
2013-06-08 13:52:20 -04:00
|
|
|
{
|
|
|
|
return _cogl_texture_2d_sliced_new_from_bitmap (bmp,
|
|
|
|
max_waste,
|
2013-07-01 20:48:54 -04:00
|
|
|
FALSE);
|
2013-06-08 13:52:20 -04:00
|
|
|
}
|
|
|
|
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2DSliced *
|
2012-11-08 15:33:00 -05:00
|
|
|
_cogl_texture_2d_sliced_new_from_foreign (CoglContext *ctx,
|
|
|
|
unsigned int gl_handle,
|
|
|
|
unsigned int gl_target,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int x_pot_waste,
|
|
|
|
int y_pot_waste,
|
2013-07-01 20:48:54 -04:00
|
|
|
CoglPixelFormat format)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTextureLoader *loader;
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* NOTE: width, height and internal format are not queriable
|
2010-02-16 09:23:11 -05:00
|
|
|
* in GLES, hence such a function prototype.
|
|
|
|
*/
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* This should only be called when the texture target is 2D. If a
|
|
|
|
rectangle texture is used then _cogl_texture_new_from_foreign
|
|
|
|
will create a cogl_texture_rectangle instead */
|
2012-11-08 15:33:00 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (gl_target == GL_TEXTURE_2D, NULL);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
/* Assert it is a valid GL texture object */
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (ctx->glIsTexture (gl_handle), FALSE);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
/* Validate width and height */
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (width > 0 && height > 0, NULL);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
/* Validate pot waste */
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (x_pot_waste >= 0 && x_pot_waste < width &&
|
|
|
|
y_pot_waste >= 0 && y_pot_waste < height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
loader = _cogl_texture_create_loader ();
|
|
|
|
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_GL_FOREIGN;
|
|
|
|
loader->src.gl_foreign.gl_handle = gl_handle;
|
|
|
|
loader->src.gl_foreign.width = width + x_pot_waste;
|
|
|
|
loader->src.gl_foreign.height = height + y_pot_waste;
|
|
|
|
loader->src.gl_foreign.format = format;
|
|
|
|
|
|
|
|
return _cogl_texture_2d_sliced_create_base (ctx,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
0, /* max waste */
|
|
|
|
format, loader);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2013-06-08 13:52:20 -04:00
|
|
|
CoglTexture2DSliced *
|
|
|
|
cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int max_waste,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
int rowstride,
|
|
|
|
const uint8_t *data,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglBitmap *bmp;
|
|
|
|
CoglTexture2DSliced *tex_2ds;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (format != COGL_PIXEL_FORMAT_ANY, NULL);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (data != NULL, NULL);
|
|
|
|
|
|
|
|
/* Rowstride from width if not given */
|
|
|
|
if (rowstride == 0)
|
|
|
|
rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format);
|
|
|
|
|
|
|
|
/* Wrap the data into a bitmap */
|
|
|
|
bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
(uint8_t *) data);
|
|
|
|
|
2013-07-01 20:48:54 -04:00
|
|
|
tex_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, max_waste);
|
2013-06-08 13:52:20 -04:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
if (tex_2ds &&
|
|
|
|
!cogl_texture_allocate (COGL_TEXTURE (tex_2ds), error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (tex_2ds);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-08 13:52:20 -04:00
|
|
|
return tex_2ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTexture2DSliced *
|
|
|
|
cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
|
|
|
|
const char *filename,
|
|
|
|
int max_waste,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglBitmap *bmp;
|
|
|
|
CoglTexture2DSliced *tex_2ds = NULL;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
bmp = _cogl_bitmap_from_file (ctx, filename, error);
|
|
|
|
if (bmp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tex_2ds = _cogl_texture_2d_sliced_new_from_bitmap (bmp,
|
|
|
|
max_waste,
|
2013-07-01 20:48:54 -04:00
|
|
|
TRUE); /* can convert in-place */
|
2013-06-08 13:52:20 -04:00
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
|
|
|
return tex_2ds;
|
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
static CoglBool
|
|
|
|
allocate_with_size (CoglTexture2DSliced *tex_2ds,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2ds);
|
|
|
|
CoglPixelFormat internal_format =
|
|
|
|
_cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY);
|
|
|
|
|
|
|
|
if (allocate_slices (tex_2ds,
|
|
|
|
loader->src.sized.width,
|
|
|
|
loader->src.sized.height,
|
|
|
|
tex_2ds->max_waste,
|
|
|
|
internal_format,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
_cogl_texture_set_allocated (COGL_TEXTURE (tex_2ds),
|
|
|
|
internal_format,
|
|
|
|
loader->src.sized.width,
|
|
|
|
loader->src.sized.height);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
allocate_from_bitmap (CoglTexture2DSliced *tex_2ds,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2ds);
|
|
|
|
CoglBitmap *bmp = loader->src.bitmap.bitmap;
|
|
|
|
int width = cogl_bitmap_get_width (bmp);
|
|
|
|
int height = cogl_bitmap_get_height (bmp);
|
|
|
|
CoglBool can_convert_in_place = loader->src.bitmap.can_convert_in_place;
|
|
|
|
CoglPixelFormat internal_format;
|
|
|
|
CoglBitmap *upload_bmp;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (tex_2ds->slice_textures == NULL, FALSE);
|
|
|
|
|
|
|
|
internal_format =
|
|
|
|
_cogl_texture_determine_internal_format (tex,
|
|
|
|
cogl_bitmap_get_format (bmp));
|
|
|
|
|
|
|
|
upload_bmp = _cogl_bitmap_convert_for_upload (bmp,
|
|
|
|
internal_format,
|
|
|
|
can_convert_in_place,
|
|
|
|
error);
|
|
|
|
if (upload_bmp == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!allocate_slices (tex_2ds,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
tex_2ds->max_waste,
|
|
|
|
internal_format,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (upload_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_cogl_texture_2d_sliced_upload_bitmap (tex_2ds,
|
|
|
|
upload_bmp,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
free_slices (tex_2ds);
|
|
|
|
cogl_object_unref (upload_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_object_unref (upload_bmp);
|
|
|
|
|
|
|
|
_cogl_texture_set_allocated (tex, internal_format, width, height);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
allocate_from_gl_foreign (CoglTexture2DSliced *tex_2ds,
|
|
|
|
CoglTextureLoader *loader,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (tex_2ds);
|
|
|
|
CoglContext *ctx = tex->context;
|
|
|
|
CoglPixelFormat format = loader->src.gl_foreign.format;
|
|
|
|
int gl_width = loader->src.gl_foreign.width;
|
|
|
|
int gl_height = loader->src.gl_foreign.height;
|
|
|
|
int x_pot_waste = gl_width - tex->width;
|
|
|
|
int y_pot_waste = gl_height - tex->height;
|
|
|
|
CoglSpan x_span;
|
|
|
|
CoglSpan y_span;
|
|
|
|
CoglTexture2D *tex_2d =
|
2013-07-01 20:48:54 -04:00
|
|
|
cogl_texture_2d_gl_new_from_foreign (ctx,
|
|
|
|
loader->src.gl_foreign.gl_handle,
|
|
|
|
gl_width,
|
|
|
|
gl_height,
|
|
|
|
format);
|
2013-06-23 11:18:18 -04:00
|
|
|
|
|
|
|
if (!cogl_texture_allocate (COGL_TEXTURE (tex_2d), error))
|
2013-07-01 20:48:54 -04:00
|
|
|
{
|
|
|
|
cogl_object_unref (tex_2d);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-06-23 11:18:18 -04:00
|
|
|
|
|
|
|
/* The texture 2d backend may use a different pixel format if it
|
|
|
|
queries the actual texture so we'll refetch the format it
|
|
|
|
actually used */
|
|
|
|
format = _cogl_texture_get_format (tex);
|
|
|
|
|
|
|
|
tex_2ds->internal_format = format;
|
|
|
|
|
|
|
|
/* Create slice arrays */
|
|
|
|
tex_2ds->slice_x_spans =
|
|
|
|
g_array_sized_new (FALSE, FALSE, sizeof (CoglSpan), 1);
|
|
|
|
|
|
|
|
tex_2ds->slice_y_spans =
|
|
|
|
g_array_sized_new (FALSE, FALSE, sizeof (CoglSpan), 1);
|
|
|
|
|
|
|
|
tex_2ds->slice_textures =
|
|
|
|
g_array_sized_new (FALSE, FALSE, sizeof (CoglTexture2D *), 1);
|
|
|
|
|
|
|
|
/* Store info for a single slice */
|
|
|
|
x_span.start = 0;
|
|
|
|
x_span.size = gl_width;
|
|
|
|
x_span.waste = x_pot_waste;
|
|
|
|
g_array_append_val (tex_2ds->slice_x_spans, x_span);
|
|
|
|
|
|
|
|
y_span.start = 0;
|
|
|
|
y_span.size = gl_height;
|
|
|
|
y_span.waste = y_pot_waste;
|
|
|
|
g_array_append_val (tex_2ds->slice_y_spans, y_span);
|
|
|
|
|
|
|
|
g_array_append_val (tex_2ds->slice_textures, tex_2d);
|
|
|
|
|
|
|
|
_cogl_texture_set_allocated (tex,
|
|
|
|
format,
|
|
|
|
tex->width,
|
|
|
|
tex->height);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
_cogl_texture_2d_sliced_allocate (CoglTexture *tex,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
|
|
|
CoglTextureLoader *loader = tex->loader;
|
|
|
|
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (loader, FALSE);
|
|
|
|
|
|
|
|
switch (loader->src_type)
|
|
|
|
{
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_SIZED:
|
|
|
|
return allocate_with_size (tex_2ds, loader, error);
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_BITMAP:
|
|
|
|
return allocate_from_bitmap (tex_2ds, loader, error);
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_GL_FOREIGN:
|
|
|
|
return allocate_from_gl_foreign (tex_2ds, loader, error);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (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
|
2010-04-26 05:01:43 -04:00
|
|
|
_cogl_texture_2d_sliced_is_foreign (CoglTexture *tex)
|
|
|
|
{
|
2010-10-04 09:34:24 -04:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex;
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
/* Make sure slices were created */
|
|
|
|
if (tex_2ds->slice_textures == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Pass the call on to the first slice */
|
2011-10-08 06:53:20 -04:00
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0);
|
|
|
|
return _cogl_texture_is_foreign (COGL_TEXTURE (slice_tex));
|
2010-04-26 05:01:43 -04:00
|
|
|
}
|
|
|
|
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
static int
|
2009-11-25 08:39:45 -05:00
|
|
|
_cogl_texture_2d_sliced_get_max_waste (CoglTexture *tex)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
return tex_2ds->max_waste;
|
|
|
|
}
|
|
|
|
|
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-25 08:39:45 -05:00
|
|
|
_cogl_texture_2d_sliced_is_sliced (CoglTexture *tex)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-23 11:18:18 -04:00
|
|
|
/* It's only after allocating a sliced texture that we will know
|
|
|
|
* whether it really needed to be sliced... */
|
|
|
|
if (!tex->allocated)
|
|
|
|
cogl_texture_allocate (tex, NULL);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
if (tex_2ds->slice_x_spans->len != 1 ||
|
|
|
|
tex_2ds->slice_y_spans->len != 1)
|
|
|
|
return TRUE;
|
|
|
|
else
|
2009-08-30 06:36:11 -04:00
|
|
|
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-25 08:39:45 -05:00
|
|
|
_cogl_texture_2d_sliced_can_hardware_repeat (CoglTexture *tex)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex;
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan *x_span;
|
|
|
|
CoglSpan *y_span;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* If there's more than one texture then we can't hardware repeat */
|
|
|
|
if (tex_2ds->slice_textures->len != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If there's any waste then we can't hardware repeat */
|
2009-09-23 10:11:55 -04:00
|
|
|
x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0);
|
|
|
|
y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, 0);
|
2010-10-04 09:34:24 -04:00
|
|
|
if (x_span->waste > 0 || y_span->waste > 0)
|
2009-11-26 13:58:17 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* Otherwise pass the query on to the single slice texture */
|
2011-10-08 06:53:20 -04:00
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0);
|
|
|
|
return _cogl_texture_can_hardware_repeat (COGL_TEXTURE (slice_tex));
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
static void
|
|
|
|
_cogl_texture_2d_sliced_transform_coords_to_gl (CoglTexture *tex,
|
2009-08-30 06:36:11 -04:00
|
|
|
float *s,
|
|
|
|
float *t)
|
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2009-09-23 10:11:55 -04:00
|
|
|
CoglSpan *x_span;
|
|
|
|
CoglSpan *y_span;
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
g_assert (!_cogl_texture_2d_sliced_is_sliced (tex));
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Don't include the waste in the texture coordinates */
|
2009-09-23 10:11:55 -04:00
|
|
|
x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0);
|
|
|
|
y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, 0);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-11-22 16:46:54 -05:00
|
|
|
*s *= tex->width / (float)x_span->size;
|
|
|
|
*t *= tex->height / (float)y_span->size;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* Let the child texture further transform the coords */
|
2011-10-08 06:53:20 -04:00
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0);
|
|
|
|
_cogl_texture_transform_coords_to_gl (COGL_TEXTURE (slice_tex), s, t);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
static CoglTransformResult
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_texture_2d_sliced_transform_quad_coords_to_gl (CoglTexture *tex,
|
|
|
|
float *coords)
|
|
|
|
{
|
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 need_repeat = FALSE;
|
2010-03-01 16:49:04 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* This is a bit lazy - in the case where the quad lies entirely
|
|
|
|
* within a single slice we could avoid the fallback. But that
|
|
|
|
* could likely lead to visual inconsistency if the fallback involves
|
|
|
|
* dropping layers, so this might be the right thing to do anyways.
|
|
|
|
*/
|
2010-01-18 04:22:04 -05:00
|
|
|
if (_cogl_texture_2d_sliced_is_sliced (tex))
|
2010-03-01 16:49:04 -05:00
|
|
|
return COGL_TRANSFORM_SOFTWARE_REPEAT;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
if (coords[i] < 0.0f || coords[i] > 1.0f)
|
|
|
|
need_repeat = TRUE;
|
|
|
|
|
|
|
|
if (need_repeat && !_cogl_texture_2d_sliced_can_hardware_repeat (tex))
|
|
|
|
return COGL_TRANSFORM_SOFTWARE_REPEAT;
|
2010-01-18 04:22:04 -05:00
|
|
|
|
|
|
|
_cogl_texture_2d_sliced_transform_coords_to_gl (tex, coords + 0, coords + 1);
|
|
|
|
_cogl_texture_2d_sliced_transform_coords_to_gl (tex, coords + 2, coords + 3);
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
return (need_repeat
|
|
|
|
? COGL_TRANSFORM_HARDWARE_REPEAT : 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-25 08:39:45 -05:00
|
|
|
_cogl_texture_2d_sliced_get_gl_texture (CoglTexture *tex,
|
2009-08-30 06:36:11 -04:00
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
if (tex_2ds->slice_textures == NULL)
|
2009-08-30 06:36:11 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
if (tex_2ds->slice_textures->len < 1)
|
2009-08-30 06:36:11 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2011-10-08 06:53:20 -04:00
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2011-10-08 06:53:20 -04:00
|
|
|
return cogl_texture_get_gl_texture (COGL_TEXTURE (slice_tex),
|
|
|
|
out_gl_handle, out_gl_target);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
static void
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_2d_sliced_gl_flush_legacy_texobj_filters (CoglTexture *tex,
|
|
|
|
GLenum min_filter,
|
|
|
|
GLenum mag_filter)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2012-11-22 18:01:08 -05:00
|
|
|
CoglTexture2D *slice_tex;
|
|
|
|
int i;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
_COGL_RETURN_IF_FAIL (tex_2ds->slice_textures != NULL);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* Apply new filters to every slice. The slice texture itself should
|
|
|
|
cache the value and avoid resubmitting the same filter value to
|
|
|
|
GL */
|
|
|
|
for (i = 0; i < tex_2ds->slice_textures->len; i++)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2011-10-08 06:53:20 -04:00
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, i);
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_gl_flush_legacy_texobj_filters (COGL_TEXTURE (slice_tex),
|
|
|
|
min_filter, mag_filter);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
static void
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_texture_2d_sliced_pre_paint (CoglTexture *tex,
|
|
|
|
CoglTexturePrePaintFlags flags)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2012-11-22 18:01:08 -05:00
|
|
|
int i;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
_COGL_RETURN_IF_FAIL (tex_2ds->slice_textures != NULL);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-04 09:34:24 -04:00
|
|
|
/* Pass the pre-paint on to every slice */
|
|
|
|
for (i = 0; i < tex_2ds->slice_textures->len; i++)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex = g_array_index (tex_2ds->slice_textures,
|
|
|
|
CoglTexture2D *, i);
|
|
|
|
_cogl_texture_pre_paint (COGL_TEXTURE (slice_tex), flags);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
static void
|
|
|
|
_cogl_texture_2d_sliced_ensure_non_quad_rendering (CoglTexture *tex)
|
|
|
|
{
|
2010-10-04 09:34:24 -04:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
|
|
|
int i;
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
_COGL_RETURN_IF_FAIL (tex_2ds->slice_textures != NULL);
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
/* Pass the call on to every slice */
|
|
|
|
for (i = 0; i < tex_2ds->slice_textures->len; i++)
|
|
|
|
{
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex = g_array_index (tex_2ds->slice_textures,
|
|
|
|
CoglTexture2D *, i);
|
|
|
|
_cogl_texture_ensure_non_quad_rendering (COGL_TEXTURE (slice_tex));
|
2010-10-04 09:34:24 -04:00
|
|
|
}
|
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
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_texture_2d_sliced_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,
|
|
|
|
CoglError **error)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2009-11-25 08:39:45 -05:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2013-06-07 19:28:14 -04:00
|
|
|
CoglBitmap *upload_bmp;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBool status;
|
2011-07-07 07:48:24 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
upload_bmp = _cogl_bitmap_convert_for_upload (bmp,
|
2013-06-27 13:33:04 -04:00
|
|
|
_cogl_texture_get_format (tex),
|
2013-06-07 19:28:14 -04:00
|
|
|
FALSE, /* can't convert in
|
|
|
|
place */
|
|
|
|
error);
|
|
|
|
if (!upload_bmp)
|
2012-11-08 12:54:10 -05:00
|
|
|
return FALSE;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2013-06-07 19:28:14 -04:00
|
|
|
status = _cogl_texture_2d_sliced_upload_subregion (tex_2ds,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_width, dst_height,
|
|
|
|
upload_bmp,
|
|
|
|
error);
|
|
|
|
cogl_object_unref (upload_bmp);
|
2011-08-31 12:22:20 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return status;
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2009-11-26 13:58:17 -05:00
|
|
|
static CoglPixelFormat
|
|
|
|
_cogl_texture_2d_sliced_get_format (CoglTexture *tex)
|
|
|
|
{
|
2010-10-04 09:34:24 -04:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
return tex_2ds->internal_format;
|
2009-11-26 13:58:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum
|
|
|
|
_cogl_texture_2d_sliced_get_gl_format (CoglTexture *tex)
|
|
|
|
{
|
2010-10-04 09:34:24 -04:00
|
|
|
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
|
2011-10-08 06:53:20 -04:00
|
|
|
CoglTexture2D *slice_tex;
|
2010-10-04 09:34:24 -04:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
/* Assert that we've allocated our slices at this point */
|
|
|
|
cogl_texture_allocate (tex, NULL); /* (abort on error) */
|
2010-10-04 09:34:24 -04:00
|
|
|
|
|
|
|
/* Pass the call on to the first slice */
|
2011-10-08 06:53:20 -04:00
|
|
|
slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0);
|
2012-11-22 16:31:25 -05:00
|
|
|
return _cogl_texture_gl_get_format (COGL_TEXTURE (slice_tex));
|
2009-11-26 13:58:17 -05:00
|
|
|
}
|
|
|
|
|
2012-02-09 06:19:04 -05:00
|
|
|
static CoglTextureType
|
|
|
|
_cogl_texture_2d_sliced_get_type (CoglTexture *tex)
|
|
|
|
{
|
|
|
|
return COGL_TEXTURE_TYPE_2D;
|
|
|
|
}
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
static const CoglTextureVtable
|
|
|
|
cogl_texture_2d_sliced_vtable =
|
|
|
|
{
|
2012-04-04 10:09:43 -04:00
|
|
|
FALSE, /* not primitive */
|
2012-11-22 18:01:08 -05:00
|
|
|
_cogl_texture_2d_sliced_allocate,
|
2009-11-25 08:39:45 -05:00
|
|
|
_cogl_texture_2d_sliced_set_region,
|
2010-11-12 11:02:13 -05:00
|
|
|
NULL, /* get_data */
|
2009-11-25 08:39:45 -05:00
|
|
|
_cogl_texture_2d_sliced_foreach_sub_texture_in_region,
|
|
|
|
_cogl_texture_2d_sliced_get_max_waste,
|
|
|
|
_cogl_texture_2d_sliced_is_sliced,
|
|
|
|
_cogl_texture_2d_sliced_can_hardware_repeat,
|
|
|
|
_cogl_texture_2d_sliced_transform_coords_to_gl,
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_texture_2d_sliced_transform_quad_coords_to_gl,
|
2009-11-25 08:39:45 -05:00
|
|
|
_cogl_texture_2d_sliced_get_gl_texture,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_2d_sliced_gl_flush_legacy_texobj_filters,
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_texture_2d_sliced_pre_paint,
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_texture_2d_sliced_ensure_non_quad_rendering,
|
2012-09-10 15:35:39 -04:00
|
|
|
_cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes,
|
2009-11-26 13:58:17 -05:00
|
|
|
_cogl_texture_2d_sliced_get_format,
|
|
|
|
_cogl_texture_2d_sliced_get_gl_format,
|
2012-02-09 06:19:04 -05:00
|
|
|
_cogl_texture_2d_sliced_get_type,
|
2012-04-04 10:09:43 -04:00
|
|
|
_cogl_texture_2d_sliced_is_foreign,
|
|
|
|
NULL /* set_auto_mipmap */
|
2009-11-25 08:39:45 -05:00
|
|
|
};
|