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
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 * Chris Lord <chris@openedhand.com>
25 * Eric Anholt <eric@anholt.net>
29 /** @file s3tc-teximage.c
31 * Tests that a full S3TC-compressed mipmap tree can be created and
35 #include "piglit-util.h"
37 int piglit_width
= 500, piglit_height
= 700;
38 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
42 const float red
[4] = {1.0, 0.0, 0.0, 1.0};
43 const float green
[4] = {0.0, 1.0, 0.0, 1.0};
44 const float blue
[4] = {0.0, 0.0, 1.0, 1.0};
45 const float white
[4] = {1.0, 1.0, 1.0, 1.0};
48 display_mipmaps(int start_x
, int start_y
)
52 glEnable(GL_TEXTURE_2D
);
54 /* Disply all the mipmap levels */
55 for (i
= SIZE
; i
> 0; i
/= 2) {
57 glTexCoord2f(0.0, 0.0); glVertex2f(start_x
+ 0, start_y
+ 0);
58 glTexCoord2f(1.0, 0.0); glVertex2f(start_x
+ i
, start_y
+ 0);
59 glTexCoord2f(1.0, 1.0); glVertex2f(start_x
+ i
, start_y
+ i
);
60 glTexCoord2f(0.0, 1.0); glVertex2f(start_x
+ 0, start_y
+ i
);
68 create_texture(GLenum format
)
71 int size
, x
, y
, level
;
74 glGenTextures(1, &tex
);
75 glBindTexture(GL_TEXTURE_2D
, tex
);
76 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
77 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
78 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
79 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
80 GL_LINEAR_MIPMAP_NEAREST
);
81 data
= malloc(SIZE
* SIZE
* 4 * sizeof(GLfloat
));
83 for (level
= 0, size
= SIZE
; size
> 0; level
++, size
>>= 1) {
84 for (y
= 0; y
< size
; y
++) {
85 for (x
= 0; x
< size
; x
++) {
94 else if (x
< size
/ 2 && y
< size
/ 2)
96 else if (y
< size
/ 2)
98 else if (x
< size
/ 2)
103 memcpy(data
+ (y
* size
+ x
) * 4, color
,
108 /* Create empty texture */
109 glTexImage2D(GL_TEXTURE_2D
, level
, format
,
111 GL_RGBA
, GL_FLOAT
, NULL
);
113 glPixelStorei(GL_UNPACK_ROW_LENGTH
, size
);
115 /* Fill in sub regions of texture */
117 glTexSubImage2D(GL_TEXTURE_2D
, level
,
119 GL_RGBA
, GL_FLOAT
, data
);
122 float *greens
= data
+ size
/ 2 * 4;
123 float *blues
= reds
+ (size
/ 2) * size
* 4;
124 float *whites
= blues
+ size
/ 2 * 4;
126 glTexSubImage2D(GL_TEXTURE_2D
, level
,
129 GL_RGBA
, GL_FLOAT
, reds
);
130 glTexSubImage2D(GL_TEXTURE_2D
, level
,
133 GL_RGBA
, GL_FLOAT
, greens
);
134 glTexSubImage2D(GL_TEXTURE_2D
, level
,
137 GL_RGBA
, GL_FLOAT
, blues
);
138 glTexSubImage2D(GL_TEXTURE_2D
, level
,
141 GL_RGBA
, GL_FLOAT
, whites
);
149 check_resulting_mipmaps(int x
, int y
)
151 GLboolean pass
= GL_TRUE
;
154 for (size
= SIZE
; size
> 0; size
/= 2) {
156 pass
= pass
&& piglit_probe_pixel_rgb(x
+ 2, y
+ 2,
159 pass
= pass
&& piglit_probe_pixel_rgb(x
+ 1, y
+ 1,
162 pass
= pass
&& piglit_probe_pixel_rgb(x
, y
,
165 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
/ 4,
168 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
* 3 / 4,
171 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
/ 4,
174 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
* 3 / 4,
188 GLboolean pass
= GL_TRUE
;
190 glClearColor(0, 0, 0, 0);
191 glClear(GL_COLOR_BUFFER_BIT
);
193 tex
= create_texture(GL_COMPRESSED_RGB_S3TC_DXT1_EXT
);
194 display_mipmaps(10, 10 + (10 + SIZE
) * 0);
195 glDeleteTextures(1, &tex
);
196 tex
= create_texture(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
);
197 display_mipmaps(10, 10 + (10 + SIZE
) * 1);
198 glDeleteTextures(1, &tex
);
199 tex
= create_texture(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
);
200 display_mipmaps(10, 10 + (10 + SIZE
) * 2);
201 glDeleteTextures(1, &tex
);
202 tex
= create_texture(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
);
203 display_mipmaps(10, 10 + (10 + SIZE
) * 3);
204 glDeleteTextures(1, &tex
);
206 pass
= pass
&& check_resulting_mipmaps(10, 10 + (10 + SIZE
) * 0);
207 pass
= pass
&& check_resulting_mipmaps(10, 10 + (10 + SIZE
) * 1);
208 pass
= pass
&& check_resulting_mipmaps(10, 10 + (10 + SIZE
) * 2);
209 pass
= pass
&& check_resulting_mipmaps(10, 10 + (10 + SIZE
) * 3);
213 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
217 piglit_init(int argc
, char **argv
)
219 piglit_require_extension("GL_EXT_texture_compression_s3tc");
221 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);