[Piglit] [PATCH 2/2] ARB_multisample/pushpop: New test for PushAttrib/PopAttrib.

Eric Anholt eric at anholt.net
Mon Feb 13 16:57:31 PST 2012


---
 tests/all.tests                              |    1 +
 tests/spec/arb_multisample/CMakeLists.gl.txt |    1 +
 tests/spec/arb_multisample/pushpop.c         |  202 ++++++++++++++++++++++++++
 3 files changed, 204 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/arb_multisample/pushpop.c

diff --git a/tests/all.tests b/tests/all.tests
index 16cd327..99abb46 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1573,6 +1573,7 @@ add_plain_test(arb_map_buffer_range, 'map_buffer_range_test')
 arb_multisample = Group()
 spec['ARB_multisample'] = arb_multisample
 arb_multisample['beginend'] = concurrent_test('arb_multisample-beginend')
+arb_multisample['pushpop'] = concurrent_test('arb_multisample-pushpop')
 
 arb_seamless_cube_map = Group()
 spec['ARB_seamless_cube_map'] = arb_seamless_cube_map
diff --git a/tests/spec/arb_multisample/CMakeLists.gl.txt b/tests/spec/arb_multisample/CMakeLists.gl.txt
index 4020caf..9ed8636 100644
--- a/tests/spec/arb_multisample/CMakeLists.gl.txt
+++ b/tests/spec/arb_multisample/CMakeLists.gl.txt
@@ -12,3 +12,4 @@ link_libraries (
 )
 
 add_executable (arb_multisample-beginend beginend.c)
