[mutter] tests/cogl: Migrate point sprite tests
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] tests/cogl: Migrate point sprite tests
- Date: Mon, 8 Aug 2022 22:13:11 +0000 (UTC)
commit 590290cd6dbdcd5b62d2e0271ce13752463d72a6
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Thu Aug 4 20:34:26 2022 +0200
tests/cogl: Migrate point sprite tests
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2555>
cogl/tests/conform/meson.build | 1 -
cogl/tests/conform/test-conform-main.c | 7 -
cogl/tests/conform/test-declarations.h | 3 -
src/tests/cogl/conform/meson.build | 2 +
.../cogl/conform/test-point-sprite-known-failure.c | 184 +++++++++++++++++++++
.../tests/cogl}/conform/test-point-sprite.c | 19 +--
6 files changed, 194 insertions(+), 22 deletions(-)
---
diff --git a/cogl/tests/conform/meson.build b/cogl/tests/conform/meson.build
index 1aa0a3bbe6..63367ffe57 100644
--- a/cogl/tests/conform/meson.build
+++ b/cogl/tests/conform/meson.build
@@ -1,6 +1,5 @@
cogl_test_conformance_sources = [
'test-conform-main.c',
- 'test-point-sprite.c',
'test-no-gl-header.c',
'test-version.c',
'test-layer-remove.c',
diff --git a/cogl/tests/conform/test-conform-main.c b/cogl/tests/conform/test-conform-main.c
index 3bc98ba184..672d3d51f2 100644
--- a/cogl/tests/conform/test-conform-main.c
+++ b/cogl/tests/conform/test-conform-main.c
@@ -78,13 +78,6 @@ main (int argc, char **argv)
TEST_REQUIREMENT_GL,
0);
- ADD_TEST (test_point_sprite,
- 0, 0);
- ADD_TEST (test_point_sprite_orientation,
- 0, TEST_KNOWN_FAILURE);
- ADD_TEST (test_point_sprite_glsl,
- 0, 0);
-
ADD_TEST (test_alpha_test, 0, 0);
ADD_TEST (test_map_buffer_range, TEST_REQUIREMENT_MAP_WRITE, 0);
diff --git a/cogl/tests/conform/test-declarations.h b/cogl/tests/conform/test-declarations.h
index 492cd22431..c2f74e2660 100644
--- a/cogl/tests/conform/test-declarations.h
+++ b/cogl/tests/conform/test-declarations.h
@@ -10,9 +10,6 @@ void test_npot_texture (void);
void test_texture_get_set_data (void);
void test_alpha_textures (void);
void test_framebuffer_get_bits (void);
-void test_point_sprite (void);
-void test_point_sprite_orientation (void);
-void test_point_sprite_glsl (void);
void test_alpha_test (void);
void test_map_buffer_range (void);
void test_primitive_and_journal (void);
diff --git a/src/tests/cogl/conform/meson.build b/src/tests/cogl/conform/meson.build
index 22b52ed72a..10a1e74bb0 100644
--- a/src/tests/cogl/conform/meson.build
+++ b/src/tests/cogl/conform/meson.build
@@ -22,6 +22,8 @@ cogl_tests = [
[ 'test-write-texture-formats', [] ],
[ 'test-point-size', [] ],
[ 'test-point-size-attribute', [] ],
+ [ 'test-point-sprite', [] ],
+ [ 'test-point-sprite-known-failure', ['gl', 'gl3', 'gles2'] ],
]
cogl_test_conformance_includes = [
diff --git a/src/tests/cogl/conform/test-point-sprite-known-failure.c
b/src/tests/cogl/conform/test-point-sprite-known-failure.c
new file mode 100644
index 0000000000..39cb2ad08a
--- /dev/null
+++ b/src/tests/cogl/conform/test-point-sprite-known-failure.c
@@ -0,0 +1,184 @@
+#include <cogl/cogl.h>
+
+#include "tests/cogl-test-utils.h"
+
+#define POINT_SIZE 8
+
+static const CoglVertexP2T2
+point =
+ {
+ POINT_SIZE, POINT_SIZE,
+ 0.0f, 0.0f
+ };
+
+static const uint8_t
+tex_data[3 * 2 * 2] =
+ {
+ 0x00, 0x00, 0xff, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0xff, 0xff, 0x00, 0x00
+ };
+
+static void
+do_test (gboolean check_orientation,
+ gboolean use_glsl)
+{
+ int fb_width = cogl_framebuffer_get_width (test_fb);
+ int fb_height = cogl_framebuffer_get_height (test_fb);
+ CoglPrimitive *prim;
+ GError *error = NULL;
+ CoglTexture2D *tex_2d;
+ CoglPipeline *pipeline, *solid_pipeline;
+ int tex_height;
+
+ cogl_framebuffer_orthographic (test_fb,
+ 0, 0, /* x_1, y_1 */
+ fb_width, /* x_2 */
+ fb_height /* y_2 */,
+ -1, 100 /* near/far */);
+
+ cogl_framebuffer_clear4f (test_fb,
+ COGL_BUFFER_BIT_COLOR,
+ 1.0f, 1.0f, 1.0f, 1.0f);
+
+ /* If we're not checking the orientation of the point sprite then
+ * we'll set the height of the texture to 1 so that the vertical
+ * orientation does not matter */
+ if (check_orientation)
+ tex_height = 2;
+ else
+ tex_height = 1;
+
+ tex_2d = cogl_texture_2d_new_from_data (test_ctx,
+ 2, tex_height, /* width/height */
+ COGL_PIXEL_FORMAT_RGB_888,
+ 6, /* row stride */
+ tex_data,
+ &error);
+ g_assert (tex_2d != NULL);
+ g_assert (error == NULL);
+
+ pipeline = cogl_pipeline_new (test_ctx);
+ cogl_pipeline_set_layer_texture (pipeline, 0, tex_2d);
+
+ cogl_pipeline_set_layer_filters (pipeline,
+ 0, /* layer_index */
+ COGL_PIPELINE_FILTER_NEAREST,
+ COGL_PIPELINE_FILTER_NEAREST);
+ cogl_pipeline_set_point_size (pipeline, POINT_SIZE);
+
+ /* If we're using GLSL then we don't need to enable point sprite
+ * coords and we can just directly reference cogl_point_coord in the
+ * snippet */
+ if (use_glsl)
+ {
+ CoglSnippet *snippet =
+ cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP,
+ NULL, /* declarations */
+ NULL /* post */);
+ static const char source[] =
+ " cogl_texel = texture2D (cogl_sampler, cogl_point_coord);\n";
+
+ cogl_snippet_set_replace (snippet, source);
+
+ /* Keep a reference to the original pipeline because there is no
+ * way to remove a snippet in order to recreate the solid
+ * pipeline */
+ solid_pipeline = cogl_pipeline_copy (pipeline);
+
+ cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
+
+ cogl_object_unref (snippet);
+ }
+ else
+ {
+ gboolean res =
+ cogl_pipeline_set_layer_point_sprite_coords_enabled (pipeline,
+ /* layer_index */
+ 0,
+ /* enable */
+ TRUE,
+ &error);
+ g_assert (res == TRUE);
+ g_assert (error == NULL);
+
+ solid_pipeline = cogl_pipeline_copy (pipeline);
+
+ res =
+ cogl_pipeline_set_layer_point_sprite_coords_enabled (solid_pipeline,
+ /* layer_index */
+ 0,
+ /* enable */
+ FALSE,
+ &error);
+
+ g_assert (res == TRUE);
+ g_assert (error == NULL);
+ }
+
+ prim = cogl_primitive_new_p2t2 (test_ctx,
+ COGL_VERTICES_MODE_POINTS,
+ 1, /* n_vertices */
+ &point);
+
+ cogl_primitive_draw (prim, test_fb, pipeline);
+
+ /* Render the primitive again without point sprites to make sure
+ disabling it works */
+
+ cogl_framebuffer_push_matrix (test_fb);
+ cogl_framebuffer_translate (test_fb,
+ POINT_SIZE * 2, /* x */
+ 0.0f, /* y */
+ 0.0f /* z */);
+ cogl_primitive_draw (prim, test_fb, solid_pipeline);
+ cogl_framebuffer_pop_matrix (test_fb);
+
+ cogl_object_unref (prim);
+ cogl_object_unref (solid_pipeline);
+ cogl_object_unref (pipeline);
+ cogl_object_unref (tex_2d);
+
+ test_utils_check_pixel (test_fb,
+ POINT_SIZE - POINT_SIZE / 4,
+ POINT_SIZE - POINT_SIZE / 4,
+ 0x0000ffff);
+ test_utils_check_pixel (test_fb,
+ POINT_SIZE + POINT_SIZE / 4,
+ POINT_SIZE - POINT_SIZE / 4,
+ 0x00ff00ff);
+ test_utils_check_pixel (test_fb,
+ POINT_SIZE - POINT_SIZE / 4,
+ POINT_SIZE + POINT_SIZE / 4,
+ check_orientation ?
+ 0x00ffffff :
+ 0x0000ffff);
+ test_utils_check_pixel (test_fb,
+ POINT_SIZE + POINT_SIZE / 4,
+ POINT_SIZE + POINT_SIZE / 4,
+ check_orientation ?
+ 0xff0000ff :
+ 0x00ff00ff);
+
+ /* When rendering without the point sprites all of the texture
+ coordinates should be 0,0 so it should get the top-left texel
+ which is blue */
+ test_utils_check_region (test_fb,
+ POINT_SIZE * 3 - POINT_SIZE / 2 + 1,
+ POINT_SIZE - POINT_SIZE / 2 + 1,
+ POINT_SIZE - 2, POINT_SIZE - 2,
+ 0x0000ffff);
+
+ if (cogl_test_verbose ())
+ g_print ("OK\n");
+}
+
+static void
+test_point_sprite_orientation (void)
+{
+ do_test (TRUE /* check orientation */,
+ FALSE /* don't use GLSL */);
+}
+
+COGL_TEST_SUITE (
+ g_test_add_func ("/point-sprite/orientation", test_point_sprite_orientation);
+)
diff --git a/cogl/tests/conform/test-point-sprite.c b/src/tests/cogl/conform/test-point-sprite.c
similarity index 96%
rename from cogl/tests/conform/test-point-sprite.c
rename to src/tests/cogl/conform/test-point-sprite.c
index ab4391cebe..071d3e6f97 100644
--- a/cogl/tests/conform/test-point-sprite.c
+++ b/src/tests/cogl/conform/test-point-sprite.c
@@ -1,7 +1,6 @@
#include <cogl/cogl.h>
-#include "test-declarations.h"
-#include "test-utils.h"
+#include "tests/cogl-test-utils.h"
#define POINT_SIZE 8
@@ -173,23 +172,21 @@ do_test (gboolean check_orientation,
g_print ("OK\n");
}
-void
+static void
test_point_sprite (void)
{
do_test (FALSE /* don't check orientation */,
FALSE /* don't use GLSL */);
}
-void
-test_point_sprite_orientation (void)
-{
- do_test (TRUE /* check orientation */,
- FALSE /* don't use GLSL */);
-}
-
-void
+static void
test_point_sprite_glsl (void)
{
do_test (FALSE /* don't check orientation */,
TRUE /* use GLSL */);
}
+
+COGL_TEST_SUITE (
+ g_test_add_func ("/point-sprite/basic", test_point_sprite);
+ g_test_add_func ("/point-sprite/glsl", test_point_sprite_glsl);
+)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]