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
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
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
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 07:56:10 -05:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2009-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
|
|
|
|
#include "config.h"
|
|
|
|
#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"
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctxt, NO_RETVAL);
|
|
|
|
|
2012-01-24 11:24:26 -05:00
|
|
|
ctxt->texture_types = g_slist_prepend (ctxt->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;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctxt, FALSE);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
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
|
|
|
|
2010-06-11 08:50:36 -04:00
|
|
|
for (l = ctxt->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-08-24 16:30:34 -04:00
|
|
|
void *
|
|
|
|
cogl_texture_ref (void *object)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
if (!cogl_is_texture (object))
|
|
|
|
return NULL;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
_COGL_OBJECT_DEBUG_REF (CoglTexture, object);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_object_ref (object);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
return object;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
void
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_unref (void *object)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
if (!cogl_is_texture (object))
|
2009-09-16 06:56:17 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
g_warning (G_STRINGIFY (cogl_texture_unref)
|
2011-08-24 16:30:34 -04:00
|
|
|
": Ignoring unref of CoglObject "
|
2009-08-30 06:36:11 -04:00
|
|
|
"due to type mismatch");
|
|
|
|
return;
|
2009-09-16 06:56:17 -04:00
|
|
|
}
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
_COGL_OBJECT_DEBUG_UNREF (CoglTexture, object);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_object_unref (object);
|
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,
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
void
|
|
|
|
_cogl_texture_free (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglPixelFormat
|
|
|
|
_cogl_texture_determine_internal_format (CoglPixelFormat src_format,
|
|
|
|
CoglPixelFormat dst_format)
|
|
|
|
{
|
|
|
|
/* If the application hasn't specified a specific format then we'll
|
|
|
|
* pick the most appropriate. By default Cogl will use a
|
|
|
|
* premultiplied internal format. Later we will add control over
|
|
|
|
* this. */
|
|
|
|
if (dst_format == COGL_PIXEL_FORMAT_ANY)
|
|
|
|
{
|
2012-02-29 07:27:19 -05:00
|
|
|
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (src_format))
|
2010-02-03 17:54:44 -05:00
|
|
|
return src_format | COGL_PREMULT_BIT;
|
|
|
|
else
|
|
|
|
return src_format;
|
|
|
|
}
|
|
|
|
else
|
2012-03-21 12:06:59 -04:00
|
|
|
/* XXX: It might be nice to make this match the component ordering
|
|
|
|
of the source format when the formats are otherwise the same
|
|
|
|
because on GL there is no way to specify the ordering of the
|
|
|
|
internal format. However when using GLES with the
|
|
|
|
GL_EXT_texture_format_BGRA8888 the order of the internal format
|
|
|
|
becomes important because it must exactly match the format of
|
|
|
|
the uploaded data. That means that if someone creates a texture
|
|
|
|
with some RGBA data and then later tries to upload BGRA data we
|
|
|
|
do actually have to swizzle the components */
|
2010-02-03 17:54:44 -05:00
|
|
|
return dst_format;
|
|
|
|
}
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_texture_prepare_for_upload (CoglBitmap *src_bmp,
|
|
|
|
CoglPixelFormat dst_format,
|
2010-02-01 07:11:58 -05:00
|
|
|
CoglPixelFormat *dst_format_out,
|
2012-11-08 12:54:10 -05:00
|
|
|
GLenum *out_glintformat,
|
|
|
|
GLenum *out_glformat,
|
|
|
|
GLenum *out_gltype,
|
|
|
|
CoglError **error)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglContext *ctx = _cogl_bitmap_get_context (src_bmp);
|
2012-02-25 15:18:05 -05:00
|
|
|
CoglPixelFormat src_format = cogl_bitmap_get_format (src_bmp);
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *dst_bmp;
|
2010-02-03 17:54:44 -05:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
dst_format = _cogl_texture_determine_internal_format (src_format,
|
|
|
|
dst_format);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2010-04-26 07:30:37 -04:00
|
|
|
/* OpenGL supports specifying a different format for the internal
|
|
|
|
format when uploading texture data. We should use this to convert
|
|
|
|
formats because it is likely to be faster and support more types
|
|
|
|
than the Cogl bitmap code. However under GLES the internal format
|
|
|
|
must be the same as the bitmap format and it only supports a
|
|
|
|
limited number of formats so we must convert using the Cogl
|
|
|
|
bitmap code instead */
|
|
|
|
|
2012-11-19 12:28:52 -05:00
|
|
|
/* If the driver doesn't natively support alpha textures then it
|
|
|
|
* won't work correctly to convert to/from component-alpha
|
|
|
|
* textures */
|
|
|
|
|
|
|
|
if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_FORMAT_CONVERSION) &&
|
|
|
|
((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_ALPHA_TEXTURES) ||
|
|
|
|
(src_format != COGL_PIXEL_FORMAT_A_8 &&
|
|
|
|
dst_format != COGL_PIXEL_FORMAT_A_8) ||
|
|
|
|
src_format == dst_format))
|
2010-02-01 07:11:58 -05:00
|
|
|
{
|
2011-07-07 15:44:56 -04:00
|
|
|
/* If the source format does not have the same premult flag as the
|
|
|
|
dst format then we need to copy and convert it */
|
|
|
|
if (_cogl_texture_needs_premult_conversion (src_format,
|
|
|
|
dst_format))
|
2010-02-01 07:11:58 -05:00
|
|
|
{
|
2012-03-01 08:55:39 -05:00
|
|
|
dst_bmp = _cogl_bitmap_convert (src_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
src_format ^ COGL_PREMULT_BIT,
|
|
|
|
error);
|
2011-07-07 15:44:56 -04:00
|
|
|
|
2012-03-01 08:55:39 -05:00
|
|
|
if (dst_bmp == NULL)
|
|
|
|
return NULL;
|
2010-02-01 07:11:58 -05:00
|
|
|
}
|
2011-07-07 15:44:56 -04:00
|
|
|
else
|
|
|
|
dst_bmp = cogl_object_ref (src_bmp);
|
|
|
|
|
|
|
|
/* Use the source format from the src bitmap type and the internal
|
|
|
|
format from the dst format type so that GL can do the
|
|
|
|
conversion */
|
2012-03-22 12:32:56 -04:00
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
src_format,
|
|
|
|
NULL, /* internal format */
|
|
|
|
out_glformat,
|
|
|
|
out_gltype);
|
|
|
|
ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
dst_format,
|
|
|
|
out_glintformat,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2011-07-07 15:44:56 -04:00
|
|
|
|
2010-02-01 07:11:58 -05:00
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
else
|
2011-07-07 15:44:56 -04:00
|
|
|
{
|
|
|
|
CoglPixelFormat closest_format;
|
|
|
|
|
2012-03-22 12:32:56 -04:00
|
|
|
closest_format = ctx->driver_vtable->pixel_format_to_gl (ctx,
|
|
|
|
dst_format,
|
|
|
|
out_glintformat,
|
|
|
|
out_glformat,
|
|
|
|
out_gltype);
|
2011-07-07 15:44:56 -04:00
|
|
|
|
|
|
|
if (closest_format != src_format)
|
2012-11-08 12:54:10 -05:00
|
|
|
dst_bmp = _cogl_bitmap_convert (src_bmp, closest_format, error);
|
2011-07-07 15:44:56 -04:00
|
|
|
else
|
|
|
|
dst_bmp = cogl_object_ref (src_bmp);
|
|
|
|
}
|
2010-04-26 07:30:37 -04:00
|
|
|
|
2010-02-01 07:11:58 -05:00
|
|
|
if (dst_format_out)
|
|
|
|
*dst_format_out = dst_format;
|
2009-09-16 06:56:17 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
return dst_bmp;
|
2009-09-16 06:56:17 -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_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;
|
|
|
|
}
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
CoglTexture *
|
|
|
|
cogl_texture_new_from_sub_texture (CoglTexture *full_texture,
|
|
|
|
int sub_x,
|
|
|
|
int sub_y,
|
|
|
|
int sub_width,
|
|
|
|
int sub_height)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
2011-10-21 06:36:25 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
return COGL_TEXTURE (cogl_sub_texture_new (ctx,
|
|
|
|
full_texture, sub_x, sub_y,
|
|
|
|
sub_width, sub_height));
|
2009-11-27 11:39:16 -05: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_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
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_get_format (CoglTexture *texture)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
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
|
|
|
unsigned int
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_texture_get_rowstride (CoglTexture *texture)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2012-02-13 18:02:04 -05:00
|
|
|
CoglPixelFormat format = cogl_texture_get_format (texture);
|
2009-11-26 12:32:52 -05:00
|
|
|
/* FIXME: This function should go away. It previously just returned
|
|
|
|
the rowstride that was used to upload the data as far as I can
|
|
|
|
tell. This is not helpful */
|
|
|
|
|
|
|
|
/* Just guess at a suitable rowstride */
|
2012-02-13 18:02:04 -05:00
|
|
|
return (_cogl_pixel_format_get_bytes_per_pixel (format)
|
2011-08-24 16:30:34 -04:00
|
|
|
* cogl_texture_get_width (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
|
|
|
{
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
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
|
|
|
|
cogl_texture_get_format. For example the atlas textures are
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Reads back the contents of a texture by rendering it to the framebuffer
|
|
|
|
* and reading back the resulting pixels.
|
|
|
|
*
|
|
|
|
* It will perform multiple renders if the texture is larger than the
|
|
|
|
* current glViewport.
|
|
|
|
*
|
|
|
|
* It assumes the projection and modelview have already been setup so
|
|
|
|
* that rendering to 0,0 with the same width and height of the viewport
|
|
|
|
* will exactly cover the viewport.
|
|
|
|
*
|
|
|
|
* NB: Normally this approach isn't normally used since we can just use
|
|
|
|
* glGetTexImage, but may be used as a fallback in some circumstances.
|
|
|
|
*/
|
2012-11-08 12:54:10 -05:00
|
|
|
static CoglBool
|
2013-01-18 14:32:24 -05:00
|
|
|
do_texture_draw_and_read (CoglFramebuffer *fb,
|
|
|
|
CoglPipeline *pipeline,
|
|
|
|
CoglTexture *texture,
|
|
|
|
CoglBitmap *target_bmp,
|
2012-11-08 12:54:10 -05:00
|
|
|
float *viewport,
|
|
|
|
CoglError **error)
|
2013-01-18 14:32:24 -05:00
|
|
|
{
|
|
|
|
float rx1, ry1;
|
|
|
|
float rx2, ry2;
|
|
|
|
float tx1, ty1;
|
|
|
|
float tx2, ty2;
|
|
|
|
int bw, bh;
|
|
|
|
CoglBitmap *rect_bmp;
|
|
|
|
unsigned int tex_width, tex_height;
|
|
|
|
CoglContext *ctx = fb->context;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
tex_width = cogl_texture_get_width (texture);
|
|
|
|
tex_height = cogl_texture_get_height (texture);
|
2009-11-26 12:32:52 -05:00
|
|
|
|
2010-02-11 11:12:26 -05:00
|
|
|
ry2 = 0;
|
|
|
|
ty2 = 0;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Walk Y axis until whole bitmap height consumed */
|
2009-11-26 12:32:52 -05:00
|
|
|
for (bh = tex_height; bh > 0; bh -= viewport[3])
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Rectangle Y coords */
|
|
|
|
ry1 = ry2;
|
|
|
|
ry2 += (bh < viewport[3]) ? bh : viewport[3];
|
|
|
|
|
|
|
|
/* Normalized texture Y coords */
|
|
|
|
ty1 = ty2;
|
2009-11-26 12:32:52 -05:00
|
|
|
ty2 = (ry2 / (float) tex_height);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-02-11 11:12:26 -05:00
|
|
|
rx2 = 0;
|
|
|
|
tx2 = 0;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Walk X axis until whole bitmap width consumed */
|
2009-11-26 12:32:52 -05:00
|
|
|
for (bw = tex_width; bw > 0; bw-=viewport[2])
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Rectangle X coords */
|
|
|
|
rx1 = rx2;
|
|
|
|
rx2 += (bw < viewport[2]) ? bw : viewport[2];
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
width = rx2 - rx1;
|
|
|
|
height = ry2 - ry1;
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Normalized texture X coords */
|
|
|
|
tx1 = tx2;
|
2009-11-26 12:32:52 -05:00
|
|
|
tx2 = (rx2 / (float) tex_width);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Draw a portion of texture */
|
2013-01-18 14:32:24 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (fb,
|
|
|
|
pipeline,
|
|
|
|
0, 0,
|
|
|
|
rx2 - rx1,
|
|
|
|
ry2 - ry1,
|
|
|
|
tx1, ty1,
|
|
|
|
tx2, ty2);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Read into a temporary bitmap */
|
2012-03-13 10:46:18 -04:00
|
|
|
rect_bmp = _cogl_bitmap_new_with_malloc_buffer
|
|
|
|
(ctx,
|
|
|
|
width, height,
|
2012-11-08 17:14:18 -05:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
error);
|
|
|
|
if (!rect_bmp)
|
|
|
|
return FALSE;
|
2012-03-13 10:46:18 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_framebuffer_read_pixels_into_bitmap
|
|
|
|
(fb,
|
|
|
|
viewport[0], viewport[1],
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
rect_bmp,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (rect_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Copy to target bitmap */
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!_cogl_bitmap_copy_subregion (rect_bmp,
|
|
|
|
target_bmp,
|
|
|
|
0, 0,
|
|
|
|
rx1, ry1,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (rect_bmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Free temp bitmap */
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (rect_bmp);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
2012-11-08 12:54:10 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Reads back the contents of a texture by rendering it to the framebuffer
|
|
|
|
* and reading back the resulting pixels.
|
|
|
|
*
|
|
|
|
* NB: Normally this approach isn't normally used since we can just use
|
|
|
|
* glGetTexImage, but may be used as a fallback in some circumstances.
|
|
|
|
*/
|
2012-11-08 12:54:10 -05:00
|
|
|
static CoglBool
|
2011-08-24 16:30:34 -04:00
|
|
|
_cogl_texture_draw_and_read (CoglTexture *texture,
|
2013-01-18 14:32:24 -05:00
|
|
|
CoglBitmap *target_bmp,
|
|
|
|
GLuint target_gl_format,
|
2012-11-08 12:54:10 -05:00
|
|
|
GLuint target_gl_type,
|
|
|
|
CoglError **error)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2013-01-18 14:32:24 -05:00
|
|
|
CoglFramebuffer *framebuffer = cogl_get_draw_framebuffer ();
|
|
|
|
CoglContext *ctx = framebuffer->context;
|
2012-11-08 12:54:10 -05:00
|
|
|
float save_viewport[4];
|
|
|
|
float viewport[4];
|
|
|
|
CoglBool status = FALSE;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
viewport[0] = 0;
|
|
|
|
viewport[1] = 0;
|
|
|
|
viewport[2] = cogl_framebuffer_get_width (framebuffer);
|
|
|
|
viewport[3] = cogl_framebuffer_get_height (framebuffer);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
cogl_framebuffer_get_viewport4fv (framebuffer, save_viewport);
|
2011-11-20 13:50:29 -05:00
|
|
|
_cogl_framebuffer_push_projection (framebuffer);
|
|
|
|
cogl_framebuffer_orthographic (framebuffer,
|
|
|
|
0, 0,
|
2012-11-08 12:54:10 -05:00
|
|
|
viewport[2],
|
|
|
|
viewport[3],
|
2011-11-20 13:50:29 -05:00
|
|
|
0, 100);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2011-11-20 13:50:29 -05:00
|
|
|
cogl_framebuffer_push_matrix (framebuffer);
|
|
|
|
cogl_framebuffer_identity_matrix (framebuffer);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Direct copy operation */
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
if (ctx->texture_download_pipeline == NULL)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2012-02-18 11:03:10 -05:00
|
|
|
ctx->texture_download_pipeline = cogl_pipeline_new (ctx);
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_pipeline_set_blend (ctx->texture_download_pipeline,
|
2009-08-30 06:36:11 -04:00
|
|
|
"RGBA = ADD (SRC_COLOR, 0)",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2011-08-24 16:30:34 -04:00
|
|
|
cogl_pipeline_set_layer_texture (ctx->texture_download_pipeline, 0, texture);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
|
2009-08-30 06:36:11 -04:00
|
|
|
0, /* layer */
|
|
|
|
"RGBA = REPLACE (TEXTURE)",
|
|
|
|
NULL);
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_pipeline_set_layer_filters (ctx->texture_download_pipeline, 0,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
2010-07-08 13:31:29 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!do_texture_draw_and_read (framebuffer,
|
|
|
|
ctx->texture_download_pipeline,
|
|
|
|
texture, target_bmp, viewport,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* XXX: As an alleged PowerVR driver bug workaround where the driver
|
|
|
|
* is apparently not maintaining the alpha component of some
|
|
|
|
* framebuffers we render the alpha component of the texture
|
|
|
|
* separately to be sure we retrieve all components of the texture.
|
|
|
|
*
|
|
|
|
* TODO: verify if this is still an issue
|
|
|
|
*/
|
2011-08-24 16:30:34 -04:00
|
|
|
if ((cogl_texture_get_format (texture) & COGL_A_BIT)/* && a_bits == 0*/)
|
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
|
|
|
uint8_t *srcdata;
|
|
|
|
uint8_t *dstdata;
|
|
|
|
uint8_t *srcpixel;
|
|
|
|
uint8_t *dstpixel;
|
2012-11-08 12:54:10 -05:00
|
|
|
int target_width = cogl_bitmap_get_width (target_bmp);
|
|
|
|
int target_height = cogl_bitmap_get_height (target_bmp);
|
|
|
|
int target_rowstride = cogl_bitmap_get_rowstride (target_bmp);
|
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (COGL_PIXEL_FORMAT_RGBA_8888);
|
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 alpha_rowstride = bpp * target_width;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBitmap *alpha_bmp;
|
|
|
|
int x,y;
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
if ((dstdata = _cogl_bitmap_map (target_bmp,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
2012-11-08 12:54:10 -05:00
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD,
|
|
|
|
error)) == NULL)
|
|
|
|
goto EXIT;
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Create temp bitmap for alpha values */
|
2012-03-13 10:46:18 -04:00
|
|
|
alpha_bmp =
|
|
|
|
_cogl_bitmap_new_with_malloc_buffer (ctx,
|
|
|
|
target_width,
|
|
|
|
target_height,
|
2012-11-08 17:14:18 -05:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
error);
|
|
|
|
if (!alpha_bmp)
|
|
|
|
{
|
|
|
|
_cogl_bitmap_unmap (target_bmp);
|
|
|
|
goto EXIT;
|
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Draw alpha values into RGB channels */
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
|
2009-08-30 06:36:11 -04:00
|
|
|
0, /* layer */
|
|
|
|
"RGBA = REPLACE (TEXTURE[A])",
|
|
|
|
NULL);
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
if (!do_texture_draw_and_read (framebuffer,
|
|
|
|
ctx->texture_download_pipeline,
|
|
|
|
texture, alpha_bmp, viewport,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (alpha_bmp);
|
|
|
|
_cogl_bitmap_unmap (target_bmp);
|
|
|
|
goto EXIT;
|
|
|
|
}
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Copy temp R to target A */
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
/* Note: we don't try to catch errors since "mapping" an
|
|
|
|
* malloc buffer should never fail */
|
2012-03-13 10:46:18 -04:00
|
|
|
srcdata = _cogl_bitmap_map (alpha_bmp,
|
|
|
|
COGL_BUFFER_ACCESS_READ,
|
2012-11-08 12:54:10 -05:00
|
|
|
0 /* hints */,
|
|
|
|
NULL);
|
2012-03-13 10:46:18 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
for (y=0; y<target_height; ++y)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
for (x=0; x<target_width; ++x)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
|
|
|
srcpixel = srcdata + x*bpp;
|
|
|
|
dstpixel = dstdata + x*bpp;
|
|
|
|
dstpixel[3] = srcpixel[0];
|
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
srcdata += alpha_rowstride;
|
|
|
|
dstdata += target_rowstride;
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
_cogl_bitmap_unmap (alpha_bmp);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_bitmap_unmap (target_bmp);
|
|
|
|
|
|
|
|
cogl_object_unref (alpha_bmp);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
status = TRUE;
|
|
|
|
|
|
|
|
EXIT:
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Restore old state */
|
2011-11-20 13:50:29 -05:00
|
|
|
cogl_framebuffer_pop_matrix (framebuffer);
|
|
|
|
_cogl_framebuffer_pop_projection (framebuffer);
|
2012-11-08 12:54:10 -05:00
|
|
|
cogl_framebuffer_set_viewport (framebuffer,
|
|
|
|
save_viewport[0],
|
|
|
|
save_viewport[1],
|
|
|
|
save_viewport[2],
|
|
|
|
save_viewport[3]);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return status;
|
2008-04-25 09:37: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
|
|
|
static CoglBool
|
2011-08-24 16:30:34 -04:00
|
|
|
get_texture_bits_via_offscreen (CoglTexture *texture,
|
2010-11-12 11:02:13 -05:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *dst_bits,
|
2010-11-12 11:02:13 -05:00
|
|
|
unsigned int dst_rowstride,
|
|
|
|
CoglPixelFormat dst_format)
|
|
|
|
{
|
2012-09-07 10:26:34 -04:00
|
|
|
CoglContext *ctx = 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;
|
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;
|
|
|
|
|
2012-02-18 10:22:15 -05:00
|
|
|
offscreen = _cogl_offscreen_new_to_texture_full
|
2011-08-24 16:30:34 -04:00
|
|
|
(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
|
|
|
|
2012-03-13 10:46:18 -04:00
|
|
|
bitmap = cogl_bitmap_new_for_data (ctx,
|
|
|
|
width, height,
|
|
|
|
dst_format,
|
|
|
|
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
|
|
|
|
{
|
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
|
2011-08-24 16:30:34 -04:00
|
|
|
texture_get_cb (CoglTexture *texture,
|
2010-11-12 11:02:13 -05:00
|
|
|
const float *subtexture_coords,
|
|
|
|
const float *virtual_coords,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglTextureGetData *tg_data = user_data;
|
2012-02-25 15:18:05 -05:00
|
|
|
CoglPixelFormat format = cogl_bitmap_get_format (tg_data->target_bmp);
|
2012-02-13 18:02:04 -05:00
|
|
|
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
2012-02-25 15:18:05 -05:00
|
|
|
unsigned int rowstride = cogl_bitmap_get_rowstride (tg_data->target_bmp);
|
2011-08-24 16:30:34 -04:00
|
|
|
int subtexture_width = cogl_texture_get_width (texture);
|
|
|
|
int subtexture_height = cogl_texture_get_height (texture);
|
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,
|
|
|
|
* so we'll fall through) */
|
|
|
|
if (x_in_subtexture == 0 && y_in_subtexture == 0 &&
|
|
|
|
width == subtexture_width && height == subtexture_height)
|
|
|
|
{
|
2011-08-24 16:30:34 -04:00
|
|
|
if (texture->vtable->get_data (texture,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
dst_bits))
|
2010-11-12 11:02:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next best option is a FBO and glReadPixels */
|
2011-08-24 16:30:34 -04:00
|
|
|
if (get_texture_bits_via_offscreen (texture,
|
2010-11-12 11:02:13 -05:00
|
|
|
x_in_subtexture, y_in_subtexture,
|
|
|
|
width, height,
|
|
|
|
dst_bits,
|
|
|
|
rowstride,
|
|
|
|
format))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Getting ugly: read the entire texture, copy out the part we want */
|
2011-08-24 16:30:34 -04:00
|
|
|
if (get_texture_bits_via_copy (texture,
|
2010-11-12 11:02:13 -05:00
|
|
|
x_in_subtexture, y_in_subtexture,
|
|
|
|
width, height,
|
|
|
|
dst_bits,
|
|
|
|
rowstride,
|
|
|
|
format))
|
|
|
|
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;
|
|
|
|
|
2012-02-23 12:42:01 -05:00
|
|
|
texture_format = cogl_texture_get_format (texture);
|
|
|
|
|
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,
|
|
|
|
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 */
|
|
|
|
if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_ALPHA_TEXTURES) == 0)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
/* XXX: In some cases _cogl_texture_2d_download_from_gl may fail
|
|
|
|
* to read back the texture data; such as for GLES which doesn't
|
|
|
|
* support glGetTexImage, so here we fallback to drawing the
|
|
|
|
* texture and reading the pixels from the framebuffer. */
|
2010-11-12 11:02:13 -05:00
|
|
|
if (!tg_data.success)
|
2012-11-08 12:54:10 -05:00
|
|
|
{
|
|
|
|
if (!_cogl_texture_draw_and_read (texture, target_bmp,
|
|
|
|
closest_gl_format,
|
|
|
|
closest_gl_type,
|
|
|
|
&ignore_error))
|
|
|
|
{
|
|
|
|
/* We have no more fallbacks so we just give up and
|
|
|
|
* hope for the best */
|
|
|
|
g_warning ("Failed to read texture since draw-and-read "
|
|
|
|
"fallback failed: %s", ignore_error->message);
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
cogl_object_unref (target_bmp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
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,
|
|
|
|
CoglBool allocated)
|
|
|
|
{
|
|
|
|
texture->allocated = allocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglBool
|
|
|
|
cogl_texture_allocate (CoglTexture *texture,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
if (texture->allocated)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
texture->allocated = texture->vtable->allocate (texture, error);
|
|
|
|
|
|
|
|
return texture->allocated;
|
|
|
|
}
|