2 * Copyright 2010 VMware, Inc.
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
21 * DEALINGS IN THE SOFTWARE.
25 * Test building a mipmap in various orders:
26 * From largest to smallest
27 * From smallest to largest
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
40 config
.window_width
= 200;
41 config
.window_height
= 200;
42 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
43 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
45 PIGLIT_GL_TEST_CONFIG_END
57 level_intensity(GLint level
)
59 return 100 + level
* 20;
64 setup_tex_image(GLint level
)
66 GLint size
= 1 << (MAX_LEVEL
- level
);
67 GLubyte
*img
= malloc(size
* size
* 4);
68 GLubyte val
= level_intensity(level
);
69 memset(img
, val
, size
* size
* 4);
70 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGB
, size
, size
, 0,
71 GL_RGBA
, GL_UNSIGNED_BYTE
, img
);
77 * Generate a mipmapped texture.
78 * Define the mipmap levels/images in the order specified by 'ord'.
81 generate_mipmap(enum order ord
)
86 glGenTextures(1, &tex
);
87 glBindTexture(GL_TEXTURE_2D
, tex
);
89 /* hint to the driver that there won't be a mipmap (but that's a lie) */
90 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
91 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
93 /* Set each mipmap level to a different intensity, starting with the
94 * smallest mipmap level and ending with the largest at level=0.
97 for (level
= 0; level
<= MAX_LEVEL
; level
++) {
98 setup_tex_image(level
);
101 else if (ord
== REVERSE
) {
102 for (level
= MAX_LEVEL
; level
>= 0; level
--) {
103 setup_tex_image(level
);
107 static const GLuint rand
[MAX_LEVEL
+ 1] = {3, 1, 2, 4, 7, 0, 6, 5};
108 assert(ord
== RANDOM
);
110 for (level
= 0; level
<= MAX_LEVEL
; level
++) {
111 setup_tex_image(rand
[level
]);
115 /* use mipmap filtering */
116 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
117 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
122 test(enum order ord
, const char *order
)
124 const int px
= piglit_width
/ 2, py
= piglit_height
/ 2;
125 GLboolean pass
= GL_TRUE
;
128 generate_mipmap(ord
);
130 glEnable(GL_TEXTURE_2D
);
132 /* render a test polygon for each mipmap level */
133 for (level
= 0; level
<= MAX_LEVEL
; level
++) {
137 expected
[0] = expected
[1] = expected
[2] = level_intensity(level
) / 255.0;
139 /* force sampling from a specific mipmap level */
140 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_LOD
, level
);
141 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LOD
, level
);
143 glClear(GL_COLOR_BUFFER_BIT
);
156 p
= piglit_probe_pixel_rgb(px
, py
, expected
);
158 printf(" At mipmap level %d, order = %s\n", level
, order
);
163 piglit_present_results();
171 piglit_init(int argc
, char **argv
)
180 if (!test(NORMAL
, "Normal"))
183 if (!test(REVERSE
, "Reverse"))
186 if (!test(RANDOM
, "Random"))