This is a copy of the render_viewport ARB_viewport_array test. I didn't
think that it was worth it to copy the scissor/depth tests, since they
basically test the same thing but making sure that scissor/depth are
applied correctly. If that works for ARB_viewport_array, it really
should work here too.

Signed-off-by: Ilia Mirkin <[email protected]>
---

Untested, mesa has no support for this and it's not extremely easy to
add to things I have access to since softpipe doesn't have viewports
and llvmpipe doesn't support writing from vs.

I do have r600g patches at:

https://github.com/imirkin/mesa/commits/flv

but they are also untested :) But hopefully this test should help
validate them.

 tests/all.py                                       |   4 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../CMakeLists.gl.txt                              |  12 ++
 .../CMakeLists.txt                                 |   1 +
 .../spec/amd_vertex_shader_viewport_index/render.c | 150 +++++++++++++++++++++
 5 files changed, 168 insertions(+)
 create mode 100644 
tests/spec/amd_vertex_shader_viewport_index/CMakeLists.gl.txt
 create mode 100644 tests/spec/amd_vertex_shader_viewport_index/CMakeLists.txt
 create mode 100644 tests/spec/amd_vertex_shader_viewport_index/render.c

diff --git a/tests/all.py b/tests/all.py
index c0f41dc..7ce90d8 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3026,6 +3026,10 @@ spec['AMD_vertex_shader_layer'] = amd_vertex_shader_layer
 add_plain_test(amd_vertex_shader_layer, 
'amd_vertex_shader_layer-layered-2d-texture-render')
 add_plain_test(amd_vertex_shader_layer, 
'amd_vertex_shader_layer-layered-depth-texture-render')
 
+amd_vertex_shader_viewport_index = {}
+spec['AMD_vertex_shader_viewport_index'] = amd_vertex_shader_viewport_index
+add_concurrent_test(amd_vertex_shader_viewport_index, 
'amd_vertex_shader_viewport_index-render')
+
 ext_fog_coord = {}
 spec['EXT_fog_coord'] = ext_fog_coord
 add_plain_test(ext_fog_coord, 'ext_fog_coord-modes')
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 489ff0c..c7001f1 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -32,6 +32,7 @@ add_subdirectory (arb_sampler_objects)
 add_subdirectory (arb_seamless_cube_map)
 add_subdirectory (amd_seamless_cubemap_per_texture)
 add_subdirectory (amd_vertex_shader_layer)
+add_subdirectory (amd_vertex_shader_viewport_index)
 add_subdirectory (arb_separate_shader_objects)
 add_subdirectory (arb_shader_texture_lod/execution)
 add_subdirectory (arb_shader_atomic_counters)
