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.h"
|
|
|
|
#include "cogl-internal.h"
|
|
|
|
#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"
|
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"
|
2008-04-29 12:10:37 -04:00
|
|
|
#include "cogl-handle.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"
|
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
|
|
|
|
2011-05-16 19:05:54 -04:00
|
|
|
GQuark
|
|
|
|
cogl_texture_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("cogl-texture-error-quark");
|
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* XXX:
|
|
|
|
* The CoglHandle macros don't support any form of inheritance, so for
|
|
|
|
* now we implement the CoglHandle support for the CoglTexture
|
|
|
|
* abstract class manually.
|
|
|
|
*/
|
2008-12-11 10:33:38 -05:00
|
|
|
|
2010-06-11 08:50:36 -04:00
|
|
|
void
|
|
|
|
_cogl_texture_register_texture_type (GQuark type)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctxt, NO_RETVAL);
|
|
|
|
|
|
|
|
ctxt->texture_types = g_slist_prepend (ctxt->texture_types,
|
|
|
|
GINT_TO_POINTER (type));
|
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
gboolean
|
|
|
|
cogl_is_texture (CoglHandle handle)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglHandleObject *obj = (CoglHandleObject *)handle;
|
2010-06-11 08:50:36 -04:00
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctxt, FALSE);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
if (handle == COGL_INVALID_HANDLE)
|
|
|
|
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)
|
|
|
|
if (GPOINTER_TO_INT (l->data) == obj->klass->type)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglHandle
|
|
|
|
cogl_texture_ref (CoglHandle handle)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return COGL_INVALID_HANDLE;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
_COGL_HANDLE_DEBUG_REF (CoglTexture, handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
cogl_handle_ref (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
return handle;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2009-03-23 08:29:15 -04:00
|
|
|
void
|
2009-08-30 06:36:11 -04:00
|
|
|
cogl_texture_unref (CoglHandle handle)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
2009-09-16 06:56:17 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
g_warning (G_STRINGIFY (cogl_texture_unref)
|
|
|
|
": Ignoring unref of Cogl handle "
|
|
|
|
"due to type mismatch");
|
|
|
|
return;
|
2009-09-16 06:56:17 -04:00
|
|
|
}
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
_COGL_HANDLE_DEBUG_UNREF (CoglTexture, handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
cogl_handle_unref (handle);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2011-01-06 08:25:45 -05:00
|
|
|
void
|
|
|
|
_cogl_texture_init (CoglTexture *texture,
|
|
|
|
const CoglTextureVtable *vtable)
|
|
|
|
{
|
|
|
|
texture->vtable = vtable;
|
|
|
|
texture->framebuffers = NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
void
|
|
|
|
_cogl_texture_free (CoglTexture *texture)
|
|
|
|
{
|
|
|
|
g_free (texture);
|
|
|
|
}
|
|
|
|
|
2010-02-03 17:54:44 -05:00
|
|
|
static gboolean
|
|
|
|
_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)
|
|
|
|
{
|
|
|
|
if ((src_format & COGL_A_BIT) &&
|
|
|
|
src_format != COGL_PIXEL_FORMAT_A_8)
|
|
|
|
return src_format | COGL_PREMULT_BIT;
|
|
|
|
else
|
|
|
|
return src_format;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return dst_format;
|
|
|
|
}
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *
|
2010-02-01 07:11:58 -05:00
|
|
|
_cogl_texture_prepare_for_upload (CoglBitmap *src_bmp,
|
|
|
|
CoglPixelFormat dst_format,
|
|
|
|
CoglPixelFormat *dst_format_out,
|
|
|
|
GLenum *out_glintformat,
|
|
|
|
GLenum *out_glformat,
|
|
|
|
GLenum *out_gltype)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglPixelFormat src_format = _cogl_bitmap_get_format (src_bmp);
|
|
|
|
CoglBitmap *dst_bmp;
|
2010-02-03 17:54:44 -05:00
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
|
|
|
|
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 */
|
|
|
|
|
2011-07-07 15:44:56 -04:00
|
|
|
if (ctx->driver == COGL_DRIVER_GL)
|
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
|
|
|
{
|
2011-07-07 15:44:56 -04:00
|
|
|
dst_bmp = _cogl_bitmap_copy (src_bmp);
|
|
|
|
|
|
|
|
if (!_cogl_bitmap_convert_premult_status (dst_bmp,
|
|
|
|
src_format ^
|
|
|
|
COGL_PREMULT_BIT))
|
|
|
|
{
|
|
|
|
cogl_object_unref (dst_bmp);
|
|
|
|
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 */
|
|
|
|
ctx->texture_driver->pixel_format_to_gl (src_format,
|
|
|
|
NULL, /* internal format */
|
|
|
|
out_glformat,
|
|
|
|
out_gltype);
|
|
|
|
ctx->texture_driver->pixel_format_to_gl (dst_format,
|
|
|
|
out_glintformat,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
closest_format = ctx->texture_driver->pixel_format_to_gl (dst_format,
|
|
|
|
out_glintformat,
|
|
|
|
out_glformat,
|
|
|
|
out_gltype);
|
|
|
|
|
|
|
|
if (closest_format != src_format)
|
|
|
|
dst_bmp = _cogl_bitmap_convert_format_and_premult (src_bmp,
|
|
|
|
closest_format);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-07-27 19:37:11 -04:00
|
|
|
void
|
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_upload (int pixels_rowstride)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2008-11-18 11:24:09 -05:00
|
|
|
if (!(pixels_rowstride & 0x7))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 8) );
|
2008-11-18 11:24:09 -05:00
|
|
|
else if (!(pixels_rowstride & 0x3))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 4) );
|
2008-11-18 11:24:09 -05:00
|
|
|
else if (!(pixels_rowstride & 0x1))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 2) );
|
2008-11-18 11:24:09 -05:00
|
|
|
else
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_UNPACK_ALIGNMENT, 1) );
|
2008-11-18 11:24:09 -05:00
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2009-07-27 19:37:11 -04:00
|
|
|
void
|
|
|
|
_cogl_texture_prep_gl_alignment_for_pixels_download (int pixels_rowstride)
|
2008-11-18 11:24:09 -05:00
|
|
|
{
|
2011-07-06 16:51:00 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2008-11-18 11:24:09 -05:00
|
|
|
if (!(pixels_rowstride & 0x7))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 8) );
|
2008-11-18 11:24:09 -05:00
|
|
|
else if (!(pixels_rowstride & 0x3))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 4) );
|
2008-11-18 11:24:09 -05:00
|
|
|
else if (!(pixels_rowstride & 0x1))
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 2) );
|
2008-04-25 09:37:36 -04:00
|
|
|
else
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, 1) );
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
/* FIXME: wrap modes should be set on pipelines not textures */
|
2009-03-23 08:29:15 -04:00
|
|
|
void
|
2010-03-25 13:29:22 -04:00
|
|
|
_cogl_texture_set_wrap_mode_parameters (CoglHandle handle,
|
|
|
|
GLenum wrap_mode_s,
|
|
|
|
GLenum wrap_mode_t,
|
2010-07-12 12:01:32 -04:00
|
|
|
GLenum wrap_mode_p)
|
2008-12-01 11:27:54 -05:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
2009-09-16 06:56:17 -04:00
|
|
|
|
2010-03-25 13:29:22 -04:00
|
|
|
tex->vtable->set_wrap_mode_parameters (tex,
|
|
|
|
wrap_mode_s,
|
|
|
|
wrap_mode_t,
|
2010-07-12 12:01:32 -04:00
|
|
|
wrap_mode_p);
|
2008-12-01 11:27:54 -05:00
|
|
|
}
|
|
|
|
|
2009-12-02 08:41:49 -05:00
|
|
|
/* This is like CoglSpanIter except it deals with floats and it
|
|
|
|
effectively assumes there is only one span from 0.0 to 1.0 */
|
|
|
|
typedef struct _CoglTextureIter
|
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
float pos, end, next_pos;
|
2009-12-02 08:41:49 -05:00
|
|
|
gboolean flipped;
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
float t_1, t_2;
|
2009-12-02 08:41:49 -05:00
|
|
|
} CoglTextureIter;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_iter_update (CoglTextureIter *iter)
|
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
float t_2;
|
2010-01-11 11:23:38 -05:00
|
|
|
float frac_part;
|
2009-12-02 08:41:49 -05:00
|
|
|
|
2010-01-11 11:23:38 -05:00
|
|
|
frac_part = modff (iter->pos, &iter->next_pos);
|
2009-12-02 08:41:49 -05:00
|
|
|
|
|
|
|
/* modff rounds the int part towards zero so we need to add one if
|
|
|
|
we're meant to be heading away from zero */
|
2010-01-11 11:23:38 -05:00
|
|
|
if (iter->pos >= 0.0f || frac_part == 0.0f)
|
2009-12-02 08:41:49 -05:00
|
|
|
iter->next_pos += 1.0f;
|
|
|
|
|
|
|
|
if (iter->next_pos > iter->end)
|
|
|
|
t_2 = iter->end;
|
|
|
|
else
|
|
|
|
t_2 = iter->next_pos;
|
|
|
|
|
|
|
|
if (iter->flipped)
|
|
|
|
{
|
|
|
|
iter->t_1 = t_2;
|
|
|
|
iter->t_2 = iter->pos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iter->t_1 = iter->pos;
|
|
|
|
iter->t_2 = t_2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_iter_begin (CoglTextureIter *iter,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
float t_1, float t_2)
|
2009-12-02 08:41:49 -05:00
|
|
|
{
|
|
|
|
if (t_1 <= t_2)
|
|
|
|
{
|
|
|
|
iter->pos = t_1;
|
|
|
|
iter->end = t_2;
|
|
|
|
iter->flipped = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iter->pos = t_2;
|
|
|
|
iter->end = t_1;
|
|
|
|
iter->flipped = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_texture_iter_update (iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_texture_iter_next (CoglTextureIter *iter)
|
|
|
|
{
|
|
|
|
iter->pos = iter->next_pos;
|
|
|
|
_cogl_texture_iter_update (iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_cogl_texture_iter_end (CoglTextureIter *iter)
|
|
|
|
{
|
|
|
|
return iter->pos >= iter->end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This invokes the callback with enough quads to cover the manually
|
|
|
|
repeated range specified by the virtual texture coordinates without
|
|
|
|
emitting coordinates outside the range [0,1] */
|
|
|
|
void
|
|
|
|
_cogl_texture_iterate_manual_repeats (CoglTextureManualRepeatCallback callback,
|
|
|
|
float tx_1, float ty_1,
|
|
|
|
float tx_2, float ty_2,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglTextureIter x_iter, y_iter;
|
|
|
|
|
|
|
|
for (_cogl_texture_iter_begin (&y_iter, ty_1, ty_2);
|
|
|
|
!_cogl_texture_iter_end (&y_iter);
|
|
|
|
_cogl_texture_iter_next (&y_iter))
|
|
|
|
for (_cogl_texture_iter_begin (&x_iter, tx_1, tx_2);
|
|
|
|
!_cogl_texture_iter_end (&x_iter);
|
|
|
|
_cogl_texture_iter_next (&x_iter))
|
|
|
|
{
|
|
|
|
float coords[4] = { x_iter.t_1, y_iter.t_1, x_iter.t_2, y_iter.t_2 };
|
|
|
|
callback (coords, user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
CoglHandle
|
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
|
|
|
cogl_texture_new_with_size (unsigned int width,
|
|
|
|
unsigned int height,
|
[cogl] Remove max_waste argument from Texture ctors
The CoglTexture constructors expose the "max-waste" argument for
controlling the maximum amount of wasted areas for slicing or,
if set to -1, disables slicing.
Slicing is really relevant only for large images that are never
repeated, so it's a useful feature only in controlled use cases.
Specifying the amount of wasted area is, on the other hand, just
a way to mess up this feature; 99% the times, you either pull this
number out of thin air, hoping it's right, or you try to do the
right thing and you choose the wrong number anyway.
Instead, we can use the CoglTextureFlags to control whether the
texture should not be sliced (useful for Clutter-GST and for the
texture-from-pixmap actors) and provide a reasonable value for
enabling the slicing ourself. At some point, we might even
provide a way to change the default at compile time or at run time,
for particular platforms.
Since max_waste is gone, the :tile-waste property of ClutterTexture
becomes read-only, and it proxies the cogl_texture_get_max_waste()
function.
Inside Clutter, the only cases where the max_waste argument was
not set to -1 are in the Pango glyph cache (which is a POT texture
anyway) and inside the test cases where we want to force slicing;
for the latter we can create larger textures that will be bigger than
the threshold we set.
Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
Signed-off-by: Robert Bragg <robert@linux.intel.com>
Signed-off-by: Neil Roberts <neil@linux.intel.com>
2009-05-23 14:18:18 -04:00
|
|
|
CoglTextureFlags flags,
|
|
|
|
CoglPixelFormat internal_format)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-11-27 13:45:36 -05:00
|
|
|
CoglHandle tex;
|
|
|
|
|
2011-05-16 19:05:54 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
|
|
|
|
|
2009-11-27 13:45:36 -05:00
|
|
|
/* First try creating a fast-path non-sliced texture */
|
2011-05-16 19:05:54 -04:00
|
|
|
tex = cogl_texture_2d_new_with_size (ctx,
|
|
|
|
width, height, internal_format,
|
|
|
|
NULL);
|
2009-11-27 13:45:36 -05:00
|
|
|
|
|
|
|
/* If it fails resort to sliced textures */
|
|
|
|
if (tex == COGL_INVALID_HANDLE)
|
|
|
|
tex = _cogl_texture_2d_sliced_new_with_size (width,
|
|
|
|
height,
|
|
|
|
flags,
|
|
|
|
internal_format);
|
|
|
|
|
|
|
|
return tex;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglHandle
|
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
|
|
|
cogl_texture_new_from_data (unsigned int width,
|
|
|
|
unsigned int height,
|
2009-01-18 09:51:19 -05:00
|
|
|
CoglTextureFlags flags,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
CoglPixelFormat internal_format,
|
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 rowstride,
|
|
|
|
const guint8 *data)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *bmp;
|
|
|
|
CoglHandle tex;
|
2009-11-27 11:59:51 -05:00
|
|
|
|
|
|
|
if (format == COGL_PIXEL_FORMAT_ANY)
|
|
|
|
return COGL_INVALID_HANDLE;
|
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
return COGL_INVALID_HANDLE;
|
|
|
|
|
|
|
|
/* Rowstride from width if not given */
|
|
|
|
if (rowstride == 0)
|
|
|
|
rowstride = width * _cogl_get_format_bpp (format);
|
|
|
|
|
|
|
|
/* Wrap the data into a bitmap */
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp = _cogl_bitmap_new_from_data ((guint8 *) data,
|
|
|
|
format,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
rowstride,
|
|
|
|
NULL, NULL);
|
2009-11-27 11:59:51 -05:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
tex = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
|
|
|
|
|
|
|
|
cogl_object_unref (bmp);
|
|
|
|
|
|
|
|
return tex;
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglHandle
|
[cogl] Remove max_waste argument from Texture ctors
The CoglTexture constructors expose the "max-waste" argument for
controlling the maximum amount of wasted areas for slicing or,
if set to -1, disables slicing.
Slicing is really relevant only for large images that are never
repeated, so it's a useful feature only in controlled use cases.
Specifying the amount of wasted area is, on the other hand, just
a way to mess up this feature; 99% the times, you either pull this
number out of thin air, hoping it's right, or you try to do the
right thing and you choose the wrong number anyway.
Instead, we can use the CoglTextureFlags to control whether the
texture should not be sliced (useful for Clutter-GST and for the
texture-from-pixmap actors) and provide a reasonable value for
enabling the slicing ourself. At some point, we might even
provide a way to change the default at compile time or at run time,
for particular platforms.
Since max_waste is gone, the :tile-waste property of ClutterTexture
becomes read-only, and it proxies the cogl_texture_get_max_waste()
function.
Inside Clutter, the only cases where the max_waste argument was
not set to -1 are in the Pango glyph cache (which is a POT texture
anyway) and inside the test cases where we want to force slicing;
for the latter we can create larger textures that will be bigger than
the threshold we set.
Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
Signed-off-by: Robert Bragg <robert@linux.intel.com>
Signed-off-by: Neil Roberts <neil@linux.intel.com>
2009-05-23 14:18:18 -04:00
|
|
|
cogl_texture_new_from_bitmap (CoglHandle bmp_handle,
|
|
|
|
CoglTextureFlags flags,
|
|
|
|
CoglPixelFormat internal_format)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2009-11-27 13:45:36 -05:00
|
|
|
CoglHandle tex;
|
|
|
|
|
2009-12-04 08:06:32 -05:00
|
|
|
/* First try putting the texture in the atlas */
|
|
|
|
if ((tex = _cogl_atlas_texture_new_from_bitmap (bmp_handle,
|
|
|
|
flags,
|
|
|
|
internal_format)))
|
|
|
|
return tex;
|
|
|
|
|
|
|
|
/* If that doesn't work try a fast path 2D texture */
|
|
|
|
if ((tex = _cogl_texture_2d_new_from_bitmap (bmp_handle,
|
|
|
|
flags,
|
2011-05-16 19:05:54 -04:00
|
|
|
internal_format,
|
|
|
|
NULL)))
|
2009-12-04 08:06:32 -05:00
|
|
|
return tex;
|
|
|
|
|
|
|
|
/* Otherwise create a sliced texture */
|
|
|
|
return _cogl_texture_2d_sliced_new_from_bitmap (bmp_handle,
|
|
|
|
flags,
|
|
|
|
internal_format);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2009-01-07 12:02:43 -05:00
|
|
|
CoglHandle
|
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
|
|
|
cogl_texture_new_from_file (const char *filename,
|
2009-01-18 09:51:19 -05:00
|
|
|
CoglTextureFlags flags,
|
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
GError **error)
|
2009-01-07 12:02:43 -05:00
|
|
|
{
|
2010-02-03 18:08:30 -05:00
|
|
|
CoglBitmap *bmp;
|
|
|
|
CoglHandle handle = COGL_INVALID_HANDLE;
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglPixelFormat src_format;
|
2009-11-27 11:59:51 -05:00
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp = cogl_bitmap_new_from_file (filename, error);
|
|
|
|
if (bmp == NULL)
|
2009-11-27 11:59:51 -05:00
|
|
|
return COGL_INVALID_HANDLE;
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
src_format = _cogl_bitmap_get_format (bmp);
|
2010-02-03 18:08:30 -05:00
|
|
|
|
|
|
|
/* We know that the bitmap data is solely owned by this function so
|
|
|
|
we can do the premult conversion in place. This avoids having to
|
|
|
|
copy the bitmap which will otherwise happen in
|
|
|
|
_cogl_texture_prepare_for_upload */
|
2010-07-07 13:44:16 -04:00
|
|
|
internal_format =
|
|
|
|
_cogl_texture_determine_internal_format (src_format, internal_format);
|
|
|
|
if (!_cogl_texture_needs_premult_conversion (src_format, internal_format) ||
|
|
|
|
_cogl_bitmap_convert_premult_status (bmp, src_format ^ COGL_PREMULT_BIT))
|
2010-02-03 18:08:30 -05:00
|
|
|
handle = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (bmp);
|
2009-11-27 11:59:51 -05:00
|
|
|
|
|
|
|
return handle;
|
2009-01-07 12:02:43 -05:00
|
|
|
}
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
CoglHandle
|
|
|
|
cogl_texture_new_from_foreign (GLuint gl_handle,
|
|
|
|
GLenum gl_target,
|
|
|
|
GLuint width,
|
|
|
|
GLuint height,
|
|
|
|
GLuint x_pot_waste,
|
|
|
|
GLuint y_pot_waste,
|
|
|
|
CoglPixelFormat format)
|
|
|
|
{
|
2010-10-04 10:27:38 -04:00
|
|
|
#if HAVE_COGL_GL
|
|
|
|
if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
{
|
|
|
|
if (x_pot_waste != 0 || y_pot_waste != 0)
|
|
|
|
{
|
|
|
|
/* It shouldn't be necessary to have waste in this case since
|
|
|
|
* the texture isn't limited to power of two sizes. */
|
|
|
|
g_warning ("You can't create a foreign GL_TEXTURE_RECTANGLE cogl "
|
|
|
|
"texture with waste\n");
|
|
|
|
return COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _cogl_texture_rectangle_new_from_foreign (gl_handle,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
format);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (x_pot_waste != 0 || y_pot_waste != 0)
|
|
|
|
return _cogl_texture_2d_sliced_new_from_foreign (gl_handle,
|
|
|
|
gl_target,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
x_pot_waste,
|
|
|
|
y_pot_waste,
|
|
|
|
format);
|
|
|
|
else
|
2011-05-16 19:05:54 -04:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
|
|
|
|
return cogl_texture_2d_new_from_foreign (ctx,
|
|
|
|
gl_handle,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
format,
|
|
|
|
NULL);
|
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2010-04-26 05:01:43 -04:00
|
|
|
gboolean
|
|
|
|
_cogl_texture_is_foreign (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
|
|
|
|
|
|
|
g_return_val_if_fail (cogl_is_texture (handle), FALSE);
|
|
|
|
|
|
|
|
tex = COGL_TEXTURE (handle);
|
|
|
|
|
|
|
|
if (tex->vtable->is_foreign)
|
|
|
|
return tex->vtable->is_foreign (tex);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-11-27 11:39:16 -05:00
|
|
|
CoglHandle
|
|
|
|
cogl_texture_new_from_sub_texture (CoglHandle full_texture,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
int sub_x,
|
|
|
|
int sub_y,
|
|
|
|
int sub_width,
|
|
|
|
int sub_height)
|
2009-11-27 11:39:16 -05:00
|
|
|
{
|
2010-01-18 04:22:04 -05:00
|
|
|
return _cogl_sub_texture_new (full_texture, sub_x, sub_y,
|
|
|
|
sub_width, sub_height);
|
2009-11-27 11:39:16 -05:00
|
|
|
}
|
|
|
|
|
2010-01-22 10:07:27 -05:00
|
|
|
CoglHandle
|
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
|
|
|
cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
|
|
|
|
unsigned int width,
|
|
|
|
unsigned int height,
|
|
|
|
CoglTextureFlags flags,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
CoglPixelFormat internal_format,
|
|
|
|
unsigned int rowstride,
|
|
|
|
const unsigned int offset)
|
2010-01-22 10:07:27 -05:00
|
|
|
{
|
|
|
|
CoglHandle texture;
|
|
|
|
CoglBuffer *cogl_buffer;
|
2011-03-02 10:19:57 -05:00
|
|
|
CoglPixelBuffer *pixel_buffer;
|
2010-07-15 08:05:55 -04:00
|
|
|
CoglBitmap *bmp;
|
2010-01-22 10:07:27 -05:00
|
|
|
|
|
|
|
g_return_val_if_fail (cogl_is_buffer (buffer), COGL_INVALID_HANDLE);
|
|
|
|
|
|
|
|
if (format == COGL_PIXEL_FORMAT_ANY)
|
|
|
|
return COGL_INVALID_HANDLE;
|
|
|
|
|
|
|
|
cogl_buffer = COGL_BUFFER (buffer);
|
2011-03-02 10:19:57 -05:00
|
|
|
pixel_buffer = COGL_PIXEL_BUFFER (buffer);
|
2010-01-22 10:07:27 -05:00
|
|
|
|
2010-02-02 07:59:51 -05:00
|
|
|
/* Rowstride from CoglBuffer or even width * bpp if not given */
|
|
|
|
if (rowstride == 0)
|
2011-03-02 10:19:57 -05:00
|
|
|
rowstride = pixel_buffer->stride;
|
2010-01-22 10:07:27 -05:00
|
|
|
if (rowstride == 0)
|
|
|
|
rowstride = width * _cogl_get_format_bpp (format);
|
|
|
|
|
|
|
|
/* use the CoglBuffer height and width as last resort */
|
|
|
|
if (width == 0)
|
2011-03-02 10:19:57 -05:00
|
|
|
width = pixel_buffer->width;
|
2010-01-22 10:07:27 -05:00
|
|
|
if (height == 0)
|
2011-03-02 10:19:57 -05:00
|
|
|
height = pixel_buffer->height;
|
2010-01-22 10:07:27 -05:00
|
|
|
if (width == 0 || height == 0)
|
|
|
|
{
|
|
|
|
/* no width or height specified, neither at creation time (because the
|
2011-03-02 10:19:57 -05:00
|
|
|
* array was created by cogl_pixel_buffer_new()) nor when calling this
|
2010-01-22 10:07:27 -05:00
|
|
|
* function */
|
|
|
|
return COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
/* Wrap the buffer into a bitmap */
|
2011-07-25 17:14:08 -04:00
|
|
|
bmp = cogl_bitmap_new_from_buffer (cogl_buffer,
|
|
|
|
format,
|
|
|
|
width, height,
|
|
|
|
rowstride,
|
|
|
|
offset);
|
2010-02-02 07:59:51 -05:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
texture = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-07-15 08:05:55 -04:00
|
|
|
cogl_object_unref (bmp);
|
2010-01-22 10:07:27 -05:00
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
unsigned int
|
2008-04-25 09:37:36 -04:00
|
|
|
cogl_texture_get_width (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return 0;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-11-26 13:58:17 -05:00
|
|
|
return tex->vtable->get_width (tex);
|
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
|
2008-04-25 09:37:36 -04:00
|
|
|
cogl_texture_get_height (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return 0;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-11-26 13:58:17 -05:00
|
|
|
return tex->vtable->get_height (tex);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglPixelFormat
|
|
|
|
cogl_texture_get_format (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return COGL_PIXEL_FORMAT_ANY;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-11-26 13:58:17 -05:00
|
|
|
return tex->vtable->get_format (tex);
|
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
|
2008-04-25 09:37:36 -04:00
|
|
|
cogl_texture_get_rowstride (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return 0;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
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 */
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-11-26 12:32:52 -05:00
|
|
|
/* Just guess at a suitable rowstride */
|
2009-11-26 13:58:17 -05:00
|
|
|
return (_cogl_get_format_bpp (cogl_texture_get_format (tex))
|
|
|
|
* cogl_texture_get_width (tex));
|
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
|
2008-04-25 09:37:36 -04:00
|
|
|
cogl_texture_get_max_waste (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return 0;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
return tex->vtable->get_max_waste (tex);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cogl_texture_is_sliced (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return FALSE;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
return tex->vtable->is_sliced (tex);
|
2009-08-30 06:36:11 -04:00
|
|
|
}
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Some CoglTextures, notably sliced textures or atlas textures when repeating
|
|
|
|
* is used, will need to divide the coordinate space into multiple GL textures
|
|
|
|
* (or rather; in the case of atlases duplicate a single texture in multiple
|
|
|
|
* positions to handle repeating)
|
|
|
|
*
|
|
|
|
* This function helps you implement primitives using such textures by
|
|
|
|
* invoking a callback once for each sub texture that intersects a given
|
|
|
|
* region specified in texture coordinates.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
_cogl_texture_foreach_sub_texture_in_region (CoglHandle handle,
|
|
|
|
float virtual_tx_1,
|
|
|
|
float virtual_ty_1,
|
|
|
|
float virtual_tx_2,
|
|
|
|
float virtual_ty_2,
|
|
|
|
CoglTextureSliceCallback callback,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
tex->vtable->foreach_sub_texture_in_region (tex,
|
|
|
|
virtual_tx_1,
|
|
|
|
virtual_ty_1,
|
|
|
|
virtual_tx_2,
|
|
|
|
virtual_ty_2,
|
|
|
|
callback,
|
|
|
|
user_data);
|
2008-04-25 09:37:36 -04: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]
|
|
|
|
*/
|
2009-09-16 06:56:17 -04:00
|
|
|
gboolean
|
|
|
|
_cogl_texture_can_hardware_repeat (CoglHandle handle)
|
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglTexture *tex = (CoglTexture *)handle;
|
2009-09-16 06:56:17 -04:00
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
return tex->vtable->can_hardware_repeat (tex);
|
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
|
|
|
|
_cogl_texture_transform_coords_to_gl (CoglHandle handle,
|
|
|
|
float *s,
|
|
|
|
float *t)
|
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
2009-09-16 06:56:17 -04:00
|
|
|
|
2010-01-04 06:49:50 -05:00
|
|
|
tex->vtable->transform_coords_to_gl (tex, s, t);
|
2009-09-16 06:56:17 -04:00
|
|
|
}
|
|
|
|
|
2010-03-01 16:49:04 -05:00
|
|
|
CoglTransformResult
|
2010-01-18 04:22:04 -05:00
|
|
|
_cogl_texture_transform_quad_coords_to_gl (CoglHandle handle,
|
|
|
|
float *coords)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
|
|
|
|
|
|
|
return tex->vtable->transform_quad_coords_to_gl (tex, coords);
|
|
|
|
}
|
|
|
|
|
2009-09-16 06:56:17 -04:00
|
|
|
GLenum
|
2009-11-26 13:58:17 -05:00
|
|
|
_cogl_texture_get_gl_format (CoglHandle handle)
|
2009-09-16 06:56:17 -04:00
|
|
|
{
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
2009-09-16 06:56:17 -04:00
|
|
|
|
2009-11-26 13:58:17 -05:00
|
|
|
return tex->vtable->get_gl_format (tex);
|
2009-09-16 06:56:17 -04:00
|
|
|
}
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
gboolean
|
|
|
|
cogl_texture_get_gl_texture (CoglHandle handle,
|
|
|
|
GLuint *out_gl_handle,
|
|
|
|
GLenum *out_gl_target)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return FALSE;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-11-25 08:39:45 -05:00
|
|
|
return tex->vtable->get_gl_texture (tex, out_gl_handle, out_gl_target);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2009-06-04 11:04:57 -04:00
|
|
|
void
|
|
|
|
_cogl_texture_set_filters (CoglHandle handle,
|
|
|
|
GLenum min_filter,
|
|
|
|
GLenum mag_filter)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
2009-06-04 11:04:57 -04:00
|
|
|
return;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2010-01-04 06:49:50 -05:00
|
|
|
tex->vtable->set_filters (tex, min_filter, mag_filter);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-09 12:39:59 -04:00
|
|
|
_cogl_texture_pre_paint (CoglHandle handle, CoglTexturePrePaintFlags flags)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
2009-06-04 11:04:57 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2010-06-09 12:39:59 -04:00
|
|
|
tex->vtable->pre_paint (tex, flags);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2010-01-18 04:22:04 -05:00
|
|
|
void
|
|
|
|
_cogl_texture_ensure_non_quad_rendering (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex;
|
|
|
|
|
|
|
|
if (!cogl_is_texture (handle))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tex = COGL_TEXTURE (handle);
|
|
|
|
|
2010-02-09 05:21:37 -05:00
|
|
|
tex->vtable->ensure_non_quad_rendering (tex);
|
2010-01-18 04:22:04 -05:00
|
|
|
}
|
|
|
|
|
2010-07-08 10:15:22 -04:00
|
|
|
gboolean
|
2011-07-25 17:14:08 -04:00
|
|
|
cogl_texture_set_region_from_bitmap (CoglHandle handle,
|
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
unsigned int dst_width,
|
|
|
|
unsigned int dst_height,
|
|
|
|
CoglBitmap *bmp)
|
2010-07-08 10:15:22 -04:00
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
/* Shortcut out early if the image is empty */
|
|
|
|
if (dst_width == 0 || dst_height == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
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
|
|
|
|
|
|
|
ret = tex->vtable->set_region (handle,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_width, dst_height,
|
2010-07-07 13:44:16 -04:00
|
|
|
bmp);
|
2010-07-08 10:15:22 -04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
gboolean
|
|
|
|
cogl_texture_set_region (CoglHandle handle,
|
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 src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
unsigned int dst_width,
|
|
|
|
unsigned int dst_height,
|
|
|
|
int width,
|
|
|
|
int height,
|
2008-04-25 09:37:36 -04:00
|
|
|
CoglPixelFormat format,
|
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 rowstride,
|
|
|
|
const guint8 *data)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *source_bmp;
|
|
|
|
gboolean ret;
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-07-08 10:15:22 -04:00
|
|
|
/* Check for valid format */
|
|
|
|
if (format == COGL_PIXEL_FORMAT_ANY)
|
2008-04-25 09:37:36 -04:00
|
|
|
return 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)
|
|
|
|
rowstride = _cogl_get_format_bpp (format) * width;
|
2010-07-08 10:15:22 -04:00
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
/* Init source bitmap */
|
|
|
|
source_bmp = _cogl_bitmap_new_from_data ((guint8 *) data,
|
|
|
|
format,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
rowstride,
|
|
|
|
NULL, /* destroy_fn */
|
|
|
|
NULL); /* destroy_fn_data */
|
|
|
|
|
2011-07-25 17:14:08 -04:00
|
|
|
ret = cogl_texture_set_region_from_bitmap (handle,
|
|
|
|
src_x, src_y,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_width, dst_height,
|
|
|
|
source_bmp);
|
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
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static void
|
2009-11-26 12:32:52 -05:00
|
|
|
do_texture_draw_and_read (CoglHandle handle,
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglBitmap *target_bmp,
|
2011-02-01 11:51:58 -05:00
|
|
|
float *viewport)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
int bpp;
|
2009-08-30 06:36:11 -04:00
|
|
|
float rx1, ry1;
|
|
|
|
float rx2, ry2;
|
|
|
|
float tx1, ty1;
|
|
|
|
float tx2, ty2;
|
|
|
|
int bw, bh;
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *rect_bmp;
|
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 tex_width, tex_height;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-11-26 12:32:52 -05:00
|
|
|
tex_width = cogl_texture_get_width (handle);
|
|
|
|
tex_height = cogl_texture_get_height (handle);
|
|
|
|
|
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;
|
|
|
|
int rowstride;
|
|
|
|
guint8 *data;
|
|
|
|
|
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;
|
|
|
|
rowstride = width * bpp;
|
|
|
|
|
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 */
|
|
|
|
cogl_rectangle_with_texture_coords (0, 0,
|
|
|
|
rx2 - rx1,
|
|
|
|
ry2 - ry1,
|
|
|
|
tx1, ty1,
|
|
|
|
tx2, ty2);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
data = g_malloc (height * rowstride);
|
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Read into a temporary bitmap */
|
2010-07-07 13:44:16 -04:00
|
|
|
rect_bmp =
|
|
|
|
_cogl_bitmap_new_from_data (data,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
rowstride,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-07-08 13:29:12 -04:00
|
|
|
cogl_read_pixels (viewport[0], viewport[1],
|
2010-07-07 13:44:16 -04:00
|
|
|
width,
|
|
|
|
height,
|
2010-07-08 13:29:12 -04:00
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2010-07-07 13:44:16 -04:00
|
|
|
data);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Copy to target bitmap */
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_bitmap_copy_subregion (rect_bmp,
|
2009-08-30 06:36:11 -04:00
|
|
|
target_bmp,
|
|
|
|
0,0,
|
|
|
|
rx1,ry1,
|
2010-07-07 13:44:16 -04:00
|
|
|
width,
|
|
|
|
height);
|
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
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
gboolean
|
2009-11-26 12:32:52 -05:00
|
|
|
_cogl_texture_draw_and_read (CoglHandle handle,
|
2009-08-30 06:36:11 -04:00
|
|
|
CoglBitmap *target_bmp,
|
|
|
|
GLuint target_gl_format,
|
|
|
|
GLuint target_gl_type)
|
|
|
|
{
|
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 bpp;
|
2010-07-07 09:41:54 -04:00
|
|
|
CoglFramebuffer *framebuffer;
|
2011-02-01 11:51:58 -05:00
|
|
|
float viewport[4];
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *alpha_bmp;
|
2009-10-13 18:09:42 -04:00
|
|
|
CoglMatrixStack *projection_stack;
|
|
|
|
CoglMatrixStack *modelview_stack;
|
2010-07-07 13:44:16 -04: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);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888);
|
|
|
|
|
2011-03-10 16:33:31 -05:00
|
|
|
framebuffer = cogl_get_draw_framebuffer ();
|
2009-08-30 06:36:11 -04:00
|
|
|
/* Viewport needs to have some size and be inside the window for this */
|
2011-06-14 19:06:29 -04:00
|
|
|
cogl_framebuffer_get_viewport4fv (framebuffer, viewport);
|
2009-08-30 06:36:11 -04:00
|
|
|
if (viewport[0] < 0 || viewport[1] < 0 ||
|
|
|
|
viewport[2] <= 0 || viewport[3] <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-07-08 13:29:12 -04:00
|
|
|
/* Setup orthographic projection into current viewport (0,0 in top-left
|
|
|
|
* corner to draw the texture upside-down so we match the way cogl_read_pixels
|
2009-08-30 06:36:11 -04:00
|
|
|
* works)
|
|
|
|
*/
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
projection_stack = _cogl_framebuffer_get_projection_stack (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_push (projection_stack);
|
|
|
|
_cogl_matrix_stack_load_identity (projection_stack);
|
|
|
|
_cogl_matrix_stack_ortho (projection_stack,
|
2011-02-01 11:51:58 -05:00
|
|
|
0, viewport[2],
|
|
|
|
viewport[3], 0,
|
|
|
|
0,
|
|
|
|
100);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
modelview_stack = _cogl_framebuffer_get_modelview_stack (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
|
|
|
_cogl_matrix_stack_load_identity (modelview_stack);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Direct copy operation */
|
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
if (ctx->texture_download_pipeline == COGL_INVALID_HANDLE)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
2010-10-27 13:54:57 -04:00
|
|
|
ctx->texture_download_pipeline = cogl_pipeline_new ();
|
|
|
|
cogl_pipeline_set_blend (ctx->texture_download_pipeline,
|
2009-08-30 06:36:11 -04:00
|
|
|
"RGBA = ADD (SRC_COLOR, 0)",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2011-09-14 07:17:09 -04:00
|
|
|
_cogl_push_source (ctx->texture_download_pipeline, FALSE);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
cogl_pipeline_set_layer_texture (ctx->texture_download_pipeline, 0, handle);
|
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
|
|
|
|
2009-11-26 12:32:52 -05:00
|
|
|
do_texture_draw_and_read (handle, target_bmp, viewport);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Check whether texture has alpha and framebuffer not */
|
|
|
|
/* FIXME: For some reason even if ALPHA_BITS is 8, the framebuffer
|
|
|
|
still doesn't seem to have an alpha buffer. This might be just
|
|
|
|
a PowerVR issue.
|
|
|
|
GLint r_bits, g_bits, b_bits, a_bits;
|
2011-07-06 16:51:00 -04:00
|
|
|
GE( ctx, glGetIntegerv (GL_ALPHA_BITS, &a_bits) );
|
|
|
|
GE( ctx, glGetIntegerv (GL_RED_BITS, &r_bits) );
|
|
|
|
GE( ctx, glGetIntegerv (GL_GREEN_BITS, &g_bits) );
|
|
|
|
GE( ctx, glGetIntegerv (GL_BLUE_BITS, &b_bits) );
|
2009-08-30 06:36:11 -04:00
|
|
|
printf ("R bits: %d\n", r_bits);
|
|
|
|
printf ("G bits: %d\n", g_bits);
|
|
|
|
printf ("B bits: %d\n", b_bits);
|
|
|
|
printf ("A bits: %d\n", a_bits); */
|
2009-11-26 12:32:52 -05:00
|
|
|
if ((cogl_texture_get_format (handle) & COGL_A_BIT)/* && a_bits == 0*/)
|
2009-08-30 06:36:11 -04:00
|
|
|
{
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-09 20:57:32 -05:00
|
|
|
guint8 *srcdata;
|
|
|
|
guint8 *dstdata;
|
|
|
|
guint8 *srcpixel;
|
|
|
|
guint8 *dstpixel;
|
|
|
|
int x,y;
|
2010-07-07 13:44:16 -04:00
|
|
|
int alpha_rowstride = bpp * target_width;
|
|
|
|
|
|
|
|
if ((dstdata = _cogl_bitmap_map (target_bmp,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD)) == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
srcdata = g_malloc (alpha_rowstride * target_height);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Create temp bitmap for alpha values */
|
2010-07-07 13:44:16 -04:00
|
|
|
alpha_bmp = _cogl_bitmap_new_from_data (srcdata,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
target_width, target_height,
|
|
|
|
alpha_rowstride,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
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);
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
do_texture_draw_and_read (handle, alpha_bmp, viewport);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
|
|
|
/* Copy temp R to target A */
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore old state */
|
2009-10-13 18:09:42 -04:00
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
|
|
|
_cogl_matrix_stack_pop (projection_stack);
|
2009-08-30 06:36:11 -04:00
|
|
|
|
2010-10-27 13:54:57 -04:00
|
|
|
/* restore the original pipeline */
|
2010-10-25 08:25:21 -04:00
|
|
|
cogl_pop_source ();
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-12 11:02:13 -05:00
|
|
|
static gboolean
|
|
|
|
get_texture_bits_via_offscreen (CoglHandle texture_handle,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
guint8 *dst_bits,
|
|
|
|
unsigned int dst_rowstride,
|
|
|
|
CoglPixelFormat dst_format)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, FALSE);
|
|
|
|
|
|
|
|
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
framebuffer = _cogl_offscreen_new_to_texture_full
|
|
|
|
(texture_handle,
|
|
|
|
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (framebuffer == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cogl_push_framebuffer (framebuffer);
|
|
|
|
|
|
|
|
_cogl_read_pixels_with_rowstride (x, y, width, height,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
dst_format, dst_bits, dst_rowstride);
|
|
|
|
|
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
|
|
|
|
cogl_object_unref (framebuffer);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
get_texture_bits_via_copy (CoglHandle texture_handle,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
guint8 *dst_bits,
|
|
|
|
unsigned int dst_rowstride,
|
|
|
|
CoglPixelFormat dst_format)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (texture_handle);
|
|
|
|
unsigned int full_rowstride;
|
|
|
|
guint8 *full_bits;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
int bpp;
|
|
|
|
int full_tex_width, full_tex_height;
|
|
|
|
|
|
|
|
full_tex_width = cogl_texture_get_width (texture_handle);
|
|
|
|
full_tex_height = cogl_texture_get_height (texture_handle);
|
|
|
|
|
|
|
|
bpp = _cogl_get_format_bpp (dst_format);
|
|
|
|
|
|
|
|
full_rowstride = bpp * full_tex_width;
|
|
|
|
full_bits = g_malloc (full_rowstride * full_tex_height);
|
|
|
|
|
|
|
|
if (tex->vtable->get_data (tex,
|
|
|
|
dst_format,
|
|
|
|
full_rowstride,
|
|
|
|
full_bits))
|
|
|
|
{
|
|
|
|
guint8 *dst = dst_bits;
|
|
|
|
guint8 *src = full_bits + x * bpp + y * full_rowstride;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
int orig_width;
|
|
|
|
int orig_height;
|
|
|
|
CoglBitmap *target_bmp;
|
|
|
|
guint8 *target_bits;
|
|
|
|
gboolean success;
|
|
|
|
} CoglTextureGetData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
texture_get_cb (CoglHandle texture_handle,
|
|
|
|
const float *subtexture_coords,
|
|
|
|
const float *virtual_coords,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (texture_handle);
|
|
|
|
CoglTextureGetData *tg_data = user_data;
|
|
|
|
CoglPixelFormat format = _cogl_bitmap_get_format (tg_data->target_bmp);
|
|
|
|
int bpp = _cogl_get_format_bpp (format);
|
|
|
|
unsigned int rowstride = _cogl_bitmap_get_rowstride (tg_data->target_bmp);
|
|
|
|
int subtexture_width = cogl_texture_get_width (texture_handle);
|
|
|
|
int subtexture_height = cogl_texture_get_height (texture_handle);
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
guint8 *dst_bits;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (tex->vtable->get_data (tex,
|
|
|
|
format,
|
|
|
|
rowstride,
|
|
|
|
dst_bits))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next best option is a FBO and glReadPixels */
|
|
|
|
if (get_texture_bits_via_offscreen (texture_handle,
|
|
|
|
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 */
|
|
|
|
if (get_texture_bits_via_copy (texture_handle,
|
|
|
|
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
|
2008-04-25 09:37:36 -04:00
|
|
|
cogl_texture_get_data (CoglHandle handle,
|
|
|
|
CoglPixelFormat format,
|
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 rowstride,
|
|
|
|
guint8 *data)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
2010-07-08 08:54:37 -04:00
|
|
|
CoglTexture *tex;
|
|
|
|
int bpp;
|
|
|
|
int byte_size;
|
|
|
|
CoglPixelFormat closest_format;
|
|
|
|
int closest_bpp;
|
|
|
|
GLenum closest_gl_format;
|
|
|
|
GLenum closest_gl_type;
|
2010-07-07 13:44:16 -04:00
|
|
|
CoglBitmap *target_bmp;
|
|
|
|
CoglBitmap *new_bmp;
|
2010-07-08 08:54:37 -04:00
|
|
|
guint8 *src;
|
|
|
|
guint8 *dst;
|
|
|
|
int y;
|
|
|
|
int tex_width;
|
|
|
|
int tex_height;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2010-11-12 11:02:13 -05:00
|
|
|
CoglTextureGetData tg_data;
|
|
|
|
|
2011-07-07 07:48:24 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!cogl_is_texture (handle))
|
2010-07-07 13:44:16 -04:00
|
|
|
return 0;
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2009-08-30 06:36:11 -04:00
|
|
|
tex = COGL_TEXTURE (handle);
|
2008-12-23 11:29:29 -05:00
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
/* Default to internal format if none specified */
|
|
|
|
if (format == COGL_PIXEL_FORMAT_ANY)
|
|
|
|
format = cogl_texture_get_format (handle);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
tex_width = cogl_texture_get_width (handle);
|
|
|
|
tex_height = cogl_texture_get_height (handle);
|
|
|
|
|
|
|
|
/* Rowstride from texture width if none specified */
|
|
|
|
bpp = _cogl_get_format_bpp (format);
|
|
|
|
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 =
|
2011-07-07 07:48:24 -04:00
|
|
|
ctx->texture_driver->find_best_gl_get_data_format (format,
|
2010-07-08 08:54:37 -04:00
|
|
|
&closest_gl_format,
|
|
|
|
&closest_gl_type);
|
|
|
|
closest_bpp = _cogl_get_format_bpp (closest_format);
|
|
|
|
|
|
|
|
/* Is the requested format supported? */
|
|
|
|
if (closest_format == format)
|
2010-07-07 13:44:16 -04:00
|
|
|
/* Target user data directly */
|
|
|
|
target_bmp = _cogl_bitmap_new_from_data (data,
|
|
|
|
format,
|
|
|
|
tex_width,
|
|
|
|
tex_height,
|
|
|
|
rowstride,
|
|
|
|
NULL, NULL);
|
|
|
|
else
|
2010-07-08 08:54:37 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
int target_rowstride = tex_width * closest_bpp;
|
|
|
|
guint8 *target_data = g_malloc (tex_height * target_rowstride);
|
|
|
|
target_bmp = _cogl_bitmap_new_from_data (target_data,
|
|
|
|
closest_format,
|
|
|
|
tex_width,
|
|
|
|
tex_height,
|
|
|
|
target_rowstride,
|
|
|
|
(CoglBitmapDestroyNotify) g_free,
|
|
|
|
NULL);
|
2010-07-08 08:54:37 -04:00
|
|
|
}
|
2010-07-07 13:44:16 -04:00
|
|
|
|
2010-11-12 11:02:13 -05:00
|
|
|
tg_data.orig_width = tex_width;
|
|
|
|
tg_data.orig_height = tex_height;
|
|
|
|
tg_data.target_bmp = target_bmp;
|
|
|
|
tg_data.target_bits = _cogl_bitmap_map (target_bmp, COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD);
|
|
|
|
if (tg_data.target_bits == NULL)
|
2010-07-08 08:54:37 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (target_bmp);
|
|
|
|
return 0;
|
2010-07-08 08:54:37 -04:00
|
|
|
}
|
2010-11-12 11:02:13 -05:00
|
|
|
tg_data.success = TRUE;
|
2010-07-08 08:54:37 -04:00
|
|
|
|
2010-11-12 11:02:13 -05:00
|
|
|
/* 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_texture_foreach_sub_texture_in_region (handle,
|
|
|
|
0, 0, 1, 1,
|
|
|
|
texture_get_cb,
|
|
|
|
&tg_data);
|
2010-07-07 13:44:16 -04:00
|
|
|
|
|
|
|
_cogl_bitmap_unmap (target_bmp);
|
|
|
|
|
|
|
|
/* 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)
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_texture_draw_and_read (tex, target_bmp,
|
2010-07-08 08:54:37 -04:00
|
|
|
closest_gl_format,
|
|
|
|
closest_gl_type);
|
|
|
|
|
|
|
|
/* Was intermediate used? */
|
|
|
|
if (closest_format != format)
|
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
guint8 *new_bmp_data;
|
|
|
|
int new_bmp_rowstride;
|
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
/* Convert to requested format */
|
2010-07-07 13:44:16 -04:00
|
|
|
new_bmp = _cogl_bitmap_convert_format_and_premult (target_bmp,
|
2010-07-08 08:54:37 -04:00
|
|
|
format);
|
|
|
|
|
|
|
|
/* Free intermediate data and return if failed */
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (target_bmp);
|
|
|
|
|
|
|
|
if (new_bmp == NULL)
|
2010-07-08 08:54:37 -04:00
|
|
|
return 0;
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
new_bmp_rowstride = _cogl_bitmap_get_rowstride (new_bmp);
|
|
|
|
new_bmp_data = _cogl_bitmap_map (new_bmp, COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD);
|
|
|
|
|
|
|
|
if (new_bmp_data == NULL)
|
|
|
|
{
|
|
|
|
cogl_object_unref (new_bmp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
/* Copy to user buffer */
|
2010-07-07 13:44:16 -04:00
|
|
|
for (y = 0; y < tex_height; ++y)
|
2010-07-08 08:54:37 -04:00
|
|
|
{
|
2010-07-07 13:44:16 -04:00
|
|
|
src = new_bmp_data + y * new_bmp_rowstride;
|
2010-07-08 08:54:37 -04:00
|
|
|
dst = data + y * rowstride;
|
2010-07-07 13:44:16 -04:00
|
|
|
memcpy (dst, src, tex_width * bpp);
|
2010-07-08 08:54:37 -04:00
|
|
|
}
|
|
|
|
|
2010-07-07 13:44:16 -04:00
|
|
|
_cogl_bitmap_unmap (new_bmp);
|
|
|
|
|
2010-07-08 08:54:37 -04:00
|
|
|
/* Free converted data */
|
2010-07-07 13:44:16 -04:00
|
|
|
cogl_object_unref (new_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
|
|
|
|
_cogl_texture_associate_framebuffer (CoglHandle handle,
|
|
|
|
CoglFramebuffer *framebuffer)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
|
|
|
static CoglUserDataKey framebuffer_destroy_notify_key;
|
|
|
|
|
|
|
|
/* Note: we don't take a reference on the framebuffer here because
|
|
|
|
* that would introduce a circular reference. */
|
|
|
|
tex->framebuffers = g_list_prepend (tex->framebuffers, framebuffer);
|
|
|
|
|
|
|
|
/* Since we haven't taken a reference on the framebuffer we setup
|
|
|
|
* some private data so we will be notified if it is destroyed... */
|
|
|
|
_cogl_object_set_user_data (COGL_OBJECT (framebuffer),
|
|
|
|
&framebuffer_destroy_notify_key,
|
|
|
|
tex,
|
|
|
|
_cogl_texture_framebuffer_destroy_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
const GList *
|
|
|
|
_cogl_texture_get_associated_framebuffers (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
|
|
|
return tex->framebuffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_texture_flush_journal_rendering (CoglHandle handle)
|
|
|
|
{
|
|
|
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
|
|
|
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... */
|
|
|
|
for (l = tex->framebuffers; l; l = l->next)
|
|
|
|
_cogl_framebuffer_flush_journal (l->data);
|
|
|
|
}
|