2 * Copyright © 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 compressedteximage.c
26 * Tests that fetching and uploading compressed texture data works
29 * The other compressed texture tests are about decoding of data that
30 * was uploaded from uncompressed, while this tries a round-trip after
31 * the initial upload, testing glGetCompressedTexImage() and
32 * glCompressedTexImage2D().
35 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 10;
43 config
.window_width
= (SIZE
*2)+60;
44 config
.window_height
= SIZE
+20;
45 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
46 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
48 PIGLIT_GL_TEST_CONFIG_END
52 const char **extension
;
55 static struct format
*format
;
57 const char *FXT1
[] = {
58 "GL_3DFX_texture_compression_FXT1",
62 const char *S3TC
[] = {
63 "GL_EXT_texture_compression_s3tc",
67 const char *S3TC_srgb
[] = {
68 "GL_EXT_texture_compression_s3tc",
69 "GL_EXT_texture_sRGB",
73 const char *RGTC
[] = {
74 "GL_ARB_texture_compression_rgtc",
78 const char *RGTC_signed
[] = {
79 "GL_ARB_texture_compression_rgtc",
80 "GL_EXT_texture_snorm",
84 const char *BPTC
[] = {
85 "GL_ARB_texture_compression_bptc",
89 static struct format formats
[] = {
90 { GL_COMPRESSED_RGB_FXT1_3DFX
, FXT1
},
91 { GL_COMPRESSED_RGBA_FXT1_3DFX
, FXT1
},
93 { GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, S3TC
},
94 { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, S3TC
},
95 { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, S3TC
},
96 { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, S3TC
},
98 { GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, S3TC_srgb
},
99 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, S3TC_srgb
},
100 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, S3TC_srgb
},
101 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, S3TC_srgb
},
103 { GL_COMPRESSED_RGBA_BPTC_UNORM
, BPTC
},
104 { GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, BPTC
},
105 { GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, BPTC
},
106 { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, BPTC
},
108 { GL_COMPRESSED_RED_RGTC1_EXT
, RGTC
},
109 { GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
, RGTC_signed
},
110 { GL_COMPRESSED_RED_GREEN_RGTC2_EXT
, RGTC
},
111 { GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
, RGTC_signed
},
115 display_mipmaps(int x
, int y
)
119 glEnable(GL_TEXTURE_2D
);
121 /* Disply all the mipmap levels */
122 for (i
= SIZE
; i
> 0; i
/= 2) {
123 piglit_draw_rect_tex(x
, y
, i
, i
,
131 check_resulting_mipmaps(int x
, int y
)
133 GLboolean pass
= GL_TRUE
;
135 float red
[4] = {1.0, 0.0, 0.0, 1.0};
136 float green
[4] = {0.0, 1.0, 0.0, 1.0};
137 float blue
[4] = {0.0, 0.0, 1.0, 1.0};
138 float white
[4] = {1.0, 1.0, 1.0, 1.0};
140 /* for r, rg textures, overwrite what the expected colors are. */
141 if (format
->token
== GL_COMPRESSED_RED_RGTC1_EXT
||
142 format
->token
== GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
) {
148 if (format
->token
== GL_COMPRESSED_RED_GREEN_RGTC2_EXT
||
149 format
->token
== GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
) {
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,
192 piglit_get_compressed_block_size(format
->token
, &bw
, &bh
, &bs
);
193 glClearColor(0.5, 0.5, 0.5, 0.5);
194 glClear(GL_COLOR_BUFFER_BIT
);
196 tex_src
= piglit_rgbw_texture(format
->token
, SIZE
, SIZE
,
198 GL_UNSIGNED_NORMALIZED
);
199 glGenTextures(1, &tex
);
201 for (level
= 0; (SIZE
>> level
) > 0; level
++) {
203 int expected_size
, size
;
208 expected_size
= piglit_compressed_image_size(format
->token
, w
, h
);
210 glBindTexture(GL_TEXTURE_2D
, tex_src
);
211 glGetTexLevelParameteriv(GL_TEXTURE_2D
, level
,
212 GL_TEXTURE_COMPRESSED_IMAGE_SIZE
,
215 if (size
!= expected_size
) {
216 fprintf(stderr
, "Format %s level %d (%dx%d) size %d "
217 "doesn't match expected size %d\n",
218 piglit_get_gl_enum_name(format
->token
),
219 level
, w
, h
, size
, expected_size
);
220 piglit_report_result(PIGLIT_FAIL
);
223 compressed
= malloc(size
);
225 glGetCompressedTexImage(GL_TEXTURE_2D
, level
, compressed
);
227 glBindTexture(GL_TEXTURE_2D
, tex
);
228 glCompressedTexImage2D(GL_TEXTURE_2D
, level
, format
->token
,
229 w
, h
, 0, size
, compressed
);
230 if (!piglit_check_gl_error(GL_NO_ERROR
))
231 piglit_report_result(PIGLIT_FAIL
);
236 glDeleteTextures(1, &tex_src
);
237 glBindTexture(GL_TEXTURE_2D
, tex
);
239 display_mipmaps(10, 10);
240 pass
= check_resulting_mipmaps(10, 10);
242 piglit_present_results();
244 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
248 usage(int argc
, char **argv
)
252 fprintf(stderr
, "Usage: %s <format>\n", argv
[0]);
253 fprintf(stderr
, "format is one of:\n");
254 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
255 fprintf(stderr
, " %s\n",
256 piglit_get_gl_enum_name(formats
[i
].token
));
262 piglit_init(int argc
, char **argv
)
267 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
274 const GLenum arg
= piglit_get_gl_enum_from_name(argv
[1]);
275 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
276 if (formats
[i
].token
== arg
) {
277 format
= &formats
[i
];
285 for (i
= 0; format
->extension
[i
]; i
++)
286 piglit_require_extension(format
->extension
[i
]);
288 if (format
->token
== GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
)
289 piglit_set_tolerance_for_bits(7, 7, 7, 7);