2 * Copyright © 2013 LunarG, 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 DEALINGS
23 * Author: Jon Ashburn <jon@lunarg.com>
28 * This (arb_texture_view-formats) tests valid and invalid new TextureView
29 * formats based on the original textures format.
31 * Section 8.18 (Texture Views) of OpenGL 4.3 Core says:
32 * "The two textures’ internal formats must be compatible according to
33 * table 8.21 if the internal format exists in that table. The internal
34 * formats must be identical if not in that table."
38 #include "piglit-util-gl.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_compat_version
= 15;
44 config
.supports_gl_core_version
= 31;
45 config
.supports_gl_es_version
= 31;
47 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
48 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
50 PIGLIT_GL_TEST_CONFIG_END
52 static const char *TestName
= "arb_texture_view-formats";
54 #define MAX_ILLEGAL_FORMATS 17
55 #define VIEW_CLASS_NOT_IN_TABLE 0xfffffff
58 * Iterate through array of texture formats and check if call to TextureView
59 * causes the gl error "err"
62 check_format_array(const GLenum err
, const unsigned int numFormats
,
63 const GLenum
*formatArray
, const GLenum target
,
64 const GLuint tex
, const GLuint levels
, const
70 for (i
= 0; i
< numFormats
; i
++) {
73 format
= formatArray
[i
];
76 glGenTextures(1, &newTex
);
77 glTextureView(newTex
, target
, tex
, format
, 0, levels
, 0,
79 glDeleteTextures(1, &newTex
);
80 if (!piglit_check_gl_error(err
)) {
81 printf("failing texView format=%s\n",
82 piglit_get_gl_enum_name(format
));
91 * Do error-check tests for texture formats
94 test_format_errors(GLenum format_class
)
96 const GLint width
= 16, height
= 16;
97 const GLsizei levels
= 5, layers
= 6;
98 GLenum target
= GL_TEXTURE_CUBE_MAP
;
101 GLenum legalFormats
[MAX_ILLEGAL_FORMATS
];
102 unsigned int numFormats
;
103 GLenum illegalFormats
[] = {
104 /* skip compressed sized formats */
159 /* a sampling of unsized formats */
168 GL_COMPRESSED_LUMINANCE_ALPHA
,
169 GL_COMPRESSED_LUMINANCE
,
170 GL_COMPRESSED_INTENSITY
,
175 GL_COMPRESSED_SRGB_ALPHA
,
176 GL_COMPRESSED_SLUMINANCE
,
177 GL_COMPRESSED_SLUMINANCE_ALPHA
,
178 /* format that is legal for TexStorage but not in table */
180 /* 16-bit norm formats */
190 int totalFormats
= ARRAY_SIZE(illegalFormats
);
192 if (piglit_is_gles() &&
193 !piglit_is_extension_supported("GL_EXT_texture_norm16"))
196 glGenTextures(1, &tex
); /* orig tex */
197 glBindTexture(target
, tex
);
199 switch (format_class
) {
200 case GL_VIEW_CLASS_128_BITS
:
201 glTexStorage2D(target
, levels
, GL_RGBA32F
, width
, height
);
202 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
204 GL_RGBA32F
, GL_RGBA32UI
, GL_RGBA32I
, 0);
206 case GL_VIEW_CLASS_96_BITS
:
207 glTexStorage2D(target
, levels
, GL_RGB32F
, width
, height
);
208 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
210 GL_RGB32F
, GL_RGB32UI
, GL_RGB32I
, 0);
212 case GL_VIEW_CLASS_64_BITS
:
213 glTexStorage2D(target
, levels
, GL_RGBA16F
, width
, height
);
214 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
216 GL_RGBA16F
, GL_RG32F
, GL_RGBA16UI
,
217 GL_RG32UI
, GL_RGBA16I
, GL_RG32I
, 0);
218 if (!piglit_is_gles() ||
219 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
221 update_valid_arrays(&legalFormats
[numFormats
],
224 GL_RGBA16
, GL_RGBA16_SNORM
, 0);
227 case GL_VIEW_CLASS_48_BITS
:
228 glTexStorage2D(target
, levels
, GL_RGB16F
, width
, height
);
229 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
231 GL_RGB16F
, GL_RGB16UI
, GL_RGB16I
, 0);
232 if (!piglit_is_gles() ||
233 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
235 update_valid_arrays(&legalFormats
[numFormats
],
238 GL_RGB16
, GL_RGB16_SNORM
, 0);
241 case GL_VIEW_CLASS_32_BITS
:
242 glTexStorage2D(target
, levels
, GL_RG16F
, width
, height
);
243 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
245 GL_RG16F
, GL_R11F_G11F_B10F
, GL_R32F
,
246 GL_RGB10_A2UI
, GL_RGBA8UI
, GL_RG16UI
,
247 GL_R32UI
, GL_RGBA8I
, GL_RG16I
,
248 GL_R32I
, GL_RGB10_A2
, GL_RGBA8
,
250 GL_SRGB8_ALPHA8
, GL_RGB9_E5
, 0);
251 if (!piglit_is_gles() ||
252 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
254 update_valid_arrays(&legalFormats
[numFormats
],
257 GL_RG16
, GL_RG16_SNORM
, 0);
260 case GL_VIEW_CLASS_24_BITS
:
261 glTexStorage2D(target
, levels
, GL_RGB8
, width
, height
);
262 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
264 GL_RGB8
, GL_RGB8_SNORM
, GL_SRGB8
,
265 GL_RGB8UI
, GL_RGB8I
, 0);
267 case GL_VIEW_CLASS_16_BITS
:
268 glTexStorage2D(target
, levels
, GL_R16F
, width
, height
);
269 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
271 GL_R16F
, GL_RG8UI
, GL_R16UI
, GL_RG8I
,
272 GL_R16I
, GL_RG8
, GL_RG8_SNORM
, 0);
273 if (!piglit_is_gles() ||
274 piglit_is_extension_supported("GL_EXT_texture_norm16")) {
276 update_valid_arrays(&legalFormats
[numFormats
],
279 GL_R16
, GL_R16_SNORM
, 0);
282 case GL_VIEW_CLASS_8_BITS
:
283 glTexStorage2D(target
, levels
, GL_R8I
, width
, height
);
284 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
286 GL_R8UI
, GL_R8I
, GL_R8
, GL_R8_SNORM
, 0);
288 case VIEW_CLASS_NOT_IN_TABLE
:
289 glTexStorage2D(target
, levels
, GL_RGBA4
, width
, height
);
290 numFormats
= update_valid_arrays(legalFormats
, illegalFormats
,
295 assert(!"Invalid format_class\n");
299 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
300 printf("%s Found gl errors prior to testing glTextureView\n",
306 /* ensure TextureView of legal formats gives no gl error */
307 pass
= check_format_array(GL_NO_ERROR
, numFormats
, legalFormats
,
308 target
, tex
, levels
, layers
) && pass
;
310 if (!piglit_khr_no_error
) {
311 /* ensure TextureView of illegal formats returns an error */
312 pass
= check_format_array(GL_INVALID_OPERATION
,
313 totalFormats
, illegalFormats
,
314 target
, tex
, levels
, layers
) && pass
;
318 glDeleteTextures(1, &tex
);
332 const bool subtest_pass = (f); \
333 piglit_report_subtest_result(subtest_pass \
334 ? PIGLIT_PASS : PIGLIT_FAIL, \
336 pass = pass && subtest_pass; \
340 piglit_init(int argc
, char **argv
)
344 #ifdef PIGLIT_USE_OPENGL
345 piglit_require_extension("GL_ARB_texture_storage");
346 piglit_require_extension("GL_ARB_texture_view");
347 piglit_require_extension("GL_EXT_texture_integer");
348 piglit_require_extension("GL_ARB_texture_float");
349 if (piglit_get_gl_version() < 31)
350 piglit_require_extension("GL_ARB_texture_cube_map");
352 piglit_require_extension("GL_OES_texture_view");
355 X(test_format_errors(GL_VIEW_CLASS_128_BITS
), "Format 128 bits validity");
356 X(test_format_errors(GL_VIEW_CLASS_96_BITS
), "Format 96 bits validity");
357 X(test_format_errors(GL_VIEW_CLASS_64_BITS
), "Format 64 bits validity");
358 X(test_format_errors(GL_VIEW_CLASS_48_BITS
), "Format 48 bits validity");
359 X(test_format_errors(GL_VIEW_CLASS_32_BITS
), "Format 32 bits validity");
360 X(test_format_errors(GL_VIEW_CLASS_24_BITS
), "Format 24 bits validity");
361 X(test_format_errors(GL_VIEW_CLASS_16_BITS
), "Format 16 bits validity");
362 X(test_format_errors(GL_VIEW_CLASS_8_BITS
), "Format 8 bits validity");
363 X(test_format_errors(VIEW_CLASS_NOT_IN_TABLE
), "Format misc validity");
365 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
366 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);