2006-05-29 08:59:36 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-06-21 22:34:25 +00:00
|
|
|
/**
|
|
|
|
* SECTION:clutter-texture
|
|
|
|
* @short_description: An actor for displaying and manipulating images.
|
|
|
|
*
|
|
|
|
* #ClutterTexture is a base class for displaying and manipulating pixel
|
|
|
|
* buffer type data.
|
2006-09-19 19:27:16 +00:00
|
|
|
*
|
2007-07-24 17:38:35 +00:00
|
|
|
* The clutter_texture_set_from_rgb_data() and clutter_texture_set_pixbuf()
|
|
|
|
* functions are used to copy image data into texture memory and subsequently
|
2007-10-12 08:17:00 +00:00
|
|
|
* realize the the texture.
|
2007-05-25 10:56:09 +00:00
|
|
|
*
|
2007-07-24 17:38:35 +00:00
|
|
|
* If texture reads are supported by underlying GL implementation,
|
2007-10-12 08:17:00 +00:00
|
|
|
* unrealizing/hiding frees image data from texture memory moving to main
|
|
|
|
* system memory. Re-realizing then performs the opposite operation.
|
|
|
|
* This process allows basic management of commonly limited available texture
|
|
|
|
* memory.
|
2007-12-17 15:51:30 +00:00
|
|
|
*
|
|
|
|
* Note: a ClutterTexture will scale its contents to fit the bounding box
|
|
|
|
* requested using clutter_actor_request_coords() and its wrappers. To
|
|
|
|
* display an area of a texture without scaling, you should set the clip
|
|
|
|
* area using clutter_actor_set_clip().
|
2006-06-21 22:34:25 +00:00
|
|
|
*/
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-04-27 21:13:06 +00:00
|
|
|
#include "config.h"
|
2007-10-12 08:17:00 +00:00
|
|
|
#endif
|
2007-04-27 21:13:06 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
#include "clutter-texture.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-marshal.h"
|
2006-07-24 21:15:19 +00:00
|
|
|
#include "clutter-feature.h"
|
2006-06-06 20:40:40 +00:00
|
|
|
#include "clutter-util.h"
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-debug.h"
|
2007-04-27 21:13:06 +00:00
|
|
|
#include "clutter-fixed.h"
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
#include "cogl.h"
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-06-13 13:17:45 +00:00
|
|
|
G_DEFINE_TYPE (ClutterTexture, clutter_texture, CLUTTER_TYPE_ACTOR);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2007-04-27 21:13:06 +00:00
|
|
|
#define PIXEL_TYPE CGL_UNSIGNED_BYTE
|
2006-05-29 08:59:36 +00:00
|
|
|
#else
|
2007-04-27 21:13:06 +00:00
|
|
|
#define PIXEL_TYPE CGL_UNSIGNED_INT_8_8_8_8_REV
|
2006-05-29 08:59:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
typedef struct {
|
|
|
|
gint pos;
|
|
|
|
gint size;
|
|
|
|
gint waste;
|
|
|
|
} ClutterTextureTileDimension;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
#define CLUTTER_TEXTURE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_TEXTURE, ClutterTexturePrivate))
|
|
|
|
|
2006-12-03 18:34:41 +00:00
|
|
|
struct _ClutterTexturePrivate
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-04-27 21:13:06 +00:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
COGLenum pixel_format;
|
|
|
|
COGLenum pixel_type;
|
2007-10-12 08:17:00 +00:00
|
|
|
COGLenum target_type;
|
2007-04-27 21:13:06 +00:00
|
|
|
GdkPixbuf *local_pixbuf; /* non video memory copy */
|
|
|
|
guint sync_actor_size : 1;
|
|
|
|
gint max_tile_waste;
|
|
|
|
guint filter_quality;
|
|
|
|
guint repeat_x : 1; /* non working */
|
|
|
|
guint repeat_y : 1; /* non working */
|
|
|
|
guint is_tiled : 1;
|
2007-03-19 10:00:38 +00:00
|
|
|
ClutterTextureTileDimension *x_tiles;
|
|
|
|
ClutterTextureTileDimension *y_tiles;
|
2007-04-27 21:13:06 +00:00
|
|
|
gint n_x_tiles;
|
|
|
|
gint n_y_tiles;
|
2007-10-26 22:06:45 +00:00
|
|
|
COGLuint *tiles;
|
2006-05-29 08:59:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_PIXBUF,
|
|
|
|
PROP_USE_TILES,
|
|
|
|
PROP_MAX_TILE_WASTE,
|
|
|
|
PROP_PIXEL_TYPE, /* Texture type */
|
|
|
|
PROP_PIXEL_FORMAT, /* Texture format */
|
|
|
|
PROP_SYNC_SIZE,
|
|
|
|
PROP_REPEAT_Y,
|
2006-06-06 20:40:40 +00:00
|
|
|
PROP_REPEAT_X,
|
|
|
|
PROP_FILTER_QUALITY
|
2006-05-29 08:59:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2006-12-13 18:12:09 +00:00
|
|
|
SIZE_CHANGE,
|
|
|
|
PIXBUF_CHANGE,
|
2006-05-29 08:59:36 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int texture_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
GQuark
|
|
|
|
clutter_texture_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("clutter-texture-error-quark");
|
|
|
|
}
|
|
|
|
|
2007-06-22 15:16:40 +00:00
|
|
|
static guchar*
|
|
|
|
un_pre_multiply_alpha (const guchar *data,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
|
|
|
gint x,y;
|
|
|
|
unsigned char *ret, *dst, *src;
|
|
|
|
|
|
|
|
ret = dst = g_malloc(sizeof(guchar) * height * rowstride);
|
|
|
|
|
|
|
|
/* FIXME: Optimise */
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
src = (guchar*)data + y * rowstride;
|
2007-10-12 08:17:00 +00:00
|
|
|
for (x = 0; x < width; x++)
|
2007-06-22 15:16:40 +00:00
|
|
|
{
|
|
|
|
guchar alpha = src[3];
|
|
|
|
if (alpha == 0)
|
|
|
|
{
|
|
|
|
src[0] = src[1] = src[2] = src[3] = alpha;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst[0] = (((src[0] >> 16) & 0xff) * 255 ) / alpha;
|
2007-10-12 08:17:00 +00:00
|
|
|
dst[1] = (((src[1] >> 8) & 0xff) * 255 ) / alpha;
|
2007-06-22 15:16:40 +00:00
|
|
|
dst[2] = (((src[2] >> 0) & 0xff) * 255 ) / alpha;
|
|
|
|
dst[3] = alpha;
|
|
|
|
}
|
|
|
|
dst += 4;
|
|
|
|
src += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-04 14:00:41 +00:00
|
|
|
#ifndef HAVE_COGL_GL
|
|
|
|
static guchar *
|
2007-06-22 15:16:40 +00:00
|
|
|
rgb_to_bgr (const guchar *data,
|
|
|
|
gboolean has_alpha,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint rowstride)
|
|
|
|
{
|
|
|
|
gint x,y, bpp = 4;
|
|
|
|
unsigned char *ret, *dst, *src;
|
|
|
|
|
|
|
|
ret = dst = g_malloc(sizeof(guchar) * height * rowstride);
|
|
|
|
|
|
|
|
if (!has_alpha)
|
|
|
|
bpp = 3;
|
|
|
|
|
|
|
|
/* FIXME: Optimise */
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
src = (guchar*)data + y * rowstride;
|
2007-10-12 08:17:00 +00:00
|
|
|
for (x = 0; x < width; x++)
|
2007-06-22 15:16:40 +00:00
|
|
|
{
|
|
|
|
dst[0] = src[2];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[0];
|
|
|
|
if (has_alpha)
|
|
|
|
dst[3] = src[3];
|
|
|
|
dst += bpp;
|
|
|
|
src += bpp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2007-07-04 14:00:41 +00:00
|
|
|
#endif /* !HAVE_COGL_GL */
|
2007-06-22 15:16:40 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
static int
|
|
|
|
tile_dimension (int to_fill,
|
|
|
|
int start_size,
|
2006-06-06 20:40:40 +00:00
|
|
|
int waste,
|
2006-12-03 18:34:41 +00:00
|
|
|
ClutterTextureTileDimension *tiles)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
int pos = 0;
|
|
|
|
int n_tiles = 0;
|
|
|
|
int size = start_size;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (tiles)
|
|
|
|
{
|
|
|
|
tiles[n_tiles].pos = pos;
|
|
|
|
tiles[n_tiles].size = size;
|
|
|
|
tiles[n_tiles].waste = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
n_tiles++;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
if (to_fill <= size)
|
|
|
|
{
|
|
|
|
if (tiles)
|
|
|
|
tiles[n_tiles-1].waste = size - to_fill;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-12 20:38:57 +00:00
|
|
|
to_fill -= size; pos += size;
|
2006-06-06 20:40:40 +00:00
|
|
|
while (size >= 2 * to_fill || size - to_fill > waste)
|
2006-05-29 08:59:36 +00:00
|
|
|
size /= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_tiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-09-19 19:27:16 +00:00
|
|
|
texture_init_tiles (ClutterTexture *texture)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
gint x_pot, y_pot;
|
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
2006-06-06 20:40:40 +00:00
|
|
|
x_pot = clutter_util_next_p2 (priv->width);
|
|
|
|
y_pot = clutter_util_next_p2 (priv->height);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-06-07 23:51:53 +00:00
|
|
|
while (!(cogl_texture_can_size (CGL_TEXTURE_2D,
|
2007-10-12 08:17:00 +00:00
|
|
|
priv->pixel_format,
|
2007-06-07 23:51:53 +00:00
|
|
|
priv->pixel_type,
|
2007-05-04 23:53:49 +00:00
|
|
|
x_pot, y_pot)
|
2007-10-12 08:17:00 +00:00
|
|
|
&& (x_pot - priv->width < priv->max_tile_waste)
|
2006-06-08 21:28:05 +00:00
|
|
|
&& (y_pot - priv->height < priv->max_tile_waste)))
|
|
|
|
{
|
2006-11-22 20:52:27 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "x_pot:%i - width:%i < max_waste:%i",
|
|
|
|
x_pot,
|
|
|
|
priv->width,
|
|
|
|
priv->max_tile_waste);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-11-22 20:52:27 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "y_pot:%i - height:%i < max_waste:%i",
|
|
|
|
y_pot,
|
|
|
|
priv->height,
|
|
|
|
priv->max_tile_waste);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-06-08 21:28:05 +00:00
|
|
|
if (x_pot > y_pot)
|
|
|
|
x_pot /= 2;
|
|
|
|
else
|
|
|
|
y_pot /= 2;
|
2007-05-04 23:53:49 +00:00
|
|
|
|
|
|
|
g_return_if_fail (x_pot != 0 || y_pot != 0);
|
2006-06-08 21:28:05 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
if (priv->x_tiles)
|
2007-07-24 17:38:35 +00:00
|
|
|
g_free (priv->x_tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
priv->n_x_tiles = tile_dimension (priv->width, x_pot,
|
2006-06-06 20:40:40 +00:00
|
|
|
priv->max_tile_waste, NULL);
|
2006-05-29 08:59:36 +00:00
|
|
|
if (priv->y_tiles)
|
2007-07-24 17:38:35 +00:00
|
|
|
g_free (priv->y_tiles);
|
2007-10-12 08:17:00 +00:00
|
|
|
priv->n_y_tiles = tile_dimension (priv->height, y_pot,
|
2006-06-06 20:40:40 +00:00
|
|
|
priv->max_tile_waste, NULL);
|
2007-11-18 23:24:55 +00:00
|
|
|
|
|
|
|
if (priv->n_x_tiles == 1 && priv->n_y_tiles == 1)
|
|
|
|
{
|
|
|
|
/* So were not actually tiled... */
|
|
|
|
priv->n_x_tiles = priv->n_y_tiles = 0;
|
|
|
|
priv->is_tiled = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->x_tiles = g_new (ClutterTextureTileDimension, priv->n_x_tiles);
|
|
|
|
tile_dimension (priv->width, x_pot, priv->max_tile_waste, priv->x_tiles);
|
|
|
|
|
2006-12-03 18:34:41 +00:00
|
|
|
priv->y_tiles = g_new (ClutterTextureTileDimension, priv->n_y_tiles);
|
2006-06-06 20:40:40 +00:00
|
|
|
tile_dimension (priv->height, y_pot, priv->max_tile_waste, priv->y_tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE,
|
2006-11-22 20:52:27 +00:00
|
|
|
"x_pot:%i, width:%i, y_pot:%i, height: %i "
|
|
|
|
"max_waste:%i, n_x_tiles: %i, n_y_tiles: %i",
|
|
|
|
x_pot, priv->width, y_pot, priv->height,
|
|
|
|
priv->max_tile_waste,
|
|
|
|
priv->n_x_tiles, priv->n_y_tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-12 08:17:00 +00:00
|
|
|
texture_render_to_gl_quad (ClutterTexture *texture,
|
|
|
|
int x_1,
|
|
|
|
int y_1,
|
|
|
|
int x_2,
|
2007-07-26 11:04:04 +00:00
|
|
|
int y_2)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
int qx1 = 0, qx2 = 0, qy1 = 0, qy2 = 0;
|
|
|
|
int qwidth = 0, qheight = 0;
|
|
|
|
int x, y, i =0, lastx = 0, lasty = 0;
|
|
|
|
float tx, ty;
|
|
|
|
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
qwidth = x_2 - x_1;
|
|
|
|
qheight = y_2 - y_1;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
if (!priv->is_tiled)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[0]);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
if (priv->target_type == CGL_TEXTURE_2D) /* POT */
|
2006-07-24 21:15:19 +00:00
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
tx = (float) priv->width / clutter_util_next_p2 (priv->width);
|
2006-07-24 21:15:19 +00:00
|
|
|
ty = (float) priv->height / clutter_util_next_p2 (priv->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tx = (float) priv->width;
|
|
|
|
ty = (float) priv->height;
|
|
|
|
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
qx1 = x_1; qx2 = x_2;
|
|
|
|
qy1 = y_1; qy2 = y_2;
|
2007-04-27 21:13:06 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
cogl_texture_quad (x_1, x_2, y_1, y_2,
|
2007-04-27 21:13:06 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
CLUTTER_FLOAT_TO_FIXED (tx),
|
|
|
|
CLUTTER_FLOAT_TO_FIXED (ty));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
for (x = 0; x < priv->n_x_tiles; x++)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
lasty = 0;
|
|
|
|
|
|
|
|
for (y=0; y < priv->n_y_tiles; y++)
|
|
|
|
{
|
|
|
|
int actual_w, actual_h;
|
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[i]);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
actual_w = priv->x_tiles[x].size - priv->x_tiles[x].waste;
|
|
|
|
actual_h = priv->y_tiles[y].size - priv->y_tiles[y].waste;
|
|
|
|
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE,
|
2006-11-22 20:52:27 +00:00
|
|
|
"rendering text tile x: %i, y: %i - %ix%i",
|
|
|
|
x, y, actual_w, actual_h);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
tx = (float) actual_w / priv->x_tiles[x].size;
|
|
|
|
ty = (float) actual_h / priv->y_tiles[y].size;
|
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
qx1 = x_1 + lastx;
|
2006-05-29 08:59:36 +00:00
|
|
|
qx2 = qx1 + ((qwidth * actual_w ) / priv->width );
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
qy1 = y_1 + lasty;
|
2006-05-29 08:59:36 +00:00
|
|
|
qy2 = qy1 + ((qheight * actual_h) / priv->height );
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
cogl_texture_quad (qx1, qx2, qy1, qy2,
|
2007-04-27 21:13:06 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
CLUTTER_FLOAT_TO_FIXED (tx),
|
|
|
|
CLUTTER_FLOAT_TO_FIXED (ty));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
lasty += (qy2 - qy1) ;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2006-06-08 21:28:05 +00:00
|
|
|
lastx += (qx2 - qx1);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-09-19 19:27:16 +00:00
|
|
|
texture_free_gl_resources (ClutterTexture *texture)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
CLUTTER_MARK();
|
|
|
|
|
|
|
|
if (priv->tiles)
|
|
|
|
{
|
2007-03-19 10:00:38 +00:00
|
|
|
if (!priv->is_tiled)
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_textures_destroy (1, priv->tiles);
|
2006-09-19 19:27:16 +00:00
|
|
|
else
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_textures_destroy (priv->n_x_tiles * priv->n_y_tiles, priv->tiles);
|
2006-09-19 19:27:16 +00:00
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
g_free (priv->tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
priv->tiles = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->x_tiles)
|
|
|
|
{
|
2007-07-24 17:38:35 +00:00
|
|
|
g_free (priv->x_tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
priv->x_tiles = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->y_tiles)
|
|
|
|
{
|
2007-07-24 17:38:35 +00:00
|
|
|
g_free (priv->y_tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
priv->y_tiles = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-20 14:26:07 +00:00
|
|
|
static void inline
|
2006-09-19 19:27:16 +00:00
|
|
|
texture_upload_data (ClutterTexture *texture,
|
2007-12-20 14:26:07 +00:00
|
|
|
const guchar *data,
|
|
|
|
gboolean has_alpha,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint rowstride,
|
|
|
|
gint bpp)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
2007-04-19 15:24:20 +00:00
|
|
|
gint x, y;
|
|
|
|
gint i = 0;
|
|
|
|
gboolean create_textures = FALSE;
|
|
|
|
GdkPixbuf *master_pixbuf = NULL;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
g_return_if_fail (data != NULL);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
CLUTTER_MARK();
|
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
if (!priv->is_tiled)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2006-09-19 19:27:16 +00:00
|
|
|
/* Single Texture */
|
2006-05-29 08:59:36 +00:00
|
|
|
if (!priv->tiles)
|
|
|
|
{
|
2007-10-26 22:06:45 +00:00
|
|
|
priv->tiles = g_new (COGLuint, 1);
|
2006-05-29 08:59:36 +00:00
|
|
|
glGenTextures (1, priv->tiles);
|
|
|
|
create_textures = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-22 20:52:27 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "syncing for single tile");
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[0]);
|
|
|
|
cogl_texture_set_alignment (priv->target_type, 4, priv->width);
|
2006-07-24 21:15:19 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
cogl_texture_set_filters
|
|
|
|
(priv->target_type,
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST,
|
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST);
|
2006-06-06 20:40:40 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
cogl_texture_set_wrap (priv->target_type,
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->repeat_x ? CGL_REPEAT : CGL_CLAMP_TO_EDGE,
|
|
|
|
priv->repeat_y ? CGL_REPEAT : CGL_CLAMP_TO_EDGE);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->filter_quality = 1;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
if (create_textures)
|
|
|
|
{
|
2007-07-26 11:04:04 +00:00
|
|
|
gint tex_width, tex_height;
|
2006-07-24 21:15:19 +00:00
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
tex_width = priv->width;
|
|
|
|
tex_height = priv->height;
|
2006-07-24 21:15:19 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
if (priv->target_type == CGL_TEXTURE_2D) /* POT */
|
2006-07-24 21:15:19 +00:00
|
|
|
{
|
2007-07-26 11:04:04 +00:00
|
|
|
tex_width = clutter_util_next_p2 (priv->width);
|
|
|
|
tex_height = clutter_util_next_p2 (priv->height);
|
2006-07-24 21:15:19 +00:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_texture_image_2d (priv->target_type,
|
|
|
|
CGL_RGBA,
|
2007-10-12 08:17:00 +00:00
|
|
|
tex_width,
|
|
|
|
tex_height,
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
|
|
|
NULL);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
2007-04-27 21:13:06 +00:00
|
|
|
|
|
|
|
cogl_texture_sub_image_2d (priv->target_type,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
|
|
|
data);
|
2006-05-29 08:59:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiple tiled texture */
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE,
|
2006-11-22 20:52:27 +00:00
|
|
|
"syncing for multiple tiles for %ix%i pixbuf",
|
|
|
|
priv->width, priv->height);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-06-20 20:29:45 +00:00
|
|
|
g_return_if_fail (priv->x_tiles != NULL && priv->y_tiles != NULL);
|
2007-04-19 15:24:20 +00:00
|
|
|
|
|
|
|
master_pixbuf = gdk_pixbuf_new_from_data (data,
|
|
|
|
GDK_COLORSPACE_RGB,
|
|
|
|
has_alpha,
|
|
|
|
8,
|
|
|
|
width, height, rowstride,
|
|
|
|
NULL, NULL);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
if (priv->tiles == NULL)
|
|
|
|
{
|
2007-10-26 22:06:45 +00:00
|
|
|
priv->tiles = g_new (COGLuint, priv->n_x_tiles * priv->n_y_tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
glGenTextures (priv->n_x_tiles * priv->n_y_tiles, priv->tiles);
|
|
|
|
create_textures = TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
for (x = 0; x < priv->n_x_tiles; x++)
|
|
|
|
for (y = 0; y < priv->n_y_tiles; y++)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-04-19 15:24:20 +00:00
|
|
|
GdkPixbuf *pixtmp;
|
|
|
|
gint src_h, src_w;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
src_w = priv->x_tiles[x].size;
|
|
|
|
src_h = priv->y_tiles[y].size;
|
2007-04-19 15:24:20 +00:00
|
|
|
|
2007-06-29 11:54:31 +00:00
|
|
|
pixtmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
|
|
|
|
has_alpha,
|
|
|
|
8,
|
|
|
|
src_w, src_h);
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
/* clip */
|
|
|
|
if (priv->x_tiles[x].pos + src_w > priv->width)
|
2007-04-19 15:24:20 +00:00
|
|
|
src_w = priv->width - priv->x_tiles[x].pos;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
if (priv->y_tiles[y].pos + src_h > priv->height)
|
2007-04-19 15:24:20 +00:00
|
|
|
src_h = priv->height - priv->y_tiles[y].pos;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-04-19 15:24:20 +00:00
|
|
|
gdk_pixbuf_copy_area (master_pixbuf,
|
|
|
|
priv->x_tiles[x].pos,
|
|
|
|
priv->y_tiles[y].pos,
|
|
|
|
src_w,
|
|
|
|
src_h,
|
|
|
|
pixtmp,
|
|
|
|
0, 0);
|
2006-05-29 08:59:36 +00:00
|
|
|
#ifdef CLUTTER_DUMP_TILES
|
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
|
2007-11-14 11:43:18 +00:00
|
|
|
filename =
|
|
|
|
g_strdup_printf("/tmp/%i-%i-%i.png",
|
|
|
|
clutter_actor_get_gid (CLUTTER_ACTOR (texture)),
|
|
|
|
x, y);
|
|
|
|
|
|
|
|
printf ("saving %s\n", filename);
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
gdk_pixbuf_save (pixtmp, filename , "png", NULL, NULL);
|
2007-11-14 11:43:18 +00:00
|
|
|
g_free (filename);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-04 23:53:49 +00:00
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[i]);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
|
|
|
cogl_texture_set_alignment (priv->target_type,
|
2007-08-12 21:30:14 +00:00
|
|
|
4, priv->x_tiles[x].size);
|
2006-06-06 20:40:40 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
cogl_texture_set_filters
|
|
|
|
(priv->target_type,
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST,
|
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST);
|
2006-09-19 19:27:16 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
cogl_texture_set_wrap (priv->target_type,
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->repeat_x ? CGL_REPEAT : CGL_CLAMP_TO_EDGE,
|
|
|
|
priv->repeat_y ? CGL_REPEAT : CGL_CLAMP_TO_EDGE);
|
2006-05-29 08:59:36 +00:00
|
|
|
if (create_textures)
|
|
|
|
{
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_texture_image_2d (priv->target_type,
|
|
|
|
CGL_RGBA,
|
2007-10-12 08:17:00 +00:00
|
|
|
gdk_pixbuf_get_width (pixtmp),
|
|
|
|
gdk_pixbuf_get_height (pixtmp),
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
|
|
|
gdk_pixbuf_get_pixels (pixtmp));
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
else
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
/* Textures already created, so just update whats inside
|
2006-05-29 08:59:36 +00:00
|
|
|
*/
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_texture_sub_image_2d (priv->target_type,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
gdk_pixbuf_get_width (pixtmp),
|
|
|
|
gdk_pixbuf_get_height (pixtmp),
|
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
|
|
|
gdk_pixbuf_get_pixels (pixtmp));
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-19 15:24:20 +00:00
|
|
|
g_object_unref (pixtmp);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2007-04-19 15:24:20 +00:00
|
|
|
|
|
|
|
g_object_unref (master_pixbuf);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
static void
|
|
|
|
clutter_texture_unrealize (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
ClutterTexture *texture;
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
|
|
|
texture = CLUTTER_TEXTURE(actor);
|
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
if (priv->tiles == NULL)
|
|
|
|
return;
|
|
|
|
|
2007-12-28 15:34:24 +00:00
|
|
|
/* there's no need to read the pixels back when unrealizing inside
|
|
|
|
* a dispose run, and the dispose() call will release the GL
|
|
|
|
* texture data as well, so we can safely bail out now
|
|
|
|
*/
|
|
|
|
if (CLUTTER_PRIVATE_FLAGS (actor) & CLUTTER_ACTOR_IN_DESTRUCTION)
|
|
|
|
return;
|
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
CLUTTER_MARK();
|
|
|
|
|
2007-05-28 20:09:19 +00:00
|
|
|
if (clutter_feature_available (CLUTTER_FEATURE_TEXTURE_READ_PIXELS))
|
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
/* Move image data from video to main memory.
|
|
|
|
* GL/ES cant do this - it probably makes sense
|
2007-05-28 20:09:19 +00:00
|
|
|
* to move this kind of thing into a ClutterProxyTexture
|
|
|
|
* where this behaviour can be better controlled.
|
2007-06-22 15:16:40 +00:00
|
|
|
*
|
|
|
|
* Or make it controllable via a property.
|
2007-05-28 20:09:19 +00:00
|
|
|
*/
|
|
|
|
if (priv->local_pixbuf == NULL)
|
2007-06-07 23:51:53 +00:00
|
|
|
{
|
|
|
|
priv->local_pixbuf = clutter_texture_get_pixbuf (texture);
|
|
|
|
CLUTTER_NOTE (TEXTURE, "moved pixels into system (pixbuf) mem");
|
|
|
|
}
|
|
|
|
|
2007-05-28 20:09:19 +00:00
|
|
|
texture_free_gl_resources (texture);
|
|
|
|
}
|
2006-09-19 19:27:16 +00:00
|
|
|
|
2006-11-22 20:52:27 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Texture unrealized");
|
2006-09-19 19:27:16 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
static void
|
2006-06-13 13:17:45 +00:00
|
|
|
clutter_texture_realize (ClutterActor *actor)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2006-09-19 19:27:16 +00:00
|
|
|
ClutterTexture *texture;
|
|
|
|
ClutterTexturePrivate *priv;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-06-13 13:17:45 +00:00
|
|
|
texture = CLUTTER_TEXTURE(actor);
|
2006-09-19 19:27:16 +00:00
|
|
|
priv = texture->priv;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
CLUTTER_MARK();
|
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
if (priv->local_pixbuf != NULL)
|
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
/* Move any local image data we have from unrealization
|
|
|
|
* back into video memory.
|
2006-09-19 19:27:16 +00:00
|
|
|
*/
|
2007-07-29 22:55:04 +00:00
|
|
|
if (priv->is_tiled)
|
2007-10-12 08:17:00 +00:00
|
|
|
texture_init_tiles (texture);
|
2007-05-25 10:56:09 +00:00
|
|
|
clutter_texture_set_pixbuf (texture, priv->local_pixbuf, NULL);
|
2006-09-19 19:27:16 +00:00
|
|
|
g_object_unref (priv->local_pixbuf);
|
|
|
|
priv->local_pixbuf = NULL;
|
|
|
|
}
|
|
|
|
else
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-06-07 23:51:53 +00:00
|
|
|
if (clutter_feature_available (CLUTTER_FEATURE_TEXTURE_READ_PIXELS))
|
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
/* Dont allow realization with no pixbuf - note set_pixbuf/data
|
|
|
|
* will set realize flags.
|
2007-06-07 23:51:53 +00:00
|
|
|
*/
|
|
|
|
CLUTTER_NOTE (TEXTURE,
|
|
|
|
"Texture has no image data cannot realize");
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-06-07 23:51:53 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "flags %i", actor->flags);
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
CLUTTER_NOTE (TEXTURE, "flags %i", actor->flags);
|
|
|
|
return;
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2006-11-22 20:52:27 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Texture realized");
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:17:45 +00:00
|
|
|
clutter_texture_show (ClutterActor *self)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2006-12-12 20:20:04 +00:00
|
|
|
ClutterActorClass *parent_class;
|
|
|
|
|
|
|
|
/* chain up parent show */
|
|
|
|
parent_class = CLUTTER_ACTOR_CLASS (clutter_texture_parent_class);
|
|
|
|
if (parent_class->show)
|
|
|
|
parent_class->show (self);
|
|
|
|
|
2006-06-13 13:17:45 +00:00
|
|
|
clutter_actor_realize (self);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:17:45 +00:00
|
|
|
clutter_texture_hide (ClutterActor *self)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2006-12-12 20:20:04 +00:00
|
|
|
ClutterActorClass *parent_class;
|
|
|
|
|
|
|
|
/* chain up parent hide */
|
|
|
|
parent_class = CLUTTER_ACTOR_CLASS (clutter_texture_parent_class);
|
|
|
|
if (parent_class->hide)
|
|
|
|
parent_class->hide (self);
|
|
|
|
|
2006-06-13 13:17:45 +00:00
|
|
|
clutter_actor_unrealize (self);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-13 13:17:45 +00:00
|
|
|
clutter_texture_paint (ClutterActor *self)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-03-19 10:00:38 +00:00
|
|
|
ClutterTexture *texture = CLUTTER_TEXTURE (self);
|
2007-07-26 11:04:04 +00:00
|
|
|
ClutterTexturePrivate *priv = texture->priv;
|
|
|
|
gint x_1, y_1, x_2, y_2;
|
2007-04-27 21:13:06 +00:00
|
|
|
ClutterColor col = { 0xff, 0xff, 0xff, 0xff };
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-23 17:02:52 +00:00
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (CLUTTER_ACTOR(texture)))
|
|
|
|
clutter_actor_realize (CLUTTER_ACTOR(texture));
|
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
if (priv->tiles == NULL)
|
2007-07-23 17:02:52 +00:00
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
/* We just need do debug this state, it doesn't really need to
|
2007-07-23 17:02:52 +00:00
|
|
|
* throw a an error as what previously happened. Sub classes
|
2007-10-12 08:17:00 +00:00
|
|
|
* quite likely may not be able to realize.
|
2007-07-23 17:02:52 +00:00
|
|
|
*/
|
2007-07-26 11:04:04 +00:00
|
|
|
CLUTTER_NOTE (PAINT, "unable to paint texture '%s', contains no tiles",
|
|
|
|
clutter_actor_get_name (self)
|
|
|
|
? clutter_actor_get_name (self)
|
2007-07-23 17:02:52 +00:00
|
|
|
: "unknown");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-21 Emmanuele Bassi <ebassi@openedhand.com>
* configure.ac: Enable debug messages also when
--enable-debug is set to "minimum".
* clutter/Makefile.am:
* clutter/clutter-debug.h: Move all debugging macros inside
this private header; make all debug macros depend on the
CLUTTER_ENABLE_DEBUG compile time define, controlled by
the --enable-debug configure switch; add G_LOG_DOMAIN define.
* clutter/clutter-main.c: Clean up the debug stuff; add
command line argument parsing using GOption; the debug
messages now are triggered like this:
CLUTTER_DEBUG=section:section:... clutter-app
or like this:
clutter-app --clutter-debug=section:section:...
where "section" is one of the sections listed in clutter-main.c,
or "all", for all sections; each section is bound to a flag,
which can be used to define a domain when adding a debug note
using the CLUTTER_NOTE() macro; the old CLUTTER_DBG() macro is
just a wrapper around that, under the CLUTTER_DEBUG_MISC domain;
CLUTTER_NOTE() is used like this:
CLUTTER_NOTE (DOMAIN, log-function);
where log function is g_printerr(), g_message(), g_warning(),
g_critical() or directly g_log() - for instance:
CLUTTER_NOTE (PANGO, g_warning ("Cache miss: %d", glyph));
will print the warning only if the "pango" flag has been
set to the CLUTTER_DEBUG envvar or passed to the --clutter-debug
command line argument.
similar to CLUTTER_SHOW_FPS, there's also the --clutter-show-fps
command line switch; also, the --display and --screen command
line switches have been added: the first overrides the DISPLAY
envvar and the second controls the X screen used by Clutter to
get the root window on the display.
* clutter/clutter-main.h:
* clutter/clutter-main.c: Add extended support for GOption
in Clutter; use clutter_init_with_args() to let Clutter
parse your own command line arguments; use instead
clutter_get_option_group() to get the GOptionGroup used by
Clutter if you want to do the parsing yourself with
g_option_context_parse(). The init sequence has been verified,
updated and moved into common functions where possible.
* clutter/pango/pangoclutter-render.c:
* clutter/*.c: Include "clutter-debug.h" where needed; use
CLUTTER_NOTE() instead of CLUTTER_DBG().
* examples/super-oh.c: Use the new clutter_init_with_args()
function, and add a --num-hands command line switch to
the SuperOH example code controlling the number of hands at
runtime.
2006-11-21 21:27:53 +00:00
|
|
|
CLUTTER_NOTE (PAINT,
|
2007-04-27 21:13:06 +00:00
|
|
|
"painting texture '%s'",
|
2006-11-22 20:52:27 +00:00
|
|
|
clutter_actor_get_name (self) ? clutter_actor_get_name (self)
|
2007-03-19 10:00:38 +00:00
|
|
|
: "unknown");
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_push_matrix ();
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
switch (priv->target_type)
|
2007-04-27 21:13:06 +00:00
|
|
|
{
|
|
|
|
case CGL_TEXTURE_2D:
|
|
|
|
cogl_enable (CGL_ENABLE_TEXTURE_2D|CGL_ENABLE_BLEND);
|
|
|
|
break;
|
|
|
|
case CGL_TEXTURE_RECTANGLE_ARB:
|
|
|
|
cogl_enable (CGL_ENABLE_TEXTURE_RECT|CGL_ENABLE_BLEND);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
col.alpha = clutter_actor_get_opacity (self);
|
2006-06-20 20:29:45 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_color (&col);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
clutter_actor_get_coords (self, &x_1, &y_1, &x_2, &y_2);
|
2007-04-27 21:13:06 +00:00
|
|
|
|
|
|
|
CLUTTER_NOTE (PAINT, "paint to x1: %i, y1: %i x2: %i, y2: %i "
|
2007-07-26 11:04:04 +00:00
|
|
|
"opacity: %i",
|
|
|
|
x_1, y_1, x_2, y_2,
|
2007-04-27 21:13:06 +00:00
|
|
|
clutter_actor_get_opacity (self));
|
|
|
|
|
2006-09-20 18:38:08 +00:00
|
|
|
/* Paint will of translated us */
|
2007-07-26 11:04:04 +00:00
|
|
|
texture_render_to_gl_quad (texture, 0, 0, x_2 - x_1, y_2 - y_1);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
cogl_pop_matrix ();
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2007-11-15 17:38:40 +00:00
|
|
|
static void
|
|
|
|
clutter_texture_request_coords (ClutterActor *self,
|
|
|
|
ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
ClutterTexture *texture = CLUTTER_TEXTURE (self);
|
|
|
|
ClutterActorBox old_request;
|
|
|
|
|
|
|
|
clutter_actor_query_coords (self, &old_request);
|
|
|
|
|
|
|
|
if (((box->x2 - box->x1) != (old_request.x2 - old_request.x1)) ||
|
|
|
|
((box->y2 - box->y1) != (old_request.y2 - old_request.y1)))
|
|
|
|
texture->priv->sync_actor_size = FALSE;
|
2007-11-23 17:12:27 +00:00
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_texture_parent_class)->request_coords (self, box);
|
2007-11-15 17:38:40 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
static void
|
2006-05-29 08:59:36 +00:00
|
|
|
clutter_texture_dispose (GObject *object)
|
|
|
|
{
|
2007-07-26 11:04:04 +00:00
|
|
|
ClutterTexture *texture = CLUTTER_TEXTURE (object);
|
2006-05-29 08:59:36 +00:00
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
priv = texture->priv;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
texture_free_gl_resources (texture);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
if (priv->local_pixbuf != NULL)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
2007-07-24 17:38:35 +00:00
|
|
|
g_object_unref (priv->local_pixbuf);
|
|
|
|
priv->local_pixbuf = NULL;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
G_OBJECT_CLASS (clutter_texture_parent_class)->dispose (object);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_texture_set_property (GObject *object,
|
2006-05-29 08:59:36 +00:00
|
|
|
guint prop_id,
|
2007-10-12 08:17:00 +00:00
|
|
|
const GValue *value,
|
2006-05-29 08:59:36 +00:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterTexture *texture;
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
|
|
|
texture = CLUTTER_TEXTURE(object);
|
|
|
|
priv = texture->priv;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
switch (prop_id)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
case PROP_PIXBUF:
|
2007-10-25 14:37:41 +00:00
|
|
|
if (g_value_get_object (value))
|
|
|
|
clutter_texture_set_pixbuf (texture,
|
|
|
|
GDK_PIXBUF (g_value_get_object (value)),
|
|
|
|
NULL);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_USE_TILES:
|
2007-03-19 10:00:38 +00:00
|
|
|
priv->is_tiled = g_value_get_boolean (value);
|
2006-07-24 21:15:19 +00:00
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
if (priv->target_type == CGL_TEXTURE_RECTANGLE_ARB && priv->is_tiled)
|
|
|
|
priv->target_type = CGL_TEXTURE_2D;
|
2006-07-24 21:15:19 +00:00
|
|
|
|
2006-11-22 20:52:27 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "Texture is tiled ? %s",
|
2007-03-19 10:00:38 +00:00
|
|
|
priv->is_tiled ? "yes" : "no");
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_MAX_TILE_WASTE:
|
2006-06-06 20:40:40 +00:00
|
|
|
priv->max_tile_waste = g_value_get_int (value);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_SYNC_SIZE:
|
2006-06-13 13:17:45 +00:00
|
|
|
priv->sync_actor_size = g_value_get_boolean (value);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_REPEAT_X:
|
|
|
|
priv->repeat_x = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_REPEAT_Y:
|
|
|
|
priv->repeat_y = g_value_get_boolean (value);
|
|
|
|
break;
|
2006-06-06 20:40:40 +00:00
|
|
|
case PROP_FILTER_QUALITY:
|
|
|
|
priv->filter_quality = g_value_get_int (value);
|
|
|
|
break;
|
2006-05-29 08:59:36 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_texture_get_property (GObject *object,
|
2006-05-29 08:59:36 +00:00
|
|
|
guint prop_id,
|
2007-10-12 08:17:00 +00:00
|
|
|
GValue *value,
|
2006-05-29 08:59:36 +00:00
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ClutterTexture *texture;
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
|
|
|
texture = CLUTTER_TEXTURE(object);
|
|
|
|
priv = texture->priv;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
switch (prop_id)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
case PROP_PIXBUF:
|
2006-09-19 19:27:16 +00:00
|
|
|
{
|
|
|
|
GdkPixbuf *pixb;
|
|
|
|
pixb = clutter_texture_get_pixbuf (texture);
|
2007-08-11 19:28:05 +00:00
|
|
|
g_value_take_object (value, pixb);
|
2006-09-19 19:27:16 +00:00
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_USE_TILES:
|
2007-03-19 10:00:38 +00:00
|
|
|
g_value_set_boolean (value, priv->is_tiled);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_MAX_TILE_WASTE:
|
2006-06-06 20:40:40 +00:00
|
|
|
g_value_set_int (value, priv->max_tile_waste);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_PIXEL_TYPE:
|
|
|
|
g_value_set_int (value, priv->pixel_type);
|
|
|
|
break;
|
|
|
|
case PROP_PIXEL_FORMAT:
|
|
|
|
g_value_set_int (value, priv->pixel_format);
|
|
|
|
break;
|
|
|
|
case PROP_SYNC_SIZE:
|
2006-06-13 13:17:45 +00:00
|
|
|
g_value_set_boolean (value, priv->sync_actor_size);
|
2006-05-29 08:59:36 +00:00
|
|
|
break;
|
|
|
|
case PROP_REPEAT_X:
|
|
|
|
g_value_set_boolean (value, priv->repeat_x);
|
|
|
|
break;
|
|
|
|
case PROP_REPEAT_Y:
|
|
|
|
g_value_set_boolean (value, priv->repeat_y);
|
|
|
|
break;
|
2006-06-06 20:40:40 +00:00
|
|
|
case PROP_FILTER_QUALITY:
|
|
|
|
g_value_set_int (value, priv->filter_quality);
|
|
|
|
break;
|
2006-05-29 08:59:36 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2007-10-12 08:17:00 +00:00
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_texture_class_init (ClutterTextureClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2006-06-13 13:17:45 +00:00
|
|
|
ClutterActorClass *actor_class;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
actor_class = (ClutterActorClass*) klass;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (ClutterTexturePrivate));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-11-15 17:38:40 +00:00
|
|
|
actor_class->paint = clutter_texture_paint;
|
|
|
|
actor_class->realize = clutter_texture_realize;
|
|
|
|
actor_class->unrealize = clutter_texture_unrealize;
|
|
|
|
actor_class->show = clutter_texture_show;
|
|
|
|
actor_class->hide = clutter_texture_hide;
|
|
|
|
actor_class->request_coords = clutter_texture_request_coords;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
gobject_class->dispose = clutter_texture_dispose;
|
|
|
|
gobject_class->set_property = clutter_texture_set_property;
|
|
|
|
gobject_class->get_property = clutter_texture_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_PIXBUF,
|
2007-08-06 12:48:13 +00:00
|
|
|
g_param_spec_object ("pixbuf",
|
|
|
|
"Pixbuf source for Texture.",
|
|
|
|
"Pixbuf source for Texture.",
|
|
|
|
GDK_TYPE_PIXBUF,
|
|
|
|
CLUTTER_PARAM_READWRITE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_USE_TILES,
|
|
|
|
g_param_spec_boolean ("tiled",
|
|
|
|
"Enable use of tiled textures",
|
|
|
|
"Enables the use of tiled GL textures to more "
|
|
|
|
"efficiently use available texture memory",
|
2007-10-12 08:17:00 +00:00
|
|
|
/* FIXME: This default set at runtime :/
|
2006-07-24 21:15:19 +00:00
|
|
|
* As tiling depends on what GL features available.
|
|
|
|
* Need to figure out better solution
|
|
|
|
*/
|
2007-10-12 08:17:00 +00:00
|
|
|
(clutter_feature_available
|
2006-07-24 21:15:19 +00:00
|
|
|
(CLUTTER_FEATURE_TEXTURE_RECTANGLE) == FALSE),
|
2006-12-04 16:26:35 +00:00
|
|
|
G_PARAM_CONSTRUCT_ONLY | CLUTTER_PARAM_READWRITE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_SYNC_SIZE,
|
|
|
|
g_param_spec_boolean ("sync-size",
|
2006-06-13 13:17:45 +00:00
|
|
|
"Sync size of actor",
|
|
|
|
"Auto sync size of actor to underlying pixbuf"
|
2006-05-29 08:59:36 +00:00
|
|
|
"dimentions",
|
|
|
|
TRUE,
|
2007-11-15 17:38:40 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_REPEAT_X,
|
|
|
|
g_param_spec_boolean ("repeat-x",
|
|
|
|
"Tile underlying pixbuf in x direction",
|
2007-10-12 08:17:00 +00:00
|
|
|
"Reapeat underlying pixbuf rather than scale"
|
2006-06-06 20:40:40 +00:00
|
|
|
"in x direction. Currently UNWORKING",
|
2006-05-29 08:59:36 +00:00
|
|
|
FALSE,
|
2007-11-15 17:38:40 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_REPEAT_Y,
|
|
|
|
g_param_spec_boolean ("repeat-y",
|
|
|
|
"Tile underlying pixbuf in y direction",
|
2007-10-12 08:17:00 +00:00
|
|
|
"Reapeat underlying pixbuf rather than scale"
|
2006-06-06 20:40:40 +00:00
|
|
|
"in y direction. Currently UNWORKING",
|
2006-05-29 08:59:36 +00:00
|
|
|
FALSE,
|
2007-11-15 17:38:40 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-06-06 20:40:40 +00:00
|
|
|
/* FIXME: Ideally this option needs to have some kind of global
|
|
|
|
* overide as to imporve performance.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_FILTER_QUALITY,
|
|
|
|
g_param_spec_int ("filter-quality",
|
|
|
|
"Quality of filter used when scaling a texture",
|
|
|
|
"Values 0 and 1 current only supported, with 0"
|
|
|
|
"being lower quality but fast, 1 being better "
|
|
|
|
"quality but slower. ( Currently just maps to "
|
|
|
|
" GL_NEAREST / GL_LINEAR )",
|
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
1,
|
2007-11-15 17:38:40 +00:00
|
|
|
CLUTTER_PARAM_READWRITE));
|
2006-06-06 20:40:40 +00:00
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_MAX_TILE_WASTE,
|
|
|
|
g_param_spec_int ("tile-waste",
|
|
|
|
"Tile dimention to waste",
|
2006-06-06 20:40:40 +00:00
|
|
|
"Max wastage dimention of a texture when using "
|
|
|
|
"tiled textures. Bigger values use less textures, "
|
2006-05-29 08:59:36 +00:00
|
|
|
"smaller values less texture memory. ",
|
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
64,
|
2006-12-04 16:26:35 +00:00
|
|
|
G_PARAM_CONSTRUCT_ONLY | CLUTTER_PARAM_READWRITE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_PIXEL_TYPE,
|
|
|
|
g_param_spec_int ("pixel-type",
|
|
|
|
"Texture Pixel Type",
|
|
|
|
"GL texture pixel type used",
|
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
PIXEL_TYPE,
|
2007-05-25 10:56:09 +00:00
|
|
|
G_PARAM_READABLE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_PIXEL_FORMAT,
|
|
|
|
g_param_spec_int ("pixel-format",
|
|
|
|
"Texture pixel format",
|
|
|
|
"GL texture pixel format used",
|
|
|
|
0,
|
|
|
|
G_MAXINT,
|
2007-04-27 21:13:06 +00:00
|
|
|
CGL_RGBA,
|
2007-05-25 10:56:09 +00:00
|
|
|
G_PARAM_READABLE));
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-12-13 18:12:09 +00:00
|
|
|
/**
|
|
|
|
* ClutterTexture::size-change:
|
|
|
|
* @texture: the texture which received the signal
|
|
|
|
* @width: the width of the new texture
|
|
|
|
* @height: the height of the new texture
|
|
|
|
*
|
|
|
|
* The ::size-change signal is emitted each time the size of the
|
|
|
|
* pixbuf used by @texture changes. The new size is given as
|
|
|
|
* argument to the callback.
|
|
|
|
*/
|
|
|
|
texture_signals[SIZE_CHANGE] =
|
2006-05-29 08:59:36 +00:00
|
|
|
g_signal_new ("size-change",
|
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (ClutterTextureClass, size_change),
|
|
|
|
NULL, NULL,
|
|
|
|
clutter_marshal_VOID__INT_INT,
|
2007-10-12 08:17:00 +00:00
|
|
|
G_TYPE_NONE,
|
2006-05-29 08:59:36 +00:00
|
|
|
2, G_TYPE_INT, G_TYPE_INT);
|
2006-12-13 18:12:09 +00:00
|
|
|
/**
|
|
|
|
* ClutterTexture::pixbuf-change:
|
|
|
|
* @texture: the texture which received the signal
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2006-12-13 18:12:09 +00:00
|
|
|
* The ::pixbuf-change signal is emitted each time the pixbuf
|
|
|
|
* used by @texture changes.
|
|
|
|
*/
|
|
|
|
texture_signals[PIXBUF_CHANGE] =
|
2006-05-29 08:59:36 +00:00
|
|
|
g_signal_new ("pixbuf-change",
|
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (ClutterTextureClass, pixbuf_change),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
2007-10-12 08:17:00 +00:00
|
|
|
G_TYPE_NONE,
|
|
|
|
0);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_texture_init (ClutterTexture *self)
|
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
self->priv = priv = CLUTTER_TEXTURE_GET_PRIVATE (self);
|
2006-06-08 21:28:05 +00:00
|
|
|
|
2007-11-15 17:38:40 +00:00
|
|
|
priv->max_tile_waste = 64;
|
2007-11-20 15:45:59 +00:00
|
|
|
priv->filter_quality = 1;
|
2007-11-15 17:38:40 +00:00
|
|
|
priv->is_tiled = TRUE;
|
|
|
|
priv->pixel_type = PIXEL_TYPE;
|
|
|
|
priv->pixel_format = CGL_RGBA;
|
|
|
|
priv->repeat_x = FALSE;
|
|
|
|
priv->repeat_y = FALSE;
|
|
|
|
priv->sync_actor_size = TRUE;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-07-24 21:15:19 +00:00
|
|
|
if (clutter_feature_available (CLUTTER_FEATURE_TEXTURE_RECTANGLE))
|
|
|
|
{
|
2007-11-15 17:38:40 +00:00
|
|
|
priv->target_type = CGL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
priv->is_tiled = FALSE;
|
2006-07-24 21:15:19 +00:00
|
|
|
}
|
|
|
|
else
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->target_type = CGL_TEXTURE_2D;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
static void
|
|
|
|
pixbuf_destroy_notify (guchar *pixels, gpointer data)
|
|
|
|
{
|
|
|
|
g_free (pixels);
|
|
|
|
}
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_get_pixbuf:
|
|
|
|
* @texture: A #ClutterTexture
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* Gets a #GdkPixbuf representation of the #ClutterTexture data.
|
|
|
|
* The created #GdkPixbuf is not owned by the texture but the caller.
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
2006-09-19 19:27:16 +00:00
|
|
|
* Return value: A #GdkPixbuf
|
2006-05-29 08:59:36 +00:00
|
|
|
**/
|
|
|
|
GdkPixbuf*
|
|
|
|
clutter_texture_get_pixbuf (ClutterTexture* texture)
|
|
|
|
{
|
2007-05-25 10:56:09 +00:00
|
|
|
#if HAVE_COGL_GL
|
2006-09-19 19:27:16 +00:00
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
guchar *pixels = NULL;
|
2007-03-19 17:02:48 +00:00
|
|
|
int bpp = 4;
|
2006-09-19 19:27:16 +00:00
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
if (priv->tiles == NULL)
|
2007-10-12 08:17:00 +00:00
|
|
|
return NULL;
|
2006-09-19 19:27:16 +00:00
|
|
|
|
2007-06-22 15:16:40 +00:00
|
|
|
if (priv->pixel_format == CGL_YCBCR_MESA)
|
|
|
|
return NULL; /* FIXME: convert YUV */
|
|
|
|
|
|
|
|
if (priv->pixel_format == CGL_RGB || priv->pixel_format == CGL_BGR)
|
2007-03-19 17:02:48 +00:00
|
|
|
bpp = 3;
|
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
if (!priv->is_tiled)
|
2006-09-19 19:27:16 +00:00
|
|
|
{
|
2007-04-19 15:24:20 +00:00
|
|
|
pixels = g_malloc (((priv->width * bpp + 3) &~ 3) * priv->height);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-04-19 15:24:20 +00:00
|
|
|
if (!pixels)
|
2006-09-19 19:27:16 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
glBindTexture(priv->target_type, priv->tiles[0]);
|
|
|
|
|
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, priv->width);
|
|
|
|
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
|
|
|
|
|
|
|
|
/* read data from gl text and return as pixbuf */
|
2007-04-27 21:13:06 +00:00
|
|
|
/* No such func in gles... */
|
2006-09-19 19:27:16 +00:00
|
|
|
glGetTexImage (priv->target_type,
|
|
|
|
0,
|
2007-10-12 08:17:00 +00:00
|
|
|
(priv->pixel_format == CGL_RGBA
|
|
|
|
|| priv->pixel_format == CGL_BGRA) ?
|
|
|
|
CGL_RGBA : CGL_RGB,
|
2007-06-22 15:16:40 +00:00
|
|
|
PIXEL_TYPE,
|
2006-09-19 19:27:16 +00:00
|
|
|
(GLvoid*)pixels);
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_data ((const guchar*)pixels,
|
|
|
|
GDK_COLORSPACE_RGB,
|
2007-06-22 15:16:40 +00:00
|
|
|
(priv->pixel_format == CGL_RGBA
|
|
|
|
|| priv->pixel_format == CGL_BGRA),
|
2006-09-19 19:27:16 +00:00
|
|
|
8,
|
|
|
|
priv->width,
|
|
|
|
priv->height,
|
2007-04-19 15:24:20 +00:00
|
|
|
((priv->width * bpp + 3) &~ 3),
|
2006-09-19 19:27:16 +00:00
|
|
|
pixbuf_destroy_notify,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int x,y,i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
|
2007-06-22 15:16:40 +00:00
|
|
|
(priv->pixel_format == CGL_RGBA
|
|
|
|
|| priv->pixel_format == CGL_BGRA),
|
2006-09-19 19:27:16 +00:00
|
|
|
8,
|
|
|
|
priv->width,
|
|
|
|
priv->height);
|
|
|
|
|
2007-04-19 15:24:20 +00:00
|
|
|
for (x = 0; x < priv->n_x_tiles; x++)
|
|
|
|
for (y = 0; y < priv->n_y_tiles; y++)
|
2006-09-19 19:27:16 +00:00
|
|
|
{
|
|
|
|
GdkPixbuf *tmp_pixb;
|
|
|
|
gint src_h, src_w;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
src_w = priv->x_tiles[x].size;
|
|
|
|
src_h = priv->y_tiles[y].size;
|
|
|
|
|
2007-07-29 22:55:04 +00:00
|
|
|
pixels = g_malloc (((src_w * bpp + 3) &~ 3) * src_h);
|
2006-09-19 19:27:16 +00:00
|
|
|
|
|
|
|
glBindTexture(priv->target_type, priv->tiles[i]);
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, src_w);
|
|
|
|
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
|
|
|
|
|
|
|
|
glGetTexImage (priv->target_type,
|
|
|
|
0,
|
2007-10-12 08:17:00 +00:00
|
|
|
(priv->pixel_format == CGL_RGBA
|
|
|
|
|| priv->pixel_format == CGL_BGRA) ?
|
|
|
|
CGL_RGBA : CGL_RGB,
|
2007-06-22 15:16:40 +00:00
|
|
|
PIXEL_TYPE,
|
2007-04-19 15:24:20 +00:00
|
|
|
(GLvoid *) pixels);
|
|
|
|
|
|
|
|
tmp_pixb =
|
|
|
|
gdk_pixbuf_new_from_data ((const guchar*)pixels,
|
|
|
|
GDK_COLORSPACE_RGB,
|
2007-06-22 15:16:40 +00:00
|
|
|
(priv->pixel_format == CGL_RGBA
|
|
|
|
|| priv->pixel_format == CGL_BGRA),
|
2007-04-19 15:24:20 +00:00
|
|
|
8,
|
|
|
|
src_w,
|
|
|
|
src_h,
|
|
|
|
((src_w * bpp + 3) &~ 3),
|
|
|
|
pixbuf_destroy_notify,
|
|
|
|
NULL);
|
2007-07-29 22:55:04 +00:00
|
|
|
|
|
|
|
/* Clip */
|
|
|
|
if (priv->x_tiles[x].pos + src_w > priv->width)
|
|
|
|
src_w = priv->width - priv->x_tiles[x].pos;
|
|
|
|
|
|
|
|
if (priv->y_tiles[y].pos + src_h > priv->height)
|
|
|
|
src_h = priv->height - priv->y_tiles[y].pos;
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
gdk_pixbuf_copy_area (tmp_pixb,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
src_w,
|
|
|
|
src_h,
|
|
|
|
pixbuf,
|
|
|
|
priv->x_tiles[x].pos,
|
2007-08-11 19:28:05 +00:00
|
|
|
priv->y_tiles[y].pos);
|
2006-09-19 19:27:16 +00:00
|
|
|
|
|
|
|
g_object_unref (tmp_pixb);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2007-06-22 15:16:40 +00:00
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pixbuf;
|
2007-04-27 21:13:06 +00:00
|
|
|
#else
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
/* FIXME: func call wont work for GLES...
|
2007-04-27 21:13:06 +00:00
|
|
|
* features need to reflect this.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
2007-12-20 14:26:07 +00:00
|
|
|
/* internal helper function for initialization of
|
|
|
|
* clutter_texture_set_from_rgb_data and clutter_texture_set_area_from_rgb_data.
|
|
|
|
*/
|
|
|
|
static inline gboolean
|
|
|
|
texture_prepare_upload (gboolean initialize,
|
|
|
|
ClutterTexture *texture,
|
|
|
|
const guchar *data,
|
|
|
|
gboolean has_alpha,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint rowstride,
|
|
|
|
gint bpp,
|
|
|
|
ClutterTextureFlags flags,
|
|
|
|
guchar **copy_data,
|
|
|
|
gboolean *texture_dirty,
|
|
|
|
gboolean *size_change)
|
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
COGLenum prev_format;
|
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (data != NULL, FALSE);
|
|
|
|
/* Needed for GL_RGBA (internal format) and gdk pixbuf usage */
|
|
|
|
g_return_val_if_fail (bpp == 4, FALSE);
|
|
|
|
|
|
|
|
if (initialize)
|
|
|
|
{
|
|
|
|
*texture_dirty = *size_change =
|
|
|
|
(width != priv->width || height != priv->height) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_format = priv->pixel_format;
|
|
|
|
|
|
|
|
if (has_alpha)
|
|
|
|
priv->pixel_format = CGL_RGBA;
|
|
|
|
else
|
|
|
|
priv->pixel_format = CGL_RGB;
|
|
|
|
|
|
|
|
if (flags & CLUTTER_TEXTURE_RGB_FLAG_BGR)
|
|
|
|
{
|
|
|
|
#if HAVE_COGL_GL
|
|
|
|
if (has_alpha)
|
|
|
|
priv->pixel_format = CGL_BGRA;
|
|
|
|
else
|
|
|
|
priv->pixel_format = CGL_BGR;
|
|
|
|
#else
|
|
|
|
/* GLES has no BGR format*/
|
|
|
|
*copy_data = rgb_to_bgr (data, has_alpha, width, height, rowstride);
|
|
|
|
#endif /* HAVE_COGL_GL */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & CLUTTER_TEXTURE_RGB_FLAG_PREMULT)
|
|
|
|
*copy_data = un_pre_multiply_alpha (data, width, height, rowstride);
|
|
|
|
|
|
|
|
if (initialize)
|
|
|
|
{
|
|
|
|
if (prev_format != priv->pixel_format || priv->pixel_type != PIXEL_TYPE)
|
|
|
|
*texture_dirty = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (prev_format != priv->pixel_format || priv->pixel_type != PIXEL_TYPE)
|
|
|
|
{
|
|
|
|
g_warning ("%s: pixel format or type mismatch", G_STRFUNC);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->pixel_type = PIXEL_TYPE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
/**
|
2007-05-25 10:56:09 +00:00
|
|
|
* clutter_texture_set_from_rgb_data:
|
2006-06-22 09:14:35 +00:00
|
|
|
* @texture: A #ClutterTexture
|
2006-09-19 19:27:16 +00:00
|
|
|
* @data: Image data in RGB type colorspace.
|
|
|
|
* @has_alpha: Set to TRUE if image data has a alpha channel.
|
|
|
|
* @width: Width in pixels of image data.
|
|
|
|
* @height: Height in pixels of image data
|
|
|
|
* @rowstride: Distance in bytes between row starts.
|
|
|
|
* @bpp: bytes per pixel ( Currently only 4 supported )
|
2007-05-25 10:56:09 +00:00
|
|
|
* @flags: #ClutterTextureFlags
|
2007-12-24 16:24:26 +00:00
|
|
|
* @error: return location for a #GError, or %NULL.
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
2006-09-19 19:27:16 +00:00
|
|
|
* Sets #ClutterTexture image data.
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
2007-12-24 16:24:26 +00:00
|
|
|
* Note: This function is likely to change in future versions.
|
2007-05-25 10:56:09 +00:00
|
|
|
*
|
2007-12-24 16:24:26 +00:00
|
|
|
* Return value: %TRUE on success, %FALSE on failure.
|
|
|
|
*
|
|
|
|
* Since: 0.4.
|
2006-05-29 08:59:36 +00:00
|
|
|
**/
|
2007-10-12 08:17:00 +00:00
|
|
|
gboolean
|
2007-05-25 10:56:09 +00:00
|
|
|
clutter_texture_set_from_rgb_data (ClutterTexture *texture,
|
|
|
|
const guchar *data,
|
|
|
|
gboolean has_alpha,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint rowstride,
|
|
|
|
gint bpp,
|
|
|
|
ClutterTextureFlags flags,
|
2007-06-06 14:27:52 +00:00
|
|
|
GError **error)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
2007-06-22 15:16:40 +00:00
|
|
|
guchar *copy_data = NULL;
|
2007-12-20 14:26:07 +00:00
|
|
|
gboolean texture_dirty = TRUE, size_change = FALSE;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
priv = texture->priv;
|
2007-12-20 14:26:07 +00:00
|
|
|
if (!texture_prepare_upload (TRUE, texture, data, has_alpha, width, height, rowstride,
|
|
|
|
bpp, flags, ©_data, &texture_dirty, &size_change))
|
2007-05-25 10:56:09 +00:00
|
|
|
{
|
2007-12-20 14:26:07 +00:00
|
|
|
return FALSE;
|
2007-05-25 10:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->width = width;
|
|
|
|
priv->height = height;
|
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
if (texture_dirty)
|
2006-07-24 21:15:19 +00:00
|
|
|
{
|
2006-09-19 19:27:16 +00:00
|
|
|
texture_free_gl_resources (texture);
|
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
if (priv->is_tiled == FALSE)
|
2006-07-24 21:15:19 +00:00
|
|
|
{
|
2007-07-24 17:38:35 +00:00
|
|
|
if (priv->target_type == CGL_TEXTURE_RECTANGLE_ARB &&
|
|
|
|
!cogl_texture_can_size (CGL_TEXTURE_RECTANGLE_ARB,
|
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
2007-10-12 08:17:00 +00:00
|
|
|
priv->width,
|
2007-07-24 17:38:35 +00:00
|
|
|
priv->height))
|
2006-09-19 19:27:16 +00:00
|
|
|
{
|
|
|
|
/* If we cant create NPOT tex of this size fall back to tiles */
|
2007-10-12 08:17:00 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE,
|
2007-05-04 23:53:49 +00:00
|
|
|
"Cannot make npots of size %ix%i "
|
|
|
|
"falling back to tiled",
|
|
|
|
priv->width,
|
|
|
|
priv->height);
|
|
|
|
|
2007-04-27 21:13:06 +00:00
|
|
|
priv->target_type = CGL_TEXTURE_2D;
|
2006-09-19 19:27:16 +00:00
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
if (priv->target_type == CGL_TEXTURE_2D &&
|
|
|
|
!cogl_texture_can_size (CGL_TEXTURE_2D,
|
2007-10-12 08:17:00 +00:00
|
|
|
priv->pixel_format,
|
2007-07-24 17:38:35 +00:00
|
|
|
priv->pixel_type,
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_util_next_p2 (priv->width),
|
2007-07-24 17:38:35 +00:00
|
|
|
clutter_util_next_p2 (priv->height)))
|
2007-10-12 08:17:00 +00:00
|
|
|
{
|
|
|
|
priv->is_tiled = TRUE;
|
2006-09-19 19:27:16 +00:00
|
|
|
}
|
2006-07-24 21:15:19 +00:00
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
/* Figure our tiling etc */
|
2007-03-19 10:00:38 +00:00
|
|
|
if (priv->is_tiled)
|
2007-10-12 08:17:00 +00:00
|
|
|
texture_init_tiles (texture);
|
2006-09-19 19:27:16 +00:00
|
|
|
}
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-11-22 20:52:27 +00:00
|
|
|
CLUTTER_NOTE (TEXTURE, "set size %ix%i\n",
|
|
|
|
priv->width,
|
|
|
|
priv->height);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-05-25 10:56:09 +00:00
|
|
|
/* Set Error from this */
|
2007-10-12 08:17:00 +00:00
|
|
|
texture_upload_data (texture,
|
|
|
|
copy_data != NULL ? copy_data : data,
|
|
|
|
has_alpha,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
rowstride,
|
2007-05-25 10:56:09 +00:00
|
|
|
bpp);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
CLUTTER_ACTOR_SET_FLAGS (CLUTTER_ACTOR (texture), CLUTTER_ACTOR_REALIZED);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2007-06-07 23:51:53 +00:00
|
|
|
if (size_change)
|
2006-09-19 19:27:16 +00:00
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
g_signal_emit (texture, texture_signals[SIZE_CHANGE],
|
2006-09-19 19:27:16 +00:00
|
|
|
0, priv->width, priv->height);
|
|
|
|
|
|
|
|
if (priv->sync_actor_size)
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_actor_set_size (CLUTTER_ACTOR(texture),
|
|
|
|
priv->width,
|
2006-09-19 19:27:16 +00:00
|
|
|
priv->height);
|
|
|
|
}
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2006-09-19 19:27:16 +00:00
|
|
|
/* rename signal */
|
2007-10-12 08:17:00 +00:00
|
|
|
g_signal_emit (texture, texture_signals[PIXBUF_CHANGE], 0);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
2006-06-13 13:17:45 +00:00
|
|
|
/* If resized actor may need resizing but paint() will do this */
|
|
|
|
if (CLUTTER_ACTOR_IS_MAPPED (CLUTTER_ACTOR(texture)))
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR(texture));
|
2006-09-19 19:27:16 +00:00
|
|
|
|
2007-06-22 15:16:40 +00:00
|
|
|
if (copy_data != NULL)
|
|
|
|
g_free (copy_data);
|
|
|
|
|
2007-05-25 10:56:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_texture_set_from_yuv_data:
|
|
|
|
* @texture: A #ClutterTexture
|
|
|
|
* @data: Image data in RGB type colorspace.
|
|
|
|
* @width: Width in pixels of image data.
|
|
|
|
* @height: Height in pixels of image data
|
|
|
|
* @flags: #ClutterTextureFlags
|
2007-07-24 17:38:35 +00:00
|
|
|
* @error: Return location for a #GError, or %NULL.
|
2007-05-25 10:56:09 +00:00
|
|
|
*
|
2007-07-24 17:38:35 +00:00
|
|
|
* Sets a #ClutterTexture from YUV image data. If an error occurred,
|
|
|
|
* %FALSE is returned and @error is set.
|
2007-05-25 10:56:09 +00:00
|
|
|
*
|
2007-07-24 17:38:35 +00:00
|
|
|
* This function is likely to change in future versions.
|
2007-05-25 10:56:09 +00:00
|
|
|
*
|
2007-07-24 17:38:35 +00:00
|
|
|
* Return value: %TRUE if the texture was successfully updated
|
|
|
|
*
|
|
|
|
* Since 0.4.
|
2007-05-25 10:56:09 +00:00
|
|
|
**/
|
2007-10-12 08:17:00 +00:00
|
|
|
gboolean
|
2007-05-25 10:56:09 +00:00
|
|
|
clutter_texture_set_from_yuv_data (ClutterTexture *texture,
|
|
|
|
const guchar *data,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
ClutterTextureFlags flags,
|
2007-06-06 14:27:52 +00:00
|
|
|
GError **error)
|
2007-05-25 10:56:09 +00:00
|
|
|
{
|
2007-06-07 23:51:53 +00:00
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
gboolean texture_dirty = TRUE, size_change = FALSE;
|
2007-05-25 10:56:09 +00:00
|
|
|
|
2007-07-24 17:38:35 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE);
|
|
|
|
|
|
|
|
if (!clutter_feature_available (CLUTTER_FEATURE_TEXTURE_YUV))
|
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_TEXTURE_ERROR,
|
|
|
|
CLUTTER_TEXTURE_ERROR_NO_YUV,
|
|
|
|
"YUV textures are not supported");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-05-25 10:56:09 +00:00
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
/* FIXME: check other image props */
|
2007-06-07 23:51:53 +00:00
|
|
|
size_change = (width != priv->width || height != priv->height);
|
|
|
|
texture_dirty = size_change || (priv->pixel_format != CGL_YCBCR_MESA);
|
2007-05-25 10:56:09 +00:00
|
|
|
|
|
|
|
priv->width = width;
|
|
|
|
priv->height = height;
|
2007-06-07 23:51:53 +00:00
|
|
|
priv->pixel_type = (flags & CLUTTER_TEXTURE_YUV_FLAG_YUV2) ?
|
2007-10-12 08:17:00 +00:00
|
|
|
CGL_UNSIGNED_SHORT_8_8_REV_MESA :
|
2007-06-07 23:51:53 +00:00
|
|
|
CGL_UNSIGNED_SHORT_8_8_MESA;
|
2007-05-25 10:56:09 +00:00
|
|
|
priv->pixel_format = CGL_YCBCR_MESA;
|
2007-06-07 23:51:53 +00:00
|
|
|
priv->target_type = CGL_TEXTURE_2D;
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
if (texture_dirty)
|
2007-06-07 23:51:53 +00:00
|
|
|
texture_free_gl_resources (texture);
|
2007-05-25 10:56:09 +00:00
|
|
|
|
|
|
|
if (!priv->tiles)
|
|
|
|
{
|
2007-10-26 22:06:45 +00:00
|
|
|
priv->tiles = g_new (COGLuint, 1);
|
2007-05-25 10:56:09 +00:00
|
|
|
glGenTextures (1, priv->tiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[0]);
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
cogl_texture_set_filters (priv->target_type,
|
2007-05-25 10:56:09 +00:00
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST,
|
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST);
|
|
|
|
|
|
|
|
if (texture_dirty)
|
|
|
|
{
|
2007-07-24 17:38:35 +00:00
|
|
|
gint new_width, new_height;
|
|
|
|
|
|
|
|
new_width = clutter_util_next_p2 (priv->width);
|
|
|
|
new_height = clutter_util_next_p2 (priv->height);
|
|
|
|
|
2007-06-07 23:51:53 +00:00
|
|
|
/* FIXME: need to check size limits correctly - does not
|
2007-07-24 17:38:35 +00:00
|
|
|
* seem to work if correct format and type are used so
|
2007-06-07 23:51:53 +00:00
|
|
|
* this is really a guess...
|
|
|
|
*/
|
|
|
|
if (cogl_texture_can_size (CGL_TEXTURE_2D,
|
2007-10-12 08:17:00 +00:00
|
|
|
CGL_RGBA,
|
2007-06-07 23:51:53 +00:00
|
|
|
CGL_UNSIGNED_BYTE,
|
2007-07-24 17:38:35 +00:00
|
|
|
new_width, new_height))
|
2007-05-25 10:56:09 +00:00
|
|
|
{
|
2007-06-07 23:51:53 +00:00
|
|
|
cogl_texture_image_2d (priv->target_type,
|
|
|
|
priv->pixel_format,
|
2007-07-24 17:38:35 +00:00
|
|
|
new_width, new_height,
|
|
|
|
priv->pixel_format,
|
2007-06-07 23:51:53 +00:00
|
|
|
priv->pixel_type,
|
|
|
|
NULL);
|
2007-05-25 10:56:09 +00:00
|
|
|
}
|
|
|
|
else
|
2007-07-24 17:38:35 +00:00
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_TEXTURE_ERROR,
|
|
|
|
CLUTTER_TEXTURE_ERROR_OUT_OF_MEMORY,
|
|
|
|
"Unable to allocate a texture of %d by %d pixels",
|
|
|
|
new_width,
|
|
|
|
new_height);
|
|
|
|
|
|
|
|
return FALSE; /* FIXME: add tiling */
|
|
|
|
}
|
2007-05-25 10:56:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-07 23:51:53 +00:00
|
|
|
cogl_texture_sub_image_2d (priv->target_type,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
priv->width,
|
|
|
|
priv->height,
|
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
|
|
|
data);
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_SET_FLAGS (CLUTTER_ACTOR (texture), CLUTTER_ACTOR_REALIZED);
|
|
|
|
|
|
|
|
if (size_change)
|
2007-05-25 10:56:09 +00:00
|
|
|
{
|
2007-10-12 08:17:00 +00:00
|
|
|
g_signal_emit (texture, texture_signals[SIZE_CHANGE],
|
2007-06-07 23:51:53 +00:00
|
|
|
0, priv->width, priv->height);
|
|
|
|
|
|
|
|
if (priv->sync_actor_size)
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_actor_set_size (CLUTTER_ACTOR(texture),
|
|
|
|
priv->width,
|
2007-06-07 23:51:53 +00:00
|
|
|
priv->height);
|
2007-05-25 10:56:09 +00:00
|
|
|
}
|
2007-06-07 23:51:53 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
g_signal_emit (texture, texture_signals[PIXBUF_CHANGE], 0);
|
2007-06-07 23:51:53 +00:00
|
|
|
|
|
|
|
if (CLUTTER_ACTOR_IS_MAPPED (CLUTTER_ACTOR(texture)))
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR(texture));
|
|
|
|
|
|
|
|
return TRUE;
|
2006-09-19 19:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_texture_set_pixbuf:
|
|
|
|
* @texture: A #ClutterTexture
|
|
|
|
* @pixbuf: A #GdkPixbuf
|
2007-07-24 17:38:35 +00:00
|
|
|
* @error: Return location for a #GError, or %NULL
|
2006-09-19 19:27:16 +00:00
|
|
|
*
|
2007-07-24 17:38:35 +00:00
|
|
|
* Sets a #ClutterTexture image data from a #GdkPixbuf. In case of
|
|
|
|
* failure, %FALSE is returned and @error is set.
|
2006-09-19 19:27:16 +00:00
|
|
|
*
|
2007-07-24 17:38:35 +00:00
|
|
|
* Return value: %TRUE if the pixbuf was successfully set
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-05-25 10:56:09 +00:00
|
|
|
gboolean
|
2007-03-19 10:00:38 +00:00
|
|
|
clutter_texture_set_pixbuf (ClutterTexture *texture,
|
2007-05-25 10:56:09 +00:00
|
|
|
GdkPixbuf *pixbuf,
|
2007-06-06 14:27:52 +00:00
|
|
|
GError **error)
|
2006-09-19 19:27:16 +00:00
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
2007-05-25 10:56:09 +00:00
|
|
|
g_return_val_if_fail (pixbuf != NULL, FALSE);
|
|
|
|
|
|
|
|
return clutter_texture_set_from_rgb_data (texture,
|
|
|
|
gdk_pixbuf_get_pixels (pixbuf),
|
|
|
|
gdk_pixbuf_get_has_alpha (pixbuf),
|
|
|
|
gdk_pixbuf_get_width (pixbuf),
|
|
|
|
gdk_pixbuf_get_height (pixbuf),
|
|
|
|
gdk_pixbuf_get_rowstride (pixbuf),
|
|
|
|
4,
|
|
|
|
0,
|
|
|
|
error);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_new_from_pixbuf:
|
2006-05-29 08:59:36 +00:00
|
|
|
* @pixbuf: A #GdkPixbuf
|
|
|
|
*
|
|
|
|
* Creates a new #ClutterTexture object.
|
|
|
|
*
|
|
|
|
* Return value: A newly created #ClutterTexture object.
|
|
|
|
**/
|
2006-06-13 13:17:45 +00:00
|
|
|
ClutterActor*
|
2006-05-29 08:59:36 +00:00
|
|
|
clutter_texture_new_from_pixbuf (GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
ClutterTexture *texture;
|
|
|
|
|
|
|
|
texture = g_object_new (CLUTTER_TYPE_TEXTURE, "pixbuf", pixbuf, NULL);
|
|
|
|
|
2006-06-13 13:17:45 +00:00
|
|
|
return CLUTTER_ACTOR(texture);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_new:
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
|
|
|
* Creates a new empty #ClutterTexture object.
|
|
|
|
*
|
|
|
|
* Return value: A newly created #ClutterTexture object.
|
|
|
|
**/
|
2007-03-19 10:00:38 +00:00
|
|
|
ClutterActor *
|
2006-05-29 08:59:36 +00:00
|
|
|
clutter_texture_new (void)
|
|
|
|
{
|
2007-03-19 10:00:38 +00:00
|
|
|
return g_object_new (CLUTTER_TYPE_TEXTURE, NULL);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_get_base_size:
|
2006-05-29 08:59:36 +00:00
|
|
|
* @texture: A #ClutterTexture
|
|
|
|
* @width: Pointer to gint to be populated with width value if non NULL.
|
|
|
|
* @height: Pointer to gint to be populated with height value if non NULL.
|
|
|
|
*
|
|
|
|
* Gets the size in pixels of the untransformed underlying texture pixbuf data.
|
|
|
|
*
|
|
|
|
**/
|
2006-09-19 19:27:16 +00:00
|
|
|
void /* FIXME: rename to get_image_size */
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_texture_get_base_size (ClutterTexture *texture,
|
2006-05-29 08:59:36 +00:00
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
2006-06-20 20:29:45 +00:00
|
|
|
/* Attempt to realize, mainly for subclasses ( such as labels )
|
|
|
|
* which maynot create pixbuf data and thus base size until
|
|
|
|
* realization happens.
|
|
|
|
*/
|
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED(CLUTTER_ACTOR(texture)))
|
|
|
|
clutter_actor_realize (CLUTTER_ACTOR(texture));
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
if (width)
|
|
|
|
*width = texture->priv->width;
|
|
|
|
|
|
|
|
if (height)
|
|
|
|
*height = texture->priv->height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_bind_tile:
|
|
|
|
* @texture: A #ClutterTexture
|
2007-07-26 11:04:04 +00:00
|
|
|
* @index_: Tile index to bind
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* Proxys a call to glBindTexture a to bind an internal 'tile'.
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* This function is only useful for sub class implementations
|
2006-05-29 08:59:36 +00:00
|
|
|
* and never should be called by an application.
|
|
|
|
**/
|
|
|
|
void
|
2007-07-26 11:04:04 +00:00
|
|
|
clutter_texture_bind_tile (ClutterTexture *texture,
|
|
|
|
gint index_)
|
2006-05-29 08:59:36 +00:00
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
2007-07-26 11:04:04 +00:00
|
|
|
g_return_if_fail (CLUTTER_IS_TEXTURE (texture));
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
priv = texture->priv;
|
2007-07-26 11:04:04 +00:00
|
|
|
|
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[index_]);
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_get_n_tiles:
|
|
|
|
* @texture: A #ClutterTexture
|
2006-05-29 08:59:36 +00:00
|
|
|
* @n_x_tiles: Location to store number of tiles in horizonally axis
|
|
|
|
* @n_y_tiles: Location to store number of tiles in vertical axis
|
|
|
|
*
|
|
|
|
* Retreives internal tile dimentioning.
|
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* This function is only useful for sub class implementations
|
2006-05-29 08:59:36 +00:00
|
|
|
* and never should be called by an application.
|
|
|
|
**/
|
|
|
|
void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_texture_get_n_tiles (ClutterTexture *texture,
|
2006-05-29 08:59:36 +00:00
|
|
|
gint *n_x_tiles,
|
|
|
|
gint *n_y_tiles)
|
|
|
|
{
|
|
|
|
if (n_x_tiles)
|
|
|
|
*n_x_tiles = texture->priv->n_x_tiles;
|
|
|
|
|
|
|
|
if (n_y_tiles)
|
|
|
|
*n_y_tiles = texture->priv->n_y_tiles;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_get_x_tile_detail:
|
|
|
|
* @texture: A #ClutterTexture
|
2006-05-29 08:59:36 +00:00
|
|
|
* @x_index: X index of tile to query
|
|
|
|
* @pos: Location to store tiles X position
|
2007-10-12 08:17:00 +00:00
|
|
|
* @size: Location to store tiles horizontal size in pixels
|
2006-05-29 08:59:36 +00:00
|
|
|
* @waste: Location to store tiles horizontal wastage in pixels
|
|
|
|
*
|
|
|
|
* Retreives details of a tile on x axis.
|
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* This function is only useful for sub class implementations
|
2006-05-29 08:59:36 +00:00
|
|
|
* and never should be called by an application.
|
|
|
|
**/
|
|
|
|
void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_texture_get_x_tile_detail (ClutterTexture *texture,
|
2006-05-29 08:59:36 +00:00
|
|
|
gint x_index,
|
|
|
|
gint *pos,
|
|
|
|
gint *size,
|
|
|
|
gint *waste)
|
|
|
|
{
|
|
|
|
g_return_if_fail(x_index < texture->priv->n_x_tiles);
|
|
|
|
|
|
|
|
if (pos)
|
|
|
|
*pos = texture->priv->x_tiles[x_index].pos;
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
*size = texture->priv->x_tiles[x_index].size;
|
|
|
|
|
|
|
|
if (waste)
|
|
|
|
*waste = texture->priv->x_tiles[x_index].waste;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_get_y_tile_detail:
|
|
|
|
* @texture: A #ClutterTexture
|
|
|
|
* @y_index: Y index of tile to query
|
2006-05-29 08:59:36 +00:00
|
|
|
* @pos: Location to store tiles Y position
|
2007-10-12 08:17:00 +00:00
|
|
|
* @size: Location to store tiles vertical size in pixels
|
2006-05-29 08:59:36 +00:00
|
|
|
* @waste: Location to store tiles vertical wastage in pixels
|
|
|
|
*
|
|
|
|
* Retreives details of a tile on y axis.
|
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* This function is only useful for sub class implementations
|
2006-05-29 08:59:36 +00:00
|
|
|
* and never should be called by an application.
|
|
|
|
**/
|
|
|
|
void
|
2007-10-12 08:17:00 +00:00
|
|
|
clutter_texture_get_y_tile_detail (ClutterTexture *texture,
|
2006-05-29 08:59:36 +00:00
|
|
|
gint y_index,
|
|
|
|
gint *pos,
|
|
|
|
gint *size,
|
|
|
|
gint *waste)
|
|
|
|
{
|
2007-03-19 10:00:38 +00:00
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (CLUTTER_IS_TEXTURE (texture));
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-03-19 10:00:38 +00:00
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
g_return_if_fail (y_index < priv->n_y_tiles);
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
if (pos)
|
2007-03-19 10:00:38 +00:00
|
|
|
*pos = priv->y_tiles[y_index].pos;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
if (size)
|
2007-03-19 10:00:38 +00:00
|
|
|
*size = priv->y_tiles[y_index].size;
|
2006-05-29 08:59:36 +00:00
|
|
|
|
|
|
|
if (waste)
|
2007-03-19 10:00:38 +00:00
|
|
|
*waste = priv->y_tiles[y_index].waste;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 09:14:35 +00:00
|
|
|
* clutter_texture_has_generated_tiles:
|
|
|
|
* @texture: A #ClutterTexture
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
|
|
|
* Checks if #ClutterTexture has generated underlying GL texture tiles.
|
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* This function is only useful for sub class implementations
|
2006-05-29 08:59:36 +00:00
|
|
|
* and never should be called by an application.
|
|
|
|
*
|
|
|
|
* Return value: TRUE if texture has pregenerated GL tiles.
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
clutter_texture_has_generated_tiles (ClutterTexture *texture)
|
|
|
|
{
|
2007-03-19 10:00:38 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE);
|
|
|
|
|
2006-05-29 08:59:36 +00:00
|
|
|
return (texture->priv->tiles != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-06-22 13:56:04 +00:00
|
|
|
* clutter_texture_is_tiled:
|
2006-06-22 09:14:35 +00:00
|
|
|
* @texture: A #ClutterTexture
|
2006-05-29 08:59:36 +00:00
|
|
|
*
|
|
|
|
* Checks if #ClutterTexture is tiled.
|
|
|
|
*
|
2007-10-12 08:17:00 +00:00
|
|
|
* This function is only useful for sub class implementations
|
2006-05-29 08:59:36 +00:00
|
|
|
* and never should be called by an application.
|
|
|
|
*
|
|
|
|
* Return value: TRUE if texture is tiled
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
clutter_texture_is_tiled (ClutterTexture *texture)
|
|
|
|
{
|
2007-03-19 10:00:38 +00:00
|
|
|
g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE);
|
|
|
|
|
|
|
|
return texture->priv->is_tiled;
|
2006-05-29 08:59:36 +00:00
|
|
|
}
|
2007-12-20 14:26:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void inline
|
|
|
|
texture_update_data (ClutterTexture *texture,
|
|
|
|
const guchar *data,
|
|
|
|
gboolean has_alpha,
|
2007-12-21 15:25:00 +00:00
|
|
|
gint x_0,
|
|
|
|
gint y_0,
|
2007-12-20 14:26:07 +00:00
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint rowstride,
|
|
|
|
gint bpp)
|
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
gint x, y;
|
|
|
|
gint i = 0;
|
|
|
|
gboolean create_textures = FALSE;
|
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
|
|
|
|
CLUTTER_MARK();
|
|
|
|
|
|
|
|
if (!priv->is_tiled)
|
|
|
|
{
|
|
|
|
g_assert (priv->tiles);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (TEXTURE, "syncing for single tile");
|
|
|
|
|
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[0]);
|
|
|
|
cogl_texture_set_alignment (priv->target_type, 4, width);
|
|
|
|
|
|
|
|
cogl_texture_set_filters
|
|
|
|
(priv->target_type,
|
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST,
|
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST);
|
|
|
|
|
|
|
|
cogl_texture_set_wrap (priv->target_type,
|
|
|
|
priv->repeat_x ? CGL_REPEAT : CGL_CLAMP_TO_EDGE,
|
|
|
|
priv->repeat_y ? CGL_REPEAT : CGL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
priv->filter_quality = 1;
|
|
|
|
|
|
|
|
cogl_texture_sub_image_2d (priv->target_type,
|
2007-12-21 15:25:00 +00:00
|
|
|
x_0,
|
|
|
|
y_0,
|
2007-12-20 14:26:07 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
|
|
|
data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiple tiled texture */
|
|
|
|
|
|
|
|
CLUTTER_NOTE (TEXTURE,
|
|
|
|
"syncing for multiple tiles for %ix%i pixbuf",
|
|
|
|
priv->width, priv->height);
|
|
|
|
|
|
|
|
g_return_if_fail (priv->x_tiles != NULL && priv->y_tiles != NULL);
|
|
|
|
|
|
|
|
if (priv->tiles == NULL)
|
|
|
|
{
|
|
|
|
g_assert (0);
|
|
|
|
priv->tiles = g_new (COGLuint, priv->n_x_tiles * priv->n_y_tiles);
|
|
|
|
glGenTextures (priv->n_x_tiles * priv->n_y_tiles, priv->tiles);
|
|
|
|
create_textures = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; x < priv->n_x_tiles; x++)
|
|
|
|
for (y = 0; y < priv->n_y_tiles; y++)
|
|
|
|
{
|
|
|
|
gint master_offset_x;
|
|
|
|
gint effective_x;
|
|
|
|
gint effective_width;
|
|
|
|
|
|
|
|
gint master_offset_y;
|
|
|
|
gint effective_y;
|
|
|
|
gint effective_height;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
-- first tile --
|
|
|
|
|--------------------- priv->width ------------------------------|
|
|
|
|
| <- priv->x_tiles[x].pos
|
|
|
|
|-----------| <- priv->x_tiles[x].size
|
2007-12-21 15:25:00 +00:00
|
|
|
|-------| <- x_0
|
2007-12-20 14:26:07 +00:00
|
|
|
|------------| <- width
|
2007-12-21 15:25:00 +00:00
|
|
|
|--------------------| <- x_0 + width
|
2007-12-20 14:26:07 +00:00
|
|
|
|-------| <- master_offset = -8
|
|
|
|
|-------| <- effective_x = 8
|
|
|
|
|---| <- effective_width
|
|
|
|
|
|
|
|
-- second tile ---
|
|
|
|
|
|
|
|
|--------------------- priv->width ------------------------------|
|
|
|
|
|-----------| <- priv->x_tiles[x].pos
|
|
|
|
|-----------| <- priv->x_tiles[x].size (src_w)
|
2007-12-21 15:25:00 +00:00
|
|
|
|-------| <- x_0
|
2007-12-20 14:26:07 +00:00
|
|
|
|------------| <- width
|
2007-12-21 15:25:00 +00:00
|
|
|
|--------------------| <- x_0 + width
|
2007-12-20 14:26:07 +00:00
|
|
|
|---| <- master_offset = 4
|
|
|
|
| <- effective_x (0 in between)
|
|
|
|
|--------| <- effective_width
|
|
|
|
|
|
|
|
|
|
|
|
XXXXXXXXXXXXXX <- master
|
|
|
|
|___________|___________|___________|___________|___________|_____%%%%%%|
|
|
|
|
*/
|
|
|
|
|
|
|
|
gint src_w, src_h;
|
|
|
|
|
|
|
|
src_w = priv->x_tiles[x].size;
|
|
|
|
src_h = priv->y_tiles[y].size;
|
|
|
|
|
|
|
|
/* skip tiles that do not intersect the updated region */
|
2007-12-21 15:25:00 +00:00
|
|
|
if ((priv->x_tiles[x].pos + src_w < x_0 ||
|
|
|
|
priv->y_tiles[y].pos + src_h < y_0 ||
|
|
|
|
priv->x_tiles[x].pos >= x_0 + width ||
|
|
|
|
priv->y_tiles[y].pos >= y_0 + height))
|
2007-12-20 14:26:07 +00:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-12-21 15:25:00 +00:00
|
|
|
master_offset_x = priv->x_tiles[x].pos - x_0;
|
2007-12-20 14:26:07 +00:00
|
|
|
|
2007-12-21 15:25:00 +00:00
|
|
|
if (priv->x_tiles[x].pos > x_0)
|
2007-12-20 14:26:07 +00:00
|
|
|
effective_x = 0;
|
|
|
|
else
|
2007-12-21 15:25:00 +00:00
|
|
|
effective_x = x_0 - priv->x_tiles[x].pos;
|
2007-12-20 14:26:07 +00:00
|
|
|
|
2007-12-21 15:25:00 +00:00
|
|
|
effective_width = (x_0 + width) - priv->x_tiles[x].pos;
|
2007-12-20 14:26:07 +00:00
|
|
|
|
|
|
|
if (effective_width > src_w - effective_x)
|
|
|
|
effective_width = src_w - effective_x;
|
|
|
|
|
2007-12-21 15:25:00 +00:00
|
|
|
master_offset_y = priv->y_tiles[y].pos - y_0;
|
2007-12-20 14:26:07 +00:00
|
|
|
|
2007-12-21 15:25:00 +00:00
|
|
|
if (priv->y_tiles[y].pos > y_0)
|
2007-12-20 14:26:07 +00:00
|
|
|
effective_y = 0;
|
|
|
|
else
|
2007-12-21 15:25:00 +00:00
|
|
|
effective_y = y_0 - priv->y_tiles[y].pos;
|
2007-12-20 14:26:07 +00:00
|
|
|
|
2007-12-21 15:25:00 +00:00
|
|
|
effective_height = (y_0 + height) - priv->y_tiles[y].pos;
|
2007-12-20 14:26:07 +00:00
|
|
|
if (effective_height > src_h - effective_y)
|
|
|
|
effective_height = src_h - effective_y;
|
|
|
|
|
|
|
|
if (master_offset_x < 0)
|
|
|
|
master_offset_x = 0;
|
|
|
|
if (master_offset_y < 0)
|
|
|
|
master_offset_y = 0;
|
|
|
|
|
|
|
|
if (master_offset_x + effective_width > width)
|
|
|
|
effective_width = width - master_offset_x;
|
|
|
|
if (master_offset_y + effective_height > height)
|
|
|
|
effective_height = height - master_offset_y;
|
|
|
|
|
|
|
|
cogl_texture_bind (priv->target_type, priv->tiles[i]);
|
|
|
|
|
|
|
|
cogl_texture_set_alignment (priv->target_type, 4, rowstride/4);
|
|
|
|
|
|
|
|
cogl_texture_set_filters
|
|
|
|
(priv->target_type,
|
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST,
|
|
|
|
priv->filter_quality ? CGL_LINEAR : CGL_NEAREST);
|
|
|
|
|
|
|
|
cogl_texture_set_wrap (priv->target_type,
|
|
|
|
priv->repeat_x ? CGL_REPEAT : CGL_CLAMP_TO_EDGE,
|
|
|
|
priv->repeat_y ? CGL_REPEAT : CGL_CLAMP_TO_EDGE);
|
|
|
|
cogl_texture_sub_image_2d (priv->target_type,
|
|
|
|
effective_x,
|
|
|
|
effective_y,
|
|
|
|
effective_width,
|
|
|
|
effective_height,
|
|
|
|
priv->pixel_format,
|
|
|
|
priv->pixel_type,
|
|
|
|
data + (master_offset_y * width + master_offset_x) * 4);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_texture_set_area_from_rgb_data:
|
|
|
|
* @texture: A #ClutterTexture
|
|
|
|
* @data: Image data in RGB type colorspace.
|
|
|
|
* @has_alpha: Set to TRUE if image data has a alpha channel.
|
|
|
|
* @x: X coordinate of upper left corner of region to update.
|
|
|
|
* @y: Y coordinate of upper left corner of region to update.
|
|
|
|
* @width: Width in pixels of region to update.
|
|
|
|
* @height: Height in pixels of region to update.
|
|
|
|
* @rowstride: Distance in bytes between row starts.
|
|
|
|
* @bpp: bytes per pixel ( Currently only 4 supported )
|
|
|
|
* @flags: #ClutterTextureFlags
|
2007-12-24 16:24:26 +00:00
|
|
|
* @error: return location for a #GError, or %NULL
|
2007-12-20 14:26:07 +00:00
|
|
|
*
|
|
|
|
* Updates a subregion of the pixel data in a #ClutterTexture.
|
|
|
|
*
|
2007-12-24 16:24:26 +00:00
|
|
|
* Return value: %TRUE on success, %FALSE on failure.
|
2007-12-20 14:26:07 +00:00
|
|
|
*
|
|
|
|
* Since 0.6.
|
2007-12-24 16:24:26 +00:00
|
|
|
*/
|
2007-12-20 14:26:07 +00:00
|
|
|
gboolean
|
|
|
|
clutter_texture_set_area_from_rgb_data (ClutterTexture *texture,
|
|
|
|
const guchar *data,
|
|
|
|
gboolean has_alpha,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint rowstride,
|
|
|
|
gint bpp,
|
|
|
|
ClutterTextureFlags flags,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ClutterTexturePrivate *priv;
|
|
|
|
guchar *copy_data = NULL;
|
|
|
|
|
|
|
|
priv = texture->priv;
|
|
|
|
|
|
|
|
if (!texture_prepare_upload (FALSE, texture, data, has_alpha, width, height, rowstride,
|
|
|
|
bpp, flags, ©_data, NULL, NULL))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
texture_update_data (texture,
|
|
|
|
copy_data != NULL ? copy_data : data,
|
|
|
|
has_alpha,
|
|
|
|
x, y,
|
|
|
|
width, height,
|
|
|
|
rowstride,
|
|
|
|
bpp);
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_SET_FLAGS (CLUTTER_ACTOR (texture), CLUTTER_ACTOR_REALIZED);
|
|
|
|
|
|
|
|
/* rename signal */
|
|
|
|
g_signal_emit (texture, texture_signals[PIXBUF_CHANGE], 0);
|
|
|
|
|
|
|
|
if (CLUTTER_ACTOR_IS_MAPPED (CLUTTER_ACTOR(texture)))
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR(texture));
|
|
|
|
|
|
|
|
if (copy_data != NULL)
|
|
|
|
g_free (copy_data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|