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
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
24 #include "piglit-util-gl.h"
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
72 test_bool(GLenum e
, const char *name
, bool val
)
74 GLboolean ret
= glIsEnabled(e
);
77 fprintf(stderr
, " %s %d doesn't match expected %d\n",
86 test_enable_bits(bool val
)
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
;
99 set_enable_bits(bool val
)
102 glEnable(GL_MULTISAMPLE
);
103 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE
);
104 glEnable(GL_SAMPLE_ALPHA_TO_ONE
);
105 glEnable(GL_SAMPLE_COVERAGE
);
107 glDisable(GL_MULTISAMPLE
);
108 glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE
);
109 glDisable(GL_SAMPLE_ALPHA_TO_ONE
);
110 glDisable(GL_SAMPLE_COVERAGE
);
115 test_coverage(bool mode
)
120 float expected
= 0.25 + (mode
? 0.5 : 0.0), coverage
;
122 glGetFloatv(GL_SAMPLE_COVERAGE_VALUE
, &coverage
);
123 if (coverage
!= expected
) {
125 " coverage value %f doesn't match expected %f\n",
130 glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT
, &invert
);
131 if (invert
!= mode
) {
133 " coverage invert value %d doesn't match expected %d\n",
142 test_state(bool enable_on
, bool coverage_mode
)
144 return test_enable_bits(enable_on
) & test_coverage(coverage_mode
);
148 set_coverage(bool mode
)
150 float coverage_val
= 0.25 + (mode
? 0.5 : 0.0);
152 glSampleCoverageARB(coverage_val
, mode
);
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);
166 set_enable_bits(false);
171 if (!test_state(affects_enabled
, affects_other
))
174 /* Now, test the bits the other direction. Caught a bug in my
175 * first pass of fixing Mesa.
177 set_enable_bits(false);
182 set_enable_bits(true);
187 return test_state(!affects_enabled
, !affects_other
);
191 piglit_init(int argc
, char **argv
)
195 piglit_require_extension("GL_ARB_multisample");
197 pass
= pushpop(0, "sanity test", true, true);
199 piglit_report_result(PIGLIT_FAIL
);
200 pass
= pushpop(GL_MULTISAMPLE_BIT
, "GL_MULTISAMPLE_BIT",
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
);