From e1bf19f8697629b2fe4ba4e676c8a6bf6c19c849 Mon Sep 17 00:00:00 2001 From: Matthew Allum Date: Fri, 4 May 2007 23:53:49 +0000 Subject: [PATCH] 2007-05-05 Matthew Allum * 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. --- ChangeLog | 12 +++++ Makefile.am | 2 +- clutter/clutter-texture.c | 41 ++++++++++------ configure.ac | 1 + tests/Makefile.am | 8 ++++ tests/test-textures.c | 99 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/test-textures.c diff --git a/ChangeLog b/ChangeLog index d443f4681..243ec4daa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-05-05 Matthew Allum + + * 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 * clutter/Makefile.am: diff --git a/Makefile.am b/Makefile.am index 2741e461e..ac3d4b209 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=clutter doc examples +SUBDIRS=clutter doc examples tests pcfiles = clutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.pc diff --git a/clutter/clutter-texture.c b/clutter/clutter-texture.c index ca792c7f5..ada0f7fe4 100644 --- a/clutter/clutter-texture.c +++ b/clutter/clutter-texture.c @@ -116,11 +116,14 @@ can_create_rect_arb (int width, GLenum pixel_format, GLenum pixel_type) { - /* FIXME: How to correctly query what max size of NPOTS text can be */ - if (width > 4096 || height > 4096) - return FALSE; +#if HAVE_COGL_GL + gint max_size = 0; - 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 @@ -172,8 +175,8 @@ texture_init_tiles (ClutterTexture *texture) x_pot = clutter_util_next_p2 (priv->width); y_pot = clutter_util_next_p2 (priv->height); - while (!(cogl_texture_can_size (x_pot, y_pot, - priv->pixel_format, priv->pixel_type) + while (!(cogl_texture_can_size (priv->pixel_format, priv->pixel_type, + x_pot, y_pot) && (x_pot - priv->width < priv->max_tile_waste) && (y_pot - priv->height < priv->max_tile_waste))) { @@ -191,6 +194,8 @@ texture_init_tiles (ClutterTexture *texture) x_pot /= 2; else y_pot /= 2; + + g_return_if_fail (x_pot != 0 || y_pot != 0); } if (priv->x_tiles) @@ -495,9 +500,9 @@ texture_upload_data (ClutterTexture *texture, } #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 (priv->target_type, @@ -1186,15 +1191,21 @@ clutter_texture_set_from_data (ClutterTexture *texture, priv->pixel_type)) { /* 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; } - else if (priv->target_type == CGL_TEXTURE_2D - && !cogl_texture_can_size - (clutter_util_next_p2(priv->width), - clutter_util_next_p2(priv->height), - priv->pixel_format, - priv->pixel_type)) + + if (priv->target_type == CGL_TEXTURE_2D + && !cogl_texture_can_size + (priv->pixel_format, + priv->pixel_type, + clutter_util_next_p2(priv->width), + clutter_util_next_p2(priv->height))) { priv->is_tiled = TRUE; } diff --git a/configure.ac b/configure.ac index 960ab405f..74f59322d 100644 --- a/configure.ac +++ b/configure.ac @@ -275,6 +275,7 @@ AC_CONFIG_FILES([ clutter/cogl/gl/Makefile clutter/cogl/gles/Makefile examples/Makefile + tests/Makefile doc/Makefile doc/reference/Makefile doc/reference/version.xml diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 000000000..cebfa5cbc --- /dev/null +++ b/tests/Makefile.am @@ -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 diff --git a/tests/test-textures.c b/tests/test-textures.c new file mode 100644 index 000000000..20b278fd3 --- /dev/null +++ b/tests/test-textures.c @@ -0,0 +1,99 @@ +#include + +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 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; +}