[Cogl] [PATCH 2/3] tests: Convert test-npot-texture to Cogl
Robert Bragg
robert at sixbynine.org
Mon Nov 19 07:46:33 PST 2012
This looks good to me:
Reviewed-by: Robert Bragg <robert at linux.intel.com>
thanks,
- Robert
On Fri, Nov 9, 2012 at 4:56 PM, Neil Roberts <neil at linux.intel.com> wrote:
> This updates the npot-texture test to use Cogl directly instead of
> relying on Clutter.
>
> Note that this currently fails when Cogl ends up using sliced
> textures. It looks like there is some bug with the meta texture
> function to iterate the primitive textures. This happens when
> COGL_DEBUG=disable-npot-textures is set.
> ---
> tests/conform/Makefile.am | 1 +
> tests/conform/test-conform-main.c | 2 +-
> tests/conform/test-npot-texture.c | 210
> +++++++++++++-------------------------
> 3 files changed, 74 insertions(+), 139 deletions(-)
>
> diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
> index 9bf7987..b6430e2 100644
> --- a/tests/conform/Makefile.am
> +++ b/tests/conform/Makefile.am
> @@ -58,6 +58,7 @@ test_sources = \
> test-layer-remove.c \
> test-alpha-test.c \
> test-map-buffer-range.c \
> + test-npot-texture.c \
> $(NULL)
>
> test_conformance_SOURCES = $(common_sources) $(test_sources)
> diff --git a/tests/conform/test-conform-main.c
> b/tests/conform/test-conform-main.c
> index 701581c..4e2c8bb 100644
> --- a/tests/conform/test-conform-main.c
> +++ b/tests/conform/test-conform-main.c
> @@ -63,7 +63,7 @@ main (int argc, char **argv)
>
> ADD_TEST (test_sparse_pipeline, 0);
>
> - UNPORTED_TEST (test_npot_texture);
> + ADD_TEST (test_npot_texture, TEST_REQUIREMENT_NPOT);
> UNPORTED_TEST (test_multitexture);
> UNPORTED_TEST (test_texture_mipmaps);
> ADD_TEST (test_sub_texture, 0);
> diff --git a/tests/conform/test-npot-texture.c
> b/tests/conform/test-npot-texture.c
> index 8aca4df..a2bbd9f 100644
> --- a/tests/conform/test-npot-texture.c
> +++ b/tests/conform/test-npot-texture.c
> @@ -1,10 +1,8 @@
> -#include <clutter/clutter.h>
> #include <cogl/cogl.h>
> -#include <string.h>
>
> -#include "test-conform-common.h"
> +#include <string.h>
>
> -static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
> +#include "test-utils.h"
>
> /* Non-power-of-two sized texture that should cause slicing */
> #define TEXTURE_SIZE 384
> @@ -22,111 +20,44 @@ static const ClutterColor stage_color = { 0x0, 0x0,
> 0x0, 0xff };
> /* The size of a part once rendered */
> #define PART_RENDER_SIZE (TEXTURE_RENDER_SIZE / PARTS)
>
> -static const ClutterColor corner_colors[PARTS * PARTS] =
> +static const uint32_t corner_colors[PARTS * PARTS] =
> {
> - /* Top left - red */ { 255, 0, 0, 255 },
> - /* Top right - green */ { 0, 255, 0, 255 },
> - /* Bottom left - blue */ { 0, 0, 255, 255 },
> - /* Bottom right - yellow */ { 255, 255, 0, 255 }
> + /* Top left - red */ 0xff0000ff,
> + /* Top right - green */ 0x00ff00ff,
> + /* Bottom left - blue */ 0x0000ffff,
> + /* Bottom right - yellow */ 0xffff00ff
> };
>
> -typedef struct _TestState
> -{
> - unsigned int frame;
> - CoglHandle texture;
> -} TestState;
> -
> -static CoglBool
> -validate_part (int xnum, int ynum, const ClutterColor *color)
> +static void
> +validate_part (int xnum,
> + int ynum,
> + uint32_t color)
> {
> - guchar *pixels, *p;
> - ClutterActor *stage = clutter_stage_get_default ();
> - CoglBool ret = TRUE;
> -
> - /* Read the appropriate part but skip out a few pixels around the
> - edges */
> - pixels = clutter_stage_read_pixels (CLUTTER_STAGE (stage),
> - xnum * PART_RENDER_SIZE +
> TEST_INSET,
> - ynum * PART_RENDER_SIZE +
> TEST_INSET,
> - PART_RENDER_SIZE - TEST_INSET * 2,
> - PART_RENDER_SIZE - TEST_INSET * 2);
> -
> - /* Make sure every pixels is the appropriate color */
> - for (p = pixels;
> - p < pixels + ((PART_RENDER_SIZE - TEST_INSET * 2)
> - * (PART_RENDER_SIZE - TEST_INSET * 2));
> - p += 4)
> - {
> - if (p[0] != color->red)
> - ret = FALSE;
> - if (p[1] != color->green)
> - ret = FALSE;
> - if (p[2] != color->blue)
> - ret = FALSE;
> - }
> -
> - g_free (pixels);
> -
> - return ret;
> + test_utils_check_region (test_fb,
> + xnum * PART_RENDER_SIZE + TEST_INSET,
> + ynum * PART_RENDER_SIZE + TEST_INSET,
> + PART_RENDER_SIZE - TEST_INSET * 2,
> + PART_RENDER_SIZE - TEST_INSET * 2,
> + color);
> }
>
> static void
> -validate_result (TestState *state)
> +validate_result (void)
> {
> /* Validate that all four corners of the texture are drawn in the
> right color */
> - g_assert (validate_part (0, 0, corner_colors + 0));
> - g_assert (validate_part (1, 0, corner_colors + 1));
> - g_assert (validate_part (0, 1, corner_colors + 2));
> - g_assert (validate_part (1, 1, corner_colors + 3));
> -
> - /* Comment this out if you want visual feedback of what this test
> - * paints.
> - */
> - clutter_main_quit ();
> -}
> -
> -static void
> -on_paint (ClutterActor *actor, TestState *state)
> -{
> - int frame_num;
> - int y, x;
> -
> - /* Just render the texture in the top left corner */
> - cogl_set_source_texture (state->texture);
> - /* Render the texture using four separate rectangles */
> - for (y = 0; y < 2; y++)
> - for (x = 0; x < 2; x++)
> - cogl_rectangle_with_texture_coords (x * TEXTURE_RENDER_SIZE / 2,
> - y * TEXTURE_RENDER_SIZE / 2,
> - (x + 1) * TEXTURE_RENDER_SIZE /
> 2,
> - (y + 1) * TEXTURE_RENDER_SIZE /
> 2,
> - x / 2.0f,
> - y / 2.0f,
> - (x + 1) / 2.0f,
> - (y + 1) / 2.0f);
> -
> - /* XXX: validate_result calls clutter_stage_read_pixels which will
> result in
> - * another paint run so to avoid infinite recursion we only aim to
> validate
> - * the first frame. */
> - frame_num = state->frame++;
> - if (frame_num == 1)
> - validate_result (state);
> -}
> -
> -static CoglBool
> -queue_redraw (void *stage)
> -{
> - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
> -
> - return TRUE;
> + validate_part (0, 0, corner_colors[0]);
> + validate_part (1, 0, corner_colors[1]);
> + validate_part (0, 1, corner_colors[2]);
> + validate_part (1, 1, corner_colors[3]);
> }
>
> -static CoglHandle
> +static CoglTexture *
> make_texture (void)
> {
> - guchar *tex_data, *p;
> - CoglHandle tex;
> + void *tex_data;
> + uint32_t *p;
> + CoglTexture *tex;
> int partx, party, width, height;
>
> p = tex_data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);
> @@ -140,31 +71,26 @@ make_texture (void)
>
> for (partx = 0; partx < PARTS; partx++)
> {
> - const ClutterColor *color = corner_colors + party * PARTS +
> partx;
> + uint32_t color = corner_colors[party * PARTS + partx];
> width = (partx < PARTS - 1
> ? PART_SIZE
> : TEXTURE_SIZE - PART_SIZE * (PARTS - 1));
>
> while (width-- > 0)
> - {
> - *(p++) = color->red;
> - *(p++) = color->green;
> - *(p++) = color->blue;
> - *(p++) = color->alpha;
> - }
> + *(p++) = GUINT32_TO_BE (color);
> }
>
> while (--height > 0)
> {
> - memcpy (p, p - TEXTURE_SIZE * 4, TEXTURE_SIZE * 4);
> - p += TEXTURE_SIZE * 4;
> + memcpy (p, p - TEXTURE_SIZE, TEXTURE_SIZE * 4);
> + p += TEXTURE_SIZE;
> }
> }
>
> tex = cogl_texture_new_from_data (TEXTURE_SIZE,
> TEXTURE_SIZE,
> COGL_TEXTURE_NO_ATLAS,
> - COGL_PIXEL_FORMAT_RGBA_8888,
> + COGL_PIXEL_FORMAT_RGBA_8888_PRE,
> COGL_PIXEL_FORMAT_ANY,
> TEXTURE_SIZE * 4,
> tex_data);
> @@ -180,55 +106,63 @@ make_texture (void)
> }
>
> /* The texture should be sliced unless NPOTs are supported */
> - g_assert (cogl_features_available (COGL_FEATURE_TEXTURE_NPOT)
> + g_assert (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT)
> ? !cogl_texture_is_sliced (tex)
> : cogl_texture_is_sliced (tex));
>
> return tex;
> }
>
> -void
> -test_npot_texture (TestUtilsGTestFixture *fixture,
> - void *data)
> +static void
> +paint (void)
> {
> - TestState state;
> - ClutterActor *stage;
> - ClutterActor *group;
> - unsigned int idle_source;
> + CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
> + CoglTexture *texture = make_texture ();
> + int y, x;
> +
> + cogl_pipeline_set_layer_texture (pipeline, 0, texture);
> +
> + /* Just render the texture in the top left corner */
> + /* Render the texture using four separate rectangles */
> + for (y = 0; y < 2; y++)
> + for (x = 0; x < 2; x++)
> + cogl_framebuffer_draw_textured_rectangle (test_fb,
> + pipeline,
> + x * TEXTURE_RENDER_SIZE /
> 2,
> + y * TEXTURE_RENDER_SIZE /
> 2,
> + (x + 1) *
> + TEXTURE_RENDER_SIZE / 2,
> + (y + 1) *
> + TEXTURE_RENDER_SIZE / 2,
> + x / 2.0f,
> + y / 2.0f,
> + (x + 1) / 2.0f,
> + (y + 1) / 2.0f);
> +
> + cogl_object_unref (pipeline);
> + cogl_object_unref (texture);
> +}
>
> +void
> +test_npot_texture (void)
> +{
> if (cogl_test_verbose ())
> {
> - if (cogl_features_available (COGL_FEATURE_TEXTURE_NPOT))
> + if (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT))
> g_print ("NPOT textures are supported\n");
> else
> g_print ("NPOT textures are not supported\n");
> }
>
> - state.frame = 0;
> -
> - state.texture = make_texture ();
> -
> - stage = clutter_stage_get_default ();
> -
> - clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
> -
> - group = clutter_group_new ();
> - clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
> -
> - /* We force continuous redrawing of the stage, since we need to skip
> - * the first few frames, and we wont be doing anything else that
> - * will trigger redrawing. */
> - idle_source = g_idle_add (queue_redraw, stage);
> -
> - g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
> -
> - clutter_actor_show_all (stage);
> -
> - clutter_main ();
> -
> - g_source_remove (idle_source);
> + cogl_framebuffer_orthographic (test_fb,
> + 0, 0,
> + cogl_framebuffer_get_width (test_fb),
> + cogl_framebuffer_get_height (test_fb),
> + -1,
> + 100);
>
> - cogl_handle_unref (state.texture);
> + paint ();
> + validate_result ();
>
> if (cogl_test_verbose ())
> g_print ("OK\n");
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/cogl/attachments/20121119/9b55164e/attachment-0001.html>
More information about the Cogl
mailing list