ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / nv_conditional_render / blitframebuffer.c
blob06e5c7d81a7080eb108e53be2d01e3429735d37a
1 /*
2 * Copyright © 2011 Intel Corporation
3 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
25 #include "piglit-util-gl.h"
27 /**
28 * @file blitframebuffer.c
30 * Tests that conditional rendering also affects glBlitFramebuffer().
32 * It is clarified on page 679 of OpenGL 4.4 spec:
33 * "Added BlitFramebuffer to commands affected by conditional rendering in
34 * section 10.10 (Bug 9562)."
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_compat_version = 10;
40 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
45 static void fill_tex(int level, int w, int h, const GLfloat *color)
47 GLfloat *data;
48 int i;
50 data = malloc(w * h * 4 * sizeof(GLfloat));
51 for (i = 0; i < 4 * w * h; i += 4) {
52 data[i + 0] = color[0];
53 data[i + 1] = color[1];
54 data[i + 2] = color[2];
55 data[i + 3] = color[3];
57 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0,
58 GL_RGBA, GL_FLOAT, data);
59 free(data);
62 static void blit_window_to_tex(GLuint tex, int w, int h)
64 GLuint fb;
66 glGenFramebuffersEXT(1, &fb);
67 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb);
68 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);
70 assert(glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT);
72 glBlitFramebufferEXT(0, h, w, 2 * h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
74 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
75 glDeleteFramebuffersEXT(1, &fb);
78 enum piglit_result
79 piglit_display(void)
81 bool pass = true;
82 float green[4] = {0.0, 1.0, 0.0, 0.0};
83 GLuint q, texture;
85 glClearColor(0.5, 0.5, 0.5, 0.5);
86 glClear(GL_COLOR_BUFFER_BIT);
88 /* Draw bottom half of window to green. */
89 glColor4fv(green);
90 piglit_draw_rect(-1, -1, 2, 1);
91 glColor4f(1, 1, 1, 1);
93 /* Set up a green texture. */
94 glGenTextures(1, &texture);
95 glBindTexture(GL_TEXTURE_2D, texture);
97 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
98 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
99 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
101 GL_LINEAR_MIPMAP_NEAREST);
102 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
104 fill_tex(0, piglit_width, piglit_height / 2, green);
106 glGenQueries(1, &q);
108 /* Generate query fail. */
109 glBeginQuery(GL_SAMPLES_PASSED, q);
110 glEndQuery(GL_SAMPLES_PASSED);
112 /* BlitFramebuffer() should be affected by conditional rendering. */
113 glBeginConditionalRenderNV(q, GL_QUERY_WAIT_NV);
114 /* Blit top half of the window to texture. */
115 blit_window_to_tex(texture, piglit_width, piglit_height / 2);
116 glEndConditionalRenderNV();
118 /* Draw the texture to top half of the window. */
119 glEnable(GL_TEXTURE_2D);
120 piglit_draw_rect_tex(-1, 0, 2, 1,
121 0, 0, 1, 1);
122 glDisable(GL_TEXTURE_2D);
124 pass = piglit_probe_rect_rgba(0, piglit_width / 2,
125 piglit_width, piglit_height / 2,
126 green);
128 piglit_present_results();
130 glDeleteQueries(1, &q);
132 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
135 void
136 piglit_init(int argc, char **argv)
138 piglit_require_gl_version(20);
140 piglit_require_extension("GL_NV_conditional_render");
141 piglit_require_extension("GL_EXT_framebuffer_object");
142 piglit_require_extension("GL_EXT_framebuffer_blit");