fix the spelling in whole piglit
[piglit.git] / tests / spec / arb_internalformat_query2 / common.c
blobba27fac485f393720b3e98454f1526493b792b09
1 /*
2 * Copyright © 2015 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
13 * Software.
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
21 * IN THE SOFTWARE.
24 #include "common.h"
25 #include <inttypes.h> /* for PRIu64 macro */
27 /* Generic callback type, doing a cast of params to void*, to avoid
28 * having two paths (32 and 64) for each check */
29 typedef void (APIENTRY *GetInternalformat)(GLenum target, GLenum internalformat,
30 GLenum pname, GLsizei bufsize,
31 void *params);
33 GLenum *valid_internalformats;
34 unsigned num_valid_internalformats;
36 /* This struct is intended to abstract the fact that there are two
37 * really similar methods, and two really similar params (just change
38 * the type). All the castings and decision about which method should
39 * be used would be done here, just to keep the code of the test
40 * cleaner.
42 struct _test_data {
43 /* int instead of a bool to make easier iterate on the
44 * possible values. */
45 int testing64;
46 int params_size;
47 void *params;
48 GetInternalformat callback;
51 /* Updates the callback and params based on current values of
52 * testing64 and params_size */
53 static void
54 sync_test_data(test_data *data)
56 if (data->params != NULL)
57 free(data->params);
59 if (data->testing64) {
60 data->callback = (GetInternalformat) glGetInternalformati64v;
61 data->params = malloc(sizeof(GLint64) * data->params_size);
62 } else {
63 data->callback = (GetInternalformat) glGetInternalformativ;
64 data->params = malloc(sizeof(GLint) * data->params_size);
68 test_data*
69 test_data_new(int testing64,
70 int params_size)
72 test_data *result;
74 result = (test_data*) malloc(sizeof(test_data));
75 result->testing64 = testing64;
76 result->params_size = params_size;
77 result->params = NULL;
79 sync_test_data(result);
81 return result;
85 * Frees @data, and sets its value to NULL.
87 void
88 test_data_clear(test_data **data)
90 test_data *_data = *data;
92 if (_data == NULL)
93 return;
95 free(_data->params);
96 _data->params = NULL;
98 free(_data);
99 *data = NULL;
102 void
103 test_data_execute(test_data *data,
104 const GLenum target,
105 const GLenum internalformat,
106 const GLenum pname)
108 data->callback(target, internalformat, pname,
109 data->params_size, data->params);
112 /* Usually we want to call GetInternalformati*v with the size of the
113 * buffer, but there are some cases where we want to specify a
114 * different size */
115 void
116 test_data_execute_with_size(test_data *data,
117 const GLenum target,
118 const GLenum internalformat,
119 const GLenum pname,
120 int size)
122 data->callback(target, internalformat, pname,
123 size, data->params);
126 void
127 test_data_set_testing64(test_data *data,
128 const int testing64)
130 if (data->testing64 == testing64)
131 return;
133 data->testing64 = testing64;
134 sync_test_data(data);
137 void
138 test_data_set_params_size(test_data *data,
139 const int params_size)
141 if (data->params_size == params_size)
142 return;
144 data->params_size = params_size;
145 sync_test_data(data);
148 GLint64
149 test_data_value_at_index(test_data *data,
150 const int index)
152 if (index > data->params_size || index < 0) {
153 fprintf(stderr, "ERROR: invalid index while retrieving"
154 " data from auxiliary test data\n");
155 return -1;
158 return data->testing64 ?
159 ((GLint64*)data->params)[index] :
160 ((GLint*)data->params)[index];
164 * Returns if @target/@internalformat is supported using
165 * INTERNALFORMAT_SUPPORTED for @target and @internalformat.
167 * @data is only used to known if we are testing the 32-bit or the
168 * 64-bit query, so the content of @data will not be modified due this
169 * call.
171 bool
172 test_data_check_supported(const test_data *data,
173 const GLenum target,
174 const GLenum internalformat)
176 bool result;
177 test_data *local_data = test_data_new(data->testing64, 1);
179 test_data_execute(local_data, target, internalformat,
180 GL_INTERNALFORMAT_SUPPORTED);
182 if (!piglit_check_gl_error(GL_NO_ERROR))
183 result = false;
184 else
185 result = test_data_value_at_index(local_data, 0) == GL_TRUE;
187 test_data_clear(&local_data);
189 return result;
194 * Spec 4.6, Table 8.14
196 static const GLenum specific_compressed_internalformats[] = {
197 GL_COMPRESSED_RED_RGTC1,
198 GL_COMPRESSED_SIGNED_RED_RGTC1,
199 GL_COMPRESSED_RG_RGTC2,
200 GL_COMPRESSED_SIGNED_RG_RGTC2,
201 GL_COMPRESSED_RGBA_BPTC_UNORM,
202 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
203 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
204 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
205 GL_COMPRESSED_RGB8_ETC2,
206 GL_COMPRESSED_SRGB8_ETC2,
207 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
208 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
209 GL_COMPRESSED_RGBA8_ETC2_EAC,
210 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
211 GL_COMPRESSED_R11_EAC,
212 GL_COMPRESSED_SIGNED_R11_EAC,
213 GL_COMPRESSED_RG11_EAC,
214 GL_COMPRESSED_SIGNED_RG11_EAC,
218 * Returns if @internalformat is a specific compressed internalformat.
220 * This is needed because specific compressed internalformats that
221 * doesn't support online compression can't be used with glTexImage*D,
222 * and glCompressedTexImage*D should be used instead. In general, for
223 * specific compressed internalformats, it is better to use
224 * glCompressedTexImage*D
226 static bool
227 internalformat_is_specific_compressed(const GLenum internalformat)
229 return value_on_set((const GLint*) specific_compressed_internalformats,
230 ARRAY_SIZE(specific_compressed_internalformats),
231 (GLint) internalformat);
234 /* Returns if @value is one of the values among @set */
235 bool
236 value_on_set(const GLint *set,
237 const unsigned set_size,
238 GLint value)
240 unsigned i;
242 for (i = 0; i < set_size; i++) {
243 if (set[i] == value)
244 return true;
247 return false;
250 bool
251 test_data_check_possible_values(test_data *data,
252 const GLint *possible_values,
253 const unsigned num_possible_values)
255 return value_on_set(possible_values, num_possible_values,
256 test_data_value_at_index(data, 0));
260 * Prints the info of a failing case for a given pname.
262 * Note that it tries to get the name of the value at @data as if it
263 * were a enum, as it is useful on that case. But there are several
264 * pnames that returns a value. A possible improvement would be that
265 * for those just printing the value.
267 void
268 print_failing_case(const GLenum target, const GLenum internalformat,
269 const GLenum pname, test_data *data)
271 print_failing_case_full(target, internalformat, pname, -1, data);
275 * Prints the info of a failing case. If expected_value is smaller
276 * that 0, it is not printed.
278 void print_failing_case_full(const GLenum target, const GLenum internalformat,
279 const GLenum pname, GLint64 expected_value,
280 test_data *data)
282 /* Knowing if it is supported is interesting in order to know
283 * if the test is being too restrictive */
284 bool supported = test_data_check_supported(data, target, internalformat);
285 GLint64 current_value = test_data_value_at_index(data, 0);
287 if (data->testing64) {
288 fprintf(stderr, " 64 bit failing case: ");
289 } else {
290 fprintf(stderr, " 32 bit failing case: ");
293 fprintf(stderr, "pname = %s, "
294 "target = %s, internalformat = %s, ",
295 piglit_get_gl_enum_name(pname),
296 piglit_get_gl_enum_name(target),
297 piglit_get_gl_enum_name(internalformat));
299 if (expected_value >= 0)
300 fprintf(stderr, "expected value = (%" PRIi64 "), ",
301 expected_value);
303 fprintf(stderr, "params[0] = (%" PRIi64 ",%s), "
304 "supported=%i\n",
305 current_value,
306 piglit_get_gl_enum_name(current_value),
307 supported);
311 * The most basic condition. From spec, a lot of pnames has a
312 * condition like this:
314 * "Possible values returned are <set>. If the resource is not
315 * supported, or if the operation is not supported, NONE is
316 * returned."
318 * So this method, calls the callback defined at @data (that should be
319 * GetInternalformativ or GetInternalformati64v) using @pname, for all
320 * @num_targets at @targets, and all @num_internalformats at
321 * @internalformats, and checks the following conditions:
323 * * If @pname is not supported (calling INTERNALFORMAT_SUPPORTED),
324 * checks that the value returned is always the same.
325 * * If @pname is supported, checks that the returned value is among
326 * one of the values defined at @possible_values
328 * @possible_values,@num_possible_values is allowed to be NULL,0, for
329 * the cases where the set of returned values is not specified in
330 * detail by the spec (like INTERNALFORMAT_PREFERRED). On that case,
331 * it is not tested the returned value, and just tested that if not
332 * supported, the returned value is the unsupported value defined by
333 * the spec.
336 bool
337 try_basic(const GLenum *targets, unsigned num_targets,
338 const GLenum *internalformats, unsigned num_internalformats,
339 const GLenum pname,
340 const GLint *possible_values, unsigned num_possible_values,
341 test_data *data)
343 bool pass = true;
344 unsigned i;
345 unsigned j;
347 for (i = 0; i < num_targets; i++) {
348 for (j = 0; j < num_internalformats; j++) {
349 bool error_test;
350 bool value_test;
351 bool supported;
353 supported = check_query2_dependencies(pname, targets[i])
354 && test_data_check_supported(data, targets[i],
355 internalformats[j]);
357 test_data_execute(data, targets[i], internalformats[j], pname);
359 if (supported && num_possible_values == 0)
360 continue;
362 error_test =
363 piglit_check_gl_error(GL_NO_ERROR);
365 value_test = supported ?
366 test_data_check_possible_values(data, possible_values,
367 num_possible_values) :
368 test_data_is_unsupported_response(data, pname);
370 if (error_test && value_test)
371 continue;
373 print_failing_case(targets[i], internalformats[j],
374 pname, data);
376 pass = false;
380 return pass;
383 /* Returns a valid format for @internalformat, so it would be possible
384 * to create a texture using glTexImageXD/glCompressedTexImageXD with
385 * that format/internalformat combination */
386 static GLenum
387 format_for_internalformat(const GLenum internalformat)
389 switch(internalformat) {
390 case GL_DEPTH_COMPONENT:
391 case GL_DEPTH_COMPONENT16:
392 case GL_DEPTH_COMPONENT24:
393 case GL_DEPTH_COMPONENT32:
394 case GL_DEPTH_COMPONENT32F:
395 return GL_DEPTH_COMPONENT;
396 case GL_DEPTH_STENCIL:
397 case GL_DEPTH24_STENCIL8:
398 case GL_DEPTH32F_STENCIL8:
399 return GL_DEPTH_STENCIL;
400 case GL_RGB10_A2UI:
401 case GL_R8I:
402 case GL_R8UI:
403 case GL_R16I:
404 case GL_R16UI:
405 case GL_R32I:
406 case GL_R32UI:
407 case GL_RG8I:
408 case GL_RG16I:
409 case GL_RG16UI:
410 case GL_RG32I:
411 case GL_RG32UI:
412 case GL_RGB8I:
413 case GL_RGB8UI:
414 case GL_RGB16I:
415 case GL_RGB16UI:
416 case GL_RGB32I:
417 case GL_RGB32UI:
418 case GL_RGBA8I:
419 case GL_RGBA8UI:
420 case GL_RGBA16I:
421 case GL_RGBA16UI:
422 case GL_RGBA32I:
423 case GL_RGBA32UI:
424 return GL_RGBA_INTEGER;
425 default:
426 return GL_RGBA;
430 static GLenum
431 type_for_internalformat(const GLenum internalformat)
433 switch(internalformat) {
434 case GL_DEPTH_STENCIL:
435 case GL_DEPTH24_STENCIL8:
436 case GL_DEPTH32F_STENCIL8:
437 return GL_UNSIGNED_INT_24_8;
438 default:
439 return GL_UNSIGNED_BYTE;
444 * Some GetInternalformati*v pnames returns the same that
445 * GetTexParameter and GetTexLevelParameter. In order to use those, a
446 * texture is needed to be bound. This method creates and bind one
447 * texture based on @target and @internalformat. It returns the
448 * texture name on @tex_out. If target is GL_TEXTURE_BUFFER, a buffer
449 * is also needed, and returned on @buffer_out. Caller is responsible
450 * to free both if the call is successful.
452 * The type and format to be used to create the texture is any one
453 * valid for the given @internalformat.
455 * For texture targets, we also use this function to check if the /resource/
456 * (defined in the ARB_internalformat_query2 spec as an object of the
457 * appropriate type that has been created with <internalformat> and <target>)
458 * is supported by the implementation. If the texture creation fails, then the
459 * resource is unsupported.
461 * Returns true if it was possible to create the texture. False
462 * otherwise (unsupported /resource/).
465 bool
466 create_texture(const GLenum target,
467 const GLenum internalformat,
468 GLuint *tex_out,
469 GLuint *buffer_out)
471 GLuint tex = 0;
472 GLuint buffer = 0;
473 GLenum type = type_for_internalformat(internalformat);
474 GLenum format = format_for_internalformat(internalformat);
475 bool result = true;
476 int height = 16;
477 int width = 16;
478 int depth = 16;
479 unsigned i;
480 bool is_specific_compressed = internalformat_is_specific_compressed(internalformat);
481 int image_size = 0;
484 * From OpenGL 4.6 spec, Section 8.5, Texture Image
485 * Specification:
487 * "An INVALID_ENUM error is generated by
488 * CompressedTexImage1D if internalformat is one of the
489 * specific compressed formats. OpenGL defines no specific
490 * one-dimensional compressed formats, but such formats
491 * may be provided by extensions."
493 * From OpenGL 4.6 spec, Section 8.7, Compressed Texture
494 * Images:
496 * "An INVALID_ENUM error is generated if the target
497 * parameter to any of the CompressedTexImagenD commands
498 * is TEXTURE_RECTANGLE or PROXY_TEXTURE_RECTANGLE ."
500 if (is_specific_compressed &&
501 (target == GL_TEXTURE_1D || target == GL_TEXTURE_RECTANGLE))
502 return false;
505 * From ARB_texture_multisample:
507 * "(2) What commands may be used on multisample textures?
509 * RESOLVED: Multisample textures can be bound for
510 * rendering and texturing, but they cannot be loaded/read
511 * with SubImage commands (TexSubImage, CopyTexSubImage,
512 * GetTexImage), they don't support compressed formats, and
513 * they don't need TexParameters since they can only be
514 * fetched with texelFetchMultisample."
516 if (is_specific_compressed &&
517 (target == GL_TEXTURE_2D_MULTISAMPLE ||
518 target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) {
519 return false;
522 if (is_specific_compressed) {
523 image_size = piglit_compressed_image_size(internalformat, width, height);
526 glGenTextures(1, &tex);
527 glBindTexture(target, tex);
529 switch(target) {
530 case GL_TEXTURE_1D:
531 glTexImage1D(target, 0, internalformat, width, 0,
532 format, type, NULL);
533 break;
534 case GL_TEXTURE_1D_ARRAY:
535 case GL_TEXTURE_2D:
536 case GL_TEXTURE_RECTANGLE:
537 if (is_specific_compressed) {
538 glCompressedTexImage2D(target, 0, internalformat,
539 width, height, 0,
540 image_size, NULL);
541 } else {
542 glTexImage2D(target, 0, internalformat,
543 width, height, 0,
544 format, type, NULL);
546 break;
547 case GL_TEXTURE_CUBE_MAP:
548 for (i = 0; i < 6; i++) {
549 if (is_specific_compressed) {
550 glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
551 internalformat,
552 width, height, 0,
553 image_size, NULL);
554 } else {
555 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
556 internalformat,
557 width, height, 0,
558 format, type, NULL);
561 break;
563 case GL_TEXTURE_CUBE_MAP_ARRAY:
564 /* cube map arrays also use TexImage3D buth depth
565 * needs to be a multiple of six */
566 depth = 6;
567 /* fall through */
568 case GL_TEXTURE_2D_ARRAY:
569 case GL_TEXTURE_3D:
570 image_size = image_size * depth;
571 if (is_specific_compressed) {
572 glCompressedTexImage3D(target, 0, internalformat,
573 width, height, depth, 0,
574 image_size, NULL);
575 } else {
576 glTexImage3D(target, 0, internalformat, width, height, depth, 0,
577 format, type, NULL);
579 break;
580 case GL_TEXTURE_2D_MULTISAMPLE:
581 glTexImage2DMultisample(target, 1, internalformat, width, height,
582 GL_FALSE);
583 break;
584 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
585 glTexImage3DMultisample(target, 1, internalformat, width, height,
586 depth, GL_FALSE);
587 break;
588 case GL_TEXTURE_BUFFER:
589 glGenBuffers(1, &buffer);
590 glBindBuffer(GL_TEXTURE_BUFFER, buffer);
591 glTexBuffer(GL_TEXTURE_BUFFER, internalformat, buffer);
592 break;
593 default:
594 result = false;
595 fprintf(stderr, "\tError: %s is not a texture target\n",
596 piglit_get_gl_enum_name(target));
599 if (!piglit_check_gl_error(GL_NO_ERROR))
600 result = false;
602 if (!result) {
603 glDeleteTextures(1, &tex);
604 glDeleteBuffers(1, &buffer);
605 } else {
606 *tex_out = tex;
607 *buffer_out = buffer;
609 return result;
613 static GLenum
614 translate_pname(const GLenum pname)
616 switch (pname) {
617 case GL_INTERNALFORMAT_RED_TYPE:
618 case GL_INTERNALFORMAT_GREEN_TYPE:
619 case GL_INTERNALFORMAT_BLUE_TYPE:
620 case GL_INTERNALFORMAT_ALPHA_TYPE:
621 return pname - GL_INTERNALFORMAT_RED_TYPE + GL_TEXTURE_RED_TYPE;
622 case GL_INTERNALFORMAT_DEPTH_TYPE:
623 /* case GL_INTERNALFORMAT_STENCIL_TYPE, */
624 return GL_TEXTURE_DEPTH_TYPE;
625 case GL_INTERNALFORMAT_RED_SIZE:
626 case GL_INTERNALFORMAT_GREEN_SIZE:
627 case GL_INTERNALFORMAT_BLUE_SIZE:
628 case GL_INTERNALFORMAT_ALPHA_SIZE:
629 return pname - GL_INTERNALFORMAT_RED_SIZE + GL_TEXTURE_RED_SIZE;
630 case GL_INTERNALFORMAT_DEPTH_SIZE:
631 return GL_TEXTURE_DEPTH_SIZE;
632 case GL_INTERNALFORMAT_STENCIL_SIZE:
633 return GL_TEXTURE_STENCIL_SIZE;
634 case GL_INTERNALFORMAT_SHARED_SIZE:
635 return GL_TEXTURE_SHARED_SIZE;
636 default:
637 assert(!"incorrect pname");
638 return 0;
643 * Builds a a texture using @target and @internalformat, and compares
644 * the result of calling GetTexLevelParameter using @pname with the
645 * result included at @data.params.
647 * At this point it is assumed that @target/@internalformat is a valid
648 * combination to create a texture unless it is not supported by the
649 * implementation. If the call to create_texture with those parameters
650 * fails, it is assumed that the resource is unsupported, so the check
651 * only compares against zero (the unsupported value).
653 * Returns true if the value is the same, false otherwise
655 bool
656 test_data_check_against_get_tex_level_parameter(test_data *data,
657 const GLenum target,
658 const GLenum pname,
659 const GLenum internalformat)
661 GLint param;
662 bool result = true;
663 GLuint tex;
664 GLuint buffer;
665 GLenum real_target = target;
666 GLenum pname_equiv = translate_pname(pname);
669 * Special case for texture buffer - this is not valid as
670 * glGetTexLevelParameteriv target with just ARB_tbo, only with gl 3.1.
671 * However, I believe the query2 should still return the correct
672 * values, despite the spec saying
673 * "For textures this query will return the same information as
674 * querying GetTexLevelParameter{if}v for TEXTURE_*_SIZE would return."
676 if (target == GL_TEXTURE_BUFFER && piglit_get_gl_version() < 31) {
677 return GL_TRUE;
680 result = create_texture(target, internalformat, &tex, &buffer);
681 if (!result)
682 return test_data_is_unsupported_response(data, pname);
684 /* For cube maps GetTexLevelParameter receives one of the face
685 * targets, or proxy */
686 if (target == GL_TEXTURE_CUBE_MAP) {
687 real_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
689 glGetTexLevelParameteriv(real_target, 0, pname_equiv, &param);
690 if (!piglit_check_gl_error(GL_NO_ERROR)) {
691 result = false;
692 fprintf(stderr, "\tError calling glGetTexLevelParameter\n");
693 goto cleanup;
696 result = test_data_value_at_index(data, 0) == param;
698 if (!result) {
699 fprintf(stderr, "\tError comparing glGetInternalformat "
700 "and glGetTexLevelParameter, params value=%" PRIi64 ", "
701 "expected value=%i\n",
702 test_data_value_at_index(data, 0), param);
705 cleanup:
706 glDeleteTextures(1, &tex);
707 glDeleteBuffers(1, &buffer);
709 return result;
713 * Returns if @pname query2 dependencies are fulfilled. So for
714 * example, FRAMEBUFFER_RENDERABLE needs
715 * ARB/EXT_framebuffer_object. With that pname, if
716 * ARB/EXT_framebuffer_object is not present, it returns false.
718 * It is assumed that @pname is a valid query2 pname, as would
719 * simplify the implementation of this method.
721 static bool
722 check_query2_pname_dependencies(const GLenum pname)
724 switch(pname) {
725 case GL_FRAMEBUFFER_RENDERABLE:
726 case GL_FRAMEBUFFER_BLEND:
727 if (!piglit_is_extension_supported("GL_ARB_framebuffer_object") &&
728 !piglit_is_extension_supported("GL_EXT_framebuffer_object"))
729 return false;
730 break;
732 case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
733 if (!piglit_is_extension_supported("GL_ARB_framebuffer_object") &&
734 !piglit_is_extension_supported("GL_EXT_framebuffer_object"))
735 return false;
736 if (!piglit_is_extension_supported("GL_EXT_texture_array"))
737 return false;
738 break;
740 case GL_MANUAL_GENERATE_MIPMAP:
741 if (!piglit_is_extension_supported("GL_ARB_framebuffer_object") &&
742 !piglit_is_extension_supported("GL_EXT_framebuffer_object"))
743 return false;
744 break;
746 case GL_MAX_LAYERS:
747 if (!piglit_is_extension_supported("GL_EXT_texture_array"))
748 return false;
749 break;
751 case GL_SRGB_READ:
752 if (!piglit_is_extension_supported("GL_EXT_texture_sRGB"))
753 return false;
754 break;
756 case GL_SRGB_WRITE:
757 if (!piglit_is_extension_supported("GL_ARB_framebuffer_sRGB"))
758 return false;
759 break;
761 case GL_SRGB_DECODE_ARB:
762 /* Note that if the extension is not supported, it
763 * should return INVALID_ENUM, not unsupported */
764 if (!piglit_is_extension_supported("GL_ARB_texture_sRGB_decode") &&
765 !piglit_is_extension_supported("GL_EXT_texture_sRGB_decode"))
766 return false;
767 break;
769 case GL_TESS_CONTROL_TEXTURE:
770 case GL_TESS_EVALUATION_TEXTURE:
771 if (!piglit_is_extension_supported("GL_ARB_tessellation_shader"))
772 return false;
773 break;
775 case GL_GEOMETRY_TEXTURE:
776 if (!piglit_is_extension_supported("GL_ARB_geometry_shader4") &&
777 !(piglit_get_gl_version() >= 32))
778 return false;
779 break;
781 case GL_COMPUTE_TEXTURE:
782 if (!piglit_is_extension_supported("GL_ARB_compute_shader"))
783 return false;
784 break;
786 case GL_TEXTURE_GATHER:
787 if (!piglit_is_extension_supported("GL_ARB_texture_gather"))
788 return false;
789 break;
791 case GL_SHADER_IMAGE_LOAD:
792 case GL_SHADER_IMAGE_STORE:
793 case GL_SHADER_IMAGE_ATOMIC:
794 case GL_IMAGE_TEXEL_SIZE:
795 case GL_IMAGE_COMPATIBILITY_CLASS:
796 case GL_IMAGE_PIXEL_FORMAT:
797 case GL_IMAGE_PIXEL_TYPE:
798 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
799 if (!piglit_is_extension_supported("GL_ARB_shader_image_load_store"))
800 return false;
801 break;
803 case GL_CLEAR_BUFFER:
804 if (!piglit_is_extension_supported("GL_ARB_clear_buffer_object"))
805 return false;
806 break;
808 case GL_TEXTURE_VIEW:
809 case GL_VIEW_COMPATIBILITY_CLASS:
810 if (!piglit_is_extension_supported("GL_ARB_texture_view"))
811 return false;
812 break;
814 case GL_SAMPLES:
815 break;
817 default:
818 return true;
821 return true;
825 * Returns if @target query2 dependencies are fulfilled. So for
826 * example, TEXTURE_1D_ARRAY needs
827 * EXT_texture_array. With that pname, if
828 * ARB/EXT_framebuffer_object is not present, it returns false.
830 * It is assumed that @target is a valid query2 target, as would
831 * simplify the implementation of this method.
833 static bool
834 check_query2_target_dependencies(const GLenum target)
836 switch(target) {
837 case GL_TEXTURE_1D_ARRAY:
838 case GL_TEXTURE_2D_ARRAY:
839 if (!piglit_is_extension_supported("GL_EXT_texture_array"))
840 return false;
841 break;
843 case GL_TEXTURE_CUBE_MAP_ARRAY:
844 if (!piglit_is_extension_supported("GL_ARB_texture_cube_map_array"))
845 return false;
846 break;
848 case GL_TEXTURE_2D_MULTISAMPLE:
849 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
850 if (!piglit_is_extension_supported("GL_ARB_texture_multisample"))
851 return false;
852 break;
854 case GL_TEXTURE_RECTANGLE:
855 if (!piglit_is_extension_supported("GL_ARB_texture_rectangle"))
856 return false;
857 break;
859 case GL_RENDERBUFFER:
860 if (!piglit_is_extension_supported("GL_ARB_framebuffer_object") &&
861 !piglit_is_extension_supported("GL_EXT_framebuffer_object"))
862 return false;
863 break;
865 case GL_TEXTURE_BUFFER:
866 if (!piglit_is_extension_supported("GL_ARB_texture_buffer_object") &&
867 piglit_get_gl_version() < 31)
868 return false;
869 break;
871 default:
872 return true;
875 return true;
878 /* Returns is @pname and @target dependencies are fulfilled */
879 bool
880 check_query2_dependencies(const GLenum pname,
881 const GLenum target)
883 return check_query2_target_dependencies(target) &&
884 check_query2_pname_dependencies(pname);
888 * Gets the unsupported response for any given @pname.
890 static GLint
891 get_unsupported_response(GLenum pname)
893 switch(pname) {
894 case GL_SAMPLES:
895 /* This one is special as if unsupported, the params
896 * parameter at GetInternalformativ should not be
897 * modified. We return 0 for this method, but should
898 * be took into account by the caller */
899 return 0;
900 break;
902 case GL_MAX_COMBINED_DIMENSIONS:
903 case GL_NUM_SAMPLE_COUNTS:
904 case GL_INTERNALFORMAT_RED_SIZE:
905 case GL_INTERNALFORMAT_GREEN_SIZE:
906 case GL_INTERNALFORMAT_BLUE_SIZE:
907 case GL_INTERNALFORMAT_ALPHA_SIZE:
908 case GL_INTERNALFORMAT_DEPTH_SIZE:
909 case GL_INTERNALFORMAT_STENCIL_SIZE:
910 case GL_INTERNALFORMAT_SHARED_SIZE:
911 case GL_MAX_WIDTH:
912 case GL_MAX_HEIGHT:
913 case GL_MAX_DEPTH:
914 case GL_MAX_LAYERS:
915 case GL_IMAGE_TEXEL_SIZE:
916 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
917 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
918 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
919 return 0;
920 break;
922 case GL_INTERNALFORMAT_PREFERRED:
923 case GL_INTERNALFORMAT_RED_TYPE:
924 case GL_INTERNALFORMAT_GREEN_TYPE:
925 case GL_INTERNALFORMAT_BLUE_TYPE:
926 case GL_INTERNALFORMAT_ALPHA_TYPE:
927 case GL_INTERNALFORMAT_DEPTH_TYPE:
928 case GL_INTERNALFORMAT_STENCIL_TYPE:
929 case GL_FRAMEBUFFER_RENDERABLE:
930 case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
931 case GL_FRAMEBUFFER_BLEND:
932 case GL_READ_PIXELS:
933 case GL_READ_PIXELS_FORMAT:
934 case GL_READ_PIXELS_TYPE:
935 case GL_TEXTURE_IMAGE_FORMAT:
936 case GL_TEXTURE_IMAGE_TYPE:
937 case GL_GET_TEXTURE_IMAGE_FORMAT:
938 case GL_GET_TEXTURE_IMAGE_TYPE:
939 case GL_MANUAL_GENERATE_MIPMAP:
940 case GL_AUTO_GENERATE_MIPMAP:
941 case GL_COLOR_ENCODING:
942 case GL_SRGB_READ:
943 case GL_SRGB_WRITE:
944 case GL_SRGB_DECODE_ARB:
945 case GL_FILTER:
946 case GL_VERTEX_TEXTURE:
947 case GL_TESS_CONTROL_TEXTURE:
948 case GL_TESS_EVALUATION_TEXTURE:
949 case GL_GEOMETRY_TEXTURE:
950 case GL_FRAGMENT_TEXTURE:
951 case GL_COMPUTE_TEXTURE:
952 case GL_TEXTURE_SHADOW:
953 case GL_TEXTURE_GATHER:
954 case GL_TEXTURE_GATHER_SHADOW:
955 case GL_SHADER_IMAGE_LOAD:
956 case GL_SHADER_IMAGE_STORE:
957 case GL_SHADER_IMAGE_ATOMIC:
958 case GL_IMAGE_COMPATIBILITY_CLASS:
959 case GL_IMAGE_PIXEL_FORMAT:
960 case GL_IMAGE_PIXEL_TYPE:
961 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
962 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
963 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
964 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
965 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
966 case GL_CLEAR_BUFFER:
967 case GL_TEXTURE_VIEW:
968 case GL_VIEW_COMPATIBILITY_CLASS:
969 return GL_NONE;
970 break;
972 case GL_INTERNALFORMAT_SUPPORTED:
973 case GL_COLOR_COMPONENTS:
974 case GL_DEPTH_COMPONENTS:
975 case GL_STENCIL_COMPONENTS:
976 case GL_COLOR_RENDERABLE:
977 case GL_DEPTH_RENDERABLE:
978 case GL_STENCIL_RENDERABLE:
979 case GL_MIPMAP:
980 case GL_TEXTURE_COMPRESSED:
981 return GL_FALSE;
982 break;
984 default:
985 fprintf(stderr, "Error: %i(%s) is not a valid GetInternalformativ pname",
986 pname, piglit_get_gl_enum_name(pname));
989 return 0;
993 * Returns if the content of @data contains the unsupported value for
994 * @pname. It is assumed that the pname would return just one value.
996 bool
997 test_data_is_unsupported_response(test_data *data,
998 GLenum pname)
1000 return test_data_value_at_index(data, 0) == get_unsupported_response(pname);
1004 * Sets the value of @data params at @index to @value.
1006 void
1007 test_data_set_value_at_index(test_data *data,
1008 const int index,
1009 const GLint64 value)
1011 if (index > data->params_size || index < 0) {
1012 fprintf(stderr, "ERROR: invalid index while setting"
1013 " auxiliary test data\n");
1014 return;
1017 if (data->testing64) {
1018 ((GLint64*)data->params)[index] = value;
1019 } else {
1020 ((GLint*)data->params)[index] = value;
1024 bool
1025 test_data_equal_at_index(test_data *data,
1026 test_data *data_copy,
1027 unsigned index)
1029 if (data->testing64 != data_copy->testing64) {
1030 fprintf(stderr, "ERROR: trying to compare incompatible"
1031 " auxiliary test data structures\n");
1032 return false;
1034 if (data->params_size != data_copy->params_size) {
1035 fprintf(stderr, "ERROR: trying to compare incompatible"
1036 " auxiliary test data structures\n");
1037 return false;
1039 if (index > data->params_size) {
1040 fprintf(stderr, "ERROR: invalid index while setting"
1041 " auxiliary test data\n");
1042 return false;
1045 return (test_data_value_at_index(data, index) ==
1046 test_data_value_at_index(data_copy, index));
1049 test_data*
1050 test_data_clone(test_data *data)
1052 test_data *clone;
1054 clone = test_data_new(data->testing64, data->params_size);
1056 return clone;
1060 test_data_get_testing64(test_data *data)
1062 return data->testing64;
1066 test_data_get_params_size(test_data *data)
1068 return data->params_size;
1071 void
1072 initialize_valid_internalformats()
1074 if (piglit_get_gl_version() == 43 ||
1075 piglit_is_extension_supported("GL_ARB_ES3_compatibility")) {
1076 unsigned i, j;
1078 num_valid_internalformats = ARRAY_SIZE(base_valid_internalformats) +
1079 ARRAY_SIZE(arb_es3_compatibility_valid_internalformats);
1081 valid_internalformats = malloc(sizeof(GLenum) *
1082 num_valid_internalformats);
1084 for (i = 0; i < ARRAY_SIZE(base_valid_internalformats); i++) {
1085 valid_internalformats[i] = base_valid_internalformats[i];
1088 for (i = ARRAY_SIZE(base_valid_internalformats), j = 0;
1089 i < num_valid_internalformats; i++, j++) {
1090 valid_internalformats[i] =
1091 arb_es3_compatibility_valid_internalformats[j];
1094 } else {
1095 num_valid_internalformats = ARRAY_SIZE(base_valid_internalformats);
1096 valid_internalformats = (GLenum *) base_valid_internalformats;