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>
This commit is contained in:
Robert Bragg 2011-10-12 17:12:08 +01:00
parent 426c8b8f41
commit 3c129f5c18
3 changed files with 124 additions and 152 deletions

View File

@ -32,7 +32,6 @@ unported_test_sources = \
test-vertex-buffer-contiguous.c \ test-vertex-buffer-contiguous.c \
test-vertex-buffer-interleved.c \ test-vertex-buffer-interleved.c \
test-vertex-buffer-mutability.c \ test-vertex-buffer-mutability.c \
test-wrap-modes.c \
test-primitive.c \ test-primitive.c \
$(NULL) $(NULL)
@ -43,6 +42,7 @@ test_sources = \
test-backface-culling.c \ test-backface-culling.c \
test-just-vertex-shader.c \ test-just-vertex-shader.c \
test-pipeline-user-matrix.c \ test-pipeline-user-matrix.c \
test-wrap-modes.c \
$(NULL) $(NULL)
test_conformance_SOURCES = $(common_sources) $(test_sources) test_conformance_SOURCES = $(common_sources) $(test_sources)

View File

@ -149,7 +149,7 @@ main (int argc, char **argv)
UNPORTED_TEST ("/cogl/texture", test_cogl_pixel_array); UNPORTED_TEST ("/cogl/texture", test_cogl_pixel_array);
UNPORTED_TEST ("/cogl/texture", test_cogl_texture_rectangle); UNPORTED_TEST ("/cogl/texture", test_cogl_texture_rectangle);
UNPORTED_TEST ("/cogl/texture", test_cogl_texture_3d); 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_pixmap_x11);
UNPORTED_TEST ("/cogl/texture", test_cogl_texture_get_set_data); UNPORTED_TEST ("/cogl/texture", test_cogl_texture_get_set_data);
UNPORTED_TEST ("/cogl/texture", test_cogl_atlas_migration); UNPORTED_TEST ("/cogl/texture", test_cogl_atlas_migration);

View File

