[Piglit] [PATCH 7/8] Rewrite glsl-fs-texturelod-01 as a shader_runner test.

Kenneth Graunke kenneth at whitecape.org
Wed Apr 4 01:51:28 PDT 2012


This is quite a bit simpler.  Technically, I don't need to set the
min/mag filters here since "texture miptree" does it already, but it's
self-documenting to include that in the test itself.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 tests/all.tests                                 |    1 -
 tests/shaders/CMakeLists.gl.txt                 |    1 -
 tests/shaders/glsl-fs-texturelod-01.c           |  163 -----------------------
 tests/shaders/glsl-fs-texturelod-01.frag        |   16 ---
 tests/shaders/glsl-fs-texturelod-01.shader_test |   52 +++++++
 tests/shaders/glsl-fs-texturelod-01.vert        |   13 --
 6 files changed, 52 insertions(+), 194 deletions(-)
 delete mode 100644 tests/shaders/glsl-fs-texturelod-01.c
 delete mode 100644 tests/shaders/glsl-fs-texturelod-01.frag
 create mode 100644 tests/shaders/glsl-fs-texturelod-01.shader_test
 delete mode 100644 tests/shaders/glsl-fs-texturelod-01.vert

diff --git a/tests/all.tests b/tests/all.tests
index 1a56b67..df56184 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -427,7 +427,6 @@ shaders['glsl-fs-texture2drect-proj3'] = PlainExecTest(['glsl-fs-texture2drect',
 							'-auto', '-proj3'])
 shaders['glsl-fs-texture2drect-proj4'] = PlainExecTest(['glsl-fs-texture2drect',
 							'-auto', '-proj4'])
-add_plain_test(shaders, 'glsl-fs-texturelod-01')
 add_plain_test(shaders, 'glsl-fs-user-varying-ff')
 add_plain_test(shaders, 'glsl-mat-attribute')
 add_plain_test(shaders, 'glsl-max-varyings')
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
index 7d8b12e..9efc26a 100644
--- a/tests/shaders/CMakeLists.gl.txt
+++ b/tests/shaders/CMakeLists.gl.txt
@@ -91,7 +91,6 @@ piglit_add_executable (glsl-fs-texturecube glsl-fs-texturecube.c)
 piglit_add_executable (glsl-fs-texturecube-2 glsl-fs-texturecube-2.c)
 piglit_add_executable (glsl-fs-textureenvcolor-statechange glsl-fs-textureenvcolor-statechange.c)
 piglit_add_executable (glsl-fs-texture2drect glsl-fs-texture2drect.c)
-piglit_add_executable (glsl-fs-texturelod-01 glsl-fs-texturelod-01.c)
 piglit_add_executable (glsl-fs-user-varying-ff glsl-fs-user-varying-ff.c)
 piglit_add_executable (glsl-vs-arrays glsl-vs-arrays.c)
 piglit_add_executable (glsl-vs-mov-after-deref glsl-vs-mov-after-deref.c)
