diff options
author | Robert Bragg <robert@linux.intel.com> | 2011-10-12 17:12:08 +0100 |
---|---|---|
committer | Robert Bragg <robert@linux.intel.com> | 2011-11-01 12:03:01 +0000 |
commit | 3c129f5c18c19fd5838313143fd6b755c7860516 (patch) | |
tree | 29e7236c61591cf89add92a4ca0db253f6f4e2c6 /tests | |
parent | 426c8b8f41626527bcf764bc275d46ffe8c2e84b (diff) | |
download | mutter-3c129f5c18c19fd5838313143fd6b755c7860516.tar.gz |
tests: ports test-wrap-modes.c to be standalone cogl test
This ports test-wrap-modes.c from being a clutter based test to one that
is a standalone cogl test.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conform/Makefile.am | 2 | ||||
-rw-r--r-- | tests/conform/test-conform-main.c | 2 | ||||
-rw-r--r-- | tests/conform/test-wrap-modes.c | 218 |
3 files changed, 97 insertions, 125 deletions
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am index 8f83b67d7..ea18f5378 100644 --- a/tests/conform/Makefile.am +++ b/tests/conform/Makefile.am @@ -32,7 +32,6 @@ unported_test_sources = \ test-vertex-buffer-contiguous.c \ test-vertex-buffer-interleved.c \ test-vertex-buffer-mutability.c \ - test-wrap-modes.c \ test-primitive.c \ $(NULL) @@ -43,6 +42,7 @@ test_sources = \ test-backface-culling.c \ test-just-vertex-shader.c \ test-pipeline-user-matrix.c \ + test-wrap-modes.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 e26e8b819..8a4c44492 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -149,7 +149,7 @@ main (int argc, char **argv) UNPORTED_TEST ("/cogl/texture", test_cogl_pixel_array); UNPORTED_TEST ("/cogl/texture", test_cogl_texture_rectangle); UNPORTED_TEST ("/cogl/texture", test_cogl_texture_3d); - UNPORTED_TEST ("/cogl/texture", test_cogl_wrap_modes); + ADD_TEST ("/cogl/texture", test_cogl_wrap_modes); UNPORTED_TEST ("/cogl/texture", test_cogl_texture_pixmap_x11); UNPORTED_TEST ("/cogl/texture", test_cogl_texture_get_set_data); UNPORTED_TEST ("/cogl/texture", test_cogl_atlas_migration); diff --git a/tests/conform/test-wrap-modes.c b/tests/conform/test-wrap-modes.c index 94045966e..8ebc01133 100644 --- a/tests/conform/test-wrap-modes.c +++ b/tests/conform/test-wrap-modes.c @@ -1,23 +1,23 @@ -#include <clutter/clutter.h> +#include <cogl/cogl.h> #include <string.h> -#include "test-conform-common.h" +#include "test-utils.h" #define TEX_SIZE 4 -static const ClutterColor stage_color = { 0x80, 0x80, 0x80, 0xff }; - typedef struct _TestState { - ClutterActor *stage; - CoglHandle texture; + CoglContext *ctx; + int width; + int height; + CoglTexture *texture; } TestState; -static CoglHandle +static CoglTexture * create_texture (CoglTextureFlags flags) { guint8 *data = g_malloc (TEX_SIZE * TEX_SIZE * 4), *p = data; - CoglHandle tex; + CoglTexture *tex; int x, y; for (y = 0; y < TEX_SIZE; y++) @@ -34,50 +34,49 @@ create_texture (CoglTextureFlags flags) COGL_PIXEL_FORMAT_ANY, TEX_SIZE * 4, data); - g_free (data); return tex; } -static CoglHandle -create_material (TestState *state, - CoglMaterialWrapMode wrap_mode_s, - CoglMaterialWrapMode wrap_mode_t) +static CoglPipeline * +create_pipeline (TestState *state, + CoglPipelineWrapMode wrap_mode_s, + CoglPipelineWrapMode wrap_mode_t) { - CoglHandle material; + CoglPipeline *pipeline; - material = cogl_material_new (); - cogl_material_set_layer (material, 0, state->texture); - cogl_material_set_layer_filters (material, 0, - COGL_MATERIAL_FILTER_NEAREST, - COGL_MATERIAL_FILTER_NEAREST); - cogl_material_set_layer_wrap_mode_s (material, 0, wrap_mode_s); - cogl_material_set_layer_wrap_mode_t (material, 0, wrap_mode_t); + pipeline = cogl_pipeline_new (); + cogl_pipeline_set_layer_texture (pipeline, 0, state->texture); + cogl_pipeline_set_layer_filters (pipeline, 0, + COGL_PIPELINE_FILTER_NEAREST, + COGL_PIPELINE_FILTER_NEAREST); + cogl_pipeline_set_layer_wrap_mode_s (pipeline, 0, wrap_mode_s); + cogl_pipeline_set_layer_wrap_mode_t (pipeline, 0, wrap_mode_t); - return material; + return pipeline; } -static CoglMaterialWrapMode +static CoglPipelineWrapMode test_wrap_modes[] = { - COGL_MATERIAL_WRAP_MODE_REPEAT, - COGL_MATERIAL_WRAP_MODE_REPEAT, + COGL_PIPELINE_WRAP_MODE_REPEAT, + COGL_PIPELINE_WRAP_MODE_REPEAT, - COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, - COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, - COGL_MATERIAL_WRAP_MODE_REPEAT, - COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, + COGL_PIPELINE_WRAP_MODE_REPEAT, + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, - COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, - COGL_MATERIAL_WRAP_MODE_REPEAT, + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, + COGL_PIPELINE_WRAP_MODE_REPEAT, - COGL_MATERIAL_WRAP_MODE_AUTOMATIC, - COGL_MATERIAL_WRAP_MODE_AUTOMATIC, + COGL_PIPELINE_WRAP_MODE_AUTOMATIC, + COGL_PIPELINE_WRAP_MODE_AUTOMATIC, - COGL_MATERIAL_WRAP_MODE_AUTOMATIC, - COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE + COGL_PIPELINE_WRAP_MODE_AUTOMATIC, + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE }; static void @@ -87,17 +86,17 @@ draw_tests (TestState *state) for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2) { - CoglMaterialWrapMode wrap_mode_s, wrap_mode_t; - CoglHandle material; + CoglPipelineWrapMode wrap_mode_s, wrap_mode_t; + CoglPipeline *pipeline; - /* Create a separate material for each pair of wrap modes so + /* Create a separate pipeline for each pair of wrap modes so that we can verify whether the batch splitting works */ wrap_mode_s = test_wrap_modes[i]; wrap_mode_t = test_wrap_modes[i + 1]; - material = create_material (state, wrap_mode_s, wrap_mode_t); - cogl_set_source (material); - cogl_handle_unref (material); - /* Render the material at four times the size of the texture */ + pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t); + cogl_set_source (pipeline); + cogl_handle_unref (pipeline); + /* Render the pipeline at four times the size of the texture */ cogl_rectangle_with_texture_coords (i * TEX_SIZE, 0, (i + 2) * TEX_SIZE, TEX_SIZE * 2, 0, 0, 2, 2); @@ -119,17 +118,17 @@ draw_tests_polygon (TestState *state) for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2) { - CoglMaterialWrapMode wrap_mode_s, wrap_mode_t; - CoglHandle material; + CoglPipelineWrapMode wrap_mode_s, wrap_mode_t; + CoglPipeline *pipeline; wrap_mode_s = test_wrap_modes[i]; wrap_mode_t = test_wrap_modes[i + 1]; - material = create_material (state, wrap_mode_s, wrap_mode_t); - cogl_set_source (material); - cogl_handle_unref (material); + pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t); + cogl_set_source (pipeline); + cogl_handle_unref (pipeline); cogl_push_matrix (); cogl_translate (TEX_SIZE * i, 0.0f, 0.0f); - /* Render the material at four times the size of the texture */ + /* Render the pipeline at four times the size of the texture */ cogl_polygon (vertices, G_N_ELEMENTS (vertices), FALSE); cogl_pop_matrix (); } @@ -154,17 +153,17 @@ draw_tests_vbo (TestState *state) for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2) { - CoglMaterialWrapMode wrap_mode_s, wrap_mode_t; - CoglHandle material; + CoglPipelineWrapMode wrap_mode_s, wrap_mode_t; + CoglPipeline *pipeline; wrap_mode_s = test_wrap_modes[i]; wrap_mode_t = test_wrap_modes[i + 1]; - material = create_material (state, wrap_mode_s, wrap_mode_t); - cogl_set_source (material); - cogl_handle_unref (material); + pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t); + cogl_set_source (pipeline); + cogl_handle_unref (pipeline); cogl_push_matrix (); cogl_translate (TEX_SIZE * i, 0.0f, 0.0f); - /* Render the material at four times the size of the texture */ + /* Render the pipeline at four times the size of the texture */ cogl_vertex_buffer_draw (vbo, COGL_VERTICES_MODE_TRIANGLE_FAN, 0, 4); cogl_pop_matrix (); } @@ -173,40 +172,6 @@ draw_tests_vbo (TestState *state) } static void -draw_frame (TestState *state) -{ - /* Draw the tests first with a non atlased texture */ - state->texture = create_texture (COGL_TEXTURE_NO_ATLAS); - draw_tests (state); - cogl_handle_unref (state->texture); - - /* Draw the tests again with a possible atlased texture. This should - end up testing software repeats */ - state->texture = create_texture (COGL_TEXTURE_NONE); - cogl_push_matrix (); - cogl_translate (0.0f, TEX_SIZE * 2.0f, 0.0f); - draw_tests (state); - cogl_pop_matrix (); - cogl_handle_unref (state->texture); - - /* Draw the tests using cogl_polygon */ - state->texture = create_texture (COGL_TEXTURE_NO_ATLAS); - cogl_push_matrix (); - cogl_translate (0.0f, TEX_SIZE * 4.0f, 0.0f); - draw_tests_polygon (state); - cogl_pop_matrix (); - cogl_handle_unref (state->texture); - - /* Draw the tests using a vertex buffer */ - state->texture = create_texture (COGL_TEXTURE_NO_ATLAS); - cogl_push_matrix (); - cogl_translate (0.0f, TEX_SIZE * 6.0f, 0.0f); - draw_tests_vbo (state); - cogl_pop_matrix (); - cogl_handle_unref (state->texture); -} - -static void validate_set (TestState *state, int offset) { guint8 data[TEX_SIZE * 2 * TEX_SIZE * 2 * 4], *p; @@ -214,7 +179,7 @@ validate_set (TestState *state, int offset) for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2) { - CoglMaterialWrapMode wrap_mode_s, wrap_mode_t; + CoglPipelineWrapMode wrap_mode_s, wrap_mode_t; wrap_mode_s = test_wrap_modes[i]; wrap_mode_t = test_wrap_modes[i + 1]; @@ -233,15 +198,15 @@ validate_set (TestState *state, int offset) guint8 green, blue; if (x < TEX_SIZE || - wrap_mode_s == COGL_MATERIAL_WRAP_MODE_REPEAT || - wrap_mode_s == COGL_MATERIAL_WRAP_MODE_AUTOMATIC) + wrap_mode_s == COGL_PIPELINE_WRAP_MODE_REPEAT || + wrap_mode_s == COGL_PIPELINE_WRAP_MODE_AUTOMATIC) green = (x & 1) * 255; else green = ((TEX_SIZE - 1) & 1) * 255; if (y < TEX_SIZE || - wrap_mode_t == COGL_MATERIAL_WRAP_MODE_REPEAT || - wrap_mode_t == COGL_MATERIAL_WRAP_MODE_AUTOMATIC) + wrap_mode_t == COGL_PIPELINE_WRAP_MODE_REPEAT || + wrap_mode_t == COGL_PIPELINE_WRAP_MODE_AUTOMATIC) blue = (y & 1) * 255; else blue = ((TEX_SIZE - 1) & 1) * 255; @@ -264,53 +229,60 @@ validate_result (TestState *state) #endif validate_set (state, 2); /* cogl_polygon */ validate_set (state, 3); /* vertex buffer */ - - /* Comment this out to see what the test paints */ - clutter_main_quit (); } static void -on_paint (ClutterActor *actor, TestState *state) +paint (TestState *state) { - draw_frame (state); + /* Draw the tests first with a non atlased texture */ + state->texture = create_texture (COGL_TEXTURE_NO_ATLAS); + draw_tests (state); + cogl_handle_unref (state->texture); - validate_result (state); -} + /* Draw the tests again with a possible atlased texture. This should + end up testing software repeats */ + state->texture = create_texture (COGL_TEXTURE_NONE); + cogl_push_matrix (); + cogl_translate (0.0f, TEX_SIZE * 2.0f, 0.0f); + draw_tests (state); + cogl_pop_matrix (); + cogl_handle_unref (state->texture); -static gboolean -queue_redraw (gpointer stage) -{ - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); + /* Draw the tests using cogl_polygon */ + state->texture = create_texture (COGL_TEXTURE_NO_ATLAS); + cogl_push_matrix (); + cogl_translate (0.0f, TEX_SIZE * 4.0f, 0.0f); + draw_tests_polygon (state); + cogl_pop_matrix (); + cogl_handle_unref (state->texture); - return TRUE; + /* Draw the tests using a vertex buffer */ + state->texture = create_texture (COGL_TEXTURE_NO_ATLAS); + cogl_push_matrix (); + cogl_translate (0.0f, TEX_SIZE * 6.0f, 0.0f); + draw_tests_vbo (state); + cogl_pop_matrix (); + cogl_handle_unref (state->texture); + + validate_result (state); } void test_cogl_wrap_modes (TestUtilsGTestFixture *fixture, void *data) { + TestUtilsSharedState *shared_state = data; TestState state; - unsigned int idle_source; - unsigned int paint_handler; - - state.stage = clutter_stage_get_default (); - - clutter_stage_set_color (CLUTTER_STAGE (state.stage), &stage_color); - - /* 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, state.stage); - - paint_handler = g_signal_connect_after (state.stage, "paint", - G_CALLBACK (on_paint), &state); - clutter_actor_show_all (state.stage); + state.ctx = shared_state->ctx; + state.width = cogl_framebuffer_get_width (shared_state->fb); + state.height = cogl_framebuffer_get_height (shared_state->fb); - clutter_main (); + cogl_ortho (0, state.width, /* left, right */ + state.height, 0, /* bottom, top */ + -1, 100 /* z near, far */); - g_source_remove (idle_source); - g_signal_handler_disconnect (state.stage, paint_handler); + paint (&state); if (g_test_verbose ()) g_print ("OK\n"); |