[Piglit] [PATCH] texturing: add reliable test for GL_TEXTURE_MAX_LEVEL using texelFetch

Christoph Bumiller christoph.bumiller at speed.at
Sun Apr 7 04:31:49 PDT 2013


From: Christoph Bumiller <e0425955 at student.tuwien.ac.at>

---
 tests/all.tests                   |    1 +
 tests/texturing/CMakeLists.gl.txt |    1 +
 tests/texturing/tex-max-level.c   |  150 +++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+), 0 deletions(-)
 create mode 100644 tests/texturing/tex-max-level.c

diff --git a/tests/all.tests b/tests/all.tests
index fbf6bd2..643a216 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -698,6 +698,7 @@ add_plain_test(gl30, 'gl30basic')
 add_plain_test(gl30, 'array-depth-roundtrip')
 add_plain_test(gl30, 'depth-cube-map')
 add_plain_test(gl30, 'sampler-cube-shadow')
+add_plain_test(gl30, 'tex-max-level')
 
 gl31 = Group()
 spec['!OpenGL 3.1'] = gl31
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index c9e5d11..faea6bd 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -60,6 +60,7 @@ piglit_add_executable (s3tc-errors s3tc-errors.c)
 piglit_add_executable (sampler-cube-shadow sampler-cube-shadow.c)
 piglit_add_executable (streaming-texture-leak streaming-texture-leak.c)
 piglit_add_executable (tex-miplevel-selection tex-miplevel-selection.c)
+piglit_add_executable (tex-max-level tex-max-level.c)
 piglit_add_executable (tex3d tex3d.c)
 piglit_add_executable (tex3d-depth1 tex3d-depth1.c)
 piglit_add_executable (tex3d-maxsize tex3d-maxsize.c)
diff --git a/tests/texturing/tex-max-level.c b/tests/texturing/tex-max-level.c
new file mode 100644
index 0000000..3072e7e
--- /dev/null
+++ b/tests/texturing/tex-max-level.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright © The Piglit Project 2013
+ *
+ * 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 tex-max-level.c
+ *
+ * Tests that GL_TEXTURE_MAX_LEVEL works properly, that is without cheating
+ * by merging it with the sampler's min/max_lod.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 30;
+
+	config.window_width = 320;
+	config.window_height = 240;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+/* Level 0: red
+ * Level 1: green
+ * Level 2: blue
+ */
+
+static const char *vsSource = "#version 130 \n"
+	"void main() { \n"
+	"   gl_Position = ftransform(); \n"
+	"} \n";
+static const char *fsSource = "#version 130 \n"
+	"uniform sampler2D tex; \n"
+	"uniform int l; \n"
+	"void main() { \n"
+	"   gl_FragColor = texelFetch(tex, ivec2(0, 0), l); \n"
+	"} \n";
+static GLuint prog;
+
+static GLuint tex;
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLuint vs, fs;
+	int i;
+	GLuint red4x4[16];
+	GLuint grn2x2[4];
+	GLuint blu1x1[1];
+
+	for (i = 0; i < 16; ++i)
+		red4x4[i] = 0x000000ff;
+	for (i = 0; i < 8; ++i)
+		grn2x2[i] = 0x0000ff00;
+	for (i = 0; i < 1; ++i)
+		blu1x1[i] = 0x00ff0000;
+
+	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vsSource);
+	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fsSource);
+	prog = piglit_link_simple_program(vs, fs);
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, red4x4);
+	glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, grn2x2);
+	glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, blu1x1);
+}
+
+static int
+draw_quad_and_test(int l_fetch, int l_max, const float test[])
+{
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, l_max);
+
+	glUniform1i(glGetUniformLocation(prog, "l"), l_fetch);
+
+	glBegin(GL_TRIANGLE_STRIP);
+	glVertex2f(-1.0f, -1.0f);
+	glVertex2f(-1.0f, +1.0f);
+	glVertex2f(+1.0f, -1.0f);
+	glVertex2f(+1.0f, +1.0f);
+	glEnd();
+
+	return piglit_probe_pixel_rgb(0, 0, test);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	static const float blue[4] = { 0, 0, 1, 0 };
+	static const float green[4] = { 0, 1, 0, 0 };
+	static const float red[4] = { 1, 0, 0, 0 };
+	static const float black[4] = { 0, 0, 0, 0 };
+
+	enum piglit_result result = PIGLIT_PASS;
+
+	glUseProgram(prog);
+	glUniform1i(glGetUniformLocation(prog, "tex"), 0);
+
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
+
+	if (!draw_quad_and_test(1, 0, black))
+		result = PIGLIT_FAIL;
+	if (!draw_quad_and_test(0, 0, red))
+		result = PIGLIT_FAIL;
+
+	if (!draw_quad_and_test(2, 1, black))
+		result = PIGLIT_FAIL;
+	if (!draw_quad_and_test(1, 1, green))
+		result = PIGLIT_FAIL;
+	if (!draw_quad_and_test(0, 1, red))
+		result = PIGLIT_FAIL;
+
+	if (!draw_quad_and_test(0, 2, red))
+		result = PIGLIT_FAIL;
+	if (!draw_quad_and_test(1, 2, green))
+		result = PIGLIT_FAIL;
+	if (!draw_quad_and_test(3, 2, black))
+		result = PIGLIT_FAIL;
+	if (!draw_quad_and_test(2, 2, blue))
+		result = PIGLIT_FAIL;
+
+	piglit_present_results();
+
+	return result;
+}
-- 
1.7.3.4



More information about the Piglit mailing list