Add more structure constructor tests.
[piglit/hramrach.git] / tests / fbo / fbo-flushing.c
blob21d8206f1e919a17e95b2f2df6d8b5e41367057c
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.h"
39 #include "piglit-framework.h"
41 #define TEX_WIDTH 128
42 #define TEX_HEIGHT 128
44 int piglit_width = 300;
45 int piglit_height = 300;
46 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
48 enum piglit_result
49 piglit_display(void)
51 GLboolean pass = GL_TRUE;
52 int y, probe_x, probe_y, size;
53 GLuint tex, fb;
54 const float red[] = {1, 0, 0, 0};
55 const float green[] = {0, 1, 0, 0};
57 glClearColor(0.5, 0.5, 0.5, 0.5);
58 glClear(GL_COLOR_BUFFER_BIT);
60 glGenTextures(1, &tex);
61 glBindTexture(GL_TEXTURE_2D, tex);
62 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
63 TEX_WIDTH, TEX_HEIGHT, 0,
64 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
69 glGenFramebuffersEXT(1, &fb);
70 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
71 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
72 GL_COLOR_ATTACHMENT0_EXT,
73 GL_TEXTURE_2D,
74 tex,
75 0);
76 assert(glGetError() == 0);
78 assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
79 GL_FRAMEBUFFER_COMPLETE_EXT);
81 /* For each power of two size we test, draw red to it, draw it to
82 * the framebuffer, then draw green to it and draw it to the
83 * framebuffer.
85 * Hopefully between these we'll catch any flushing fail.
87 y = 0;
88 for (size = TEX_WIDTH; size > 0; size /= 2) {
89 glDisable(GL_TEXTURE_2D);
90 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
91 glColor4fv(red);
92 piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);
93 piglit_draw_rect(0, y, size, size);
95 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
96 glEnable(GL_TEXTURE_2D);
97 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
98 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
99 piglit_draw_rect_tex(0, y, size, size, 0, 0, 1, 1);
101 glDisable(GL_TEXTURE_2D);
102 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
103 glColor4fv(green);
104 piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);
105 piglit_draw_rect(0, y, size, size);
107 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
108 glEnable(GL_TEXTURE_2D);
109 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
110 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
111 piglit_draw_rect_tex(0, y, size, size, 0, 0, 1, 1);
112 y += size + 5;
115 glDeleteFramebuffersEXT(1, &fb);
116 glDeleteTextures(1, &tex);
118 y = 0;
119 for (size = TEX_WIDTH; size > 0; size /= 2) {
120 for (probe_y = 0; probe_y < size; probe_y++) {
121 for (probe_x = 0; probe_x < size; probe_x++) {
122 pass = pass && piglit_probe_pixel_rgb(probe_x,
123 probe_y,
124 green);
127 y += size + 5;
130 glutSwapBuffers();
132 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
135 void
136 piglit_init(int argc, char **argv)
138 piglit_require_extension("GL_EXT_framebuffer_object");