ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_multisample / pushpop.c
blobe6d8cf34d1e98614a4a29aa70026658045f0eeae
1 /*
2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 #include "piglit-util-gl.h"
26 /**
27 * @file pushpop.c
29 * From the GL_ARB_multisample spec:
31 * "An additional group of state variables, MULTISAMPLE_BIT_ARB,
32 * is defined by this extension. When PushAttrib is called with
33 * bit MULTISAMPLE_BIT_ARB set, the multisample group of state
34 * variables is pushed onto the attribute stack. When PopAttrib
35 * is called, these state variables are restored to their
36 * previous values if they were pushed. Some multisample state
37 * is included in the ENABLE_BIT group as well. In order to avoid
38 * incompatibility with GL implementations that do not support
39 * SGIS_multisample, ALL_ATTRIB_BITS does not include
40 * MULTISAMPLE_BIT_ARB."
42 * Get Value Get Command Type Initial Value Attribute
43 * --------- ----------- ---- ------------- ---------
44 * MULTISAMPLE_ARB IsEnabled B TRUE multisample/enable
45 * SAMPLE_ALPHA_TO_COVERAGE_ARB IsEnabled B FALSE multisample/enable
46 * SAMPLE_ALPHA_TO_ONE_ARB IsEnabled B FALSE multisample/enable
47 * SAMPLE_COVERAGE_ARB IsEnabled B FALSE multisample/enable
49 * SAMPLE_COVERAGE_VALUE_ARB GetFloatv R+ 1 multisample
50 * SAMPLE_COVERAGE_INVERT_ARB GetBooleanv B FALSE multisample
54 PIGLIT_GL_TEST_CONFIG_BEGIN
56 config.supports_gl_compat_version = 10;
58 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
60 config.khr_no_error_support = PIGLIT_NO_ERRORS;
62 PIGLIT_GL_TEST_CONFIG_END
64 enum piglit_result
65 piglit_display(void)
67 /* UNREACHED */
68 return PIGLIT_FAIL;
71 static bool
72 test_bool(GLenum e, const char *name, bool val)
74 GLboolean ret = glIsEnabled(e);
76 if (ret != val) {
77 fprintf(stderr, " %s %d doesn't match expected %d\n",
78 name, ret, val);
79 return false;
80 } else {
81 return true;
85 static bool
86 test_enable_bits(bool val)
88 bool pass = true;
90 pass = test_bool(GL_MULTISAMPLE, "multisample", val) && pass;
91 pass = test_bool(GL_SAMPLE_ALPHA_TO_COVERAGE, "alpha to coverage", val) && pass;
92 pass = test_bool(GL_SAMPLE_ALPHA_TO_ONE, "alpha to one", val) && pass;
93 pass = test_bool(GL_SAMPLE_COVERAGE, "sample coverage", val) && pass;
95 return pass;
98 static void
99 set_enable_bits(bool val)
101 if (val) {
102 glEnable(GL_MULTISAMPLE);
103 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
104 glEnable(GL_SAMPLE_ALPHA_TO_ONE);
105 glEnable(GL_SAMPLE_COVERAGE);
106 } else {
107 glDisable(GL_MULTISAMPLE);
108 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
109 glDisable(GL_SAMPLE_ALPHA_TO_ONE);
110 glDisable(GL_SAMPLE_COVERAGE);
114 static bool
115 test_coverage(bool mode)
117 bool pass = true;
118 GLboolean invert;
120 float expected = 0.25 + (mode ? 0.5 : 0.0), coverage;
122 glGetFloatv(GL_SAMPLE_COVERAGE_VALUE, &coverage);
123 if (coverage != expected) {
124 fprintf(stderr,
125 " coverage value %f doesn't match expected %f\n",
126 expected, coverage);
127 pass = false;
130 glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT, &invert);
131 if (invert != mode) {
132 fprintf(stderr,
133 " coverage invert value %d doesn't match expected %d\n",
134 invert, mode);
135 pass = false;
138 return pass;
141 static bool
142 test_state(bool enable_on, bool coverage_mode)
144 return test_enable_bits(enable_on) & test_coverage(coverage_mode);
147 static void
148 set_coverage(bool mode)
150 float coverage_val = 0.25 + (mode ? 0.5 : 0.0);
152 glSampleCoverageARB(coverage_val, mode);
155 static bool
156 pushpop(GLuint bit, const char *test,
157 bool affects_enabled, bool affects_other)
159 printf("%s test:\n", test);
161 set_enable_bits(true);
162 set_coverage(true);
164 if (bit != 0) {
165 glPushAttrib(bit);
166 set_enable_bits(false);
167 set_coverage(false);
168 glPopAttrib();
171 if (!test_state(affects_enabled, affects_other))
172 return false;
174 /* Now, test the bits the other direction. Caught a bug in my
175 * first pass of fixing Mesa.
177 set_enable_bits(false);
178 set_coverage(false);
180 if (bit != 0) {
181 glPushAttrib(bit);
182 set_enable_bits(true);
183 set_coverage(true);
184 glPopAttrib();
187 return test_state(!affects_enabled, !affects_other);
190 void
191 piglit_init(int argc, char **argv)
193 bool pass = true;
195 piglit_require_extension("GL_ARB_multisample");
197 pass = pushpop(0, "sanity test", true, true);
198 if (!pass)
199 piglit_report_result(PIGLIT_FAIL);
200 pass = pushpop(GL_MULTISAMPLE_BIT, "GL_MULTISAMPLE_BIT",
201 true, true) && pass;
202 pass = pushpop(GL_ENABLE_BIT, "GL_ENABLE_BIT",
203 true, false) && pass;
204 pass = pushpop(GL_ALL_ATTRIB_BITS, "GL_ALL_ATTRIB_BITS",
205 true, false) && pass;
207 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);