[Piglit] [PATCH] incomplete-texture: test sampling from an incomplete texture object

Brian Paul brianp at vmware.com
Fri Oct 14 15:11:29 PDT 2011


---
 tests/all.tests                      |    1 +
 tests/texturing/CMakeLists.gl.txt    |    1 +
 tests/texturing/incomplete-texture.c |  252 ++++++++++++++++++++++++++++++++++
 3 files changed, 254 insertions(+), 0 deletions(-)
 create mode 100644 tests/texturing/incomplete-texture.c

diff --git a/tests/all.tests b/tests/all.tests
index def3672..93b5ab4 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -621,6 +621,7 @@ add_plain_test(texturing, 'gen-nonzero-unit')
 add_plain_test(texturing, 'gen-texsubimage')
 add_plain_test(texturing, 'getteximage-formats')
 add_plain_test(texturing, 'getteximage-simple')
+add_plain_test(texturing, 'incomplete-texture')
 add_plain_test(texturing, 'levelclamp')
 add_plain_test(texturing, 'lodbias')
 add_plain_test(texturing, 'lodclamp')
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index 1c6526a..35ffe6f 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -28,6 +28,7 @@ add_executable (gen-teximage gen-teximage.c)
 add_executable (gen-texsubimage gen-texsubimage.c)
 add_executable (getteximage-simple getteximage-simple.c)
 add_executable (getteximage-formats getteximage-formats.c)
+add_executable (incomplete-texture incomplete-texture.c)
 add_executable (fragment-and-vertex-texturing fragment-and-vertex-texturing.c)
 add_executable (levelclamp levelclamp.c)
 add_executable (lodbias lodbias.c)
