[Piglit] [PATCH] gl: Add GL_NV_primitive_restart test
Jordan Justen
jordan.l.justen at intel.com
Mon Apr 23 11:38:30 PDT 2012
This test draws two boxes with a primitive restart
index used between drawing the two boxes.
These draw modes are tested:
* GL_TRIANGLES, GL_QUADS, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN
Three restart indices are tested:
* ~0
* an index in the middle of the array
* just passed the end of the array
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
tests/all.tests | 4 +
tests/spec/CMakeLists.txt | 1 +
tests/spec/nv_primitive_restart/CMakeLists.gl.txt | 16 ++
tests/spec/nv_primitive_restart/CMakeLists.txt | 1 +
.../nv_primitive_restart/nv_primitive_restart.c | 262 ++++++++++++++++++++
5 files changed, 284 insertions(+)
create mode 100644 tests/spec/nv_primitive_restart/CMakeLists.gl.txt
create mode 100644 tests/spec/nv_primitive_restart/CMakeLists.txt
create mode 100644 tests/spec/nv_primitive_restart/nv_primitive_restart.c
diff --git a/tests/all.tests b/tests/all.tests
index d3c1868..9cdc2e4 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1661,6 +1661,10 @@ nv_conditional_render['drawpixels'] = PlainExecTest(['nv_conditional_render-draw
nv_conditional_render['generatemipmap'] = PlainExecTest(['nv_conditional_render-generatemipmap', '-auto'])
nv_conditional_render['vertex_array'] = PlainExecTest(['nv_conditional_render-vertex_array', '-auto'])
+nv_primitive_restart = Group()
+spec['NV_primitive_restart'] = nv_primitive_restart
+add_plain_test(nv_primitive_restart, 'nv_primitive_restart')
+
oes_compressed_paletted_texture = Group()
spec['OES_compressed_paletted_texture'] = oes_compressed_paletted_texture
oes_compressed_paletted_texture['invalid formats'] = PlainExecTest(['arb_texture_compression-invalid-formats', 'paletted'])
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index b1a2fb3..801b268 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -26,6 +26,7 @@ add_subdirectory (ext_packed_float)
add_subdirectory (ext_timer_query)
add_subdirectory (ext_transform_feedback)
add_subdirectory (nv_conditional_render)
+add_subdirectory (nv_primitive_restart)
add_subdirectory (nv_texture_barrier)
add_subdirectory (oes_compressed_etc1_rgb8_texture)
add_subdirectory (oes_compressed_paletted_texture)
diff --git a/tests/spec/nv_primitive_restart/CMakeLists.gl.txt b/tests/spec/nv_primitive_restart/CMakeLists.gl.txt
new file mode 100644
index 0000000..fb61445
--- /dev/null
+++ b/tests/spec/nv_primitive_restart/CMakeLists.gl.txt
@@ -0,0 +1,16 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+ ${GLUT_INCLUDE_DIR}
+ ${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+ piglitutil
+ ${OPENGL_gl_LIBRARY}
+ ${OPENGL_glu_LIBRARY}
+ ${GLUT_glut_LIBRARY}
+)
+
+piglit_add_executable (nv_primitive_restart nv_primitive_restart.c)
+
diff --git a/tests/spec/nv_primitive_restart/CMakeLists.txt b/tests/spec/nv_primitive_restart/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/nv_primitive_restart/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/nv_primitive_restart/nv_primitive_restart.c b/tests/spec/nv_primitive_restart/nv_primitive_restart.c
new file mode 100644
index 0000000..084fb0f
--- /dev/null
+++ b/tests/spec/nv_primitive_restart/nv_primitive_restart.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file nv_primitive_restart.c
+ *
+ * Tests GL_NV_primitive_restart feature
+ */
+
+#include "piglit-util.h"
+
+#define PX_SIZE 10
+#define GRID_SIZE(x) ((x) * PX_SIZE)
+#define GRID2(x, y) (GRID_SIZE(x)), (GRID_SIZE(y))
+#define GRID_RECT(x, y, w, h) GRID2(x, y), GRID2(w, h)
+
+int piglit_width = (5 * PX_SIZE), piglit_height = 3 * PX_SIZE;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+/* Define vertices for 2 boxes */
+static const float verts[] = {
+ GRID2(1.0, 1.0), // BOX1 SW (Lower-left)
+ GRID2(2.0, 1.0), // BOX1 SE (Lower-right)
+ GRID2(2.0, 2.0), // BOX1 NE (Upper-right)
+ GRID2(1.0, 2.0), // BOX1 NW (Upper-left)
+
+ GRID2(1.5, 1.5), // Test Index within array
+
+ GRID2(3.0, 1.0), // BOX2 SW (Lower-left)
+ GRID2(4.0, 1.0), // BOX2 SE (Lower-right)
+ GRID2(4.0, 2.0), // BOX2 NE (Upper-right)
+ GRID2(3.0, 2.0), // BOX2 NW (Upper-left)
+};
+
+/* Enum of indices of the box corners */
+enum box_corners {
+ BOX1SW,
+ BOX1SE,
+ BOX1NE,
+ BOX1NW,
+ EMBEDDED_TEST_INDEX,
+ BOX2SW,
+ BOX2SE,
+ BOX2NE,
+ BOX2NW,
+};
+
+#define BOX_INDEX_DELTA (BOX2SW - BOX1SW)
+
+/* Array of all restart indices */
+static const int restarts[] = {
+ /* Commonly used restart index */
+ ~0,
+ /* Restart index just passed the end of the array */
+ ARRAY_SIZE(verts),
+ /* Restart index embedded in the array */
+ EMBEDDED_TEST_INDEX,
+};
+
+/* Array of all draw modes */
+static const int modes[] = {
+ GL_TRIANGLES,
+ GL_QUADS,
+ GL_TRIANGLE_STRIP,
+ GL_TRIANGLE_FAN,
+};
+
+static const float grey[4] = {0.5, 0.5, 0.5, 1.0};
+static const float white[4] = {1.0, 1.0, 1.0, 1.0};
+
+static
+void
+draw_individually(GLenum mode, int *indices, int count)
+{
+ int i;
+
+ glBegin(mode);
+ for (i = 0; i < count; i++) {
+ glArrayElement(indices[i]);
+ }
+ glEnd();
+}
+
+static
+void
+draw_elements(GLenum mode, int *indices, int count)
+{
+ glDrawElements(mode, count, GL_UNSIGNED_INT, indices);
+}
+
+static
+void
+setup_indices(GLenum mode, int restart, int **indices, int *count)
+{
+ int offset;
+ /* Worst case scenario, GL_TRIANGLES with 6 indices per box,
+ with 2 boxes, and 1 restart index */
+ static int local_indices[(2 * 6) + 1];
+ int *next;
+
+ *indices = &local_indices[0];
+
+ /* This loop will draw two boxes using the requested mode with
+ a restart index used between each box */
+ for (next = *indices, offset = 0; ; ) {
+ switch (mode) {
+ case GL_TRIANGLES:
+ *next++ = BOX1NW + offset;
+ *next++ = BOX1NE + offset;
+ *next++ = BOX1SW + offset;
+ *next++ = BOX1SW + offset;
+ *next++ = BOX1SE + offset;
+ *next++ = BOX1NE + offset;
+ break;
+ case GL_QUADS:
+ case GL_TRIANGLE_FAN:
+ *next++ = BOX1NW + offset;
+ *next++ = BOX1NE + offset;
+ *next++ = BOX1SE + offset;
+ *next++ = BOX1SW + offset;
+ break;
+ case GL_TRIANGLE_STRIP:
+ *next++ = BOX1NW + offset;
+ *next++ = BOX1NE + offset;
+ *next++ = BOX1SW + offset;
+ *next++ = BOX1SE + offset;
+ break;
+ }
+ if (offset == 0) {
+ *next++ = restart;
+ offset = BOX_INDEX_DELTA;
+ } else {
+ break;
+ }
+ }
+
+ *count = next - *indices;
+}
+
+static
+enum piglit_result
+draw_and_test(GLenum mode, int restart, int enable_draw_elements)
+{
+ enum piglit_result result = PIGLIT_PASS;
+ int *indices;
+ int count;
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ glPrimitiveRestartIndexNV(restart);
+ setup_indices(mode, restart, &indices, &count);
+ if (!enable_draw_elements) {
+ draw_individually(mode, indices, count);
+ } else {
+ draw_elements(mode, indices, count);
+ }
+
+ /* Verify the left box was drawn correctly */
+ if (!piglit_probe_rect_rgba(GRID_RECT(1, 1, 1, 1), white))
+ result = PIGLIT_FAIL;
+
+ /* Verify the right box was drawn correctly */
+ if (!piglit_probe_rect_rgba(GRID_RECT(3, 1, 1, 1), white))
+ result = PIGLIT_FAIL;
+
+ /* Verify the upper part of the window was not drawn on */
+ if (!piglit_probe_rect_rgba(GRID_RECT(0, 0, 5, 1), grey))
+ result = PIGLIT_FAIL;
+
+ /* Verify the lower part of the window was not drawn on */
+ if (!piglit_probe_rect_rgba(GRID_RECT(0, 2, 5, 1), grey))
+ result = PIGLIT_FAIL;
+
+ /* Verify the middle part of the window was not drawn on */
+ if (!piglit_probe_rect_rgba(GRID_RECT(2, 1, 1, 1), grey))
+ result = PIGLIT_FAIL;
+
+ return result;
+}
+
+static
+enum piglit_result
+draw_all_scenarios(int enable_draw_elements)
+{
+ enum piglit_result result = PIGLIT_PASS;
+ enum piglit_result draw_result;
+ int mindex;
+ int rindex;
+
+ glVertexPointer(2, GL_FLOAT, 0, verts);
+
+ /* Check each restart index */
+ for (rindex = 0; rindex < ARRAY_SIZE(restarts); rindex++) {
+ /* Check each mode type */
+ for (mindex = 0; mindex < ARRAY_SIZE(modes); mindex++) {
+ draw_result = draw_and_test(modes[mindex],
+ restarts[rindex],
+ enable_draw_elements);
+ if (draw_result != PIGLIT_PASS) {
+ result = draw_result;
+ }
+ }
+ }
+
+ return result;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ enum piglit_result result = PIGLIT_PASS;
+ enum piglit_result draw_result;
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_PRIMITIVE_RESTART_NV);
+
+ draw_result = draw_all_scenarios(0); /* glArrayElement */
+ if (draw_result != PIGLIT_PASS) {
+ result = draw_result;
+ }
+
+ draw_result = draw_all_scenarios(1); /* glDrawElements */
+ if (draw_result != PIGLIT_PASS) {
+ result = draw_result;
+ }
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_PRIMITIVE_RESTART_NV);
+
+ piglit_present_results();
+
+ return result;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ piglit_require_extension("GL_NV_primitive_restart");
+
+ glClearColor(grey[0], grey[1], grey[2], grey[3]);
+ glColor4fv(white);
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+}
--
1.7.10
More information about the Piglit
mailing list