1 /*
2  * Copyright © 2012 Intel Corporation
3  *
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:
10  *
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.
14  *
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.
22  */
23 
24 /**
25  * \file enable-flag.cpp
26  *
27  * This test verifies the proper functioning of the GL_MULTISAMPLE
28  * flag.  From the GL 3.0 spec (p.116):
29  *
30  *     "Multisample rasterization is enabled or disabled by calling
31  *     Enable or Disable with the symbolic constant MULTISAMPLE."
32  *
33  * Elsewhere in the spec, where multisample rasterization is described
34  * (sections 3.4.3, 3.5.4, and 3.6.6), the following text is
35  * consistently used:
36  *
37  *     "If MULTISAMPLE is enabled, and the value of SAMPLE_BUFFERS is
38  *     one, then..."
39  *
40  * So, in other words, disabling GL_MULTISAMPLE should prevent
41  * multisample rasterization from occurring, even if the draw
42  * framebuffer is multisampled.
43  *
44  *
45  * This test operates by performing the following operations:
46  *
47  * 1. Verify that the default state of GL_MULTISAMPLE is enabled.
48  *
49  * 2. Draw a test image into a multisampled buffer, with
50  *    GL_MULTISAMPLE disabled.
51  *
52  * 3. Blit this image to the left half of the piglit window (which is
53  *    not multisampled) to resolve it.
54  *
55  * 4. Draw the same test image into a single-sampled buffer.
56  *
57  * 5. Blit this image to the right half of the piglit window.
58  *
59  * 6. Verify that the two halves of the piglit window match.  If they
60  *    don't, then presumably the disabling of GL_MULTISAMPLE failed to
61  *    take effect.
62  */
63 
64 #include "piglit-test-pattern.h"
65 #include "piglit-fbo.h"
66 using namespace piglit_util_fbo;
67 using namespace piglit_util_test_pattern;
68 
69 PIGLIT_GL_TEST_CONFIG_BEGIN
70 
71 	config.supports_gl_compat_version = 10;
72 
73 	config.window_width = 512;
74 	config.window_height = 256;
75 	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
76 	config.khr_no_error_support = PIGLIT_NO_ERRORS;
77 
78 PIGLIT_GL_TEST_CONFIG_END
79 
80 namespace {
81 
82 const int pattern_width = 256; const int pattern_height = 256;
83 
84 Fbo singlesampled_fbo;
85 Fbo multisampled_fbo;
86 Triangles triangles;
87 
88 extern "C" void
piglit_init(int argc,char ** argv)89 piglit_init(int argc, char **argv)
90 {
91 	piglit_require_gl_version(21);
92 	piglit_require_extension("GL_ARB_framebuffer_object");
93 	piglit_require_extension("GL_ARB_vertex_array_object");
94 
95 	GLint max_samples;
96 	glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
97 
98 	singlesampled_fbo.setup(FboConfig(0, pattern_width,
99 					  pattern_height));
100 	multisampled_fbo.setup(FboConfig(max_samples, pattern_width,
101 					 pattern_height));
102 	triangles.compile();
103 }
104 
105 extern "C" enum piglit_result
piglit_display()106 piglit_display()
107 {
108 	bool pass = true;
109 
110 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
111 	glViewport(0, 0, piglit_width, piglit_height);
112 	glClear(GL_COLOR_BUFFER_BIT);
113 
114 	/* Verify that the default state of GL_MULTISAMPLE is
115 	 * enabled.
116 	 */
117 	pass = glIsEnabled(GL_MULTISAMPLE) && pass;
118 
119 	/* Draw a test image into a multisampled buffer, with
120 	 * GL_MULTISAMPLE disabled.
121 	 */
122 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, multisampled_fbo.handle);
123 	multisampled_fbo.set_viewport();
124 	glDisable(GL_MULTISAMPLE);
125 	triangles.draw(TestPattern::no_projection);
126 	glEnable(GL_MULTISAMPLE);
127 
128 	/* Blit this image to the left half of the piglit window
129 	 * (which is not multisampled) to resolve it.
130 	 */
131 	glBindFramebuffer(GL_READ_FRAMEBUFFER, multisampled_fbo.handle);
132 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
133 	glBlitFramebuffer(0, 0, pattern_width, pattern_height,
134 			  0, 0, pattern_width, pattern_height,
135 			  GL_COLOR_BUFFER_BIT, GL_NEAREST);
136 
137 	/* Draw the same test image into a single-sampled buffer. */
138 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, singlesampled_fbo.handle);
139 	singlesampled_fbo.set_viewport();
140 	triangles.draw(TestPattern::no_projection);
141 
142 	/* Blit this image to the right half of the piglit window. */
143 	glBindFramebuffer(GL_READ_FRAMEBUFFER, singlesampled_fbo.handle);
144 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
145 	glBlitFramebuffer(0, 0, pattern_width, pattern_height,
146 			  pattern_width, 0, 2*pattern_width, pattern_height,
147 			  GL_COLOR_BUFFER_BIT, GL_NEAREST);
148 
149 	/* Verify that the two halves of the piglit window match.  If
150 	 * they don't, then presumably the disabling of GL_MULTISAMPLE
151 	 * failed to take effect.
152 	 */
153 	glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
154 	pass = piglit_probe_rect_halves_equal_rgba(0, 0, 2*pattern_width,
155 						   pattern_height) && pass;
156 
157 	piglit_present_results();
158 
159 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
160 }
161 
162 } /* Anonymous namespace */
163