mirror of
https://github.com/brl/mutter.git
synced 2025-02-18 06:04:10 +00:00
2007-05-05 Matthew Allum <mallum@openedhand.com>
* clutter/clutter-texture.c: Fix typos with new cogl using texture code. Fixes tiled textures. Add a check for max npots size. * configure.ac: * Makefile.am: * tests/Makefile.am: * tests/test-textures.c: Add a simple texture test.
This commit is contained in:
parent
76981c44a4
commit
e1bf19f869
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2007-05-05 Matthew Allum <mallum@openedhand.com>
|
||||||
|
|
||||||
|
* clutter/clutter-texture.c:
|
||||||
|
Fix typos with new cogl using texture code. Fixes tiled textures.
|
||||||
|
Add a check for max npots size.
|
||||||
|
|
||||||
|
* configure.ac:
|
||||||
|
* Makefile.am:
|
||||||
|
* tests/Makefile.am:
|
||||||
|
* tests/test-textures.c:
|
||||||
|
Add a simple texture test.
|
||||||
|
|
||||||
2007-05-02 Matthew Allum <mallum@openedhand.com>
|
2007-05-02 Matthew Allum <mallum@openedhand.com>
|
||||||
|
|
||||||
* clutter/Makefile.am:
|
* clutter/Makefile.am:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
SUBDIRS=clutter doc examples
|
SUBDIRS=clutter doc examples tests
|
||||||
|
|
||||||
pcfiles = clutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.pc
|
pcfiles = clutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.pc
|
||||||
|
|
||||||
|
@ -116,11 +116,14 @@ can_create_rect_arb (int width,
|
|||||||
GLenum pixel_format,
|
GLenum pixel_format,
|
||||||
GLenum pixel_type)
|
GLenum pixel_type)
|
||||||
{
|
{
|
||||||
/* FIXME: How to correctly query what max size of NPOTS text can be */
|
#if HAVE_COGL_GL
|
||||||
if (width > 4096 || height > 4096)
|
gint max_size = 0;
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &max_size);
|
||||||
|
|
||||||
|
return (max_size && width <= max_size && height <= max_size);
|
||||||
|
#endif
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -172,8 +175,8 @@ texture_init_tiles (ClutterTexture *texture)
|
|||||||
x_pot = clutter_util_next_p2 (priv->width);
|
x_pot = clutter_util_next_p2 (priv->width);
|
||||||
y_pot = clutter_util_next_p2 (priv->height);
|
y_pot = clutter_util_next_p2 (priv->height);
|
||||||
|
|
||||||
while (!(cogl_texture_can_size (x_pot, y_pot,
|
while (!(cogl_texture_can_size (priv->pixel_format, priv->pixel_type,
|
||||||
priv->pixel_format, priv->pixel_type)
|
x_pot, y_pot)
|
||||||
&& (x_pot - priv->width < priv->max_tile_waste)
|
&& (x_pot - priv->width < priv->max_tile_waste)
|
||||||
&& (y_pot - priv->height < priv->max_tile_waste)))
|
&& (y_pot - priv->height < priv->max_tile_waste)))
|
||||||
{
|
{
|
||||||
@ -191,6 +194,8 @@ texture_init_tiles (ClutterTexture *texture)
|
|||||||
x_pot /= 2;
|
x_pot /= 2;
|
||||||
else
|
else
|
||||||
y_pot /= 2;
|
y_pot /= 2;
|
||||||
|
|
||||||
|
g_return_if_fail (x_pot != 0 || y_pot != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->x_tiles)
|
if (priv->x_tiles)
|
||||||
@ -495,9 +500,9 @@ texture_upload_data (ClutterTexture *texture,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cogl_texture_bind (priv->target_type, priv->tiles[0]);
|
cogl_texture_bind (priv->target_type, priv->tiles[i]);
|
||||||
|
|
||||||
cogl_texture_set_alignment (priv->target_type, 4, priv->width);
|
cogl_texture_set_alignment (priv->target_type, 4, src_w);
|
||||||
|
|
||||||
cogl_texture_set_filters
|
cogl_texture_set_filters
|
||||||
(priv->target_type,
|
(priv->target_type,
|
||||||
@ -1186,15 +1191,21 @@ clutter_texture_set_from_data (ClutterTexture *texture,
|
|||||||
priv->pixel_type))
|
priv->pixel_type))
|
||||||
{
|
{
|
||||||
/* If we cant create NPOT tex of this size fall back to tiles */
|
/* If we cant create NPOT tex of this size fall back to tiles */
|
||||||
priv->is_tiled = TRUE;
|
CLUTTER_NOTE (TEXTURE,
|
||||||
|
"Cannot make npots of size %ix%i "
|
||||||
|
"falling back to tiled",
|
||||||
|
priv->width,
|
||||||
|
priv->height);
|
||||||
|
|
||||||
priv->target_type = CGL_TEXTURE_2D;
|
priv->target_type = CGL_TEXTURE_2D;
|
||||||
}
|
}
|
||||||
else if (priv->target_type == CGL_TEXTURE_2D
|
|
||||||
&& !cogl_texture_can_size
|
if (priv->target_type == CGL_TEXTURE_2D
|
||||||
(clutter_util_next_p2(priv->width),
|
&& !cogl_texture_can_size
|
||||||
clutter_util_next_p2(priv->height),
|
(priv->pixel_format,
|
||||||
priv->pixel_format,
|
priv->pixel_type,
|
||||||
priv->pixel_type))
|
clutter_util_next_p2(priv->width),
|
||||||
|
clutter_util_next_p2(priv->height)))
|
||||||
{
|
{
|
||||||
priv->is_tiled = TRUE;
|
priv->is_tiled = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -275,6 +275,7 @@ AC_CONFIG_FILES([
|
|||||||
clutter/cogl/gl/Makefile
|
clutter/cogl/gl/Makefile
|
||||||
clutter/cogl/gles/Makefile
|
clutter/cogl/gles/Makefile
|
||||||
examples/Makefile
|
examples/Makefile
|
||||||
|
tests/Makefile
|
||||||
doc/Makefile
|
doc/Makefile
|
||||||
doc/reference/Makefile
|
doc/reference/Makefile
|
||||||
doc/reference/version.xml
|
doc/reference/version.xml
|
||||||
|
8
tests/Makefile.am
Normal file
8
tests/Makefile.am
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
noinst_PROGRAMS = test-textures
|
||||||
|
|
||||||
|
INCLUDES = -I$(top_srcdir)/
|
||||||
|
LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la
|
||||||
|
AM_CFLAGS = $(CLUTTER_CFLAGS)
|
||||||
|
LDFLAGS = $(CLUTTER_LIBS)
|
||||||
|
|
||||||
|
test_textures_SOURCES = test-textures.c
|
99
tests/test-textures.c
Normal file
99
tests/test-textures.c
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#include <clutter/clutter.h>
|
||||||
|
|
||||||
|
GdkPixbuf*
|
||||||
|
make_pixbuf (int width, int height, int bpp, int has_alpha)
|
||||||
|
{
|
||||||
|
#define CHECK_SIZE 20
|
||||||
|
|
||||||
|
GdkPixbuf *px;
|
||||||
|
gint x,y, rowstride, n_channels, i = 0;
|
||||||
|
guchar *pixels;
|
||||||
|
|
||||||
|
px = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
|
||||||
|
has_alpha,
|
||||||
|
8,
|
||||||
|
width,
|
||||||
|
height);
|
||||||
|
|
||||||
|
if (!px) return NULL;
|
||||||
|
|
||||||
|
rowstride = gdk_pixbuf_get_rowstride (px);
|
||||||
|
n_channels = gdk_pixbuf_get_n_channels (px);
|
||||||
|
|
||||||
|
for (y=0; y<height; y++)
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
for (x=0; x<width; x++)
|
||||||
|
{
|
||||||
|
guchar *p, r, g, b, a;
|
||||||
|
|
||||||
|
p = gdk_pixbuf_get_pixels (px) + y * rowstride + x * n_channels;
|
||||||
|
|
||||||
|
p[0] = p[1] = p[2] = 0; p[3] = 0xff;
|
||||||
|
|
||||||
|
if (x && y && y % CHECK_SIZE && x % CHECK_SIZE)
|
||||||
|
{
|
||||||
|
if (x % CHECK_SIZE == 1)
|
||||||
|
{
|
||||||
|
if (++i > 3)
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
p[i] = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SPIN() while (g_main_context_pending (NULL)) \
|
||||||
|
g_main_context_iteration (NULL, FALSE);
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
ClutterActor *texture;
|
||||||
|
ClutterActor *stage;
|
||||||
|
GdkPixbuf *pixbuf;
|
||||||
|
gint i, cols, rows;
|
||||||
|
|
||||||
|
clutter_init (&argc, &argv);
|
||||||
|
|
||||||
|
stage = clutter_stage_get_default ();
|
||||||
|
clutter_actor_show_all (CLUTTER_ACTOR (stage));
|
||||||
|
|
||||||
|
SPIN();
|
||||||
|
|
||||||
|
for (i=100; i<5000; i += 100)
|
||||||
|
{
|
||||||
|
pixbuf = make_pixbuf (i, i, 4, TRUE);
|
||||||
|
|
||||||
|
if (!pixbuf)
|
||||||
|
g_error("%ix%i pixbuf creation failed", i, i);
|
||||||
|
|
||||||
|
printf("o %ix%i pixbuf... ", i, i);
|
||||||
|
|
||||||
|
texture = clutter_texture_new_from_pixbuf (pixbuf);
|
||||||
|
|
||||||
|
g_object_unref (pixbuf);
|
||||||
|
|
||||||
|
if (!texture)
|
||||||
|
g_error("Pixbuf creation failed");
|
||||||
|
|
||||||
|
printf("uploaded to texture... ", i, i);
|
||||||
|
|
||||||
|
clutter_group_add (CLUTTER_GROUP (stage), texture);
|
||||||
|
clutter_actor_set_size (texture, 400, 400);
|
||||||
|
clutter_actor_show (texture);
|
||||||
|
|
||||||
|
clutter_texture_get_n_tiles(CLUTTER_TEXTURE(texture), &cols, &rows);
|
||||||
|
printf("with tiles: %i x %i\n", cols, rows);
|
||||||
|
|
||||||
|
SPIN();
|
||||||
|
|
||||||
|
clutter_group_remove (CLUTTER_GROUP (stage), texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user