diff --git a/tests/spec/amd_vertex_shader_viewport_index/CMakeLists.gl.txt 
b/tests/spec/amd_vertex_shader_viewport_index/CMakeLists.gl.txt
new file mode 100644
index 0000000..a3da135
--- /dev/null
+++ b/tests/spec/amd_vertex_shader_viewport_index/CMakeLists.gl.txt
@@ -0,0 +1,12 @@
+include_directories(
+       ${GLEXT_INCLUDE_DIR}
+       ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+       piglitutil_${piglit_target_api}
+       ${OPENGL_gl_LIBRARY}
+       ${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (amd_vertex_shader_viewport_index-render render.c)
diff --git a/tests/spec/amd_vertex_shader_viewport_index/CMakeLists.txt 
b/tests/spec/amd_vertex_shader_viewport_index/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/amd_vertex_shader_viewport_index/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/amd_vertex_shader_viewport_index/render.c 
b/tests/spec/amd_vertex_shader_viewport_index/render.c
new file mode 100644
index 0000000..d6a51e6
--- /dev/null
+++ b/tests/spec/amd_vertex_shader_viewport_index/render.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright © 2013 LunarG, Inc.
+ *
+ * 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.
+ *
+ * Author: Jon Ashburn <[email protected]>
+ */
+
+/**
+ * Tests rendering into a single framebuffer surface with multiple viewports
+ * via a vertex shader.  Confirm that each area of the surface delineated by
+ * a viewport renders the correct color.
+ * From the extension registry for ARB_viewport_array:
+ *    "This extension enhances OpenGL by providing a mechanism to expose
+ *    multiple viewports. Each viewport is specified as a rectangle. The
+ *    destination viewport may be selected per-primitive by the geometry
+ *    shader. This allows the Geometry Shader to produce different versions
+ *    of primitives destined for separate viewport rectangles on the same
+ *    surface.
+ * This extension allows specifying the viewport from the vertex shader.
+ */
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+       config.supports_gl_core_version = 31;
+
+       config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+const char *vsSource = {
+       "#version 140\n"
+        "#extension GL_AMD_vertex_shader_viewport_index : enable\n"
+       "in vec4 piglit_vertex;\n"
+       "uniform int idx;\n"
+       "void main() {\n"
+       "       gl_ViewportIndex = idx;\n"
+       "       gl_Position = piglit_vertex;\n"
+       "}\n"
+};
+
+const char *fsSource = {
+       "#version 140\n"
+       "uniform vec3 color;\n"
+       "void main() {\n"
+       "       gl_FragColor = vec4(color.xyz, 1.0);\n"
+       "}\n"
+};
+
+static GLint colorLoc;
+static GLint vpIndexLoc;
+
+/**
+ * Draws a single quad into multiple viewport  each with a different
+ * color.  Reads back the expected color  to test if the drawing was correct.
+ * @param  changeVPloc;   if true then the vertex shader viewport location
+ *         is changed with each loop, otherwise viewport location is fixed.
+ */
+static bool
+draw_multi_viewport(const bool changeVPLoc)
+{
+       bool pass = true;
+       int i, j;
+       const int divX=2, divY=4;
+       GLfloat w = (GLfloat) piglit_width / (GLfloat) divX;
+       GLfloat h = (GLfloat) piglit_height / (GLfloat) divY;
+       const GLfloat colors[][3] = {{0.0, 0.0, 1.0},
+                                 {0.0, 1.0, 0.0},
+                                 {1.0, 0.0, 0.0},
+                                 {1.0, 1.0, 0.0},
+                                 {0.0, 1.0, 1.0},
+                                 {1.0, 0.0, 1.0},
+                                 {1.0, 1.0, 1.0},
+                                 {0.0, 0.0, 0.5},
+                                 {0.0, 0.0, 0.0}};
+
+       assert(ARRAY_SIZE(colors) == divX*divY + 1);
+
+       glViewport(0, 0, piglit_width, piglit_height); /* for glClear() */
+       glClear(GL_COLOR_BUFFER_BIT);
+       glUniform1i(vpIndexLoc, divX * divY);
+       glViewportIndexedf(divX * divY, -10.0, -30.0, piglit_width, 20.0);
+       for (i = 0; i < divX; i++) {
+               for (j = 0; j < divY; j++) {
+                       int p;
+                       GLfloat *expected;
+                       glUniform3fv(colorLoc, 1, &colors[j + i*divY][0]);
+                       if (changeVPLoc) {
+                               glUniform1i(vpIndexLoc, j + i*divY);
+                               expected = (GLfloat *) &colors[j + i*divY][0];
+                       } else  {
+                               expected = (GLfloat *) &colors[divX * divY][0];
+                       }
+                       glViewportIndexedf(j + i*divY, i * w, j * h, w, h);
+                       piglit_draw_rect(-1, -1, 2, 2);
+                       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+                       p = piglit_probe_pixel_rgb(i * w + w/2, j * h + h/2,
+                                                  expected);
+                       piglit_present_results();
+                       if (!p) {
+                               printf("Wrong color for viewport i,j %d %d 
changeVP=%d\n",
+                                      i, j, changeVPLoc);
+                               pass = false;
+                       }
+               }
+       }
+       return pass;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+       bool pass = true;
+
+       pass = draw_multi_viewport(true);
+       pass = draw_multi_viewport(false) && pass;
+       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+       GLuint program;
+
+       piglit_require_extension("GL_AMD_vertex_shader_viewport_index");
+
+       program = piglit_build_simple_program(vsSource, fsSource);
+       glUseProgram(program);
+       colorLoc = glGetUniformLocation(program, "color");
+       vpIndexLoc = glGetUniformLocation(program, "idx");
+}
-- 
1.8.5.5

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to