[cogl/cogl-1.14: 52/174] Add a test case for cogl_buffer_map_range
- From: Robert Bragg <rbragg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/cogl-1.14: 52/174] Add a test case for cogl_buffer_map_range
- Date: Tue, 22 Jan 2013 18:35:08 +0000 (UTC)
commit 53f43a428fef9b47d4201fdfd48dad468210de11
Author: Neil Roberts <neil linux intel com>
Date: Wed Oct 17 21:40:26 2012 +0100
Add a test case for cogl_buffer_map_range
This adds a small test case which maps a sub region of a small
attribute buffer and replaces the texture coordinates of one of the
vertices. The vertices are then drawn and the correct colours are
checked.
There is now a new test requirement for the
COGL_FEATURE_ID_MAP_BUFFER_FOR_WRITE feature which this test requires.
Reviewed-by: Robert Bragg <robert linux intel com>
(cherry picked from commit 22183265b021dd038338b4398056c0a1eae77edb)
tests/conform/Makefile.am | 1 +
tests/conform/test-conform-main.c | 2 +
tests/conform/test-map-buffer-range.c | 122 +++++++++++++++++++++++++++++++++
tests/conform/test-utils.c | 6 ++
tests/conform/test-utils.h | 3 +-
5 files changed, 133 insertions(+), 1 deletions(-)
---
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index 3e1bfbb..a02a52a 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -58,6 +58,7 @@ test_sources = \
test-euler-quaternion.c \
test-layer-remove.c \
test-alpha-test.c \
+ test-map-buffer-range.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 df9d2a5..9e2df06 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -102,6 +102,8 @@ main (int argc, char **argv)
ADD_TEST (test_alpha_test, 0);
+ ADD_TEST (test_map_buffer_range, TEST_REQUIREMENT_MAP_WRITE);
+
UNPORTED_TEST (test_viewport);
ADD_TEST (test_gles2_context, TEST_REQUIREMENT_GLES2_CONTEXT);
diff --git a/tests/conform/test-map-buffer-range.c b/tests/conform/test-map-buffer-range.c
new file mode 100644
index 0000000..6b70643
--- /dev/null
+++ b/tests/conform/test-map-buffer-range.c
@@ -0,0 +1,122 @@
+#include <cogl/cogl.h>
+
+#include <string.h>
+
+#include "test-utils.h"
+
+static uint8_t
+tex_data[2 * 2 * 4] =
+ {
+ 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff
+ };
+
+/* Vertex data for a quad with all of the texture coordinates set to
+ * the top left (red) pixel */
+static CoglVertexP2T2
+vertex_data[4] =
+ {
+ { -1, -1, 0, 0 },
+ { 1, -1, 0, 0 },
+ { -1, 1, 0, 0 },
+ { 1, 1, 0, 0 }
+ };
+
+void
+test_map_buffer_range (void)
+{
+ CoglTexture2D *tex;
+ CoglPipeline *pipeline;
+ int fb_width, fb_height;
+ CoglAttributeBuffer *buffer;
+ CoglVertexP2T2 *data;
+ CoglAttribute *pos_attribute;
+ CoglAttribute *tex_coord_attribute;
+
+ tex = cogl_texture_2d_new_from_data (ctx,
+ 2, 2, /* width/height */
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ COGL_PIXEL_FORMAT_ANY,
+ 2 * 4, /* rowstride */
+ tex_data,
+ NULL /* error */);
+
+ pipeline = cogl_pipeline_new (ctx);
+
+ cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (tex));
+ cogl_pipeline_set_layer_filters (pipeline,
+ 0, /* layer */
+ COGL_PIPELINE_FILTER_NEAREST,
+ COGL_PIPELINE_FILTER_NEAREST);
+ cogl_pipeline_set_layer_wrap_mode (pipeline,
+ 0, /* layer */
+ COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
+
+ fb_width = cogl_framebuffer_get_width (fb);
+ fb_height = cogl_framebuffer_get_height (fb);
+
+ buffer = cogl_attribute_buffer_new (ctx,
+ sizeof (vertex_data),
+ vertex_data);
+
+ /* Replace the texture coordinates of the third vertex with the
+ * coordinates for a green texel */
+ data = cogl_buffer_map_range (COGL_BUFFER (buffer),
+ sizeof (vertex_data[0]) * 2,
+ sizeof (vertex_data[0]),
+ COGL_BUFFER_ACCESS_WRITE,
+ COGL_BUFFER_MAP_HINT_DISCARD_RANGE);
+ g_assert (data != NULL);
+
+ data->x = vertex_data[2].x;
+ data->y = vertex_data[2].y;
+ data->s = 1.0f;
+ data->t = 0.0f;
+
+ cogl_buffer_unmap (COGL_BUFFER (buffer));
+
+ pos_attribute =
+ cogl_attribute_new (buffer,
+ "cogl_position_in",
+ sizeof (vertex_data[0]),
+ offsetof (CoglVertexP2T2, x),
+ 2, /* n_components */
+ COGL_ATTRIBUTE_TYPE_FLOAT);
+ tex_coord_attribute =
+ cogl_attribute_new (buffer,
+ "cogl_tex_coord_in",
+ sizeof (vertex_data[0]),
+ offsetof (CoglVertexP2T2, s),
+ 2, /* n_components */
+ COGL_ATTRIBUTE_TYPE_FLOAT);
+
+ cogl_framebuffer_clear4f (fb,
+ COGL_BUFFER_BIT_COLOR,
+ 0, 0, 0, 1);
+
+ cogl_framebuffer_vdraw_attributes (fb,
+ pipeline,
+ COGL_VERTICES_MODE_TRIANGLE_STRIP,
+ 0, /* first_vertex */
+ 4, /* n_vertices */
+ pos_attribute,
+ tex_coord_attribute,
+ NULL);
+
+ /* Top left pixel should be the one that is replaced to be green */
+ test_utils_check_pixel (fb, 1, 1, 0x00ff00ff);
+ /* The other three corners should be left as red */
+ test_utils_check_pixel (fb, fb_width - 2, 1, 0xff0000ff);
+ test_utils_check_pixel (fb, 1, fb_height - 2, 0xff0000ff);
+ test_utils_check_pixel (fb, fb_width - 2, fb_height - 2, 0xff0000ff);
+
+ cogl_object_unref (buffer);
+ cogl_object_unref (pos_attribute);
+ cogl_object_unref (tex_coord_attribute);
+
+ cogl_object_unref (pipeline);
+ cogl_object_unref (tex);
+
+ if (cogl_test_verbose ())
+ g_print ("OK\n");
+}
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index 84cb23b..5868fbc 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -83,6 +83,12 @@ test_utils_init (TestFlags flags)
missing_requirement = TRUE;
}
+ if (flags & TEST_REQUIREMENT_MAP_WRITE &&
+ !cogl_has_feature (ctx, COGL_FEATURE_ID_MAP_BUFFER_FOR_WRITE))
+ {
+ missing_requirement = TRUE;
+ }
+
if (flags & TEST_KNOWN_FAILURE)
{
missing_requirement = TRUE;
diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h
index 6fcdca1..68741b2 100644
--- a/tests/conform/test-utils.h
+++ b/tests/conform/test-utils.h
@@ -14,7 +14,8 @@ typedef enum _TestFlags
TEST_REQUIREMENT_NPOT = 1<<2,
TEST_REQUIREMENT_TEXTURE_3D = 1<<3,
TEST_REQUIREMENT_POINT_SPRITE = 1<<4,
- TEST_REQUIREMENT_GLES2_CONTEXT = 1<<5
+ TEST_REQUIREMENT_GLES2_CONTEXT = 1<<5,
+ TEST_REQUIREMENT_MAP_WRITE = 1<<6
} TestFlags;
extern CoglContext *ctx;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]