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
27 * Test that glWindowRectanglesEXT works inside of a call list. See
28 * draw.c for testing technique comments.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 30;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
38 PIGLIT_GL_TEST_CONFIG_END
46 static const float blue
[4] = {0, 0, 1, 1};
47 static const float green
[4] = {0, 1, 0, 1};
48 static const float red
[4] = {1, 0, 0, 1};
49 static const int rect
[4] = {10, 10, 10, 10};
52 bool passa
= true, passb
= true;
54 glBindFramebuffer(GL_FRAMEBUFFER
, fb
);
57 glViewport(0, 0, 20, 20);
59 glClearColor(0, 0, 1, 1);
60 glClear(GL_COLOR_BUFFER_BIT
);
64 /* Try a single rect in exclusive mode */
65 glNewList(list
, GL_COMPILE_AND_EXECUTE
);
66 glWindowRectanglesEXT(GL_EXCLUSIVE_EXT
, 1, rect
);
67 glUniform4fv(color
, 1, green
);
68 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
71 if (!piglit_probe_rect_rgba(0, 0, 10, 10, green
)) {
72 printf(" FAIL: green color not filled in \n");
75 if (!piglit_probe_rect_rgba(10, 10, 10, 10, blue
)) {
76 printf(" FAIL: green color fills in excluded area\n");
80 /* And now in inclusive mode */
81 glNewList(list
+ 1, GL_COMPILE_AND_EXECUTE
);
82 glWindowRectanglesEXT(GL_INCLUSIVE_EXT
, 1, rect
);
83 glUniform4fv(color
, 1, red
);
84 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
87 if (!piglit_probe_rect_rgba(0, 0, 10, 10, green
)) {
88 printf(" FAIL: green color overwritten\n");
91 if (!piglit_probe_rect_rgba(10, 10, 10, 10, red
)) {
92 printf(" FAIL: red color not written to included area\n");
96 piglit_report_subtest_result(passa
? PIGLIT_PASS
: PIGLIT_FAIL
,
97 "compile and execute");
98 glClear(GL_COLOR_BUFFER_BIT
);
101 if (!piglit_probe_rect_rgba(0, 0, 10, 10, green
)) {
102 printf(" FAIL: green color not filled in \n");
105 if (!piglit_probe_rect_rgba(10, 10, 10, 10, blue
)) {
106 printf(" FAIL: green color fills in excluded area\n");
110 glCallList(list
+ 1);
111 if (!piglit_probe_rect_rgba(0, 0, 10, 10, green
)) {
112 printf(" FAIL: green color overwritten\n");
115 if (!piglit_probe_rect_rgba(10, 10, 10, 10, red
)) {
116 printf(" FAIL: red color not written to included area\n");
120 piglit_report_subtest_result(passb
? PIGLIT_PASS
: PIGLIT_FAIL
,
123 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
124 glBlitFramebuffer(0, 0, 20, 20,
125 0, 0, piglit_width
, piglit_height
,
126 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
128 piglit_present_results();
130 return (passa
&& passb
) ? PIGLIT_PASS
: PIGLIT_FAIL
;
134 piglit_init(int argc
, char **argv
)
136 const char * subtests
[] = { "compile and execute", "call", NULL
};
137 piglit_register_subtests(subtests
);
139 static const float verts
[4][4] = {
149 piglit_require_extension("GL_EXT_window_rectangles");
151 prog
= piglit_build_simple_program(
153 "void main() { gl_Position = gl_Vertex; }\n",
156 "uniform vec4 color;\n"
157 "void main() { gl_FragColor = color; }\n");
158 color
= glGetUniformLocation(prog
, "color");
160 glEnableVertexAttribArray(0);
161 glGenBuffers(1, &bo
);
162 glBindBuffer(GL_ARRAY_BUFFER
, bo
);
163 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
, GL_STATIC_DRAW
);
164 glVertexAttribPointer(0, 4, GL_FLOAT
, GL_FALSE
, 0, (GLvoid
const *)0);
166 glGenFramebuffers(1, &fb
);
167 glBindFramebuffer(GL_FRAMEBUFFER
, fb
);
168 glGenRenderbuffers(1, &rb
);
169 glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
170 glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGB
, 20, 20);
171 glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
172 GL_RENDERBUFFER
, rb
);