diff --git a/tests/shaders/glsl-fs-texturelod-01.c b/tests/shaders/glsl-fs-texturelod-01.c
deleted file mode 100644
index aa7719c..0000000
--- a/tests/shaders/glsl-fs-texturelod-01.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright © 2010 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.
- */
-
-#include "piglit-util.h"
-
-/// \name GL State
-/// \{
-static GLuint texture_id;
-static const GLuint texture_unit = 0;
-static const int num_lod = 4;
-static GLint lod_uniform;
-/// \}
-
-/// \name Colors
-/// \{
-static const int num_colors = 4;
-static const float color_wheel[4][4] = {
-	{1, 0, 0, 1}, // red
-	{0, 1, 0, 1}, // green
-	{0, 0, 1, 1}, // blue
-	{1, 1, 1, 1}, // white
-};
-/// \}
-
-/// \name Piglit State
-/// \{
-int piglit_width = 100;
-int piglit_height = 100;
-int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
-/// \}
-
-static void
-setup_mipmap_level(int lod, int width, int height)
-{
-	GLfloat *texture_data;
-	const float *color;
-	int i;
-	const GLenum internal_format = GL_RGBA;
-
-	texture_data = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
-	assert(texture_data != NULL);
-
-	color = color_wheel[lod % num_colors];
-
-	for (i = 0; i < width * height; ++i) {
-		texture_data[4 * i + 0] = color[0];
-		texture_data[4 * i + 1] = color[1];
-		texture_data[4 * i + 2] = color[2];
-		texture_data[4 * i + 3] = color[3];
-	}
-	glTexImage2D(GL_TEXTURE_2D, lod, internal_format, width, height, 0,
-				 GL_RGBA, GL_FLOAT, texture_data);
-
-	free(texture_data);
-}
-
-static void
-setup_texture()
-{
-	int lod;
-
-	glGenTextures(1, &texture_id);
-	glActiveTexture(GL_TEXTURE0 + texture_unit);
-	glBindTexture(GL_TEXTURE_2D, texture_id);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
-
-	for (lod = 0; lod < num_lod; ++lod) {
-		const int level_size = (2 * num_lod) >> lod;
-		printf("Creating level %d at size %d\n", lod, level_size);
-		setup_mipmap_level(lod, level_size, level_size);
-	}
-
-	glEnable(GL_TEXTURE_2D);
-}
-
-enum piglit_result
-piglit_display()
-{
-	int lod;
-	int x;
-	GLboolean pass = GL_TRUE;
-
-	glClearColor(0.4, 0.4, 0.4, 0.0);
-	glClear(GL_COLOR_BUFFER_BIT);
-
-	for (lod = 0; lod < num_lod; ++lod) {
-		x = 10 + lod * 20;
-		glUniform1f(lod_uniform, lod);
-		piglit_draw_rect(x, 10, 10, 10);
-
-		pass &= piglit_probe_rect_rgba(x, 10, 10, 10,
-				color_wheel[lod % num_colors]);
-	}
-
-	glutSwapBuffers();
-
-	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
-}
-
-void
-piglit_init(int argc, char **argv)
-{
-	GLint vs, fs, prog, sampler_uniform;
-
-	if (piglit_get_gl_version() < 20) {
-		printf("Requires OpenGL 2.0\n");
-		piglit_report_result(PIGLIT_SKIP);
-	}
-	if (!piglit_is_extension_supported("GL_ARB_shader_texture_lod")) {
-		printf("Requires extension GL_ARB_shader_texture_lod\n");
-		piglit_report_result(PIGLIT_SKIP);
-	}
-
-	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
-
-	setup_texture();
-
-	// Compile and use program.
-	vs = piglit_compile_shader(GL_VERTEX_SHADER,
-			"shaders/glsl-fs-texturelod-01.vert");
-	fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
-			"shaders/glsl-fs-texturelod-01.frag");
-	prog = piglit_link_simple_program(vs, fs);
-	glUseProgram(prog);
-
-	// Setup uniforms.
-	sampler_uniform = glGetUniformLocation(prog, "sampler");
-	if (sampler_uniform == -1) {
-		printf("error: Unable to get location of uniform 'sampler'\n");
-		piglit_report_result(PIGLIT_FAIL);
-		return;
-	}
-	glUniform1i(sampler_uniform, texture_unit);
-	lod_uniform = glGetUniformLocation(prog, "lod");
-	if (lod_uniform == -1) {
-		printf("error: Unable to get location of uniform 'lod'\n");
-		piglit_report_result(PIGLIT_FAIL);
-		return;
-	}
-}
diff --git a/tests/shaders/glsl-fs-texturelod-01.frag b/tests/shaders/glsl-fs-texturelod-01.frag
deleted file mode 100644
index 23d2510..0000000
--- a/tests/shaders/glsl-fs-texturelod-01.frag
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * \file glsl-fs-texture-lod-01.frag
- */
-
-#version 120
-#extension GL_ARB_shader_texture_lod: enable
-
-uniform sampler2D sampler;
-uniform float lod;
-
-varying vec2 texcoord;
-
-void main()
-{
-	gl_FragColor = texture2DLod(sampler, texcoord, lod);
-}
diff --git a/tests/shaders/glsl-fs-texturelod-01.shader_test b/tests/shaders/glsl-fs-texturelod-01.shader_test
new file mode 100644
index 0000000..98c2cb7
--- /dev/null
+++ b/tests/shaders/glsl-fs-texturelod-01.shader_test
@@ -0,0 +1,52 @@
+[require]
+GLSL >= 1.20
+
+[vertex shader]
+#version 120
+
+varying vec2 texcoord;
+
+void main()
+{
+       texcoord = (vec2(gl_Vertex) + 1.0) / 2.0;
+       gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}
+
+[fragment shader]
+#version 120
+#extension GL_ARB_shader_texture_lod: enable
+
+uniform sampler2D sampler;
+uniform float lod;
+
+varying vec2 texcoord;
+
+void main()
+{
+       gl_FragColor = texture2DLod(sampler, texcoord, lod);
+}
+
+[test]
+ortho
+clear color 0.4 0.4 0.4 0.0
+clear
+uniform int sampler 0
+texture miptree 0
+texparameter 2D min nearest_mipmap_nearest
+texparameter 2D mag nearest
+
+uniform float lod 0
+draw rect 10 10 10 10
+probe rgb 15 15 1.0 0.0 0.0
+
+uniform float lod 1
+draw rect 30 10 10 10
+probe rgb 35 15 0.0 1.0 0.0
+
+uniform float lod 2
+draw rect 50 10 10 10
+probe rgb 55 15 0.0 0.0 1.0
+
+uniform float lod 3
+draw rect 70 10 10 10
+probe rgb 75 15 1.0 1.0 1.0
diff --git a/tests/shaders/glsl-fs-texturelod-01.vert b/tests/shaders/glsl-fs-texturelod-01.vert
deleted file mode 100644
index 0902f74..0000000
--- a/tests/shaders/glsl-fs-texturelod-01.vert
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
- * \file glsl-fs-texture-lod-01.vert
- */
-
-#version 120
-
-varying vec2 texcoord;
-
-void main()
-{
-	texcoord = (vec2(gl_Vertex) + 1.0) / 2.0;
-	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
-}
-- 
1.7.7.6



More information about the Piglit mailing list