arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / fbo / fbo-generatemipmap-filtering.c
blob8219265ceeb2ce7bf5670b3718d5a278279db235
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.
24 /** @file fbo-generatemipmap.c
26 * Tests that glGenerateMipmapEXT uses appropriate filtering for a 2D texture.
29 #include "piglit-util-gl.h"
31 #define TEX_WIDTH 256
32 #define TEX_HEIGHT 256
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
38 config.window_width = 700;
39 config.window_height = 300;
40 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
45 static int
46 create_tex(void)
48 GLuint tex;
49 uint8_t data[TEX_WIDTH * TEX_HEIGHT * 4];
50 int x, y;
52 glGenTextures(1, &tex);
53 glBindTexture(GL_TEXTURE_2D, tex);
55 for (y = 0; y < TEX_HEIGHT; y++) {
56 for (x = 0; x < TEX_WIDTH; x++) {
57 uint8_t *p = data + (y * TEX_WIDTH + x) * 4;
59 if ((x + 1) % 8 < 4) {
60 p[0] = 255;
61 p[1] = 0;
62 } else {
63 p[0] = 0;
64 p[1] = 255;
66 p[2] = 0;
67 p[3] = 255;
71 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
72 TEX_WIDTH, TEX_HEIGHT,
74 GL_RGBA, GL_UNSIGNED_BYTE, data);
76 /* Leave the worst possible filtering setup in place for calling
77 * glGenerateMipmap.
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
82 glGenerateMipmapEXT(GL_TEXTURE_2D);
84 return tex;
87 static void
88 draw_mipmap(int x, int y, int dim)
90 glViewport(0, 0, piglit_width, piglit_height);
91 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
93 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
95 glEnable(GL_TEXTURE_2D);
96 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
97 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
98 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
100 piglit_draw_rect_tex(x, y, dim, dim,
101 0, 0, 1, 1);
102 glDisable(GL_TEXTURE_2D);
105 enum piglit_result
106 piglit_display(void)
108 GLboolean pass = GL_TRUE;
109 int dim;
110 GLuint tex;
111 int x;
112 float blend[] = {0.5, 0.5, 0.0, 1.0};
114 glClearColor(0.5, 0.5, 0.5, 0.5);
115 glClear(GL_COLOR_BUFFER_BIT);
117 tex = create_tex();
119 x = 1;
120 for (dim = TEX_WIDTH; dim > 1; dim /= 2) {
121 draw_mipmap(x, 1, dim);
122 x += dim + 1;
125 x = 1;
126 for (dim = TEX_WIDTH; dim > 1; dim /= 2) {
127 if (dim < TEX_WIDTH / 4) {
128 pass &= piglit_probe_rect_rgba(x, 1, dim, dim,
129 blend);
132 x += dim + 1;
135 glDeleteTextures(1, &tex);
137 piglit_present_results();
139 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
142 void piglit_init(int argc, char **argv)
144 piglit_require_extension("GL_EXT_framebuffer_object");