2 * Copyright (C) 2016 Ilia Mirkin
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"
26 PIGLIT_GL_TEST_CONFIG_BEGIN
28 config
.supports_gl_compat_version
= 30;
29 config
.supports_gl_es_version
= 30;
30 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
32 PIGLIT_GL_TEST_CONFIG_END
36 static int max_rectangles
;
41 static const float blue
[4] = {0, 0, 1, 1};
42 static const float green
[4] = {0, 1, 0, 1};
43 static const int rect
[4 * 8] = {
56 glBindFramebuffer(GL_FRAMEBUFFER
, fb
);
59 glViewport(0, 0, 20, 20);
61 for (int num_rectangles
= 1; num_rectangles
<= max_rectangles
; num_rectangles
++) {
62 glClearColor(0, 0, 1, 1);
63 glClear(GL_COLOR_BUFFER_BIT
);
65 glWindowRectanglesEXT(GL_EXCLUSIVE_EXT
, num_rectangles
, rect
);
66 glUniform4fv(color
, 1, green
);
67 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
69 bool subresult
= true;
71 for (int y
= 0; y
< 20; y
++) {
72 for (int x
= 0; x
< 20; x
++) {
73 bool excluded
= false;
75 for (int i
= 0; i
< num_rectangles
; i
++) {
76 if (rect
[i
*4+0] == x
&&
83 subresult
&= piglit_probe_pixel_rgba(x
, y
, blue
);
85 subresult
&= piglit_probe_pixel_rgba(x
, y
, green
);
88 piglit_report_subtest_result(subresult
? PIGLIT_PASS
: PIGLIT_FAIL
,
89 "exclusive, num rectangles = %u", num_rectangles
);
93 for (int num_rectangles
= 1; num_rectangles
<= max_rectangles
; num_rectangles
++) {
94 glClearColor(0, 0, 1, 1);
95 glClear(GL_COLOR_BUFFER_BIT
);
97 glWindowRectanglesEXT(GL_INCLUSIVE_EXT
, num_rectangles
, rect
);
98 glUniform4fv(color
, 1, green
);
99 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
101 bool subresult
= true;
103 for (int y
= 0; y
< 20; y
++) {
104 for (int x
= 0; x
< 20; x
++) {
105 bool included
= false;
107 for (int i
= 0; i
< num_rectangles
; i
++) {
108 if (rect
[i
*4+0] == x
&&
115 subresult
&= piglit_probe_pixel_rgba(x
, y
, green
);
117 subresult
&= piglit_probe_pixel_rgba(x
, y
, blue
);
120 piglit_report_subtest_result(subresult
? PIGLIT_PASS
: PIGLIT_FAIL
,
121 "inclusive, num rectangles = %u", num_rectangles
);
125 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
126 glBlitFramebuffer(0, 0, 20, 20,
127 0, 0, piglit_width
, piglit_height
,
128 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
130 piglit_present_results();
132 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
136 piglit_init(int argc
, char **argv
)
138 static const float verts
[4][4] = {
148 piglit_require_extension("GL_EXT_window_rectangles");
149 glGetIntegerv(GL_MAX_WINDOW_RECTANGLES_EXT
, &max_rectangles
);
150 assert(max_rectangles
<= 8);
152 prog
= piglit_build_simple_program(
153 #ifdef PIGLIT_USE_OPENGL
157 "precision highp float;\n"
159 "in vec4 piglit_vertex;\n"
160 "void main() { gl_Position = piglit_vertex; }\n",
162 #ifdef PIGLIT_USE_OPENGL
166 "precision highp float;\n"
169 "uniform vec4 color;\n"
170 "void main() { col = color; }\n");
171 color
= glGetUniformLocation(prog
, "color");
173 glEnableVertexAttribArray(0);
174 glGenBuffers(1, &bo
);
175 glBindBuffer(GL_ARRAY_BUFFER
, bo
);
176 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
, GL_STATIC_DRAW
);
177 glVertexAttribPointer(glGetAttribLocation(prog
, "piglit_vertex"),
178 4, GL_FLOAT
, GL_FALSE
, 0, (GLvoid
const *)0);
180 glGenFramebuffers(1, &fb
);
181 glBindFramebuffer(GL_FRAMEBUFFER
, fb
);
182 glGenRenderbuffers(1, &rb
);
183 glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
184 glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 20, 20);
185 glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
186 GL_RENDERBUFFER
, rb
);