2011-01-20 12:45:47 -05:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2011-01-20 12:45:47 -05:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2011-01-20 12:45:47 -05:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2011-01-20 12:45:47 -05:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2011-01-20 12:45:47 -05:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil Roberts <neil@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
#include "cogl-util.h"
|
2011-01-20 12:45:47 -05:00
|
|
|
#include "cogl-blit.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2011-01-20 12:45:47 -05:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2012-09-18 06:59:21 -04:00
|
|
|
#include "cogl-texture-private.h"
|
2011-01-20 12:45:47 -05:00
|
|
|
#include "cogl-texture-2d-private.h"
|
2011-09-14 07:17:09 -04:00
|
|
|
#include "cogl-private.h"
|
2012-02-17 16:46:39 -05:00
|
|
|
#include "cogl1-context.h"
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
static const CoglBlitMode *_cogl_blit_default_mode = NULL;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-01-20 12:45:47 -05:00
|
|
|
_cogl_blit_texture_render_begin (CoglBlitData *data)
|
|
|
|
{
|
2012-09-18 06:59:21 -04:00
|
|
|
CoglContext *ctx = data->src_tex->context;
|
2012-04-16 09:14:10 -04:00
|
|
|
CoglOffscreen *offscreen;
|
|
|
|
CoglFramebuffer *fb;
|
2011-01-20 12:45:47 -05:00
|
|
|
CoglPipeline *pipeline;
|
|
|
|
unsigned int dst_width, dst_height;
|
2012-11-22 18:01:08 -05:00
|
|
|
CoglError *ignore_error = NULL;
|
2011-01-20 12:45:47 -05:00
|
|
|
|
2013-08-16 17:43:19 -04:00
|
|
|
offscreen = _cogl_offscreen_new_with_texture_full
|
2011-01-20 12:45:47 -05:00
|
|
|
(data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
fb = COGL_FRAMEBUFFER (offscreen);
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!cogl_framebuffer_allocate (fb, &ignore_error))
|
2012-02-06 07:23:39 -05:00
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
cogl_error_free (ignore_error);
|
2012-04-16 09:14:10 -04:00
|
|
|
cogl_object_unref (fb);
|
2012-02-06 07:23:39 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-08 18:35:45 -05:00
|
|
|
data->dest_fb = fb;
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
dst_width = cogl_texture_get_width (data->dst_tex);
|
|
|
|
dst_height = cogl_texture_get_height (data->dst_tex);
|
|
|
|
|
|
|
|
/* Set up an orthographic projection so we can use pixel
|
|
|
|
coordinates to render to the texture */
|
2012-04-16 09:14:10 -04:00
|
|
|
cogl_framebuffer_orthographic (fb,
|
|
|
|
0, 0, dst_width, dst_height,
|
|
|
|
-1 /* near */, 1 /* far */);
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
/* We cache a pipeline used for migrating on to the context so
|
|
|
|
that it doesn't have to continuously regenerate a shader
|
|
|
|
program */
|
|
|
|
if (ctx->blit_texture_pipeline == NULL)
|
|
|
|
{
|
2012-02-18 11:03:10 -05:00
|
|
|
ctx->blit_texture_pipeline = cogl_pipeline_new (ctx);
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_layer_filters (ctx->blit_texture_pipeline, 0,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
2011-02-24 13:42:47 -05:00
|
|
|
|
|
|
|
/* Disable blending by just directly taking the contents of the
|
|
|
|
source texture */
|
|
|
|
cogl_pipeline_set_blend (ctx->blit_texture_pipeline,
|
|
|
|
"RGBA = ADD(SRC_COLOR, 0)",
|
|
|
|
NULL);
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pipeline = ctx->blit_texture_pipeline;
|
|
|
|
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, data->src_tex);
|
|
|
|
|
2013-01-18 14:32:24 -05:00
|
|
|
data->pipeline = pipeline;
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_texture_render_blit (CoglBlitData *data,
|
2012-11-08 18:35:45 -05:00
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2011-01-20 12:45:47 -05:00
|
|
|
{
|
2012-11-08 18:35:45 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (data->dest_fb,
|
2013-01-18 14:32:24 -05:00
|
|
|
data->pipeline,
|
|
|
|
dst_x, dst_y,
|
|
|
|
dst_x + width,
|
|
|
|
dst_y + height,
|
|
|
|
src_x / (float) data->src_width,
|
|
|
|
src_y / (float) data->src_height,
|
|
|
|
(src_x + width) /
|
|
|
|
(float) data->src_width,
|
|
|
|
(src_y + height) /
|
|
|
|
(float) data->src_height);
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_texture_render_end (CoglBlitData *data)
|
|
|
|
{
|
2012-09-18 06:59:21 -04:00
|
|
|
CoglContext *ctx = data->src_tex->context;
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
/* Attach the target texture to the texture render pipeline so that
|
|
|
|
we don't keep a reference to the source texture forever. This is
|
|
|
|
assuming that the destination texture will live for a long time
|
|
|
|
which is currently the case when cogl_blit_* is used from the
|
|
|
|
atlas code. It may be better in future to keep around a set of
|
|
|
|
dummy 1x1 textures for each texture target that we could bind
|
|
|
|
instead. This would also be useful when using a pipeline as a
|
|
|
|
hash table key such as for the ARBfp program cache. */
|
|
|
|
cogl_pipeline_set_layer_texture (ctx->blit_texture_pipeline, 0,
|
|
|
|
data->dst_tex);
|
2013-01-18 14:32:24 -05:00
|
|
|
|
2012-11-08 18:35:45 -05:00
|
|
|
cogl_object_unref (data->dest_fb);
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-01-20 12:45:47 -05:00
|
|
|
_cogl_blit_framebuffer_begin (CoglBlitData *data)
|
|
|
|
{
|
2012-09-18 06:59:21 -04:00
|
|
|
CoglContext *ctx = data->src_tex->context;
|
2012-04-16 09:14:10 -04:00
|
|
|
CoglOffscreen *dst_offscreen = NULL, *src_offscreen = NULL;
|
|
|
|
CoglFramebuffer *dst_fb, *src_fb;
|
2012-11-22 18:01:08 -05:00
|
|
|
CoglError *ignore_error = NULL;
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
/* We can only blit between FBOs if both textures are the same
|
|
|
|
format and the blit framebuffer extension is supported */
|
2013-06-27 13:33:04 -04:00
|
|
|
if ((_cogl_texture_get_format (data->src_tex) & ~COGL_A_BIT) !=
|
|
|
|
(_cogl_texture_get_format (data->dst_tex) & ~COGL_A_BIT) ||
|
2013-11-25 11:11:36 -05:00
|
|
|
!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT))
|
2011-01-20 12:45:47 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2013-08-16 17:43:19 -04:00
|
|
|
dst_offscreen = _cogl_offscreen_new_with_texture_full
|
2011-01-20 12:45:47 -05:00
|
|
|
(data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
dst_fb = COGL_FRAMEBUFFER (dst_offscreen);
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!cogl_framebuffer_allocate (dst_fb, &ignore_error))
|
|
|
|
{
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
goto error;
|
|
|
|
}
|
2012-04-16 09:14:10 -04:00
|
|
|
|
2013-08-16 17:43:19 -04:00
|
|
|
src_offscreen= _cogl_offscreen_new_with_texture_full
|
2012-04-16 09:14:10 -04:00
|
|
|
(data->src_tex,
|
|
|
|
COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL,
|
|
|
|
0 /* level */);
|
|
|
|
|
|
|
|
src_fb = COGL_FRAMEBUFFER (src_offscreen);
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!cogl_framebuffer_allocate (src_fb, &ignore_error))
|
|
|
|
{
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
goto error;
|
|
|
|
}
|
2012-04-16 09:14:10 -04:00
|
|
|
|
2012-11-08 18:35:45 -05:00
|
|
|
data->src_fb = src_fb;
|
|
|
|
data->dest_fb = dst_fb;
|
2012-04-16 09:14:10 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
2012-06-20 10:18:15 -04:00
|
|
|
error:
|
2012-04-16 09:14:10 -04:00
|
|
|
|
|
|
|
if (dst_offscreen)
|
|
|
|
cogl_object_unref (dst_offscreen);
|
|
|
|
if (src_offscreen)
|
|
|
|
cogl_object_unref (src_offscreen);
|
2011-01-20 12:45:47 -05:00
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
return FALSE;
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_framebuffer_blit (CoglBlitData *data,
|
2012-11-08 18:35:45 -05:00
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2011-01-20 12:45:47 -05:00
|
|
|
{
|
2012-11-08 18:35:45 -05:00
|
|
|
_cogl_blit_framebuffer (data->src_fb,
|
|
|
|
data->dest_fb,
|
|
|
|
src_x, src_y,
|
2011-01-20 12:45:47 -05:00
|
|
|
dst_x, dst_y,
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_framebuffer_end (CoglBlitData *data)
|
|
|
|
{
|
2012-11-08 18:35:45 -05:00
|
|
|
cogl_object_unref (data->src_fb);
|
|
|
|
cogl_object_unref (data->dest_fb);
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-01-20 12:45:47 -05:00
|
|
|
_cogl_blit_copy_tex_sub_image_begin (CoglBlitData *data)
|
|
|
|
{
|
2012-04-16 09:14:10 -04:00
|
|
|
CoglOffscreen *offscreen;
|
|
|
|
CoglFramebuffer *fb;
|
2012-11-22 18:01:08 -05:00
|
|
|
CoglError *ignore_error = NULL;
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
/* This will only work if the target texture is a CoglTexture2D */
|
2011-05-16 19:05:54 -04:00
|
|
|
if (!cogl_is_texture_2d (data->dst_tex))
|
2011-01-20 12:45:47 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2013-08-16 17:43:19 -04:00
|
|
|
offscreen = _cogl_offscreen_new_with_texture_full
|
2011-01-20 12:45:47 -05:00
|
|
|
(data->src_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
|
|
|
|
|
2012-04-16 09:14:10 -04:00
|
|
|
fb = COGL_FRAMEBUFFER (offscreen);
|
2012-11-22 18:01:08 -05:00
|
|
|
if (!cogl_framebuffer_allocate (fb, &ignore_error))
|
2012-02-06 07:23:39 -05:00
|
|
|
{
|
2012-11-22 18:01:08 -05:00
|
|
|
cogl_error_free (ignore_error);
|
2012-04-16 09:14:10 -04:00
|
|
|
cogl_object_unref (fb);
|
2012-02-06 07:23:39 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-08 18:35:45 -05:00
|
|
|
data->src_fb = fb;
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_copy_tex_sub_image_blit (CoglBlitData *data,
|
2012-11-08 18:35:45 -05:00
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2011-01-20 12:45:47 -05:00
|
|
|
{
|
2012-04-16 09:14:10 -04:00
|
|
|
_cogl_texture_2d_copy_from_framebuffer (COGL_TEXTURE_2D (data->dst_tex),
|
2012-11-09 12:55:54 -05:00
|
|
|
src_x, src_y,
|
|
|
|
width, height,
|
2012-11-08 18:35:45 -05:00
|
|
|
data->src_fb,
|
2011-01-20 12:45:47 -05:00
|
|
|
dst_x, dst_y,
|
2012-11-09 12:55:54 -05:00
|
|
|
0); /* level */
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_copy_tex_sub_image_end (CoglBlitData *data)
|
|
|
|
{
|
2012-11-08 18:35:45 -05:00
|
|
|
cogl_object_unref (data->src_fb);
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-01-20 12:45:47 -05:00
|
|
|
_cogl_blit_get_tex_data_begin (CoglBlitData *data)
|
|
|
|
{
|
2013-06-27 13:33:04 -04:00
|
|
|
data->format = _cogl_texture_get_format (data->src_tex);
|
2012-02-13 18:02:04 -05:00
|
|
|
data->bpp = _cogl_pixel_format_get_bytes_per_pixel (data->format);
|
2011-01-20 12:45:47 -05:00
|
|
|
|
|
|
|
data->image_data = g_malloc (data->bpp * data->src_width *
|
|
|
|
data->src_height);
|
|
|
|
cogl_texture_get_data (data->src_tex, data->format,
|
|
|
|
data->src_width * data->bpp, data->image_data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_get_tex_data_blit (CoglBlitData *data,
|
2012-11-08 18:35:45 -05:00
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2011-01-20 12:45:47 -05:00
|
|
|
{
|
2012-11-09 12:55:54 -05:00
|
|
|
CoglError *ignore = NULL;
|
|
|
|
int rowstride = data->src_width * data->bpp;
|
|
|
|
int offset = rowstride * src_y + src_x * data->bpp;
|
|
|
|
|
|
|
|
_cogl_texture_set_region (data->dst_tex,
|
|
|
|
width, height,
|
|
|
|
data->format,
|
|
|
|
rowstride,
|
|
|
|
data->image_data + offset,
|
|
|
|
dst_x, dst_y,
|
|
|
|
0, /* level */
|
|
|
|
&ignore);
|
2012-11-08 12:54:10 -05:00
|
|
|
/* TODO: support chaining up errors during the blit */
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_blit_get_tex_data_end (CoglBlitData *data)
|
|
|
|
{
|
|
|
|
g_free (data->image_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These should be specified in order of preference */
|
|
|
|
static const CoglBlitMode
|
|
|
|
_cogl_blit_modes[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"texture-render",
|
|
|
|
_cogl_blit_texture_render_begin,
|
|
|
|
_cogl_blit_texture_render_blit,
|
|
|
|
_cogl_blit_texture_render_end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"framebuffer",
|
|
|
|
_cogl_blit_framebuffer_begin,
|
|
|
|
_cogl_blit_framebuffer_blit,
|
|
|
|
_cogl_blit_framebuffer_end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"copy-tex-sub-image",
|
|
|
|
_cogl_blit_copy_tex_sub_image_begin,
|
|
|
|
_cogl_blit_copy_tex_sub_image_blit,
|
|
|
|
_cogl_blit_copy_tex_sub_image_end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"get-tex-data",
|
|
|
|
_cogl_blit_get_tex_data_begin,
|
|
|
|
_cogl_blit_get_tex_data_blit,
|
|
|
|
_cogl_blit_get_tex_data_end
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_blit_begin (CoglBlitData *data,
|
2012-04-16 09:14:10 -04:00
|
|
|
CoglTexture *dst_tex,
|
|
|
|
CoglTexture *src_tex)
|
2011-01-20 12:45:47 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (_cogl_blit_default_mode == NULL)
|
|
|
|
{
|
|
|
|
const char *default_mode_string;
|
|
|
|
|
|
|
|
/* Allow the default to be specified with an environment
|
|
|
|
variable. For the time being these functions are only used
|
|
|
|
when blitting between atlas textures so the environment
|
|
|
|
variable is named to be specific to the atlas code. If we
|
|
|
|
want to use the code in other places we should create another
|
|
|
|
environment variable for each specific use case */
|
|
|
|
if ((default_mode_string = g_getenv ("COGL_ATLAS_DEFAULT_BLIT_MODE")))
|
|
|
|
{
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (_cogl_blit_modes); i++)
|
|
|
|
if (!strcmp (_cogl_blit_modes[i].name, default_mode_string))
|
|
|
|
{
|
|
|
|
_cogl_blit_default_mode = _cogl_blit_modes + i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= G_N_ELEMENTS (_cogl_blit_modes))
|
|
|
|
{
|
|
|
|
g_warning ("Unknown blit mode %s", default_mode_string);
|
|
|
|
_cogl_blit_default_mode = _cogl_blit_modes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Default to the first blit mode */
|
|
|
|
_cogl_blit_default_mode = _cogl_blit_modes;
|
|
|
|
}
|
|
|
|
|
2012-11-08 18:35:45 -05:00
|
|
|
memset (data, 0, sizeof (CoglBlitData));
|
|
|
|
|
2011-01-20 12:45:47 -05:00
|
|
|
data->dst_tex = dst_tex;
|
|
|
|
data->src_tex = src_tex;
|
|
|
|
|
|
|
|
data->src_width = cogl_texture_get_width (src_tex);
|
|
|
|
data->src_height = cogl_texture_get_height (src_tex);
|
|
|
|
|
|
|
|
/* Try the default blit mode first */
|
|
|
|
if (!_cogl_blit_default_mode->begin_func (data))
|
|
|
|
{
|
|
|
|
COGL_NOTE (ATLAS, "Failed to set up blit mode %s",
|
|
|
|
_cogl_blit_default_mode->name);
|
|
|
|
|
|
|
|
/* Try all of the other modes in order */
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (_cogl_blit_modes); i++)
|
|
|
|
if (_cogl_blit_modes + i != _cogl_blit_default_mode &&
|
|
|
|
_cogl_blit_modes[i].begin_func (data))
|
|
|
|
{
|
|
|
|
/* Use this mode as the default from now on */
|
|
|
|
_cogl_blit_default_mode = _cogl_blit_modes + i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
COGL_NOTE (ATLAS,
|
|
|
|
"Failed to set up blit mode %s",
|
|
|
|
_cogl_blit_modes[i].name);
|
|
|
|
|
|
|
|
/* The last blit mode can't fail so this should never happen */
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (i < G_N_ELEMENTS (_cogl_blit_modes));
|
2011-01-20 12:45:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
data->blit_mode = _cogl_blit_default_mode;
|
|
|
|
|
|
|
|
COGL_NOTE (ATLAS, "Setup blit using %s", _cogl_blit_default_mode->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_blit (CoglBlitData *data,
|
2012-11-08 18:35:45 -05:00
|
|
|
int src_x,
|
|
|
|
int src_y,
|
|
|
|
int dst_x,
|
|
|
|
int dst_y,
|
|
|
|
int width,
|
|
|
|
int height)
|
2011-01-20 12:45:47 -05:00
|
|
|
{
|
|
|
|
data->blit_mode->blit_func (data, src_x, src_y, dst_x, dst_y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_blit_end (CoglBlitData *data)
|
|
|
|
{
|
|
|
|
data->blit_mode->end_func (data);
|
|
|
|
}
|