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 compressedtextureimage.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().
34 * Adapted for testing glGetCompressedTextureImage in ARB_direct_state_access
35 * by Laura Ekstrand <laura@jlekstrand.net>, November 2014.
38 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_compat_version
= 10;
46 config
.window_width
= (SIZE
*2)+60;
47 config
.window_height
= SIZE
+20;
48 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
49 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
51 PIGLIT_GL_TEST_CONFIG_END
55 const char **extension
;
58 static struct format
*format
;
60 const char *FXT1
[] = {
61 "GL_3DFX_texture_compression_FXT1",
65 const char *S3TC
[] = {
66 "GL_EXT_texture_compression_s3tc",
70 const char *S3TC_srgb
[] = {
71 "GL_EXT_texture_compression_s3tc",
72 "GL_EXT_texture_sRGB",
76 const char *RGTC
[] = {
77 "GL_ARB_texture_compression_rgtc",
81 const char *RGTC_signed
[] = {
82 "GL_ARB_texture_compression_rgtc",
83 "GL_EXT_texture_snorm",
87 const char *BPTC
[] = {
88 "GL_ARB_texture_compression_bptc",
92 static struct format formats
[] = {
93 { GL_COMPRESSED_RGB_FXT1_3DFX
, FXT1
},
94 { GL_COMPRESSED_RGBA_FXT1_3DFX
, FXT1
},
96 { GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, S3TC
},
97 { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, S3TC
},
98 { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, S3TC
},
99 { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, S3TC
},
101 { GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, S3TC_srgb
},
102 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, S3TC_srgb
},
103 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, S3TC_srgb
},
104 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, S3TC_srgb
},
106 { GL_COMPRESSED_RGBA_BPTC_UNORM
, BPTC
},
107 { GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, BPTC
},
108 { GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, BPTC
},
109 { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, BPTC
},
111 { GL_COMPRESSED_RED_RGTC1_EXT
, RGTC
},
112 { GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
, RGTC_signed
},
113 { GL_COMPRESSED_RED_GREEN_RGTC2_EXT
, RGTC
},
114 { GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
, RGTC_signed
},
118 display_mipmaps(int x
, int y
)
122 glEnable(GL_TEXTURE_2D
);
124 /* Disply all the mipmap levels */
125 for (i
= SIZE
; i
> 0; i
/= 2) {
126 piglit_draw_rect_tex(x
, y
, i
, i
,
134 check_resulting_mipmaps(int x
, int y
)
138 float red
[4] = {1.0, 0.0, 0.0, 1.0};
139 float green
[4] = {0.0, 1.0, 0.0, 1.0};
140 float blue
[4] = {0.0, 0.0, 1.0, 1.0};
141 float white
[4] = {1.0, 1.0, 1.0, 1.0};
143 /* for r, rg textures, overwrite what the expected colors are. */
144 if (format
->token
== GL_COMPRESSED_RED_RGTC1_EXT
||
145 format
->token
== GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
) {
151 if (format
->token
== GL_COMPRESSED_RED_GREEN_RGTC2_EXT
||
152 format
->token
== GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
) {
157 for (size
= SIZE
; size
> 0; size
/= 2) {
159 pass
= pass
&& piglit_probe_pixel_rgb(x
+ 2, y
+ 2,
162 pass
= pass
&& piglit_probe_pixel_rgb(x
+ 1, y
+ 1,
165 pass
= pass
&& piglit_probe_pixel_rgb(x
, y
,
168 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
/ 4,
171 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
* 3 / 4,
174 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
/ 4,
177 pass
= pass
&& piglit_probe_pixel_rgb(x
+ size
* 3 / 4,
195 piglit_get_compressed_block_size(format
->token
, &bw
, &bh
, &bs
);
196 glClearColor(0.5, 0.5, 0.5, 0.5);
197 glClear(GL_COLOR_BUFFER_BIT
);
199 tex_src
= piglit_rgbw_texture(format
->token
, SIZE
, SIZE
,
201 GL_UNSIGNED_NORMALIZED
);
202 glCreateTextures(GL_TEXTURE_2D
, 1, &tex
);
204 for (level
= 0; (SIZE
>> level
) > 0; level
++) {
206 int expected_size
, size
;
211 expected_size
= piglit_compressed_image_size(format
->token
, w
, h
);
213 glBindTexture(GL_TEXTURE_2D
, tex_src
);
214 glGetTexLevelParameteriv(GL_TEXTURE_2D
, level
,
215 GL_TEXTURE_COMPRESSED_IMAGE_SIZE
,
218 if (size
!= expected_size
) {
219 fprintf(stderr
, "Format %s level %d (%dx%d) size %d "
220 "doesn't match expected size %d\n",
221 piglit_get_gl_enum_name(format
->token
),
222 level
, w
, h
, size
, expected_size
);
223 piglit_report_result(PIGLIT_FAIL
);
226 compressed
= malloc(size
);
228 glGetCompressedTextureImage(tex_src
, level
, size
, compressed
);
230 glBindTexture(GL_TEXTURE_2D
, tex
);
231 glCompressedTexImage2D(GL_TEXTURE_2D
, level
, format
->token
,
232 w
, h
, 0, size
, compressed
);
233 if (!piglit_check_gl_error(GL_NO_ERROR
))
234 piglit_report_result(PIGLIT_FAIL
);
239 glDeleteTextures(1, &tex_src
);
240 glBindTextureUnit(tex
, 0);
242 display_mipmaps(10, 10);
243 pass
= check_resulting_mipmaps(10, 10);
245 piglit_present_results();
247 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
251 usage(int argc
, char **argv
)
255 fprintf(stderr
, "Usage: %s <format>\n", argv
[0]);
256 fprintf(stderr
, "format is one of:\n");
257 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
258 fprintf(stderr
, " %s\n",
259 piglit_get_gl_enum_name(formats
[i
].token
));
265 piglit_init(int argc
, char **argv
)
268 piglit_require_extension("GL_ARB_direct_state_access");
270 piglit_ortho_projection(piglit_width
, piglit_height
, false);
277 const GLenum arg
= piglit_get_gl_enum_from_name(argv
[1]);
278 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
279 if (formats
[i
].token
== arg
) {
280 format
= &formats
[i
];
288 for (i
= 0; format
->extension
[i
]; i
++)
289 piglit_require_extension(format
->extension
[i
]);