1 /*
2  * Copyright © 2013 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 /** \file attachments-blit-scaled-linear.cpp
25  *
26  * This test verifies that same output is produced by scaled blitting
27  * of texture or renderbuffer color attachments with GL_LINEAR filter.
28  * It compares the output from following rendering scenarios:
29  * 1. Scaled blit using a single-sampled framebuffer with texture attachment.
30  * 2. Scaled blit using a single-sampled framebuffer with renderbuffer
31  *    attachment.
32  */
33 
34 #include "piglit-test-pattern.h"
35 #include "piglit-fbo.h"
36 using namespace piglit_util_fbo;
37 using namespace piglit_util_test_pattern;
38 
39 const int pattern_width = 258; const int pattern_height = 258;
40 
41 PIGLIT_GL_TEST_CONFIG_BEGIN
42 
43 	config.supports_gl_compat_version = 10;
44 
45 	config.window_width = pattern_width * 2;
46 	config.window_height = pattern_height;
47 	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
48 	config.khr_no_error_support = PIGLIT_NO_ERRORS;
49 
50 PIGLIT_GL_TEST_CONFIG_END
51 
52 static TestPattern *test_pattern;
53 const int srcX0 = 6, srcY0 = 7, dstX0 = 0, dstY0 = 0;
54 const int srcX1 = pattern_width / 2, srcY1 = pattern_height / 2;
55 static Fbo fbo_tex, fbo_rb;
56 
57 void
piglit_init(int argc,char ** argv)58 piglit_init(int argc, char **argv)
59 {
60 	piglit_require_gl_version(21);
61 	/* Create two singlesample FBOs with same format and dimensions but
62 	 * different color attachment types.
63 	 */
64 	FboConfig Config(0, pattern_width, pattern_height);
65 	fbo_rb.setup(Config);
66 	Config.num_rb_attachments = 0;
67 	Config.num_tex_attachments = 1;
68 	fbo_tex.setup(Config);
69 
70 	test_pattern = new Triangles();
71 	test_pattern->compile();
72 
73 	if (!piglit_check_gl_error(GL_NO_ERROR)) {
74 		piglit_report_result(PIGLIT_FAIL);
75 	}
76 }
77 
test_blit_scaled_linear()78 bool test_blit_scaled_linear()
79 {
80 	GLfloat scale;
81 	GLint samples;
82 	bool pass = true, result = true;
83 
84 	/* Draw the test pattern into the framebuffer with texture
85 	 * attachment.
86 	 */
87 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_tex.handle);
88 	glViewport(0, 0, srcX1, srcY1);
89 	glGetIntegerv(GL_SAMPLES, &samples);
90 	glClear(GL_COLOR_BUFFER_BIT);
91 	test_pattern->draw(TestPattern::no_projection);
92 
93 	/* Blit the framebuffer with texture attachment into the
94 	 * framebuffer with renderbuffer attachment without scaling.
95 	 */
96 	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_tex.handle);
97 	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_rb.handle);
98 	glClear(GL_COLOR_BUFFER_BIT);
99 	glBlitFramebuffer(0, 0,
100 			  fbo_tex.config.width,
101 			  fbo_tex.config.height,
102 			  0, 0,
103 			  fbo_tex.config.width,
104 			  fbo_tex.config.height,
105 			  GL_COLOR_BUFFER_BIT, GL_NEAREST);
106 
107 	for(scale = 0.1; scale < 2.5f; scale += 0.1) {
108 		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
109 		glClear(GL_COLOR_BUFFER_BIT);
110 
111 		/* Do scaled blit of fbo_tex to left half of piglit_winsys_fbo.
112                  */
113 		glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_tex.handle);
114 		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
115                 glClearColor(0.0, 1.0, 0.0, 1.0);
116 		glClear(GL_COLOR_BUFFER_BIT);
117                 glClearColor(0.0, 0.0, 0.0, 0.0);
118 		glEnable(GL_SCISSOR_TEST);
119 		glScissor(0, 0, pattern_width, pattern_height);
120 		glBlitFramebuffer(srcX0, srcY0,
121 				  srcX1, srcY1,
122 				  dstX0, dstY0,
123 				  dstX0 + srcX1 * scale, dstY0 + srcY1 * scale,
124 				  GL_COLOR_BUFFER_BIT,
125 				  GL_LINEAR);
126 		glDisable(GL_SCISSOR_TEST);
127 
128 		/* Do scaled blit of fbo_rb to right half piglit_winsys_fbo. */
129 		glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_rb.handle);
130 		glBlitFramebuffer(srcX0, srcY0,
131 				  srcX1, srcY1,
132 				  pattern_width + dstX0, dstY0,
133 				  pattern_width + dstX0 + srcX1 * scale,
134 				  dstY0 + srcY1 * scale,
135 				  GL_COLOR_BUFFER_BIT,
136 				  GL_LINEAR);
137 
138 		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
139 		glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
140 		result = piglit_probe_rect_halves_equal_rgba(0, 0,
141                                                            piglit_width,
142                                                            piglit_height);
143 		pass = result && pass;
144 		piglit_present_results();
145 		printf("scale = %f, result = %s\n",
146 		       scale, result ? "pass" : "fail");
147 	}
148 	return pass;
149 }
150 
151 enum piglit_result
piglit_display()152 piglit_display()
153 {
154 	bool pass = true;
155 	printf("Left Image: Linear scaled blit using texture attachment.\n"
156 	       "Right Image: Linear scaled blit using renderbuffer attachment.\n");
157 	pass = test_blit_scaled_linear()
158 	       && pass;
159 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
160 }
161