[Piglit] [PATCH] Add test case to verify Cube Shadow support in fixed function pipeline

Anuj Phogat anuj.phogat at gmail.com
Tue Dec 6 16:54:25 PST 2011


Adding a test case to verify Cube Shadow support in fixed function pipeline.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 tests/all.tests                          |    1 +
 tests/texturing/CMakeLists.gl.txt        |    1 +
 tests/texturing/sampler-cube-shadow-ff.c |  225 ++++++++++++++++++++++++++++++
 3 files changed, 227 insertions(+), 0 deletions(-)
 create mode 100644 tests/texturing/sampler-cube-shadow-ff.c

diff --git a/tests/all.tests b/tests/all.tests
index 68a379c..13e97a7 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -654,6 +654,7 @@ add_plain_test(texturing, 'rgtc-teximage-01')
 add_plain_test(texturing, 'rgtc-teximage-02')
 add_plain_test(texturing, 's3tc-teximage')
 add_plain_test(texturing, 's3tc-texsubimage')
+add_plain_test(texturing, 'sampler-cube-shadow-ff')
 add_concurrent_test(texturing, 'sized-texture-format-channels')
 add_plain_test(texturing, 'streaming-texture-leak')
 add_plain_test(texturing, 'tex-border-1')
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index e717e15..0361100 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -66,6 +66,7 @@ add_executable (depth-tex-modes      depth-tex-modes.c depth-tex-modes-common.c)
 add_executable (depth-tex-modes-rg   depth-tex-modes-rg.c depth-tex-modes-common.c)
 add_executable (depth-tex-modes-glsl depth-tex-modes-glsl.c)
 add_executable (depth-tex-compare depth-tex-compare.c)
+add_executable (sampler-cube-shadow-ff sampler-cube-shadow-ff.c)
 add_executable (sized-texture-format-channels sized-texture-format-channels.c)
 add_executable (tex-border-1 tex-border-1.c)
 add_executable (tex-skipped-unit tex-skipped-unit.c)