+add_executable (arb_multisample-pushpop pushpop.c)
diff --git a/tests/spec/arb_multisample/pushpop.c b/tests/spec/arb_multisample/pushpop.c
new file mode 100644
index 0000000..4af7f72
--- /dev/null
+++ b/tests/spec/arb_multisample/pushpop.c
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ */
+
+#include "piglit-util.h"
+
+/**
+ * @file pushpop.c
+ *
+ * From the GL_ARB_multisample spec:
+ *
+ *     "An additional group of state variables, MULTISAMPLE_BIT_ARB,
+ *      is defined by this extension.  When PushAttrib is called with
+ *      bit MULTISAMPLE_BIT_ARB set, the multisample group of state
+ *      variables is pushed onto the attribute stack.  When PopAttrib
+ *      is called, these state variables are restored to their
+ *      previous values if they were pushed.  Some multisample state
+ *      is included in the ENABLE_BIT group as well. In order to avoid
+ *      incompatibility with GL implementations that do not support
+ *      SGIS_multisample, ALL_ATTRIB_BITS does not include
+ *      MULTISAMPLE_BIT_ARB."
+ *
+ *      Get Value                       Get Command    Type    Initial Value    Attribute
+ *      ---------                       -----------    ----    -------------    ---------
+ *      MULTISAMPLE_ARB                 IsEnabled      B       TRUE             multisample/enable
+ *      SAMPLE_ALPHA_TO_COVERAGE_ARB    IsEnabled      B       FALSE            multisample/enable
+ *      SAMPLE_ALPHA_TO_ONE_ARB         IsEnabled      B       FALSE            multisample/enable
+ *      SAMPLE_COVERAGE_ARB             IsEnabled      B       FALSE            multisample/enable
+ *
+ *      SAMPLE_COVERAGE_VALUE_ARB       GetFloatv      R+      1                multisample
+ *      SAMPLE_COVERAGE_INVERT_ARB      GetBooleanv    B       FALSE            multisample
+ *
+ */
+
+int piglit_width = 32;
+int piglit_height = 32;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
+
+enum piglit_result
+piglit_display(void)
+{
+	/* UNREACHED */
+	return PIGLIT_FAIL;
+}
+
+static bool
+test_bool(GLenum e, const char *name, bool val)
+{
+	GLboolean ret = glIsEnabled(e);
+
+	if (ret != val) {
+		fprintf(stderr, "  %s %d doesn't match expected %d\n",
+			name, ret, val);
+		return false;
+	} else {
+		return true;
+	}
+}
+
+static bool
+test_enable_bits(bool val)
+{
+	bool pass = true;
+
+	pass = test_bool(GL_MULTISAMPLE, "multisample", val) && pass;
+	pass = test_bool(GL_SAMPLE_ALPHA_TO_COVERAGE, "alpha to coverage", val) && pass;
+	pass = test_bool(GL_SAMPLE_ALPHA_TO_ONE, "alpha to one", val) && pass;
+	pass = test_bool(GL_SAMPLE_COVERAGE, "sample coverage", val) && pass;
+
+	return pass;
+}
+
+static void
+set_enable_bits(bool val)
+{
+	if (val) {
+		glEnable(GL_MULTISAMPLE);
+		glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
+		glEnable(GL_SAMPLE_ALPHA_TO_ONE);
+		glEnable(GL_SAMPLE_COVERAGE);
+	} else {
+		glDisable(GL_MULTISAMPLE);
+		glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
+		glDisable(GL_SAMPLE_ALPHA_TO_ONE);
+		glDisable(GL_SAMPLE_COVERAGE);
+	}
+}
+
+static bool
+test_coverage(bool mode)
+{
+	bool pass = true;
+	GLboolean invert;
+
+	float expected = 0.25 + (mode ? 0.5 : 0.0), coverage;
+
+	glGetFloatv(GL_SAMPLE_COVERAGE_VALUE, &coverage);
+	if (coverage != expected) {
+		fprintf(stderr,
+			"  coverage value %f doesn't match expected %f\n",
+			expected, coverage);
+		pass = false;
+	}
+
+	glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT, &invert);
+	if (invert != mode) {
+		fprintf(stderr,
+			"  coverage invert value %d doesn't match expected %d\n",
+			invert, mode);
+		pass = false;
+	}
+
+	return pass;
+}
+
+static bool
+test_state(bool enable_on, bool coverage_mode)
+{
+	return test_enable_bits(enable_on) & test_coverage(coverage_mode);
+}
+
+static void
+set_coverage(bool mode)
+{
+	float coverage_val = 0.25 + (mode ? 0.5 : 0.0);
+
+	glSampleCoverageARB(coverage_val, mode);
+}
+
+static bool
+pushpop(GLuint bit, const char *test,
+	bool affects_enabled, bool affects_other)
+{
+	printf("%s test:\n", test);
+
+	set_enable_bits(true);
+	set_coverage(true);
+
+	if (bit != 0) {
+		glPushAttrib(bit);
+		set_enable_bits(false);
+		set_coverage(false);
+		glPopAttrib();
+	}
+
+	if (!test_state(affects_enabled, affects_other))
+		return false;
+
+	/* Now, test the bits the other direction.  Caught a bug in my
+	 * first pass of fixing Mesa.
+	 */
+	set_enable_bits(false);
+	set_coverage(false);
+
+	if (bit != 0) {
+		glPushAttrib(bit);
+		set_enable_bits(true);
+		set_coverage(true);
+		glPopAttrib();
+	}
+
+	return test_state(!affects_enabled, !affects_other);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	bool pass = true;
+
+	piglit_require_extension("GL_ARB_multisample");
+
+	pass = pushpop(0, "sanity test", true, true);
+	if (!pass)
+		piglit_report_result(PIGLIT_FAIL);
+	pass = pushpop(GL_MULTISAMPLE_BIT, "GL_MULTISAMPLE_BIT",
+		       true, true) && pass;
+	pass = pushpop(GL_ENABLE_BIT, "GL_ENABLE_BIT",
+		       true, false) && pass;
+	pass = pushpop(GL_ALL_ATTRIB_BITS, "GL_ALL_ATTRIB_BITS",
+		       true, false) && pass;
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.7.9



More information about the Piglit mailing list