glsl-array-bounds: set out-of-bounds array index inside shader
[piglit.git] / tests / fbo / fbo-flushing.c
blob44ee03cd87e10a0a599e9700ad500e9dc59ceb3d
1 /*
2 * Copyright © 2009 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.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /** @file fbo-flushing.c
30 * Tests that rendering to a texture then texturing from it gets correct
31 * results.
33 * This caught a bug where the texture cache wasn't flushed appropriately
34 * on the Intel drivers once additional batchbuffer flushing had been
35 * removed.
38 #include "piglit-util-gl.h"
40 #define TEX_WIDTH 128
41 #define TEX_HEIGHT 128
43 PIGLIT_GL_TEST_CONFIG_BEGIN
45 config.supports_gl_compat_version = 10;
47 config.window_width = 300;
48 config.window_height = 300;
49 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
50 config.khr_no_error_support = PIGLIT_NO_ERRORS;
52 PIGLIT_GL_TEST_CONFIG_END
54 enum piglit_result
55 piglit_display(void)
57 GLboolean pass = GL_TRUE;
58 int y, size;
59 GLuint tex, fb;
60 const float red[] = {1, 0, 0, 0};
61 const float green[] = {0, 1, 0, 0};
63 glClearColor(0.5, 0.5, 0.5, 0.5);
64 glClear(GL_COLOR_BUFFER_BIT);
66 glGenTextures(1, &tex);
67 glBindTexture(GL_TEXTURE_2D, tex);
68 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
69 TEX_WIDTH, TEX_HEIGHT, 0,
70 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
75 glGenFramebuffersEXT(1, &fb);
76 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
77 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
78 GL_COLOR_ATTACHMENT0_EXT,
79 GL_TEXTURE_2D,
80 tex,
81 0);
82 if (!piglit_check_gl_error(GL_NO_ERROR))
83 piglit_report_result(PIGLIT_FAIL);
85 assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
86 GL_FRAMEBUFFER_COMPLETE_EXT);
88 /* For each power of two size we test, draw red to it, draw it to
89 * the framebuffer, then draw green to it and draw it to the
90 * framebuffer.
92 * Hopefully between these we'll catch any flushing fail.
94 y = 0;
95 for (size = TEX_WIDTH; size > 0; size /= 2) {
96 glDisable(GL_TEXTURE_2D);
97 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
98 glColor4fv(red);
99 piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);
100 piglit_draw_rect(0, y, size, size);
102 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
103 glEnable(GL_TEXTURE_2D);
104 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
105 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
106 piglit_draw_rect_tex(0, y, size, size, 0, 0, 1, 1);
108 glDisable(GL_TEXTURE_2D);
109 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
110 glColor4fv(green);
111 piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);
112 piglit_draw_rect(0, y, size, size);
114 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
115 glEnable(GL_TEXTURE_2D);
116 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
117 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
118 piglit_draw_rect_tex(0, y, size, size, 0, 0, 1, 1);
119 y += size + 5;
122 glDeleteFramebuffersEXT(1, &fb);
123 glDeleteTextures(1, &tex);
125 y = 0;
126 for (size = TEX_WIDTH; size > 0; size /= 2) {
127 pass = pass && piglit_probe_rect_rgb(0, y, size, size, green);
128 y += size + 5;
131 piglit_present_results();
133 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
136 void
137 piglit_init(int argc, char **argv)
139 piglit_require_extension("GL_EXT_framebuffer_object");