diff --git a/tests/texturing/sampler-cube-shadow-ff.c b/tests/texturing/sampler-cube-shadow-ff.c
new file mode 100644
index 0000000..82ffd65
--- /dev/null
+++ b/tests/texturing/sampler-cube-shadow-ff.c
@@ -0,0 +1,225 @@
+/*
+ * Copyright © 2011 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.
+ */
+
+/* Author: Anuj Phogat */
+/*
+ * Test to verify samplerCubeShadow support
+ * This test is valid only if:
+ *        - GL version >= 3.0 and GLSL version >= 1.30
+ * 
+ * It draws 6 polygons using each cubemap face as a depth texture for shadow comparisons.
+ * Color of pixels inside the polygon is decided by shadow comparison between texture's
+ * depth value and provided reference value ('q'texture coordinate)
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 400, piglit_height = 300;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static GLuint tex;
+
+static GLfloat vertices[12] =  {
+         100.0, 175.0, 0.0,
+         100.0, 125.0, 0.0,
+         150.0, 125.0, 0.0,
+         150.0, 175.0, 0.0};
+
+static GLuint indices[4] = {1, 2, 0, 3};
+
+/* These texture coordinates should have 1 or -1 in the major axis ('r' coordinate) selecting
+ * the face, a nearly-1-or-negative-1 value in the other two coordinates (s,t) and a reference
+ * value ('q' coordinate) used for shadow comparisons.
+ */
+static GLfloat cube_shadow_texcoords[6][4][4] = {
+  {  /* GL_TEXTURE_CUBE_MAP_POSITIVE_X */
+     {1.0,  0.99,  0.99,  0.00},
+     {1.0,  0.99, -0.99, -0.50},
+     {1.0, -0.99, -0.99,  0.00},
+     {1.0, -0.99,  0.99,  0.50},
+  },
+  {  /* GL_TEXTURE_CUBE_MAP_NEGATIVE_X */
+     {-1.0,  0.99, -0.99,  0.20},
+     {-1.0,  0.99,  0.99,  0.50},
+     {-1.0, -0.99,  0.99,  0.20},
+     {-1.0, -0.99, -0.99, -0.50},
+  },
+  {  /* GL_TEXTURE_CUBE_MAP_POSITIVE_Y */
+     {-0.99, 1.0, -0.99, -0.50},
+     { 0.99, 1.0, -0.99,  0.35},
+     { 0.99, 1.0,  0.99,  1.20},
+     {-0.99, 1.0,  0.99,  0.35},
+  },
+  {  /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Y */
+     {-0.99, -1.0,  0.99,  1.50},
+     {-0.99, -1.0, -0.99,  0.50},
+     { 0.99, -1.0, -0.99, -0.50},
+     { 0.99, -1.0,  0.99,  0.50},
+  },
+  {  /* GL_TEXTURE_CUBE_MAP_POSITIVE_Z */
+     {-0.99,  0.99, 1.0, 0.85},
+     {-0.99, -0.99, 1.0, 0.85},
+     { 0.99, -0.99, 1.0, 0.85},
+     { 0.99,  0.99, 1.0, 0.85},
+  },
+  {  /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Z */
+     { 0.99,  0.99, -1.0, 0.90},
+     {-0.99,  0.99, -1.0, 0.90},
+     {-0.99, -0.99, -1.0, 0.90},
+     { 0.99, -0.99, -1.0, 0.90},
+  },
+};
+
+static void
+loadTex(void)
+{
+   #define height 2
+   #define width 2
+   int i, j;
+   
+   GLfloat texDepthDataPosX[width][height];
+   GLfloat texDepthDataNegX[width][height];
+   GLfloat texDepthDataPosY[width][height];
+   GLfloat texDepthDataNegY[width][height];
+   GLfloat texDepthDataPosZ[width][height];
+   GLfloat texDepthDataNegZ[width][height];
+
+   /*Set the cubemap depth values for each face*/
+   for (i=0; i < height; ++i) {
+       for (j=0; j < width; ++j) {
+           texDepthDataPosX[i][j] = 0.0;
+           texDepthDataNegX[i][j] = 0.2;
+           texDepthDataPosY[i][j] = 0.35;
+           texDepthDataNegY[i][j] = 0.50;
+           texDepthDataPosZ[i][j] = 0.75;
+           texDepthDataNegZ[i][j] = 1.0;
+       }
+   }
+
+   /*Render the epth cube texture using LUMINANCE*/
+   glGenTextures(1, &tex);
+   glActiveTexture(GL_TEXTURE0);
+   glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
+   glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_FALSE);
+   glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+   glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+   glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+   glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+   glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+   glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
+   glTexParameterf( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE );
+   glTexParameterf( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
+   
+   /*Set a different depth value to each face of cubemap*/
+   glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthDataPosX);
+   glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthDataNegX);
+   glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthDataPosY);
+   glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthDataNegY);
+   glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthDataPosZ);
+   glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthDataNegZ);
+
+   #undef height
+   #undef width
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+   /*GL version must be 3.0*/
+   piglit_require_gl_version(30);
+   glEnable(GL_TEXTURE_CUBE_MAP);
+   loadTex();
+   glMatrixMode(GL_PROJECTION);
+   glPushMatrix();
+   glLoadIdentity();
+   glOrtho(0, piglit_width, 0, piglit_height, -1, 1);
+   glMatrixMode(GL_MODELVIEW);
+   glPushMatrix();
+   glLoadIdentity();
+   glClearColor(0.1, 0.1, 0.1, 1.0);
+   glVertexPointer(3, GL_FLOAT, 0, vertices);
+   glEnableClientState(GL_VERTEX_ARRAY);
+   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+   GLboolean pass = GL_TRUE;
+   GLfloat white[3] = {1.0, 0.0, 0.0};
+   GLfloat black[3] = {0.0, 0.0, 0.0};
+   
+   glClear(GL_COLOR_BUFFER_BIT);
+   glMatrixMode(GL_MODELVIEW);
+   
+   /*Apply each face of cubemap as texture to a polygon*/
+   glTexCoordPointer(4, GL_FLOAT, 0, cube_shadow_texcoords[0]);
+   glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices);
+   
+   glPushMatrix();
+   glTranslatef(75.0, 0.0, 0.0);
+   glTexCoordPointer(4, GL_FLOAT, 0, cube_shadow_texcoords[1]);
+   glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices);
+   
+   glTranslatef(75.0, 0.0, 0.0);
+   glTexCoordPointer(4, GL_FLOAT, 0, cube_shadow_texcoords[2]);
+   glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices);
+   glPopMatrix();
+   
+   glPushMatrix();
+   glTranslatef(0.0, 75.0, 0.0);
+   glTexCoordPointer(4, GL_FLOAT, 0, cube_shadow_texcoords[3]);
+   glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices);
+
+   glTranslatef(75.0, 0.0, 0.0);
+   glTexCoordPointer(4, GL_FLOAT, 0, cube_shadow_texcoords[4]);
+   glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices);
+
+   glTranslatef(75.0, 0.0, 0.0);
+   glTexCoordPointer(4, GL_FLOAT, 0, cube_shadow_texcoords[5]);
+   glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices);
+   glPopMatrix();
+
+   /*Test the pixel color of polygons against the expected output*/
+   pass = piglit_probe_pixel_rgb(110, 135, white);
+   pass = pass && piglit_probe_pixel_rgb(140, 165, black)
+   ;
+   pass = pass && piglit_probe_pixel_rgb(185, 135, black);
+   pass = pass && piglit_probe_pixel_rgb(215, 165, white);
+
+   pass = pass && piglit_probe_pixel_rgb(260, 165, white);
+   pass = pass && piglit_probe_pixel_rgb(290, 135, black);
+
+   pass = pass && piglit_probe_pixel_rgb(110, 240, black);
+   pass = pass && piglit_probe_pixel_rgb(140, 210, white);
+
+   pass = pass && piglit_probe_pixel_rgb(185, 210, black);
+   pass = pass && piglit_probe_pixel_rgb(215, 240, black);
+
+   pass = pass && piglit_probe_pixel_rgb(260, 210, white);
+   pass = pass && piglit_probe_pixel_rgb(290, 240, white);
+   
+   piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+   piglit_present_results();
+   return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
1.7.7



More information about the Piglit mailing list