[Piglit] [PATCH 6/7] nv_fog_distance: Simple rendering test
Ian Romanick
idr at freedesktop.org
Thu Apr 26 21:29:15 UTC 2018
From: Ian Romanick <ian.d.romanick at intel.com>
A heavily modified version of this test passes on a Geforce3 (NV20)
running NVIDIA's 71.86.15 drivers. These are the last drivers that
support NV10 through NV2x, and they are shipped in 2011.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
tests/all.py | 3 +
tests/spec/nv_fog_distance/CMakeLists.gl.txt | 1 +
tests/spec/nv_fog_distance/simple-draw.c | 245 +++++++++++++++++++++++++++
3 files changed, 249 insertions(+)
create mode 100644 tests/spec/nv_fog_distance/simple-draw.c
diff --git a/tests/all.py b/tests/all.py
index 41e9dda10..70698ba10 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3918,6 +3918,9 @@ with profile.test_list.group_manager(
PiglitGLTest,
grouptools.join('spec', 'nv_fog_distance')) as g:
g(['nv_fog_distance-coverage'], 'coverage')
+ g(['nv_fog_distance-simple-draw', 'radial'], 'simple draw - GL_EYE_RADIAL_NV')
+ g(['nv_fog_distance-simple-draw', 'eye-plane'], 'simple draw - GL_EYE_PLANE')
+ g(['nv_fog_distance-simple-draw', 'eye-plane-absolute'], 'simple draw - GL_EYE_PLANE_ABSOLUTE_NV')
with profile.test_list.group_manager(
PiglitGLTest,
diff --git a/tests/spec/nv_fog_distance/CMakeLists.gl.txt b/tests/spec/nv_fog_distance/CMakeLists.gl.txt
index 9abea3bef..6a4300e8c 100644
--- a/tests/spec/nv_fog_distance/CMakeLists.gl.txt
+++ b/tests/spec/nv_fog_distance/CMakeLists.gl.txt
@@ -9,3 +9,4 @@ link_libraries (
)
piglit_add_executable (nv_fog_distance-coverage coverage.c)
+piglit_add_executable (nv_fog_distance-simple-draw simple-draw.c)
diff --git a/tests/spec/nv_fog_distance/simple-draw.c b/tests/spec/nv_fog_distance/simple-draw.c
new file mode 100644
index 000000000..e7be6bf5e
--- /dev/null
+++ b/tests/spec/nv_fog_distance/simple-draw.c
@@ -0,0 +1,245 @@
+/* Copyright © 2017 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 simple-draw.c
+ * Simple rendering tests of GL_NV_fog_distance
+ */
+
+#include "piglit-util-gl.h"
+#include "minmax-test.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLenum distance_mode = GL_EYE_RADIAL_NV;
+static GLuint vbo[2];
+
+/* Generate an NxM grid of vertices spanning [-1,-1]x[1,1]
+ */
+static unsigned
+generate_mesh(unsigned n, unsigned m, float z, GLuint vbo[2])
+{
+ /* Generate the grid of vertices by linearly interpolating across
+ * [-1,1]x[-1,1]. This is the easy part.
+ *
+ * Each vertex is 3 floats. There are N*M vertices.
+ */
+ glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * n * m,
+ NULL, GL_STATIC_DRAW);
+
+ float *verts = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
+ for (unsigned i = 0; i < m; i++) {
+ const float y = -1.0 + ((2.0 * i) / (m - 1));
+
+ for (unsigned j = 0; j < n; j++) {
+ const float x = -1.0 + ((2.0 * j) / (n - 1));
+
+ verts[0] = x;
+ verts[1] = y;
+ verts[2] = z;
+ verts += 3;
+ }
+ }
+
+ glUnmapBuffer(GL_ARRAY_BUFFER);
+
+ /* Generate the indices to draw the grid. This is a bit more tricky.
+ * There are M rows of vertices, so there are M-1 rows of triangle
+ * strips. Each strip requires 2*N elements.
+ *
+ * Going from one strip to the next is tricky. We can generate a two
+ * degenerate triangles by emitting the last vertex an extra time.
+ * The last two real indices combined with the extra instance of the
+ * last index is the first degenerate triangle, and the last two
+ * emitted indices combined with the first vertex of the next will
+ * create the second. Since both of these triangles will have zero
+ * area, neither will be drawn.
+ *
+ * There are always an even number of real triangles in each row, and
+ * there are always two degenerate triangles. This ensures that the
+ * first triangle in the next row will have the same winding as the
+ * first triangle in the current row.
+ *
+ * This would be a bit easier with primitive restart.
+ */
+ const unsigned total_elements = ((n * 2) + 1) * (m - 1);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(GLuint) * total_elements,
+ NULL, GL_STATIC_DRAW);
+
+ unsigned *elements = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
+
+ for (unsigned i = 0; i < (m - 1); i++) {
+ unsigned last;
+
+ for (unsigned j = 0; j < n; j++) {
+ elements[0] = ((i + 0) * n) + j;
+ elements[1] = ((i + 1) * n) + j;
+ last = ((i + 1) * n) + j;
+
+ elements += 2;
+ }
+
+ *(elements++) = last;
+ }
+
+ glUnmapBuffer(GL_ARRAY_BUFFER);
+
+ /* It's not necessary to draw the last "extra" vertex since it just
+ * joins the last row of triangles with a row that does not exist.
+ */
+ return total_elements - 1;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ unsigned verts_to_draw;
+ static const float fog_color[4] = { 0.0, 1.0, 0.0, 1.0 };
+ static const float draw_color[4] = { 1.0, 0.0, 0.0, 1.0 };
+ static const float mix_color[4] = { 0.5, 0.5, 0.0, 1.0 };
+ bool pass = true;
+
+ glViewport(0, 0, piglit_width, piglit_height);
+
+ /* Pick a Z value for the mesh. Select fog start and stop distances
+ * such that the middle of the window (the closest point) will have
+ * zero fog and the corners (the farthest points) will have full fog.
+ */
+ float z = 0.5;
+ float fog_start;
+ float fog_end;
+
+ switch (distance_mode) {
+ case GL_EYE_RADIAL_NV:
+ fog_start = z;
+ fog_end = sqrt(1.0 + 1.0 + (z * z));
+ break;
+ case GL_EYE_PLANE:
+ fog_start = 0.0;
+ fog_end = 1.0;
+ break;
+ case GL_EYE_PLANE_ABSOLUTE_NV:
+ /* For eye-plane absolute, set Z such that the eye-plane
+ * distance is negative.
+ */
+ z = -0.5;
+ fog_start = 0.0;
+ fog_end = 1.0;
+ break;
+ default:
+ assert(!"Impossible distance mode.");
+ }
+
+ verts_to_draw = generate_mesh(MAX2(2, (piglit_width + 1) / 2),
+ MAX2(2, (piglit_height + 1) / 2),
+ z, vbo);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
+ glVertexPointer(3, GL_FLOAT, 0, (void *)0);
+
+ glFogi(GL_FOG_DISTANCE_MODE_NV, distance_mode);
+ glFogf(GL_FOG_START, fog_start);
+ glFogf(GL_FOG_END, fog_end);
+ glFogfv(GL_FOG_COLOR, fog_color);
+
+ glColor3fv(draw_color);
+ glDrawElements(GL_TRIANGLE_STRIP, verts_to_draw, GL_UNSIGNED_INT,
+ (void *) 0);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ switch (distance_mode) {
+ case GL_EYE_RADIAL_NV:
+ pass = piglit_probe_pixel_rgb(0, 0, fog_color) && pass;
+ pass = piglit_probe_pixel_rgb(piglit_width / 2,
+ piglit_height / 2,
+ draw_color) && pass;
+ break;
+ case GL_EYE_PLANE:
+ case GL_EYE_PLANE_ABSOLUTE_NV:
+ pass = piglit_probe_pixel_rgb(0, 0, mix_color) && pass;
+ pass = piglit_probe_pixel_rgb(piglit_width / 2,
+ piglit_height / 2,
+ mix_color) && pass;
+ break;
+ default:
+ assert(!"Impossible distance mode.");
+ }
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ static const struct {
+ const char *name;
+ GLenum mode;
+ } modes[] = {
+ { "radial", GL_EYE_RADIAL_NV },
+ { "eye-plane", GL_EYE_PLANE },
+ { "eye-plane-absolute", GL_EYE_PLANE_ABSOLUTE_NV }
+ };
+
+ piglit_require_extension("GL_NV_fog_distance");
+ piglit_require_extension("GL_EXT_fog_coord");
+ piglit_require_extension("GL_ARB_vertex_buffer_object");
+
+ if (argc > 1) {
+ unsigned i;
+
+ for (i = 0; i < ARRAY_SIZE(modes); i++) {
+ if (strcmp(modes[i].name, argv[1]) == 0) {
+ distance_mode = modes[i].mode;
+ break;
+ }
+ }
+
+ if (i == ARRAY_SIZE(modes)) {
+ printf("Unknown distance mode \"%s\".\n",
+ argv[1]);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ }
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnable(GL_FOG);
+ glFogi(GL_FOG_MODE, GL_LINEAR);
+ glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH);
+
+ glGenBuffers(2, vbo);
+}
--
2.14.3
More information about the Piglit
mailing list