[Piglit] [PATCH] Test case for glTexImage2D with depth cube map

Anuj Phogat anuj.phogat at gmail.com
Mon Nov 21 19:20:04 PST 2011


From: Anuj Phogat <anuj.phogat at gmail.com>

Hi,

   I developed this testcase (depth-cube-map) to test depth cube map support on
   mesa-dev. It draws a polygon using one of cube map faces as texture. Testing is done
   by comparing the polygon's pixel color with texture color.
   I would be happy to make any suggested changes/additions to this test case.

Thanks
Anuj

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 tests/texturing/depth-cube-map.c |  221 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 221 insertions(+), 0 deletions(-)
 create mode 100644 tests/texturing/depth-cube-map.c

diff --git a/tests/texturing/depth-cube-map.c b/tests/texturing/depth-cube-map.c
new file mode 100644
index 0000000..8680769
--- /dev/null
+++ b/tests/texturing/depth-cube-map.c
@@ -0,0 +1,221 @@
+/*
+ * 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, Ben Holmes
+/*
+ * Test to verify cubemap depth texture support
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 400, piglit_height = 400;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static GLuint tex;
+static GLint prog;
+static GLint fs;
+static GLint vs;
+
+
+static GLfloat vertices[12] = {350.0, 50.0, 0.0,
+				350.0, 350.0, 0.0,
+				50.0, 50.0, 0.0,
+				50.0, 350.0, 0.0};
+
+static GLfloat texCoords[12] = {1.0, 0.0, -1.0,
+				1.0, 1.0, -1.0,
+				0.0, 0.0, -1.0,
+				0.0, 1.0, -1.0};
+
+static GLuint elements[4] = {0, 1, 2, 3};
+
+static const char *vertShaderText =
+	"attribute vec3 textureCoords;\n"
+	"varying vec3 texCoords;\n"
+	"void main()\n"
+	"{ \n"
+	"	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+	"	texCoords = textureCoords;\n"
+	"} \n";
+
+static const char *fragShaderText =
+	"uniform samplerCube depthcubeTex;\n"
+	"varying vec3 texCoords;\n"
+	"void main()\n"
+	"{ \n"
+	"       vec4 depth = textureCube(depthcubeTex, texCoords);\n"
+	"       gl_FragColor = vec4(depth.xyz, 1.0);\n"
+	"} \n";
+
+static void compileLinkProg(void);
+static void loadTex(void);
+
+void
+piglit_init(int argc, char **argv)
+{
+	if (!GLEW_VERSION_2_0) {
+		printf("Requires OpenGL 2.0\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+
+	if (piglit_automatic)
+		printf(" Depth Cube Map\n");
+
+	loadTex();
+
+	piglit_require_extension("GL_ARB_texture_rectangle");
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+	glOrtho(0, 400, 0, 400, -1, 1);
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glEnable(GL_TEXTURE_CUBE_MAP);
+	glClearColor(0.0, 0.0, 0.0, 1.0);
+
+	compileLinkProg();
+}
+
+static void
+compileLinkProg(void)
+{
+	GLint stat;
+
+	vs = glCreateShader(GL_VERTEX_SHADER);
+	fs = glCreateShader(GL_FRAGMENT_SHADER);
+	glShaderSource(vs, 1, (const GLchar **) &vertShaderText, NULL);
+	glShaderSource(fs, 1, (const GLchar **) &fragShaderText, NULL);
+	glCompileShader(vs);
+	glGetShaderiv(vs, GL_COMPILE_STATUS, &stat);
+	if (!stat) {
+		printf("error compiling vertex shader!\n");
+		exit(1);
+	}
+	glCompileShader(fs);
+	glGetShaderiv(fs, GL_COMPILE_STATUS, &stat);
+	if (!stat) {
+		printf("error compiling fragment shader!\n");
+		exit(1);
+	}
+
+	prog = glCreateProgram();
+	glAttachShader(prog, vs);
+	glAttachShader(prog, fs);
+	glBindAttribLocation(prog, 1, "textureCoords");
+	glLinkProgram(prog);
+	glUseProgram(prog);
+
+	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), vertices);
+	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), texCoords);
+	glEnableVertexAttribArray(0);
+	glEnableVertexAttribArray(1);
+}
+
+static void
+loadTex(void)
+{
+	#define height 2
+	#define width 2
+	int i, j;
+	unsigned int face;
+
+	GLfloat texDepthData[width][height];
+	GLfloat texDepthData1[width][height];
+	for (i=0; i < width; ++i) {
+		for (j=0; j < height; ++j) {
+                    texDepthData[i][j] = 1.0;
+		}
+	}
+
+	//render the cube depth 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_NEAREST);
+	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	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);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
+	
+	for ( face = 0; face < 6; face++) {
+	     // Set a white colored texture to all the faces of cubemap
+	     glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_DEPTH_COMPONENT,
+	            width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, texDepthData);
+	}
+
+	#undef height
+	#undef width
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLint loc1;
+
+	GLboolean pass = GL_TRUE;
+	GLfloat white[3] = {1.0, 1.0, 1.0};
+	GLenum err;
+
+	loc1 = glGetUniformLocation(prog, "depthcubeTex");
+	glClear(GL_COLOR_BUFFER_BIT);
+	glMatrixMode(GL_MODELVIEW);
+
+	glUniform1i(loc1, 0);
+	glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, elements);
+	glFinish();
+	pass = piglit_probe_pixel_rgb(200, 200, white);
+
+	err = glGetError();
+	switch (err)
+	{
+	case GL_INVALID_ENUM:
+		printf("GL_INVALID_ENUM\n");
+		break;
+	case GL_INVALID_VALUE:
+		printf("GL_INVALID_VALUE\n");
+		break;
+	case GL_INVALID_OPERATION:
+		printf("GL_INVALID_OPERATION\n");
+		break;
+	case GL_STACK_OVERFLOW:
+		printf("GL_STACK_OVERLFOW\n");
+		break;
+	case GL_STACK_UNDERFLOW:
+		printf("GL_STACK_UNDERFLOW\n");
+		break;
+	case GL_OUT_OF_MEMORY:
+		printf("GL_OUT_OF_MEMORY\n");
+		break;
+
+	}
+	glutSwapBuffers();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+
+}
-- 
1.7.7



More information about the Piglit mailing list