ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / ext_window_rectangles / render.c
blob0062399f03d6684bdbc5d9ed7d4c42a6e62b51ef
1 /*
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
13 * Software.
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.
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
34 GLint prog, color;
35 GLuint fb;
36 static int max_rectangles;
38 enum piglit_result
39 piglit_display(void)
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] = {
44 0, 0, 1, 1,
45 2, 0, 1, 1,
46 4, 0, 1, 1,
47 1, 1, 1, 1,
48 3, 1, 1, 1,
49 5, 1, 1, 1,
50 0, 2, 1, 1,
51 2, 2, 1, 1,
54 bool pass = true;
56 glBindFramebuffer(GL_FRAMEBUFFER, fb);
57 glUseProgram(prog);
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 &&
77 rect[i*4+1] == y) {
78 excluded = true;
79 break;
82 if (excluded)
83 subresult &= piglit_probe_pixel_rgba(x, y, blue);
84 else
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);
90 pass &= subresult;
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 &&
109 rect[i*4+1] == y) {
110 included = true;
111 break;
114 if (included)
115 subresult &= piglit_probe_pixel_rgba(x, y, green);
116 else
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);
122 pass &= subresult;
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;
135 void
136 piglit_init(int argc, char **argv)
138 static const float verts[4][4] = {
139 /* x y z w */
140 { -1, -1, 1.0, 1 },
141 { 1, -1, 1.0, 1 },
142 { -1, 1, 0.1, 1 },
143 { 1, 1, 0.1, 1 }
146 GLuint bo, rb;
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
154 "#version 130\n"
155 #else
156 "#version 300 es\n"
157 "precision highp float;\n"
158 #endif
159 "in vec4 piglit_vertex;\n"
160 "void main() { gl_Position = piglit_vertex; }\n",
162 #ifdef PIGLIT_USE_OPENGL
163 "#version 130\n"
164 #else
165 "#version 300 es\n"
166 "precision highp float;\n"
167 #endif
168 "out vec4 col;\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);