shader_runner: don't use deleted query objects
[piglit.git] / tests / fbo / fbo-generatemipmap.c
blobf19d45fca225f80b65fe04fc28d8ba1639777c34
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-generatemipmap.c
30 * Tests that glGenerateMipmapEXT works correctly on a 2D texture.
33 #include "piglit-util-gl.h"
35 #define TEX_WIDTH 256
36 #define TEX_HEIGHT 256
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config.supports_gl_compat_version = 10;
42 config.window_width = 700;
43 config.window_height = 300;
44 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
45 config.khr_no_error_support = PIGLIT_NO_ERRORS;
47 PIGLIT_GL_TEST_CONFIG_END
49 static const float red[] = {1, 0, 0, 0};
50 static const float green[] = {0, 1, 0, 0};
51 static const float blue[] = {0, 0, 1, 0};
52 static const float white[] = {1, 1, 1, 1};
54 static int
55 create_fbo(void)
57 GLuint tex, fb;
58 GLenum status;
59 int i, dim;
61 glGenTextures(1, &tex);
62 glBindTexture(GL_TEXTURE_2D, tex);
64 for (i = 0, dim = TEX_WIDTH; dim >0; i++, dim /= 2) {
65 glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA,
66 dim, dim,
68 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
70 if (!piglit_check_gl_error(GL_NO_ERROR))
71 piglit_report_result(PIGLIT_FAIL);
73 glGenFramebuffersEXT(1, &fb);
74 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
75 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
76 GL_COLOR_ATTACHMENT0_EXT,
77 GL_TEXTURE_2D,
78 tex,
79 0);
80 if (!piglit_check_gl_error(GL_NO_ERROR))
81 piglit_report_result(PIGLIT_FAIL);
83 status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
84 if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
85 fprintf(stderr, "FBO incomplete\n");
86 goto done;
89 glViewport(0, 0, TEX_WIDTH, TEX_HEIGHT);
90 piglit_ortho_projection(TEX_WIDTH, TEX_HEIGHT, GL_FALSE);
92 glColor4fv(red);
93 piglit_draw_rect(0, 0, TEX_WIDTH / 2, TEX_HEIGHT / 2);
94 glColor4fv(green);
95 piglit_draw_rect(TEX_WIDTH / 2, 0, TEX_WIDTH, TEX_HEIGHT / 2);
96 glColor4fv(blue);
97 piglit_draw_rect(0, TEX_HEIGHT / 2, TEX_WIDTH/2, TEX_HEIGHT);
98 glColor4fv(white);
99 piglit_draw_rect(TEX_WIDTH / 2, TEX_HEIGHT / 2, TEX_WIDTH, TEX_HEIGHT);
101 glGenerateMipmapEXT(GL_TEXTURE_2D);
102 done:
103 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
104 glDeleteFramebuffersEXT(1, &fb);
106 return tex;
109 static void
110 draw_mipmap(int x, int y, int dim)
112 glViewport(0, 0, piglit_width, piglit_height);
113 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
115 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
117 glEnable(GL_TEXTURE_2D);
118 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
119 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
122 piglit_draw_rect_tex(x, y, dim, dim,
123 0, 0, 1, 1);
124 glDisable(GL_TEXTURE_2D);
127 static GLboolean
128 test_mipmap_drawing(int start_x, int start_y, int dim)
130 GLboolean pass = GL_TRUE;
131 pass = pass && piglit_probe_rect_rgb(
132 start_x, start_y, dim/2, dim/2, red);
133 pass = pass && piglit_probe_rect_rgb(
134 start_x + dim/2, start_y, dim/2, dim/2, green);
135 pass = pass && piglit_probe_rect_rgb(
136 start_x, start_y + dim/2, dim/2, dim/2, blue);
137 pass = pass && piglit_probe_rect_rgb(
138 start_x + dim/2, start_y + dim/2, dim/2, dim/2, white);
140 return pass;
143 enum piglit_result
144 piglit_display(void)
146 GLboolean pass = GL_TRUE;
147 int dim;
148 GLuint tex;
149 int x;
151 glClearColor(0.5, 0.5, 0.5, 0.5);
152 glClear(GL_COLOR_BUFFER_BIT);
154 tex = create_fbo();
156 x = 1;
157 for (dim = TEX_WIDTH; dim > 1; dim /= 2) {
158 draw_mipmap(x, 1, dim);
159 x += dim + 1;
162 x = 1;
163 for (dim = TEX_WIDTH; dim > 1; dim /= 2) {
164 pass &= test_mipmap_drawing(x, 1, dim);
165 x += dim + 1;
168 glDeleteTextures(1, &tex);
170 piglit_present_results();
172 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
175 void piglit_init(int argc, char **argv)
177 piglit_require_extension("GL_EXT_framebuffer_object");