@ -1,23 +1,23 @@
#include <clutter/clutter.h> #include <cogl/cogl.h>
#include <string.h> #include <string.h>
#include "test-conform-common.h" #include "test-utils.h"
#define TEX_SIZE 4 #define TEX_SIZE 4
static const ClutterColor stage_color = { 0x80, 0x80, 0x80, 0xff };
typedef struct _TestState typedef struct _TestState
{ {
ClutterActor *stage; CoglContext *ctx;
CoglHandle texture; int width;
int height;
CoglTexture *texture;
} TestState; } TestState;
static CoglHandle static CoglTexture *
create_texture (CoglTextureFlags flags) create_texture (CoglTextureFlags flags)
{ {
guint8 *data = g_malloc (TEX_SIZE * TEX_SIZE * 4), *p = data; guint8 *data = g_malloc (TEX_SIZE * TEX_SIZE * 4), *p = data;
CoglHandle tex; CoglTexture *tex;
int x, y; int x, y;
for (y = 0; y < TEX_SIZE; y++) for (y = 0; y < TEX_SIZE; y++)
@ -34,50 +34,49 @@ create_texture (CoglTextureFlags flags)
COGL_PIXEL_FORMAT_ANY, COGL_PIXEL_FORMAT_ANY,
TEX_SIZE * 4, TEX_SIZE * 4,
data); data);
g_free (data); g_free (data);
return tex; return tex;
} }
static CoglHandle static CoglPipeline *
create_material (TestState *state, create_pipeline (TestState *state,
CoglMaterialWrapMode wrap_mode_s, CoglPipelineWrapMode wrap_mode_s,
CoglMaterialWrapMode wrap_mode_t) CoglPipelineWrapMode wrap_mode_t)
{ {
CoglHandle material; CoglPipeline *pipeline;
material = cogl_material_new (); pipeline = cogl_pipeline_new ();
cogl_material_set_layer (material, 0, state->texture); cogl_pipeline_set_layer_texture (pipeline, 0, state->texture);
cogl_material_set_layer_filters (material, 0, cogl_pipeline_set_layer_filters (pipeline, 0,
COGL_MATERIAL_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST,
COGL_MATERIAL_FILTER_NEAREST); COGL_PIPELINE_FILTER_NEAREST);
cogl_material_set_layer_wrap_mode_s (material, 0, wrap_mode_s); cogl_pipeline_set_layer_wrap_mode_s (pipeline, 0, wrap_mode_s);
cogl_material_set_layer_wrap_mode_t (material, 0, wrap_mode_t); cogl_pipeline_set_layer_wrap_mode_t (pipeline, 0, wrap_mode_t);
return material; return pipeline;
} }
static CoglMaterialWrapMode static CoglPipelineWrapMode
test_wrap_modes[] = test_wrap_modes[] =
{ {
COGL_MATERIAL_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT,
COGL_MATERIAL_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT,
COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
COGL_MATERIAL_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT,
COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
COGL_MATERIAL_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT,
COGL_MATERIAL_WRAP_MODE_AUTOMATIC, COGL_PIPELINE_WRAP_MODE_AUTOMATIC,
COGL_MATERIAL_WRAP_MODE_AUTOMATIC, COGL_PIPELINE_WRAP_MODE_AUTOMATIC,
COGL_MATERIAL_WRAP_MODE_AUTOMATIC, COGL_PIPELINE_WRAP_MODE_AUTOMATIC,
COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE
}; };
static void static void
@ -87,17 +86,17 @@ draw_tests (TestState *state)
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2) 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;
CoglHandle material; 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 */ that we can verify whether the batch splitting works */
wrap_mode_s = test_wrap_modes[i]; wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1]; wrap_mode_t = test_wrap_modes[i + 1];
material = create_material (state, wrap_mode_s, wrap_mode_t); pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
cogl_set_source (material); cogl_set_source (pipeline);
cogl_handle_unref (material); cogl_handle_unref (pipeline);
/* Render the material at four times the size of the texture */ /* Render the pipeline at four times the size of the texture */
cogl_rectangle_with_texture_coords (i * TEX_SIZE, 0, cogl_rectangle_with_texture_coords (i * TEX_SIZE, 0,
(i + 2) * TEX_SIZE, TEX_SIZE * 2, (i + 2) * TEX_SIZE, TEX_SIZE * 2,
0, 0, 2, 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) 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;
CoglHandle material; CoglPipeline *pipeline;
wrap_mode_s = test_wrap_modes[i]; wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1]; wrap_mode_t = test_wrap_modes[i + 1];
material = create_material (state, wrap_mode_s, wrap_mode_t); pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
cogl_set_source (material); cogl_set_source (pipeline);
cogl_handle_unref (material); cogl_handle_unref (pipeline);
cogl_push_matrix (); cogl_push_matrix ();
cogl_translate (TEX_SIZE * i, 0.0f, 0.0f); 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_polygon (vertices, G_N_ELEMENTS (vertices), FALSE);
cogl_pop_matrix (); cogl_pop_matrix ();
} }
@ -154,17 +153,17 @@ draw_tests_vbo (TestState *state)
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2) 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;
CoglHandle material; CoglPipeline *pipeline;
wrap_mode_s = test_wrap_modes[i]; wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1]; wrap_mode_t = test_wrap_modes[i + 1];
material = create_material (state, wrap_mode_s, wrap_mode_t); pipeline = create_pipeline (state, wrap_mode_s, wrap_mode_t);
cogl_set_source (material); cogl_set_source (pipeline);
cogl_handle_unref (material); cogl_handle_unref (pipeline);
cogl_push_matrix (); cogl_push_matrix ();
cogl_translate (TEX_SIZE * i, 0.0f, 0.0f); 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_vertex_buffer_draw (vbo, COGL_VERTICES_MODE_TRIANGLE_FAN, 0, 4);
cogl_pop_matrix (); cogl_pop_matrix ();
} }
@ -173,7 +172,67 @@ draw_tests_vbo (TestState *state)
} }
static void static void
draw_frame (TestState *state) validate_set (TestState *state, int offset)
{
guint8 data[TEX_SIZE * 2 * TEX_SIZE * 2 * 4], *p;
int x, y, i;
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2)
{
CoglPipelineWrapMode wrap_mode_s, wrap_mode_t;
wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1];
cogl_read_pixels (i * TEX_SIZE, offset * TEX_SIZE * 2,
TEX_SIZE * 2, TEX_SIZE * 2,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888,
data);
p = data;
for (y = 0; y < TEX_SIZE * 2; y++)
for (x = 0; x < TEX_SIZE * 2; x++)
{
guint8 green, blue;
if (x < TEX_SIZE ||
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_PIPELINE_WRAP_MODE_REPEAT ||
wrap_mode_t == COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
blue = (y & 1) * 255;
else
blue = ((TEX_SIZE - 1) & 1) * 255;
g_assert_cmpint (p[0], ==, 0);
g_assert_cmpint (p[1], ==, green);
g_assert_cmpint (p[2], ==, blue);
p += 4;
}
}
}
static void
validate_result (TestState *state)
{
validate_set (state, 0); /* non-atlased rectangle */
#if 0 /* this doesn't currently work */
validate_set (state, 1); /* atlased rectangle */
#endif
validate_set (state, 2); /* cogl_polygon */
validate_set (state, 3); /* vertex buffer */
}
static void
paint (TestState *state)
{ {
/* Draw the tests first with a non atlased texture */ /* Draw the tests first with a non atlased texture */
state->texture = create_texture (COGL_TEXTURE_NO_ATLAS); state->texture = create_texture (COGL_TEXTURE_NO_ATLAS);
@ -204,113 +263,26 @@ draw_frame (TestState *state)
draw_tests_vbo (state); draw_tests_vbo (state);
cogl_pop_matrix (); cogl_pop_matrix ();
cogl_handle_unref (state->texture); cogl_handle_unref (state->texture);
}
static void
validate_set (TestState *state, int offset)
{
guint8 data[TEX_SIZE * 2 * TEX_SIZE * 2 * 4], *p;
int x, y, i;
for (i = 0; i < G_N_ELEMENTS (test_wrap_modes); i += 2)
{
CoglMaterialWrapMode wrap_mode_s, wrap_mode_t;
wrap_mode_s = test_wrap_modes[i];
wrap_mode_t = test_wrap_modes[i + 1];
cogl_read_pixels (i * TEX_SIZE, offset * TEX_SIZE * 2,
TEX_SIZE * 2, TEX_SIZE * 2,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888,
data);
p = data;
for (y = 0; y < TEX_SIZE * 2; y++)
for (x = 0; x < TEX_SIZE * 2; x++)
{
guint8 green, blue;
if (x < TEX_SIZE ||
wrap_mode_s == COGL_MATERIAL_WRAP_MODE_REPEAT ||
wrap_mode_s == COGL_MATERIAL_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)
blue = (y & 1) * 255;
else
blue = ((TEX_SIZE - 1) & 1) * 255;
g_assert_cmpint (p[0], ==, 0);
g_assert_cmpint (p[1], ==, green);
g_assert_cmpint (p[2], ==, blue);
p += 4;
}
}
}
static void
validate_result (TestState *state)
{
validate_set (state, 0); /* non-atlased rectangle */
#if 0 /* this doesn't currently work */
validate_set (state, 1); /* atlased rectangle */
#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)
{
draw_frame (state);
validate_result (state); validate_result (state);
} }
static gboolean
queue_redraw (gpointer stage)
{
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
return TRUE;
}
void void
test_cogl_wrap_modes (TestUtilsGTestFixture *fixture, test_cogl_wrap_modes (TestUtilsGTestFixture *fixture,
void *data) void *data)
{ {
TestUtilsSharedState *shared_state = data;
TestState state; TestState state;
unsigned int idle_source;
unsigned int paint_handler;
state.stage = clutter_stage_get_default (); state.ctx = shared_state->ctx;
state.width = cogl_framebuffer_get_width (shared_state->fb);
state.height = cogl_framebuffer_get_height (shared_state->fb);
clutter_stage_set_color (CLUTTER_STAGE (state.stage), &stage_color); cogl_ortho (0, state.width, /* left, right */
state.height, 0, /* bottom, top */
-1, 100 /* z near, far */);
/* We force continuous redrawing of the stage, since we need to skip paint (&state);
* 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);
clutter_main ();
g_source_remove (idle_source);
g_signal_handler_disconnect (state.stage, paint_handler);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");