2 * Copyright © 2008-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
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 * Eric Anholt <eric@anholt.net>
29 * @file lodclamp-between.c
31 * Tests that setting LOD clamp to between two texture levels results in
32 * appropriate mipmap filtering.
35 #include "piglit-util.h"
41 int piglit_window_mode
= GLUT_DOUBLE
| GLUT_RGB
;
42 int piglit_width
= 100;
43 int piglit_height
= 200;
45 static GLfloat colors
[][3] = {
55 set_level_color(int level
, int size
, int color
)
60 tex
= malloc(size
* size
* 3 * sizeof(GLfloat
));
62 for (y
= 0; y
< size
; y
++) {
63 for (x
= 0; x
< size
; x
++) {
64 tex
[(y
* size
+ x
) * 3 + 0] = colors
[color
][0];
65 tex
[(y
* size
+ x
) * 3 + 1] = colors
[color
][1];
66 tex
[(y
* size
+ x
) * 3 + 2] = colors
[color
][2];
70 glTexImage2D(GL_TEXTURE_2D
, level
, GL_RGB
,
72 GL_RGB
, GL_FLOAT
, tex
);
81 GLboolean pass
= GL_TRUE
;
85 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
87 /* Clear background to gray */
88 glClearColor(0.5, 0.5, 0.5, 1.0);
89 glClear(GL_COLOR_BUFFER_BIT
);
91 /* Create the texture. */
92 glGenTextures(1, &tex
);
93 glBindTexture(GL_TEXTURE_2D
, tex
);
95 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
96 GL_LINEAR_MIPMAP_LINEAR
);
97 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
98 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
99 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
101 /* Fill in each level */
102 for (level
= 0, dim
= MAX_SIZE
; dim
> 0; level
++, dim
/= 2) {
103 set_level_color(level
, dim
, level
);
106 glEnable(GL_TEXTURE_2D
);
108 /* Draw areas of the base level size with clamping to mip lods
109 * between each texture level.
113 for (level
= 0, dim
= MAX_SIZE
; dim
> 1; level
++, dim
/= 2) {
114 float clamp
= (float)level
+ 0.5;
116 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_LOD
, clamp
);
118 piglit_draw_rect_tex(x
, y
, MAX_SIZE
, MAX_SIZE
,
124 /* Verify that the resulting images are blended between the levels. */
126 for (level
= 0, dim
= MAX_SIZE
; dim
> 1; level
++, dim
/= 2) {
130 for (i
= 0; i
< 3; i
++) {
131 expected
[i
] = (colors
[level
][i
] +
132 colors
[level
+ 1][i
]) / 2.0;
135 pass
= piglit_probe_pixel_rgb(x
+ MAX_SIZE
/ 2,
142 glDeleteTextures(1, &tex
);
146 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
150 piglit_init(int argc
, char **argv
)