diff --git a/tests/texturing/incomplete-texture.c b/tests/texturing/incomplete-texture.c
new file mode 100644
index 0000000..ffc932b
--- /dev/null
+++ b/tests/texturing/incomplete-texture.c
@@ -0,0 +1,252 @@
+/*
+ * Copyright © 2011 VMware, 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.
+ */
+
+/**
+ * Test what texture color is received when sampling from a missing/incomplete
+ * texture, with fixed-function, ARB_vp, and GLSL.
+ *
+ * Brian Paul
+ * Oct 2011
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 150, piglit_height = 50;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+
+
+static void
+draw_rect(int pos)
+{
+	int x = pos * (piglit_width / 3) + 5;
+	int y = 5;
+	int w = piglit_width / 3 - 10;
+	int h = piglit_height - 10;
+	piglit_draw_rect_tex(x, y, w, h, 0, 0, 1, 1);
+}
+
+
+static GLboolean
+probe_pos(int pos, const GLfloat expected[4])
+{
+	int x = pos * (piglit_width / 3) + 5 + piglit_width / 6;
+	int y = piglit_height / 2;
+	return piglit_probe_pixel_rgb(x, y, expected);
+}
+
+
+/**
+ * For fixed function, if the texture is incomplete, it's as if that texture
+ * unit was disabled.
+ */
+GLboolean
+test_fixed_function(void)
+{
+	static const GLfloat expected[4] = { 0, 1, 0, 1.0 };
+	int pos = 0;
+	GLboolean p;
+
+	glColor4fv(expected);
+	glEnable(GL_TEXTURE_2D);
+	draw_rect(pos);
+	glDisable(GL_TEXTURE_2D);
+
+	p = probe_pos(pos, expected);
+	if (!p)
+		printf("  Testing fixed-function\n");
+	return p;
+}
+
+
+/**
+ * The GL_ARB_fragment_shader spec, issue 23 says:
+ *   (23) What is the result of a sample from an incomplete texture? 
+ *   The definition of texture completeness can be found in section 3.8.9 
+ *   of the core GL spec. 
+ *
+ *   RESOLVED: The result of a sample from an incomplete texture is the 
+ *   constant vector (0,0,0,1).  
+ */
+GLboolean
+test_arb_fp(void)
+{
+	static const char *fragProgramText =
+		"!!ARBfp1.0\n"
+		"TEX result.color.rgb, fragment.texcoord[0], texture[0], 2D;\n"
+		"END\n";
+	static const GLfloat expected[4] = { 0, 0, 0, 1.0 };
+	int pos = 1;
+	GLboolean p;
+	GLuint prog;
+
+	glGenProgramsARB(1, &prog);
+	glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
+	glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,
+                           GL_PROGRAM_FORMAT_ASCII_ARB,
+                           strlen(fragProgramText),
+                           (const GLubyte *) fragProgramText);
+
+	glEnable(GL_FRAGMENT_PROGRAM_ARB);
+
+	glColor3f(0, 1, 0);
+	draw_rect(1);
+
+	glDisable(GL_FRAGMENT_PROGRAM_ARB);
+	glDeleteProgramsARB(1, &prog);
+
+	p = probe_pos(pos, expected);
+	if (!p)
+		printf("  Testing ARB fragment program\n");
+	return p;
+}
+
+
+/**
+ * Section 3.11.2 of the GL 2.1 spec says:
+ *    If a fragment shader uses a sampler whose associated texture object is
+ *    not complete, as defined in section 3.8.10, the texture image unit will
+ *    return (R, G, B, A) = (0, 0, 0, 1).
+ */
+GLboolean
+test_glsl(void)
+{
+	static const char *fragShaderText =
+		"uniform sampler2D tex;\n"
+		"void main()\n"
+		"{\n"
+		"   gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);\n"
+		"}\n";
+	static const GLfloat expected[4] = { 0, 0, 0, 1.0 };
+	int pos = 2;
+	GLboolean p;
+	GLuint frag, prog;
+	GLint tex;
+
+	frag = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragShaderText);
+	prog = piglit_link_simple_program(0, frag);
+
+	glUseProgram(prog);
+	tex = glGetUniformLocation(prog, "tex");
+	glUniform1i(tex, 0);
+
+	glColor3f(0, 1, 0);
+	draw_rect(2);
+
+	glUseProgram(0);
+	piglit_DeleteShader(frag);
+	piglit_DeleteProgram(prog);
+
+	p = probe_pos(pos, expected);
+	if (!p)
+		printf("  Testing GLSL\n");
+	return p;
+}
+
+
+static GLuint
+_piglit_get_glsl_version(void)
+{
+	return 120;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass = GL_TRUE;
+
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	pass = test_fixed_function() && pass;
+
+	if (piglit_is_extension_supported("GL_ARB_fragment_program")) {
+		pass = test_arb_fp() && pass;
+	}
+
+	if (_piglit_get_glsl_version() >= 120) {
+		pass = test_glsl() && pass;
+	}
+
+	glutSwapBuffers();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+static void
+reshape(int width, int height)
+{
+	piglit_width = width;
+	piglit_height = height;
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+	glViewport(0, 0, width, height);
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+#define TW 64
+#define TH 64
+	GLubyte img[TH][TW][4];
+	GLuint t;
+	int i, j, w, h;
+
+	/* solid red texture */
+	for (i = 0; i < TH; i++) {
+		for (j = 0; j < TW; j++) {
+			img[i][j][0] = 0xff;
+			img[i][j][1] = 0x0;
+			img[i][j][2] = 0x0;
+			img[i][j][3] = 0x0;
+		}
+	}
+
+	/* make a texture with the last mipmap level omitted so
+	 * that it's incomplete
+	 */
+	glGenTextures(1, &t);
+	glBindTexture(GL_TEXTURE_2D, t);
+	w = TW;
+	h = TH;
+	for (i = 0; w > 1 && h > 1; i++) {
+		glTexImage2D(GL_TEXTURE_2D, i, GL_RGB, w, h, 0,
+			     GL_RGBA, GL_UNSIGNED_BYTE, img);
+		w /= 2;
+		h /= 2;
+	}
+
+	if (0) {
+		/* Enable this to force the texture to be complete */
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	}
+
+	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+	glClearColor(0.5, 0.5, 0.5, 0.0);
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+	glutReshapeFunc(reshape);
+}
-- 
1.7.3.4



More information about the Piglit mailing list