2008-04-25 09:37:36 -04:00
|
|
|
/*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Cogl
|
2008-04-25 09:37:36 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2008-04-25 09:37:36 -04:00
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
2010-11-12 11:02:13 -05:00
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
2008-04-25 09:37:36 -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-04-27 10:48:12 -04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Matthew Allum <mallum@openedhand.com>
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
2008-04-25 09:37:36 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2016-05-05 10:21:51 -04:00
|
|
|
#include "cogl-config.h"
|
2008-04-25 09:37:36 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-bitmap.h"
|
2009-04-30 13:00:22 -04:00
|
|
|
#include "cogl-bitmap-private.h"
|
2010-01-22 10:07:27 -05:00
|
|
|
#include "cogl-buffer-private.h"
|
2011-03-02 10:19:57 -05:00
|
|
|
#include "cogl-pixel-buffer-private.h"
|
2010-11-12 11:02:13 -05:00
|
|
|
#include "cogl-private.h"
|
2008-10-30 13:25:00 -04:00
|
|
|
#include "cogl-texture-private.h"
|
2009-07-27 19:37:11 -04:00
|
|
|
#include "cogl-texture-driver.h"
|
2009-08-30 06:36:11 -04:00
|
|
|
#include "cogl-texture-2d-sliced-private.h"
|
2009-11-27 13:45:36 -05:00
|
|
|
#include "cogl-texture-2d-private.h"
|
2012-09-10 16:45:33 -04:00
|
|
|
#include "cogl-texture-2d-gl.h"
|
2012-11-09 12:55:54 -05:00
|
|
|
#include "cogl-texture-3d-private.h"
|
2010-10-04 10:27:38 -04:00
|
|
|
#include "cogl-texture-rectangle-private.h"
|
2009-11-27 11:39:16 -05:00
|
|
|
#include "cogl-sub-texture-private.h"
|
2009-12-04 08:06:32 -05:00
|
|
|
#include "cogl-atlas-texture-private.h"
|
2010-10-27 13:54:57 -04:00
|
|
|
#include "cogl-pipeline.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"
|
2011-01-06 08:25:45 -05:00
|
|
|
#include "cogl-object-private.h"
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
#include "cogl-primitives.h"
|
2009-11-26 14:06:35 -05:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2012-02-17 16:46:39 -05:00
|
|
|
#include "cogl1-context.h"
|
2012-02-17 20:19:17 -05:00
|
|
|
#include "cogl-sub-texture.h"
|
2012-04-04 10:10:04 -04:00
|
|
|
#include "cogl-primitive-texture.h"
|
2012-11-08 12:54:10 -05:00
|
|
|
#include "cogl-error-private.h"
|
2013-09-02 11:02:42 -04:00
|
|
|
#include "cogl-gtype-private.h"
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2009-01-20 11:20:54 -05:00
|
|
|
#include <math.h>
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2013-01-24 06:41:38 -05:00
|
|
|
/* This isn't defined in the GLES headers */
|
|
|
|
#ifndef GL_RED
|
|
|
|
#define GL_RED 0x1903
|
|
|
|
#endif
|
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
COGL_GTYPE_DEFINE_INTERFACE (Texture, texture);
|
|
|
|
|
2012-08-31 14:28:27 -04:00
|
|
|
uint32_t
|
2011-05-16 19:05:54 -04:00
|
|
|
cogl_texture_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("cogl-texture-error-quark");
|
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* XXX:
|
2012-04-16 09:14:10 -04:00
|
|
|
* The CoglObject macros don't support any form of inheritance, so for
|
|
|
|
* now we implement the CoglObject support for the CoglTexture
|
2009-08-30 06:36:11 -04:00
|
|
|
* abstract class manually.
|
|
|
|
*/
|
2008-12-11 10:33:38 -05:00
|
|
|
|
2013-02-12 17:55:45 -05:00
|
|
|
static GSList *_cogl_texture_types;
|
|
|
|
|
2010-06-11 08:50:36 -04:00
|
|
|
void
|
2012-01-24 11:24:26 -05:00
|
|
|
_cogl_texture_register_texture_type (const CoglObjectClass *klass)
|
2010-06-11 08:50:36 -04:00
|
|
|
{
|
2013-02-12 17:55:45 -05:00
|
|
|
_cogl_texture_types = g_slist_prepend (_cogl_texture_types, (void *) klass);
|
2010-06-11 08:50:36 -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
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_is_texture (void *object)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
CoglObject *obj = (CoglObject *)object;
|
2010-06-11 08:50:36 -04:00
|
|
|
GSList *l;
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
if (object == NULL)
|
2009-08-30 06:36:11 -04:00
|
|
|
return FALSE;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2013-02-12 17:55:45 -05:00
|
|
|
for (l = _cogl_texture_types; l; l = l->next)
|
2012-01-24 11:24:26 -05:00
|
|
|
if (l->data == obj->klass)
|
2010-06-11 08:50:36 -04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
void
|
|
|
|
_cogl_texture_init (CoglTexture *texture,
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *context,
|
2012-11-22 16:46:54 -05:00
|
|
|
int width,
|
|
|
|
int height,
|
2013-07-01 20:48:54 -04:00
|
|
|
CoglPixelFormat src_format,
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglTextureLoader *loader,
|
2011-01-06 08:25:45 -05:00
|
|
|
const CoglTextureVtable *vtable)
|
|
|
|
{
|
2012-09-07 10:26:34 -04:00
|
|
|
texture->context = context;
|
2012-11-09 12:55:54 -05:00
|
|
|
texture->max_level = 0;
|
2012-11-22 16:46:54 -05:00
|
|
|
texture->width = width;
|
|
|
|
texture->height = height;
|
2012-11-22 18:01:08 -05:00
|
|
|
texture->allocated = FALSE;
|
2011-01-06 08:25:45 -05:00
|
|
|
texture->vtable = vtable;
|
|
|
|
texture->framebuffers = NULL;
|
2013-06-23 11:18:18 -04:00
|
|
|
|
|
|
|
texture->loader = loader;
|
|
|
|
|
2013-07-01 20:48:54 -04:00
|
|
|
_cogl_texture_set_internal_format (texture, src_format);
|
|
|
|
|
|
|
|
/* Although we want to initialize texture::components according
|
|
|
|
* to the source format, we always want the internal layout to
|
|
|
|
* be considered premultiplied by default.
|
|
|
|
*
|
|
|
|
* NB: this ->premultiplied state is user configurable so to avoid
|
|
|
|
* awkward documentation, setting this to 'true' does not depend on
|
|
|
|
* ->components having an alpha component (we will simply ignore the
|
|
|
|
* premultiplied status later if there is no alpha component).
|
|
|
|
* This way we don't have to worry about updating the
|
|
|
|
* ->premultiplied state in _set_components(). Similarly we don't
|
|
|
|
* have to worry about updating the ->components state in
|
|
|
|
* _set_premultiplied().
|
|
|
|
*/
|
|
|
|
texture->premultiplied = TRUE;
|
2013-06-23 11:18:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_free_loader (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
if (texture->loader)
|
|
|
|
{
|
|
|
|
CoglTextureLoader *loader = texture->loader;
|
|
|
|
switch (loader->src_type)
|
|
|
|
{
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_SIZED:
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE:
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_GL_FOREIGN:
|
2016-10-20 03:52:57 -04:00
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE_EXTERNAL:
|
2013-06-23 11:18:18 -04:00
|
|
|
break;
|
|
|
|
case COGL_TEXTURE_SOURCE_TYPE_BITMAP:
|
|
|
|
cogl_object_unref (loader->src.bitmap.bitmap);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_slice_free (CoglTextureLoader, loader);
|
|
|
|
texture->loader = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglTextureLoader *
|
|
|
|
_cogl_texture_create_loader (void)
|
|
|
|
{
|
|
|
|
return g_slice_new0 (CoglTextureLoader);
|
2011-01-06 08:25:45 -05:00
|
|
|
}
|
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
void
|
|
|
|
_cogl_texture_free (CoglTexture *texture)
|
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_free_loader (texture);
|
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
g_free (texture);
|
|
|
|
}
|
|
|
|
|
2012-11-08 15:33:00 -05:00
|
|
|
CoglBool
|
2010-02-03 17:54:44 -05:00
|
|
|
_cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
|
|
|
|
CoglPixelFormat dst_format)
|
|
|
|
{
|
2010-06-01 08:32:57 -04:00
|
|
|
return ((src_format & dst_format & COGL_A_BIT) &&
|
2010-02-03 17:54:44 -05:00
|
|
|
src_format != COGL_PIXEL_FORMAT_A_8 &&
|
2010-06-01 08:32:57 -04:00
|
|
|
dst_format != COGL_PIXEL_FORMAT_A_8 &&
|
2010-02-03 17:54:44 -05:00
|
|
|
(src_format & COGL_PREMULT_BIT) !=
|
|
|
|
(dst_format & COGL_PREMULT_BIT));
|
|
|
|
}
|
|
|
|
|
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
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_is_foreign (CoglTexture *texture)
|
2010-04-26 05:01:43 -04:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
if (texture->vtable->is_foreign)
|
|
|
|
return texture->vtable->is_foreign (texture);
|
2010-04-26 05:01:43 -04:00
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_get_width (CoglTexture *texture)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2012-11-22 16:46:54 -05:00
|
|
|
return texture->width;
|
2008-04-25 09:37:36 -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
|
|
|
unsigned int
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_get_height (CoglTexture *texture)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2012-11-22 16:46:54 -05:00
|
|
|
return texture->height;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPixelFormat
|
2013-06-27 13:33:04 -04:00
|
|
|
_cogl_texture_get_format (CoglTexture *texture)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2013-06-30 12:16:58 -04:00
|
|
|
if (!texture->allocated)
|
|
|
|
cogl_texture_allocate (texture, NULL);
|
2011-08-24 16:30:34 -04:00
|
|
|
return texture->vtable->get_format (texture);
|
2008-04-25 09:37:36 -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
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_get_max_waste (CoglTexture *texture)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
return texture->vtable->get_max_waste (texture);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2012-11-09 12:55:54 -05:00
|
|
|
int
|
|
|
|
_cogl_texture_get_n_levels (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
int width = cogl_texture_get_width (texture);
|
|
|
|
int height = cogl_texture_get_height (texture);
|
|
|
|
int max_dimension = MAX (width, height);
|
|
|
|
|
|
|
|
if (cogl_is_texture_3d (texture))
|
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (texture);
|
|
|
|
max_dimension = MAX (max_dimension, tex_3d->depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _cogl_util_fls (max_dimension);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_texture_get_level_size (CoglTexture *texture,
|
|
|
|
int level,
|
|
|
|
int *width,
|
|
|
|
int *height,
|
|
|
|
int *depth)
|
|
|
|
{
|
|
|
|
int current_width = cogl_texture_get_width (texture);
|
|
|
|
int current_height = cogl_texture_get_height (texture);
|
|
|
|
int current_depth;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (cogl_is_texture_3d (texture))
|
|
|
|
{
|
|
|
|
CoglTexture3D *tex_3d = COGL_TEXTURE_3D (texture);
|
|
|
|
current_depth = tex_3d->depth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
current_depth = 0;
|
|
|
|
|
|
|
|
/* NB: The OpenGL spec (like D3D) uses a floor() convention to
|
|
|
|
* round down the size of a mipmap level when dividing the size
|
|
|
|
* of the previous level results in a fraction...
|
|
|
|
*/
|
|
|
|
for (i = 0; i < level; i++)
|
|
|
|
{
|
|
|
|
current_width = MAX (1, current_width >> 1);
|
|
|
|
current_height = MAX (1, current_height >> 1);
|
|
|
|
current_depth = MAX (1, current_depth >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = current_width;
|
|
|
|
if (height)
|
|
|
|
*height = current_height;
|
|
|
|
if (depth)
|
|
|
|
*depth = current_depth;
|
|
|
|
}
|
|
|
|
|
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
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_is_sliced (CoglTexture *texture)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2013-06-30 12:16:58 -04:00
|
|
|
if (!texture->allocated)
|
|
|
|
cogl_texture_allocate (texture, NULL);
|
2011-08-24 16:30:34 -04:00
|
|
|
return texture->vtable->is_sliced (texture);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* If this returns FALSE, that implies _foreach_sub_texture_in_region
|
|
|
|
* will be needed to iterate over multiple sub textures for regions whos
|
|
|
|
* texture coordinates extend out of the range [0,1]
|
|
|
|
*/
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_can_hardware_repeat (CoglTexture *texture)
|
2009-09-16 06:56:17 -04:00
|
|
|
{
|
2013-06-30 12:16:58 -04:00
|
|
|
if (!texture->allocated)
|
|
|
|
cogl_texture_allocate (texture, NULL);
|
2011-08-24 16:30:34 -04:00
|
|
|
return texture->vtable->can_hardware_repeat (texture);
|
2009-09-16 06:56:17 -04:00
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* NB: You can't use this with textures comprised of multiple sub textures (use
|
|
|
|
* cogl_texture_is_sliced() to check) since coordinate transformation for such
|
|
|
|
* textures will be different for each slice. */
|
2009-09-16 06:56:17 -04:00
|
|
|
void
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_transform_coords_to_gl (CoglTexture *texture,
|
2009-09-16 06:56:17 -04:00
|
|
|
float *s,
|
|
|
|
float *t)
|
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
texture->vtable->transform_coords_to_gl (texture, s, t);
|
2009-09-16 06:56:17 -04:00
|
|
|
}
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
CoglTransformResult
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture,
|
2010-01-18 04:22:04 -05:00
|
|
|
float *coords)
|
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
return texture->vtable->transform_quad_coords_to_gl (texture, coords);
|
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
|
|
|
CoglBool
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_get_gl_texture (CoglTexture *texture,
|
2008-04-25 09:37:36 -04:00
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
2013-06-26 17:50:11 -04:00
|
|
|
if (!texture->allocated)
|
|
|
|
cogl_texture_allocate (texture, NULL);
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
return texture->vtable->get_gl_texture (texture,
|
|
|
|
out_gl_handle, out_gl_target);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2012-02-09 06:19:04 -05:00
|
|
|
CoglTextureType
|
|
|
|
_cogl_texture_get_type (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
return texture->vtable->get_type (texture);
|
|
|
|
}
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
void
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_pre_paint (CoglTexture *texture, CoglTexturePrePaintFlags flags)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
/* Assert that the storage for the texture exists already if we're
|
|
|
|
* about to reference it for painting.
|
|
|
|
*
|
|
|
|
* Note: we abort on error here since it's a bit late to do anything
|
|
|
|
* about it if we fail to allocate the texture and the app could
|
|
|
|
* have explicitly allocated the texture earlier to handle problems
|
|
|
|
* gracefully.
|
|
|
|
*
|
|
|
|
* XXX: Maybe it could even be considered a programmer error if the
|
|
|
|
* texture hasn't been allocated by this point since it implies we
|
|
|
|
* are abount to paint with undefined texture contents?
|
|
|
|
*/
|
|
|
|
cogl_texture_allocate (texture, NULL);
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
texture->vtable->pre_paint (texture, flags);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
void
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_ensure_non_quad_rendering (CoglTexture *texture)
|
2010-01-18 04:22:04 -05:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
texture->vtable->ensure_non_quad_rendering (texture);
|
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
|
|
|
CoglBool
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
2012-11-09 12:55:54 -05:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglBitmap *bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
2012-11-09 12:55:54 -05:00
|
|
|
int level,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError **error)
|
2010-07-08 10:15:22 -04:00
|
|
|
{
|
2012-02-25 15:18:05 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL ((cogl_bitmap_get_width (bmp) - src_x)
|
2012-11-09 12:55:54 -05:00
|
|
|
>= width, FALSE);
|
2012-02-25 15:18:05 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL ((cogl_bitmap_get_height (bmp) - src_y)
|
2012-11-09 12:55:54 -05:00
|
|
|
>= height, FALSE);
|
2012-11-22 18:01:08 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (width > 0, FALSE);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (height > 0, FALSE);
|
2011-11-22 07:06:40 -05:00
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
/* Assert that the storage for this texture has been allocated */
|
|
|
|
if (!cogl_texture_allocate (texture, error))
|
|
|
|
return FALSE;
|
2010-07-08 10:15:22 -04:00
|
|
|
|
2011-08-31 12:22:20 -04:00
|
|
|
/* Note that we don't prepare the bitmap for upload here because
|
|
|
|
some backends may be internally using a different format for the
|
|
|
|
actual GL texture than that reported by
|
2013-06-27 13:33:04 -04:00
|
|
|
_cogl_texture_get_format. For example the atlas textures are
|
2011-08-31 12:22:20 -04:00
|
|
|
always stored in an RGBA texture even if the texture format is
|
|
|
|
advertised as RGB. */
|
2010-07-08 10:15:22 -04:00
|
|
|
|
2012-11-09 12:55:54 -05:00
|
|
|
return texture->vtable->set_region (texture,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
width, height,
|
|
|
|
level,
|
|
|
|
bmp,
|
|
|
|
error);
|
2010-07-08 10:15:22 -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
|
2012-11-08 12:54:10 -05:00
|
|
|
cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
unsigned int dst_width,
|
|
|
|
unsigned int dst_height,
|
|
|
|
CoglBitmap *bitmap)
|
|
|
|
{
|
|
|
|
CoglError *ignore_error = NULL;
|
|
|
|
CoglBool status =
|
|
|
|
_cogl_texture_set_region_from_bitmap (texture,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_width, dst_height,
|
|
|
|
bitmap,
|
2012-11-09 12:55:54 -05:00
|
|
|
dst_x, dst_y,
|
|
|
|
0, /* level */
|
2012-11-08 12:54:10 -05:00
|
|
|
&ignore_error);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-11-09 12:55:54 -05:00
|
|
|
CoglBool
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_texture_set_region (CoglTexture *texture,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
2012-11-09 12:55:54 -05:00
|
|
|
int rowstride,
|
2012-11-08 12:54:10 -05:00
|
|
|
const uint8_t *data,
|
2012-11-09 12:55:54 -05:00
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int level,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError **error)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = texture->context;
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *source_bmp;
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglBool ret;
|
2012-03-13 10:46:18 -04:00
|
|
|
|
2012-11-09 12:55:54 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (format != COGL_PIXEL_FORMAT_ANY, FALSE);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2010-07-08 10:15:22 -04:00
|
|
|
/* Rowstride from width if none specified */
|
2010-07-07 13:44:16 -04:00
|
|
|
if (rowstride == 0)
|
2012-02-13 18:02:04 -05:00
|
|
|
rowstride = _cogl_pixel_format_get_bytes_per_pixel (format) * width;
|
2010-07-08 10:15:22 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
/* Init source bitmap */
|
2012-03-13 10:46:18 -04:00
|
|
|
source_bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
(uint8_t *) data);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
ret = _cogl_texture_set_region_from_bitmap (texture,
|
2012-11-09 12:55:54 -05:00
|
|
|
0, 0,
|
|
|
|
width, height,
|
2012-11-08 12:54:10 -05:00
|
|
|
source_bmp,
|
2012-11-09 12:55:54 -05:00
|
|
|
dst_x, dst_y,
|
|
|
|
level,
|
2012-11-08 12:54:10 -05:00
|
|
|
error);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
cogl_object_unref (source_bmp);
|
|
|
|
|
|
|
|
return ret;
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBool
|
|
|
|
cogl_texture_set_region (CoglTexture *texture,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
unsigned int dst_width,
|
|
|
|
unsigned int dst_height,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
unsigned int rowstride,
|
|
|
|
const uint8_t *data)
|
|
|
|
{
|
|
|
|
CoglError *ignore_error = NULL;
|
2012-11-09 12:55:54 -05:00
|
|
|
const uint8_t *first_pixel;
|
|
|
|
int bytes_per_pixel = _cogl_pixel_format_get_bytes_per_pixel (format);
|
|
|
|
CoglBool status;
|
|
|
|
|
|
|
|
/* Rowstride from width if none specified */
|
|
|
|
if (rowstride == 0)
|
|
|
|
rowstride = bytes_per_pixel * width;
|
|
|
|
|
|
|
|
first_pixel = data + rowstride * src_y + bytes_per_pixel * src_x;
|
|
|
|
|
|
|
|
status = _cogl_texture_set_region (texture,
|
|
|
|
dst_width,
|
|
|
|
dst_height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
first_pixel,
|
|
|
|
dst_x,
|
|
|
|
dst_y,
|
|
|
|
0,
|
|
|
|
&ignore_error);
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!status)
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-11-26 08:14:27 -05:00
|
|
|
CoglBool
|
|
|
|
cogl_texture_set_data (CoglTexture *texture,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
int rowstride,
|
|
|
|
const uint8_t *data,
|
|
|
|
int level,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
int level_width;
|
|
|
|
int level_height;
|
|
|
|
|
|
|
|
_cogl_texture_get_level_size (texture,
|
|
|
|
level,
|
|
|
|
&level_width,
|
|
|
|
&level_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return _cogl_texture_set_region (texture,
|
|
|
|
level_width,
|
|
|
|
level_height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
data,
|
|
|
|
0, 0, /* dest x, y */
|
|
|
|
level,
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
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-12-01 16:31:33 -05:00
|
|
|
get_texture_bits_via_offscreen (CoglTexture *meta_texture,
|
|
|
|
CoglTexture *sub_texture,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
uint8_t *dst_bits,
|
|
|
|
unsigned int dst_rowstride,
|
|
|
|
CoglPixelFormat closest_format)
|
2010-11-12 11:02:13 -05:00
|
|
|
{
|
2013-12-01 16:31:33 -05:00
|
|
|
CoglContext *ctx = sub_texture->context;
|
2012-02-18 10:22:15 -05:00
|
|
|
CoglOffscreen *offscreen;
|
2010-11-12 11:02:13 -05:00
|
|
|
CoglFramebuffer *framebuffer;
|
2012-02-25 14:23:51 -05:00
|
|
|
CoglBitmap *bitmap;
|
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 ret;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError *ignore_error = NULL;
|
2013-12-01 16:31:33 -05:00
|
|
|
CoglPixelFormat real_format;
|
2010-11-12 11:02:13 -05:00
|
|
|
|
2011-10-12 17:31:12 -04:00
|
|
|
if (!cogl_has_feature (ctx, COGL_FEATURE_ID_OFFSCREEN))
|
2010-11-12 11:02:13 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2013-08-16 17:43:19 -04:00
|
|
|
offscreen = _cogl_offscreen_new_with_texture_full
|
2013-12-01 16:31:33 -05:00
|
|
|
(sub_texture,
|
2010-11-12 11:02:13 -05:00
|
|
|
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL,
|
|
|
|
0);
|
|
|
|
|
2012-02-18 10:22:15 -05:00
|
|
|
framebuffer = COGL_FRAMEBUFFER (offscreen);
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!cogl_framebuffer_allocate (framebuffer, &ignore_error))
|
|
|
|
{
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-02-18 10:22:15 -05:00
|
|
|
|
2013-12-01 16:31:33 -05:00
|
|
|
/* Currently the framebuffer's internal format corresponds to the
|
|
|
|
* internal format of @sub_texture but in the case of atlas textures
|
|
|
|
* it's possible that this format doesn't reflect the correct
|
|
|
|
* premultiplied alpha status or what components are valid since
|
|
|
|
* atlas textures are always stored in a shared texture with a
|
|
|
|
* format of _RGBA_8888.
|
|
|
|
*
|
|
|
|
* Here we override the internal format to make sure the
|
|
|
|
* framebuffer's internal format matches the internal format of the
|
|
|
|
* parent meta_texture instead.
|
|
|
|
*/
|
|
|
|
real_format = _cogl_texture_get_format (meta_texture);
|
|
|
|
_cogl_framebuffer_set_internal_format (framebuffer, real_format);
|
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
bitmap = cogl_bitmap_new_for_data (ctx,
|
|
|
|
width, height,
|
2013-12-01 16:31:33 -05:00
|
|
|
closest_format,
|
2012-03-13 10:46:18 -04:00
|
|
|
dst_rowstride,
|
|
|
|
dst_bits);
|
2012-11-08 12:54:10 -05:00
|
|
|
ret = _cogl_framebuffer_read_pixels_into_bitmap (framebuffer,
|
|
|
|
x, y,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
bitmap,
|
|
|
|
&ignore_error);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
|
2012-02-25 14:23:51 -05:00
|
|
|
cogl_object_unref (bitmap);
|
2010-11-12 11:02:13 -05:00
|
|
|
|
|
|
|
cogl_object_unref (framebuffer);
|
|
|
|
|
2012-03-31 08:29:01 -04:00
|
|
|
return ret;
|
2010-11-12 11:02:13 -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
|
|
|
|
get_texture_bits_via_copy (CoglTexture *texture,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
uint8_t *dst_bits,
|
|
|
|
unsigned int dst_rowstride,
|
2010-11-12 11:02:13 -05:00
|
|
|
CoglPixelFormat dst_format)
|
|
|
|
{
|
|
|
|
unsigned int full_rowstride;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *full_bits;
|
|
|
|
CoglBool ret = TRUE;
|
2010-11-12 11:02:13 -05:00
|
|
|
int bpp;
|
|
|
|
int full_tex_width, full_tex_height;
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
full_tex_width = cogl_texture_get_width (texture);
|
|
|
|
full_tex_height = cogl_texture_get_height (texture);
|
2010-11-12 11:02:13 -05:00
|
|
|
|
2012-02-13 18:02:04 -05:00
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (dst_format);
|
2010-11-12 11:02:13 -05:00
|
|
|
|
|
|
|
full_rowstride = bpp * full_tex_width;
|
|
|
|
full_bits = g_malloc (full_rowstride * full_tex_height);
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
if (texture->vtable->get_data (texture,
|
|
|
|
dst_format,
|
|
|
|
full_rowstride,
|
|
|
|
full_bits))
|
2010-11-12 11:02:13 -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
|
|
|
uint8_t *dst = dst_bits;
|
|
|
|
uint8_t *src = full_bits + x * bpp + y * full_rowstride;
|
2010-11-12 11:02:13 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
memcpy (dst, src, bpp * width);
|
|
|
|
dst += dst_rowstride;
|
|
|
|
src += full_rowstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
g_free (full_bits);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2013-12-01 16:31:33 -05:00
|
|
|
CoglTexture *meta_texture;
|
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
|
|
|
int orig_width;
|
|
|
|
int orig_height;
|
2010-11-12 11:02:13 -05:00
|
|
|
CoglBitmap *target_bmp;
|
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 *target_bits;
|
|
|
|
CoglBool success;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError *error;
|
2010-11-12 11:02:13 -05:00
|
|
|
} CoglTextureGetData;
|
|
|
|
|
|
|
|
static void
|
2013-12-01 16:31:33 -05:00
|
|
|
texture_get_cb (CoglTexture *subtexture,
|
2010-11-12 11:02:13 -05:00
|
|
|
const float *subtexture_coords,
|
|
|
|
const float *virtual_coords,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglTextureGetData *tg_data = user_data;
|
2013-12-01 16:31:33 -05:00
|
|
|
CoglTexture *meta_texture = tg_data->meta_texture;
|
|
|
|
CoglPixelFormat closest_format = cogl_bitmap_get_format (tg_data->target_bmp);
|
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (closest_format);
|
2012-02-25 15:18:05 -05:00
|
|
|
unsigned int rowstride = cogl_bitmap_get_rowstride (tg_data->target_bmp);
|
2013-12-01 16:31:33 -05:00
|
|
|
int subtexture_width = cogl_texture_get_width (subtexture);
|
|
|
|
int subtexture_height = cogl_texture_get_height (subtexture);
|
2010-11-12 11:02:13 -05:00
|
|
|
|
|
|
|
int x_in_subtexture = (int) (0.5 + subtexture_width * subtexture_coords[0]);
|
|
|
|
int y_in_subtexture = (int) (0.5 + subtexture_height * subtexture_coords[1]);
|
|
|
|
int width = ((int) (0.5 + subtexture_width * subtexture_coords[2])
|
|
|
|
- x_in_subtexture);
|
|
|
|
int height = ((int) (0.5 + subtexture_height * subtexture_coords[3])
|
|
|
|
- y_in_subtexture);
|
|
|
|
int x_in_bitmap = (int) (0.5 + tg_data->orig_width * virtual_coords[0]);
|
|
|
|
int y_in_bitmap = (int) (0.5 + tg_data->orig_height * virtual_coords[1]);
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *dst_bits;
|
2010-11-12 11:02:13 -05:00
|
|
|
|
|
|
|
if (!tg_data->success)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dst_bits = tg_data->target_bits + x_in_bitmap * bpp + y_in_bitmap * rowstride;
|
|
|
|
|
|
|
|
/* If we can read everything as a single slice, then go ahead and do that
|
|
|
|
* to avoid allocating an FBO. We'll leave it up to the GL implementation to
|
|
|
|
* do glGetTexImage as efficiently as possible. (GLES doesn't have that,
|
2013-12-01 16:31:33 -05:00
|
|
|
* so we'll fall through)
|
|
|
|
*/
|
2010-11-12 11:02:13 -05:00
|
|
|
if (x_in_subtexture == 0 && y_in_subtexture == 0 &&
|
|
|
|
width == subtexture_width && height == subtexture_height)
|
|
|
|
{
|
2013-12-01 16:31:33 -05:00
|
|
|
if (subtexture->vtable->get_data (subtexture,
|
|
|
|
closest_format,
|
|
|
|
rowstride,
|
|
|
|
dst_bits))
|
2010-11-12 11:02:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next best option is a FBO and glReadPixels */
|
2013-12-01 16:31:33 -05:00
|
|
|
if (get_texture_bits_via_offscreen (meta_texture,
|
|
|
|
subtexture,
|
2010-11-12 11:02:13 -05:00
|
|
|
x_in_subtexture, y_in_subtexture,
|
|
|
|
width, height,
|
|
|
|
dst_bits,
|
|
|
|
rowstride,
|
2013-12-01 16:31:33 -05:00
|
|
|
closest_format))
|
2010-11-12 11:02:13 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Getting ugly: read the entire texture, copy out the part we want */
|
2013-12-01 16:31:33 -05:00
|
|
|
if (get_texture_bits_via_copy (subtexture,
|
2010-11-12 11:02:13 -05:00
|
|
|
x_in_subtexture, y_in_subtexture,
|
|
|
|
width, height,
|
|
|
|
dst_bits,
|
|
|
|
rowstride,
|
2013-12-01 16:31:33 -05:00
|
|
|
closest_format))
|
2010-11-12 11:02:13 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* No luck, the caller will fall back to the draw-to-backbuffer and
|
|
|
|
* read implementation */
|
|
|
|
tg_data->success = FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
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
|
|
|
cogl_texture_get_data (CoglTexture *texture,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
unsigned int rowstride,
|
|
|
|
uint8_t *data)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = texture->context;
|
|
|
|
int bpp;
|
|
|
|
int byte_size;
|
|
|
|
CoglPixelFormat closest_format;
|
|
|
|
GLenum closest_gl_format;
|
|
|
|
GLenum closest_gl_type;
|
|
|
|
CoglBitmap *target_bmp;
|
|
|
|
int tex_width;
|
|
|
|
int tex_height;
|
|
|
|
CoglPixelFormat texture_format;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError *ignore_error = NULL;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2010-11-12 11:02:13 -05:00
|
|
|
CoglTextureGetData tg_data;
|
|
|
|
|
2013-06-27 13:33:04 -04:00
|
|
|
texture_format = _cogl_texture_get_format (texture);
|
2012-02-23 12:42:01 -05:00
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
/* Default to internal format if none specified */
|
|
|
|
if (format == COGL_PIXEL_FORMAT_ANY)
|
2012-02-23 12:42:01 -05:00
|
|
|
format = texture_format;
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
tex_width = cogl_texture_get_width (texture);
|
|
|
|
tex_height = cogl_texture_get_height (texture);
|
2010-07-08 08:54:37 -04:00
|
|
|
|
|
|
|
/* Rowstride from texture width if none specified */
|
2012-02-13 18:02:04 -05:00
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2010-07-08 08:54:37 -04:00
|
|
|
if (rowstride == 0)
|
|
|
|
rowstride = tex_width * bpp;
|
|
|
|
|
|
|
|
/* Return byte size if only that requested */
|
|
|
|
byte_size = tex_height * rowstride;
|
|
|
|
if (data == NULL)
|
|
|
|
return byte_size;
|
|
|
|
|
|
|
|
closest_format =
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->texture_driver->find_best_gl_get_data_format (ctx,
|
2017-05-18 08:57:43 -04:00
|
|
|
texture_format,
|
2012-03-22 12:32:56 -04:00
|
|
|
format,
|
2010-07-08 08:54:37 -04:00
|
|
|
&closest_gl_format,
|
|
|
|
&closest_gl_type);
|
|
|
|
|
2012-02-23 12:42:01 -05:00
|
|
|
/* We can assume that whatever data GL gives us will have the
|
|
|
|
premult status of the original texture */
|
2012-02-29 07:27:19 -05:00
|
|
|
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (closest_format))
|
2012-02-23 12:42:01 -05:00
|
|
|
closest_format = ((closest_format & ~COGL_PREMULT_BIT) |
|
|
|
|
(texture_format & COGL_PREMULT_BIT));
|
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
/* If the application is requesting a conversion from a
|
|
|
|
* component-alpha texture and the driver doesn't support them
|
|
|
|
* natively then we can only read into an alpha-format buffer. In
|
|
|
|
* this case the driver will be faking the alpha textures with a
|
|
|
|
* red-component texture and it won't swizzle to the correct format
|
|
|
|
* while reading */
|
2013-11-25 11:11:36 -05:00
|
|
|
if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_ALPHA_TEXTURES))
|
2012-11-19 12:28:52 -05:00
|
|
|
{
|
|
|
|
if (texture_format == COGL_PIXEL_FORMAT_A_8)
|
|
|
|
{
|
|
|
|
closest_format = COGL_PIXEL_FORMAT_A_8;
|
|
|
|
closest_gl_format = GL_RED;
|
|
|
|
closest_gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
else if (format == COGL_PIXEL_FORMAT_A_8)
|
|
|
|
{
|
|
|
|
/* If we are converting to a component-alpha texture then we
|
|
|
|
* need to read all of the components to a temporary buffer
|
|
|
|
* because there is no way to get just the 4th component.
|
|
|
|
* Note: it doesn't matter whether the texture is
|
|
|
|
* pre-multiplied here because we're only going to look at
|
|
|
|
* the alpha component */
|
|
|
|
closest_format = COGL_PIXEL_FORMAT_RGBA_8888;
|
|
|
|
closest_gl_format = GL_RGBA;
|
|
|
|
closest_gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
/* Is the requested format supported? */
|
|
|
|
if (closest_format == format)
|
2010-07-07 13:44:16 -04:00
|
|
|
/* Target user data directly */
|
2012-03-13 10:46:18 -04:00
|
|
|
target_bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
tex_width,
|
|
|
|
tex_height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
data);
|
2010-07-07 13:44:16 -04:00
|
|
|
else
|
2012-11-08 17:14:18 -05:00
|
|
|
{
|
|
|
|
target_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
tex_width, tex_height,
|
|
|
|
closest_format,
|
|
|
|
&ignore_error);
|
|
|
|
if (!target_bmp)
|
|
|
|
{
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-11-12 11:02:13 -05:00
|
|
|
tg_data.target_bits = _cogl_bitmap_map (target_bmp, COGL_BUFFER_ACCESS_WRITE,
|
2012-11-08 12:54:10 -05:00
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD,
|
|
|
|
&ignore_error);
|
|
|
|
if (tg_data.target_bits)
|
|
|
|
{
|
2013-12-01 16:31:33 -05:00
|
|
|
tg_data.meta_texture = texture;
|
2012-11-08 12:54:10 -05:00
|
|
|
tg_data.orig_width = tex_width;
|
|
|
|
tg_data.orig_height = tex_height;
|
|
|
|
tg_data.target_bmp = target_bmp;
|
|
|
|
tg_data.error = NULL;
|
|
|
|
tg_data.success = TRUE;
|
|
|
|
|
|
|
|
/* If there are any dependent framebuffers on the texture then we
|
|
|
|
need to flush their journals so the texture contents will be
|
|
|
|
up-to-date */
|
|
|
|
_cogl_texture_flush_journal_rendering (texture);
|
|
|
|
|
|
|
|
/* Iterating through the subtextures allows piecing together
|
|
|
|
* the data for a sliced texture, and allows us to do the
|
|
|
|
* read-from-framebuffer logic here in a simple fashion rather than
|
|
|
|
* passing offsets down through the code. */
|
|
|
|
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (texture),
|
|
|
|
0, 0, 1, 1,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
COGL_PIPELINE_WRAP_MODE_REPEAT,
|
|
|
|
texture_get_cb,
|
|
|
|
&tg_data);
|
|
|
|
|
|
|
|
_cogl_bitmap_unmap (target_bmp);
|
|
|
|
}
|
|
|
|
else
|
2010-07-08 08:54:37 -04:00
|
|
|
{
|
2012-11-08 12:54:10 -05:00
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
tg_data.success = FALSE;
|
2010-07-08 08:54:37 -04:00
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2017-10-27 09:49:55 -04:00
|
|
|
/* XXX: In some cases this api may fail to read back the texture
|
|
|
|
* data; such as for GLES which doesn't support glGetTexImage
|
|
|
|
*/
|
2010-11-12 11:02:13 -05:00
|
|
|
if (!tg_data.success)
|
2012-11-08 12:54:10 -05:00
|
|
|
{
|
2017-10-27 09:49:55 -04:00
|
|
|
cogl_object_unref (target_bmp);
|
|
|
|
return 0;
|
2012-11-08 12:54:10 -05:00
|
|
|
}
|
2010-07-08 08:54:37 -04:00
|
|
|
|
|
|
|
/* Was intermediate used? */
|
|
|
|
if (closest_format != format)
|
|
|
|
{
|
2012-03-13 07:33:05 -04:00
|
|
|
CoglBitmap *new_bmp;
|
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 result;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError *error = NULL;
|
2012-03-13 07:33:05 -04:00
|
|
|
|
|
|
|
/* Convert to requested format directly into the user's buffer */
|
2012-03-13 10:46:18 -04:00
|
|
|
new_bmp = cogl_bitmap_new_for_data (ctx,
|
|
|
|
tex_width, tex_height,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
data);
|
2012-11-08 12:54:10 -05:00
|
|
|
result = _cogl_bitmap_convert_into_bitmap (target_bmp, new_bmp, &error);
|
2012-03-13 07:33:05 -04:00
|
|
|
|
|
|
|
if (!result)
|
2012-11-08 12:54:10 -05:00
|
|
|
{
|
|
|
|
cogl_error_free (error);
|
|
|
|
/* Return failure after cleaning up */
|
|
|
|
byte_size = 0;
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
cogl_object_unref (new_bmp);
|
2010-07-08 08:54:37 -04:00
|
|
|
}
|
|
|
|
|
2012-03-13 07:33:05 -04:00
|
|
|
cogl_object_unref (target_bmp);
|
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
return byte_size;
|
|
|
|
}
|
2011-01-06 08:25:45 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_framebuffer_destroy_cb (void *user_data,
|
|
|
|
void *instance)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = user_data;
|
|
|
|
CoglFramebuffer *framebuffer = instance;
|
|
|
|
|
|
|
|
tex->framebuffers = g_list_remove (tex->framebuffers, framebuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_associate_framebuffer (CoglTexture *texture,
|
2011-01-06 08:25:45 -05:00
|
|
|
CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
static CoglUserDataKey framebuffer_destroy_notify_key;
|
|
|
|
|
|
|
|
/* Note: we don't take a reference on the framebuffer here because
|
|
|
|
* that would introduce a circular reference. */
|
2011-08-24 16:30:34 -04:00
|
|
|
texture->framebuffers = g_list_prepend (texture->framebuffers, framebuffer);
|
2011-01-06 08:25:45 -05:00
|
|
|
|
|
|
|
/* Since we haven't taken a reference on the framebuffer we setup
|
2011-08-24 16:30:34 -04:00
|
|
|
* some private data so we will be notified if it is destroyed... */
|
2011-01-06 08:25:45 -05:00
|
|
|
_cogl_object_set_user_data (COGL_OBJECT (framebuffer),
|
|
|
|
&framebuffer_destroy_notify_key,
|
2011-08-24 16:30:34 -04:00
|
|
|
texture,
|
2011-01-06 08:25:45 -05:00
|
|
|
_cogl_texture_framebuffer_destroy_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
const GList *
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_get_associated_framebuffers (CoglTexture *texture)
|
2011-01-06 08:25:45 -05:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
return texture->framebuffers;
|
2011-01-06 08:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_flush_journal_rendering (CoglTexture *texture)
|
2011-01-06 08:25:45 -05:00
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
/* It could be that a referenced texture is part of a framebuffer
|
|
|
|
* which has an associated journal that must be flushed before it
|
|
|
|
* can be sampled from by the current primitive... */
|
2011-08-24 16:30:34 -04:00
|
|
|
for (l = texture->framebuffers; l; l = l->next)
|
2011-01-06 08:25:45 -05:00
|
|
|
_cogl_framebuffer_flush_journal (l->data);
|
|
|
|
}
|
2011-10-08 09:13:03 -04:00
|
|
|
|
|
|
|
/* This function lets you define a meta texture as a grid of textures
|
|
|
|
* whereby the x and y grid-lines are defined by an array of
|
|
|
|
* CoglSpans. With that grid based description this function can then
|
|
|
|
* iterate all the cells of the grid that lye within a region
|
|
|
|
* specified as virtual, meta-texture, coordinates. This function can
|
|
|
|
* also cope with regions that extend beyond the original meta-texture
|
|
|
|
* grid by iterating cells repeatedly according to the wrap_x/y
|
|
|
|
* arguments.
|
|
|
|
*
|
|
|
|
* To differentiate between texture coordinates of a specific, real,
|
|
|
|
* slice texture and the texture coordinates of a composite, meta
|
|
|
|
* texture, the coordinates of the meta texture are called "virtual"
|
|
|
|
* coordinates and the coordinates of spans are called "slice"
|
|
|
|
* coordinates.
|
|
|
|
*
|
|
|
|
* Note: no guarantee is given about the order in which the slices
|
|
|
|
* will be visited.
|
|
|
|
*
|
|
|
|
* Note: The slice coordinates passed to @callback are always
|
|
|
|
* normalized coordinates even if the span coordinates aren't
|
|
|
|
* normalized.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_cogl_texture_spans_foreach_in_region (CoglSpan *x_spans,
|
|
|
|
int n_x_spans,
|
|
|
|
CoglSpan *y_spans,
|
|
|
|
int n_y_spans,
|
|
|
|
CoglTexture **textures,
|
|
|
|
float *virtual_coords,
|
|
|
|
float x_normalize_factor,
|
|
|
|
float y_normalize_factor,
|
|
|
|
CoglPipelineWrapMode wrap_x,
|
|
|
|
CoglPipelineWrapMode wrap_y,
|
|
|
|
CoglMetaTextureCallback callback,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglSpanIter iter_x;
|
|
|
|
CoglSpanIter iter_y;
|
|
|
|
float slice_coords[4];
|
2012-12-10 11:41:54 -05:00
|
|
|
float span_virtual_coords[4];
|
2011-10-08 09:13:03 -04:00
|
|
|
|
|
|
|
/* Iterate the y axis of the virtual rectangle */
|
|
|
|
for (_cogl_span_iter_begin (&iter_y,
|
|
|
|
y_spans,
|
|
|
|
n_y_spans,
|
|
|
|
y_normalize_factor,
|
|
|
|
virtual_coords[1],
|
|
|
|
virtual_coords[3],
|
|
|
|
wrap_y);
|
|
|
|
!_cogl_span_iter_end (&iter_y);
|
|
|
|
_cogl_span_iter_next (&iter_y))
|
|
|
|
{
|
|
|
|
if (iter_y.flipped)
|
|
|
|
{
|
|
|
|
slice_coords[1] = iter_y.intersect_end;
|
|
|
|
slice_coords[3] = iter_y.intersect_start;
|
2012-12-10 11:41:54 -05:00
|
|
|
span_virtual_coords[1] = iter_y.intersect_end;
|
|
|
|
span_virtual_coords[3] = iter_y.intersect_start;
|
2011-10-08 09:13:03 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slice_coords[1] = iter_y.intersect_start;
|
|
|
|
slice_coords[3] = iter_y.intersect_end;
|
2012-12-10 11:41:54 -05:00
|
|
|
span_virtual_coords[1] = iter_y.intersect_start;
|
|
|
|
span_virtual_coords[3] = iter_y.intersect_end;
|
2011-10-08 09:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Map the current intersection to normalized slice coordinates */
|
|
|
|
slice_coords[1] = (slice_coords[1] - iter_y.pos) / iter_y.span->size;
|
|
|
|
slice_coords[3] = (slice_coords[3] - iter_y.pos) / iter_y.span->size;
|
|
|
|
|
|
|
|
/* Iterate the x axis of the virtual rectangle */
|
|
|
|
for (_cogl_span_iter_begin (&iter_x,
|
|
|
|
x_spans,
|
|
|
|
n_x_spans,
|
|
|
|
x_normalize_factor,
|
|
|
|
virtual_coords[0],
|
|
|
|
virtual_coords[2],
|
|
|
|
wrap_x);
|
|
|
|
!_cogl_span_iter_end (&iter_x);
|
|
|
|
_cogl_span_iter_next (&iter_x))
|
|
|
|
{
|
|
|
|
CoglTexture *span_tex;
|
|
|
|
|
|
|
|
if (iter_x.flipped)
|
|
|
|
{
|
|
|
|
slice_coords[0] = iter_x.intersect_end;
|
|
|
|
slice_coords[2] = iter_x.intersect_start;
|
2012-12-10 11:41:54 -05:00
|
|
|
span_virtual_coords[0] = iter_x.intersect_end;
|
|
|
|
span_virtual_coords[2] = iter_x.intersect_start;
|
2011-10-08 09:13:03 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slice_coords[0] = iter_x.intersect_start;
|
|
|
|
slice_coords[2] = iter_x.intersect_end;
|
2012-12-10 11:41:54 -05:00
|
|
|
span_virtual_coords[0] = iter_x.intersect_start;
|
|
|
|
span_virtual_coords[2] = iter_x.intersect_end;
|
2011-10-08 09:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Map the current intersection to normalized slice coordinates */
|
|
|
|
slice_coords[0] = (slice_coords[0] - iter_x.pos) / iter_x.span->size;
|
|
|
|
slice_coords[2] = (slice_coords[2] - iter_x.pos) / iter_x.span->size;
|
|
|
|
|
|
|
|
/* Pluck out the cogl texture for this span */
|
meta-texture: Fix textures[] index
textures[iter_y.index * n_y_spans + iter_x.index]
only works for vertical rectangles when n_x_spans > 0 (ie x != {0} )
is also wrong for horizontal rectangles ( x = {0, 1, 2, 3} , y = {0, 1}
-> second line will start at 2 = iter_y.index * n_y_spans + iter_x.index
-> iteration are 0, 1, 2, 3, \n 2, 3, 4, 5 instead of 0, 1, 2, 3 \n 4, 5, 6, 7
Reviewed-by: Robert Bragg <robert@linux.inte.com>
(cherry picked from commit bf0d187f1b5423b9ce1281aab1333fa2dfb9863f)
2012-08-31 03:17:55 -04:00
|
|
|
span_tex = textures[iter_y.index * n_x_spans + iter_x.index];
|
2011-10-08 09:13:03 -04:00
|
|
|
|
|
|
|
callback (COGL_TEXTURE (span_tex),
|
|
|
|
slice_coords,
|
|
|
|
span_virtual_coords,
|
|
|
|
user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-22 18:01:08 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_texture_set_allocated (CoglTexture *texture,
|
2013-06-23 11:18:18 -04:00
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
int width,
|
|
|
|
int height)
|
2012-11-22 18:01:08 -05:00
|
|
|
{
|
2013-06-23 11:18:18 -04:00
|
|
|
_cogl_texture_set_internal_format (texture, internal_format);
|
|
|
|
|
|
|
|
texture->width = width;
|
|
|
|
texture->height = height;
|
|
|
|
texture->allocated = TRUE;
|
|
|
|
|
|
|
|
_cogl_texture_free_loader (texture);
|
2012-11-22 18:01:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglBool
|
|
|
|
cogl_texture_allocate (CoglTexture *texture,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
if (texture->allocated)
|
|
|
|
return TRUE;
|
|
|
|
|
2014-01-14 10:52:45 -05:00
|
|
|
if (texture->components == COGL_TEXTURE_COMPONENTS_RG &&
|
|
|
|
!cogl_has_feature (texture->context, COGL_FEATURE_ID_TEXTURE_RG))
|
|
|
|
_cogl_set_error (error,
|
|
|
|
COGL_TEXTURE_ERROR,
|
|
|
|
COGL_TEXTURE_ERROR_FORMAT,
|
|
|
|
"A red-green texture was requested but the driver "
|
|
|
|
"does not support them");
|
|
|
|
|
2012-11-22 18:01:08 -05:00
|
|
|
texture->allocated = texture->vtable->allocate (texture, error);
|
|
|
|
|
|
|
|
return texture->allocated;
|
|
|
|
}
|
2013-06-23 11:18:18 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_texture_set_internal_format (CoglTexture *texture,
|
|
|
|
CoglPixelFormat internal_format)
|
|
|
|
{
|
|
|
|
texture->premultiplied = FALSE;
|
|
|
|
|
|
|
|
if (internal_format == COGL_PIXEL_FORMAT_ANY)
|
|
|
|
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
|
|
|
|
|
|
|
|
if (internal_format == COGL_PIXEL_FORMAT_A_8)
|
|
|
|
{
|
|
|
|
texture->components = COGL_TEXTURE_COMPONENTS_A;
|
|
|
|
return;
|
|
|
|
}
|
2014-01-14 10:52:45 -05:00
|
|
|
else if (internal_format == COGL_PIXEL_FORMAT_RG_88)
|
|
|
|
{
|
|
|
|
texture->components = COGL_TEXTURE_COMPONENTS_RG;
|
|
|
|
return;
|
|
|
|
}
|
2013-06-23 11:18:18 -04:00
|
|
|
else if (internal_format & COGL_DEPTH_BIT)
|
|
|
|
{
|
|
|
|
texture->components = COGL_TEXTURE_COMPONENTS_DEPTH;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (internal_format & COGL_A_BIT)
|
|
|
|
{
|
|
|
|
texture->components = COGL_TEXTURE_COMPONENTS_RGBA;
|
|
|
|
if (internal_format & COGL_PREMULT_BIT)
|
|
|
|
texture->premultiplied = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
texture->components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglPixelFormat
|
|
|
|
_cogl_texture_determine_internal_format (CoglTexture *texture,
|
|
|
|
CoglPixelFormat src_format)
|
|
|
|
{
|
|
|
|
switch (texture->components)
|
|
|
|
{
|
|
|
|
case COGL_TEXTURE_COMPONENTS_DEPTH:
|
|
|
|
if (src_format & COGL_DEPTH_BIT)
|
|
|
|
return src_format;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglContext *ctx = texture->context;
|
|
|
|
|
|
|
|
if (_cogl_has_private_feature (ctx,
|
|
|
|
COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL) ||
|
|
|
|
_cogl_has_private_feature (ctx,
|
|
|
|
COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL))
|
|
|
|
{
|
|
|
|
return COGL_PIXEL_FORMAT_DEPTH_24_STENCIL_8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return COGL_PIXEL_FORMAT_DEPTH_16;
|
|
|
|
}
|
|
|
|
case COGL_TEXTURE_COMPONENTS_A:
|
|
|
|
return COGL_PIXEL_FORMAT_A_8;
|
2014-01-14 10:52:45 -05:00
|
|
|
case COGL_TEXTURE_COMPONENTS_RG:
|
|
|
|
return COGL_PIXEL_FORMAT_RG_88;
|
2013-06-23 11:18:18 -04:00
|
|
|
case COGL_TEXTURE_COMPONENTS_RGB:
|
|
|
|
if (src_format != COGL_PIXEL_FORMAT_ANY &&
|
|
|
|
!(src_format & COGL_A_BIT) && !(src_format & COGL_DEPTH_BIT))
|
|
|
|
return src_format;
|
|
|
|
else
|
|
|
|
return COGL_PIXEL_FORMAT_RGB_888;
|
|
|
|
case COGL_TEXTURE_COMPONENTS_RGBA:
|
|
|
|
{
|
|
|
|
CoglPixelFormat format;
|
|
|
|
|
|
|
|
if (src_format != COGL_PIXEL_FORMAT_ANY &&
|
|
|
|
(src_format & COGL_A_BIT) && src_format != COGL_PIXEL_FORMAT_A_8)
|
|
|
|
format = src_format;
|
|
|
|
else
|
|
|
|
format = COGL_PIXEL_FORMAT_RGBA_8888;
|
|
|
|
|
|
|
|
if (texture->premultiplied)
|
|
|
|
{
|
|
|
|
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (format))
|
|
|
|
return format |= COGL_PREMULT_BIT;
|
|
|
|
else
|
|
|
|
return COGL_PIXEL_FORMAT_RGBA_8888_PRE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return format & ~COGL_PREMULT_BIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (COGL_PIXEL_FORMAT_RGBA_8888_PRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_texture_set_components (CoglTexture *texture,
|
|
|
|
CoglTextureComponents components)
|
|
|
|
{
|
|
|
|
_COGL_RETURN_IF_FAIL (!texture->allocated);
|
|
|
|
|
|
|
|
if (texture->components == components)
|
|
|
|
return;
|
|
|
|
|
|
|
|
texture->components = components;
|
|
|
|
}
|
|
|
|
|
2014-01-02 13:02:01 -05:00
|
|
|
CoglTextureComponents
|
2013-06-23 11:18:18 -04:00
|
|
|
cogl_texture_get_components (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
return texture->components;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_texture_set_premultiplied (CoglTexture *texture,
|
|
|
|
CoglBool premultiplied)
|
|
|
|
{
|
|
|
|
_COGL_RETURN_IF_FAIL (!texture->allocated);
|
|
|
|
|
|
|
|
premultiplied = !!premultiplied;
|
|
|
|
|
|
|
|
if (texture->premultiplied == premultiplied)
|
|
|
|
return;
|
|
|
|
|
|
|
|
texture->premultiplied = premultiplied;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglBool
|
|
|
|
cogl_texture_get_premultiplied (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
return texture->premultiplied;
|
|
|
|
}
|
2013-07-01 20:48:54 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_texture_copy_internal_format (CoglTexture *src,
|
|
|
|
CoglTexture *dest)
|
|
|
|
{
|
|
|
|
cogl_texture_set_components (dest, src->components);
|
|
|
|
cogl_texture_set_premultiplied (dest, src->premultiplied);
|
|
|
|
}
|