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
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
24 /** @file fbo-generatemipmap.c
26 * Tests that glGenerateMipmapEXT uses appropriate filtering for a 2D texture.
29 #include "piglit-util-gl.h"
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
49 uint8_t data
[TEX_WIDTH
* TEX_HEIGHT
* 4];
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) {
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
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
);
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
,
102 glDisable(GL_TEXTURE_2D
);
108 GLboolean pass
= GL_TRUE
;
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
);
120 for (dim
= TEX_WIDTH
; dim
> 1; dim
/= 2) {
121 draw_mipmap(x
, 1, dim
);
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
,
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");