[Piglit] [PATCH] arb_texture_filter_minmax: A basic texture reduction mode test

Plamena Manolova plamena.manolova at intel.com
Tue Jan 31 17:48:13 UTC 2017


This tests whether texture reduction modes function as expected when
GL_ARB_texture_filter_minmax is available and the GL_RED format and
bilinear filtering is used.
---
 tests/all.py                                       |   5 +
 tests/spec/CMakeLists.txt                          |   1 +
 .../arb_texture_filter_minmax/CMakeLists.gl.txt    |   6 +
 .../spec/arb_texture_filter_minmax/CMakeLists.txt  |   1 +
 tests/spec/arb_texture_filter_minmax/basic.c       | 214 +++++++++++++++++++++
 5 files changed, 227 insertions(+)
 create mode 100644 tests/spec/arb_texture_filter_minmax/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_texture_filter_minmax/CMakeLists.txt
 create mode 100644 tests/spec/arb_texture_filter_minmax/basic.c

diff --git a/tests/all.py b/tests/all.py
index 74ffb42..ba8ebca 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2884,6 +2884,11 @@ with profile.test_list.group_manager(
     g(['vp-clipdistance-04'], run_concurrent=False)
 
 with profile.test_list.group_manager(
+        PiglitGLTest,
+        grouptools.join('spec', 'arb_texture_filter_minmax')) as g:
+    g(['arb_texture_filter_minmax-basic'])
+
+with profile.test_list.group_manager(
         PiglitGLTest, grouptools.join('spec', 'ext_framebuffer_blit')) as g:
     g(['fbo-blit'], run_concurrent=False)
     g(['fbo-copypix'], run_concurrent=False)
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 548515d..200ea9f 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -154,3 +154,4 @@ add_subdirectory (ext_window_rectangles)
 add_subdirectory (arb_shader_texture_image_samples)
 add_subdirectory (arb_texture_barrier)
 add_subdirectory (intel_conservative_rasterization)
+add_subdirectory (arb_texture_filter_minmax)
diff --git a/tests/spec/arb_texture_filter_minmax/CMakeLists.gl.txt b/tests/spec/arb_texture_filter_minmax/CMakeLists.gl.txt
new file mode 100644
index 0000000..ea74899
--- /dev/null
+++ b/tests/spec/arb_texture_filter_minmax/CMakeLists.gl.txt
@@ -0,0 +1,6 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+link_libraries(piglitutil_${piglit_target_api})
+piglit_add_executable (arb_texture_filter_minmax-basic basic.c)
diff --git a/tests/spec/arb_texture_filter_minmax/CMakeLists.txt b/tests/spec/arb_texture_filter_minmax/CMakeLists.txt
new file mode 100644
index 0000000..4a012b9
--- /dev/null
+++ b/tests/spec/arb_texture_filter_minmax/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
\ No newline at end of file
diff --git a/tests/spec/arb_texture_filter_minmax/basic.c b/tests/spec/arb_texture_filter_minmax/basic.c
new file mode 100644
index 0000000..4598330
--- /dev/null
+++ b/tests/spec/arb_texture_filter_minmax/basic.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2015 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.
+ */
+
+/*
+ * This tests whether texture reduction modes function as expected when
+ * GL_ARB_texture_filter_minmax is available and the GL_RED format and
+ * bilinear filtering is used.
+ */
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+	config.supports_gl_compat_version = 33;
+	config.supports_gl_core_version = 33;
+	config.window_width = 40;
+	config.window_height = 40;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLuint tex, prog, vbo;
+
+static const char *vs_text =
+	"#version 420\n"
+	"in vec4 pos_in;\n"
+	"in vec2 tex_in;\n"
+	"out vec2 tex_out;\n"
+	"void main()\n"
+	"{\n"
+	"	tex_out = tex_in;\n"
+	"	gl_Position = pos_in;\n"
+	"}\n";
+
+static const char *fs_text =
+	"#version 420\n"
+	"in vec2 tex_out;\n"
+	"out vec4 color;\n"
+	"uniform sampler2D sampler;\n"
+	"void main()\n"
+	"{\n"
+	"	color = texture(sampler, tex_out);\n"
+	"}\n";
+
+static GLuint
+make_shader_program(void)
+{
+	GLuint prog;
+
+	prog = piglit_build_simple_program(vs_text, fs_text);
+
+	glBindAttribLocation(prog, 0, "pos_in");
+	glBindAttribLocation(prog, 1, "tex_in");
+	glLinkProgram(prog);
+	glUseProgram(prog);
+	glUniform1i(glGetUniformLocation(prog, "sampler"), 0);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	return prog;
+}
+
+static GLuint
+make_vbo(void)
+{
+	static const float pos_tc[24][4] = {
+		{ -1.0, -1.0, 0.0, 0.0 },
+		{  0.0, -1.0, 1.0, 0.0 },
+		{  0.0,  0.0, 1.0, 1.0 },
+		{  0,0,  0.0, 1.0, 1.0 },
+		{ -1.0,  0.0, 0.0, 1.0 },
+		{ -1.0, -1.0, 0.0, 0.0 },
+
+		{  0.0, -1.0, 0.0, 0.0 },
+		{  1.0, -1.0, 1.0, 0.0 },
+		{  1.0,  0.0, 1.0, 1.0 },
+		{  1.0,  0.0, 1.0, 1.0 },
+		{  0.0,  0.0, 0.0, 1.0 },
+		{  0.0, -1.0, 0.0, 0.0 },
+
+		{ -1.0,  0.0, 0.0, 0.0 },
+		{  0.0,  0.0, 1.0, 0.0 },
+		{  0.0,  1.0, 1.0, 1.0 },
+		{  0.0,  1.0, 1.0, 1.0 },
+		{ -1.0,  1.0, 0.0, 1.0 },
+		{ -1.0,  0.0, 0.0, 0.0 },
+
+		{  0.0,  0.0, 0.0, 0.0 },
+		{  1.0,  0.0, 1.0, 0.0 },
+		{  1.0,  1.0, 1.0, 1.0 },
+		{  1.0,  1.0, 1.0, 1.0 },
+		{  0.0,  1.0, 0.0, 1.0 },
+		{  0.0,  0.0, 0.0, 0.0 }
+	};
+	const int stride = sizeof(pos_tc[0]);
+	GLuint vbo, vao;
+
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+
+	glGenBuffers(1, &vbo);
+	glBindBuffer(GL_ARRAY_BUFFER, vbo);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(pos_tc), pos_tc, GL_STATIC_DRAW);
+	piglit_check_gl_error(GL_NO_ERROR);
+
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride, (void *) 0);
+	glEnableVertexAttribArray(0);
+
+	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, stride,
+		(void*) (sizeof(GLfloat) * 2));
+	glEnableVertexAttribArray(1);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	return vbo;
+}
+
+static GLuint
+make_texture(void)
+{
+	GLuint tex, i, j, k;
+	GLfloat *pixels = (GLfloat*)malloc(sizeof(GLfloat) * 100);
+
+	for (i = 0, k = 0; i < 10; i++) {
+		if (i % 2 == 0) {
+			pixels[k] = 0.0;
+		} else {
+			pixels[k] = 1.0;
+		}
+		k++;
+
+		for (j = 1; j < 10; j++, k++) {
+			if (pixels[k - 1] == 1.0) {
+				pixels[k] = 0.0;
+			} else {
+				pixels[k] = 1.0;
+			}
+		}
+	}
+
+	glGenTextures(1, &tex);
+	glActiveTexture(GL_TEXTURE0);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, 10, 10, 0, GL_RED, GL_FLOAT, pixels);
+
+	free(pixels);
+	return tex;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_texture_filter_minmax");
+
+	prog = make_shader_program();
+	vbo = make_vbo();
+	tex = make_texture();
+
+	glClearColor(0.0, 0.0, 0.0, 1.0);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+	float red[4] = {1.0, 0.0, 0.0, 1.0};
+	float black[4] = {0.0, 0.0, 0.0, 1.0};
+
+	glViewport(0, 0, piglit_width, piglit_height);
+	glClear(GL_COLOR_BUFFER_BIT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_REDUCTION_MODE_ARB, GL_MAX);
+	glDrawArrays(GL_TRIANGLES, 0, 6);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_REDUCTION_MODE_ARB, GL_MIN);
+	glDrawArrays(GL_TRIANGLES, 6, 6);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_REDUCTION_MODE_ARB,
+		GL_WEIGHTED_AVERAGE_ARB);
+	glDrawArrays(GL_TRIANGLES, 12, 6);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glDrawArrays(GL_TRIANGLES, 18, 6);
+	piglit_present_results();
+
+	pass = piglit_probe_rect_rgba(0, 0, piglit_width / 2,
+		piglit_height / 2, red) && pass;
+	pass = piglit_probe_rect_rgba(piglit_width / 2, 0, piglit_width / 2,
+		piglit_height / 2, black) && pass;
+
+	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
2.4.3



More information about the Piglit mailing list