summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2012-02-09 20:36:14 +0000
committerNeil Roberts <neil@linux.intel.com>2012-02-13 17:15:35 +0000
commitbf7f1e358d2dc90db984758652a88b8947eaf698 (patch)
treed79616ef0fc8b2e7b27121eff011afcaf5644488
parent971d7f33a0de15f46aa94ab3922d3cc1a46fbde6 (diff)
downloadcogl-bf7f1e358d2dc90db984758652a88b8947eaf698.tar.gz
Add a test for pipelines with sparse layer indices
There are currently quite a few places in Cogl where we muddle the layer index and the texture unit number. The theory is that these two numbers shouldn't be related and it should be possible to pick large layer numbers with gaps. This patch adds a test case to check that we can reference a large layer number from a texture combine string by creating a pipeline with only three layers but that have very large layer indices. This doesn't currently work because Cogl interprets the numbers in the combine strings to be the unit indices and not the layer indices. The documentation however calls these numbers layer numbers so presumably it is not meant to work that way. There are probably many other bugs related to this that the test case doesn't pick up so it would be good to add some more tests here, for example to test that you can bind an attribute to the texture coordinates for a large layer index. Reviewed-by: Robert Bragg <robert@linux.intel.com>
-rw-r--r--tests/conform/Makefile.am1
-rw-r--r--tests/conform/test-conform-main.c2
-rw-r--r--tests/conform/test-sparse-pipeline.c89
3 files changed, 92 insertions, 0 deletions
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index 63208b00..6b2d1ddc 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -47,6 +47,7 @@ test_sources = \
test-offscreen.c \
test-primitive.c \
test-texture-3d.c \
+ test-sparse-pipeline.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 f75f3ead..a732be68 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -142,6 +142,8 @@ main (int argc, char **argv)
ADD_TEST ("/cogl", test_cogl_color_mask);
ADD_TEST ("/cogl", test_cogl_backface_culling);
+ ADD_TEST ("/cogl/pipeline", test_cogl_sparse_pipeline);
+
UNPORTED_TEST ("/cogl/texture", test_cogl_npot_texture);
UNPORTED_TEST ("/cogl/texture", test_cogl_multitexture);
UNPORTED_TEST ("/cogl/texture", test_cogl_texture_mipmaps);
diff --git a/tests/conform/test-sparse-pipeline.c b/tests/conform/test-sparse-pipeline.c
new file mode 100644
index 00000000..433c0baa
--- /dev/null
+++ b/tests/conform/test-sparse-pipeline.c
@@ -0,0 +1,89 @@
+#include <cogl/cogl2-experimental.h>
+#include <string.h>
+
+#include "test-utils.h"
+
+typedef struct _TestState
+{
+ CoglContext *context;
+ int fb_width;
+ int fb_height;
+ CoglFramebuffer *fb;
+} TestState;
+
+static CoglTexture *
+create_color_texture (CoglContext *context,
+ guint32 color)
+{
+ CoglTexture2D *tex_2d;
+
+ color = GUINT32_TO_BE (color);
+
+ tex_2d = cogl_texture_2d_new_from_data (context,
+ 1, 1, /* width/height */
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ 4, /* rowstride */
+ (guint8 *) &color,
+ NULL);
+
+ return COGL_TEXTURE (tex_2d);
+}
+
+static void
+test_sparse_layer_combine (TestState *state)
+{
+ CoglPipeline *pipeline;
+ CoglTexture *tex1, *tex2;
+
+ cogl_framebuffer_clear4f (state->fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
+
+ /* This tests that the TEXTURE_* numbers used in the layer combine
+ string refer to the layer number rather than the unit numbers by
+ creating a pipeline with very large layer numbers. This should
+ end up being mapped to much smaller unit numbers */
+
+ tex1 = create_color_texture (state->context, 0xff0000ff);
+ tex2 = create_color_texture (state->context, 0x00ff00ff);
+
+ pipeline = cogl_pipeline_new ();
+
+ cogl_pipeline_set_layer_texture (pipeline, 50, tex1);
+ cogl_pipeline_set_layer_texture (pipeline, 100, tex2);
+ cogl_pipeline_set_layer_combine (pipeline, 200,
+ "RGBA = ADD(TEXTURE_50, TEXTURE_100)",
+ NULL);
+
+ cogl_push_source (pipeline);
+ cogl_rectangle (-1, -1, 1, 1);
+ cogl_pop_source ();
+
+ test_utils_check_pixel (2, 2, 0xffff00ff);
+
+ cogl_object_unref (pipeline);
+ cogl_object_unref (tex1);
+ cogl_object_unref (tex2);
+}
+
+void
+test_cogl_sparse_pipeline (TestUtilsGTestFixture *fixture,
+ void *data)
+{
+ TestUtilsSharedState *shared_state = data;
+ TestState state;
+
+ state.context = shared_state->ctx;
+ state.fb_width = cogl_framebuffer_get_width (shared_state->fb);
+ state.fb_height = cogl_framebuffer_get_height (shared_state->fb);
+ state.fb = shared_state->fb;
+
+ test_sparse_layer_combine (&state);
+
+ /* FIXME: This should have a lot more tests, for example testing
+ whether using an attribute with sparse texture coordinates will
+ work */
+
+ if (g_test_verbose ())
+ g_print ("OK\n");
+}
+