fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / spec / intel_blackhole_render / blackhole_blit.c
blob4567aeec3bd4c7137cf9a6fe981b2d557292c686
1 /*
2 * Copyright © 2019 Intel Corporation
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.
25 /** @file blackhole_blit.c
27 * Verifies that with GL_INTEL_black_render enabled, blit operations
28 * have no effect.
31 #include "piglit-util-gl.h"
32 #include "piglit-matrix.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 #if defined(PIGLIT_USE_OPENGL)
37 config.supports_gl_core_version = 42;
38 #elif defined(PIGLIT_USE_OPENGL_ES2) || defined(PIGLIT_USE_OPENGL_ES3)
39 config.supports_gl_es_version = 20;
40 #endif
42 config.window_width = 400;
43 config.window_height = 400;
44 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
46 PIGLIT_GL_TEST_CONFIG_END
48 static enum piglit_result
49 run(void)
51 float delta = 1.01 / piglit_width;
52 GLuint prog, fb, fb_tex;
54 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
55 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
57 glClearColor(0.0, 0.0, 1.0, 1.0);
58 glClear(GL_COLOR_BUFFER_BIT);
60 glGenFramebuffersEXT(1, &fb);
61 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, fb);
62 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, fb);
64 glCreateTextures(GL_TEXTURE_2D, 1, &fb_tex);
65 glBindTexture(GL_TEXTURE_2D, fb_tex);
66 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
67 piglit_width, piglit_height, 0,
68 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
69 glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
70 GL_TEXTURE_2D, fb_tex, 0);
72 /* This atom should be disabled by default */
73 if (glIsEnabled(GL_BLACKHOLE_RENDER_INTEL))
74 return PIGLIT_FAIL;
76 prog = piglit_build_simple_program(
77 #if defined(PIGLIT_USE_OPENGL)
78 "#version 330\n"
79 "in vec4 piglit_vertex;\n"
80 #elif defined(PIGLIT_USE_OPENGL_ES2) || defined(PIGLIT_USE_OPENGL_ES3)
81 "#version 100\n"
82 "attribute vec4 piglit_vertex;\n"
83 #endif
84 "void main()\n"
85 "{\n"
86 " gl_Position = piglit_vertex;\n"
87 "}\n",
88 #if defined(PIGLIT_USE_OPENGL)
89 "#version 330\n"
90 #elif defined(PIGLIT_USE_OPENGL_ES2) || defined(PIGLIT_USE_OPENGL_ES3)
91 "#version 100\n"
92 #endif
93 "void main()\n"
94 "{\n"
95 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
96 "}\n");
97 if (!prog)
98 piglit_report_result(PIGLIT_FAIL);
100 glViewport(0, 0, piglit_width, piglit_height);
102 glClearColor(0.0, 0.0, 0.0, 0.0);
104 glUseProgram(prog);
106 GLuint vao;
107 glGenVertexArrays(1, &vao);
108 glBindVertexArray(vao);
110 GLuint vbo;
111 float vertices[3][2] = {
112 { -0.5, -1 + delta, },
113 { 0, 0.8, },
114 { 0.5, -1 + delta, },
116 glGenBuffers(1, &vbo);
117 glBindBuffer(GL_ARRAY_BUFFER, vbo);
118 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
119 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL);
120 glEnableVertexAttribArray(0);
122 glDisable(GL_BLACKHOLE_RENDER_INTEL);
123 glClear(GL_COLOR_BUFFER_BIT);
124 glDrawArrays(GL_TRIANGLES, 0, 3);
126 if(!piglit_check_gl_error(GL_NO_ERROR))
127 return PIGLIT_FAIL;
129 const float shader_expected[] = { 1.0, 0.0, 0.0, 1.0 };
130 if (!piglit_probe_pixel_rgba(piglit_width / 2,
131 piglit_height / 2,
132 shader_expected))
133 return PIGLIT_FAIL;
135 piglit_present_results();
137 glClearColor(0.0, 1.0, 0.0, 1.0);
138 glClear(GL_COLOR_BUFFER_BIT);
140 const float clear_expected[] = { 0.0, 1.0, 0.0, 1.0 };
141 if (!piglit_probe_pixel_rgba(piglit_width / 2,
142 piglit_height / 2,
143 clear_expected))
144 return PIGLIT_FAIL;
146 piglit_present_results();
148 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
149 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
151 glEnable(GL_BLACKHOLE_RENDER_INTEL);
153 if (!glIsEnabled(GL_BLACKHOLE_RENDER_INTEL))
154 return PIGLIT_FAIL;
156 glBlitFramebuffer(0, 0, piglit_width, piglit_height,
157 0, 0, piglit_width, piglit_height,
158 GL_COLOR_BUFFER_BIT, GL_LINEAR);
160 glDisable(GL_BLACKHOLE_RENDER_INTEL);
162 if(!piglit_check_gl_error(GL_NO_ERROR))
163 return PIGLIT_FAIL;
165 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
167 /* Blitting into piglit_winsys_fbo was dropped because of the
168 * blackhole state, expect the first clear color.
170 const float blackhole_expected[] = { 0.0, 0.0, 1.0, 1.0 };
171 if (!piglit_probe_pixel_rgba(piglit_width / 2,
172 piglit_height / 2,
173 blackhole_expected))
174 return PIGLIT_FAIL;
176 piglit_present_results();
178 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
179 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
181 glBlitFramebuffer(0, 0, piglit_width, piglit_height,
182 0, 0, piglit_width, piglit_height,
183 GL_COLOR_BUFFER_BIT, GL_LINEAR);
185 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
187 /* Now the clear color that landed in fb should have been
188 * copied into piglit_winsys_fbo.
190 if (!piglit_probe_pixel_rgba(piglit_width / 2,
191 piglit_height / 2,
192 clear_expected))
193 return PIGLIT_FAIL;
195 return PIGLIT_PASS;
198 enum piglit_result
199 piglit_display(void)
201 enum piglit_result result = run();
203 glDisable(GL_BLACKHOLE_RENDER_INTEL);
205 return result;
208 void piglit_init(int argc, char **argv)
210 piglit_require_extension("GL_INTEL_blackhole_render");