arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / fbo / fbo-flushing-2.c
blob1938929d41e012b8dcf33ea2c286aa10dd66312b
1 /*
2 * Copyright © 2009,2011 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-2.c
30 * Tests that rendering to a texture then texturing from it gets
31 * correct results.
33 * This caught a bug where the texture cache wasn't flushed
34 * appropriately on the Intel drivers once additional state changes
35 * had been removed.
38 #include "piglit-util-gl.h"
40 #define TEX_WIDTH 8
41 #define TEX_HEIGHT 8
43 PIGLIT_GL_TEST_CONFIG_BEGIN
45 config.supports_gl_compat_version = 10;
47 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
48 config.khr_no_error_support = PIGLIT_NO_ERRORS;
50 PIGLIT_GL_TEST_CONFIG_END
52 enum piglit_result
53 piglit_display(void)
55 GLboolean pass = GL_TRUE;
56 int x, y;
57 GLuint tex, fb;
58 float blue[] = {1, 0, 0, 0};
59 float green[] = {0, 1, 0, 0};
60 bool draw_green;
61 float *draw_colors[] = {blue, green};
62 float w_screen = 2.0f * TEX_WIDTH / piglit_width;
63 float h_screen = 2.0f * TEX_HEIGHT / piglit_height;
65 glGenTextures(1, &tex);
66 glBindTexture(GL_TEXTURE_2D, tex);
67 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
68 TEX_WIDTH, TEX_HEIGHT, 0,
69 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
73 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
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 draw_green = true;
89 for (y = 0; y <= piglit_height - TEX_HEIGHT; y += TEX_HEIGHT) {
90 float y_screen = -1.0 + 2.0 * ((float)y / piglit_height);
92 for (x = 0; x <= piglit_width - TEX_WIDTH; x += TEX_WIDTH) {
93 float x_screen = -1.0 + 2.0 * ((float)x / piglit_width);
95 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
96 glDisable(GL_TEXTURE_2D);
97 glColor4fv(draw_colors[draw_green]);
98 piglit_draw_rect(-1, -1, 2, 2);
100 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
101 glEnable(GL_TEXTURE_2D);
102 piglit_draw_rect_tex(x_screen, y_screen,
103 w_screen, h_screen,
104 0, 0,
105 1, 1);
107 draw_green = !draw_green;
109 /* Make it a checkerboard. */
110 draw_green = !draw_green;
113 glDeleteFramebuffersEXT(1, &fb);
114 glDeleteTextures(1, &tex);
116 draw_green = true;
117 for (y = 0; y <= piglit_height - TEX_HEIGHT; y += TEX_HEIGHT) {
118 for (x = 0; x <= piglit_width - TEX_WIDTH; x += TEX_WIDTH) {
119 float *expected = draw_colors[draw_green];
121 pass = pass && piglit_probe_rect_rgb(x, y,
122 TEX_WIDTH,
123 TEX_HEIGHT,
124 expected);
126 draw_green = !draw_green;
128 draw_green = !draw_green;
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");