glsl-1.30: add more loop unroll tests
[piglit.git] / tests / spec / ext_direct_state_access / textures.c
blob509941e111bd882599ec7373e7420e70e5f1dcd9
1 /*
2 * Copyright © 2019 Advanced Micro Devices, 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
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 "piglit-util-gl.h"
26 PIGLIT_GL_TEST_CONFIG_BEGIN
28 config.supports_gl_compat_version = 12;
30 config.window_visual = PIGLIT_GL_VISUAL_RGBA |
31 PIGLIT_GL_VISUAL_DOUBLE;
32 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
34 PIGLIT_GL_TEST_CONFIG_END
36 void
37 piglit_init(int argc, char **argv)
39 piglit_require_extension("GL_EXT_direct_state_access");
43 static GLuint
44 init_texture(GLenum target, int* image_size, float** expected_pixels)
46 GLuint tex;
48 const int height = (target == GL_TEXTURE_1D) ? 1 : piglit_height;
49 const int depth = (target == GL_TEXTURE_3D) ? 2 : 1;
50 float* image = piglit_rgbw_image(GL_RGBA, piglit_width, height * depth,
51 false, GL_UNSIGNED_NORMALIZED);
52 *image_size = piglit_width * height * depth * 4 * sizeof(float);
54 glGenTextures(1, &tex);
55 glTextureParameteriEXT(tex, target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
56 glTextureParameteriEXT(tex, target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
57 glTextureParameteriEXT(tex, target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
58 glTextureParameteriEXT(tex, target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
59 glTextureParameteriEXT(tex, target, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
60 if (target == GL_TEXTURE_1D) {
61 glTextureImage1DEXT(tex, target, 0, GL_RGBA,
62 piglit_width, 0,
63 GL_RGBA, GL_FLOAT, image);
64 } else if (target == GL_TEXTURE_2D) {
65 glTextureImage2DEXT(tex, target, 0, GL_RGBA,
66 piglit_width, height, 0,
67 GL_RGBA, GL_FLOAT, image);
68 } else {
69 /* 2 layers 3D image */
70 glTextureImage3DEXT(tex, target, 0, GL_RGBA,
71 piglit_width, height, depth, 0,
72 GL_RGBA, GL_FLOAT, image);
75 if (expected_pixels != NULL) {
76 *expected_pixels = image;
77 } else {
78 free(image);
81 return tex;
84 static GLenum
85 dimension_to_target(int n)
87 assert(n == 1 || n == 2 || n == 3);
88 switch (n) {
89 case 1: return GL_TEXTURE_1D;
90 case 2: return GL_TEXTURE_2D;
91 case 3:
92 default:
93 return GL_TEXTURE_3D;
97 static GLenum use_display_list = GL_NONE;
98 static GLuint list;
100 static enum piglit_result
101 test_TextureImageNDEXT(void* data)
103 bool pass = true;
104 const int n = (int)(intptr_t) data;
105 const GLenum target = dimension_to_target(n);
106 int image_size;
107 float* expected_pixels, *got_pixels;
108 GLuint tex;
110 if (use_display_list != GL_NONE)
111 glNewList(list, use_display_list);
113 tex = init_texture(target, &image_size, &expected_pixels);
115 if (use_display_list != GL_NONE)
116 glEndList(list);
118 if (use_display_list == GL_COMPILE) {
119 /* Texture shouldn't have been initialized yet */
120 pass = !glIsTexture(tex);
121 glCallList(list);
124 got_pixels = (float*) malloc(image_size);
125 glGetTextureImageEXT(tex, target, 0, GL_RGBA, GL_FLOAT, got_pixels);
127 pass = memcmp(expected_pixels, got_pixels, image_size) == 0 && pass;
129 /* The GL_EXT_direct_state_access spec says:
131 * INVALID_OPERATION is generated [...] if the target parameter does
132 * not match the target type of the texture object named by the texture
133 * parameter.
135 if (n == 2) {
136 glTextureImage2DEXT(tex, GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA,
137 piglit_width, piglit_height, 0,
138 GL_RGBA, GL_FLOAT, got_pixels);
139 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
142 free(expected_pixels);
143 free(got_pixels);
145 glDeleteTextures(1, &tex);
147 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
150 static enum piglit_result
151 test_TextureSubImageNDEXT(void* data)
153 bool pass = true;
154 int i;
155 const int n = (int)(intptr_t) data;
156 const GLenum target = dimension_to_target(n);
157 int image_size;
158 float* original_pixels, *modified_pixels, *got_pixels;
159 GLuint tex = init_texture(target, &image_size, &original_pixels);
160 int len = image_size / sizeof(float);
162 if (use_display_list != GL_NONE)
163 glNewList(list, use_display_list);
165 /* Replace the whole texture using glTextureSubImageNDEXT, line by line */
166 modified_pixels = (float*) malloc(image_size);
167 for (i = 0; i < len; i++) {
168 modified_pixels[i] = original_pixels[(i + 1) % len];
171 if (n == 1) {
172 glTextureSubImage1DEXT(tex, target, 0,
173 0, piglit_width,
174 GL_RGBA, GL_FLOAT,
175 modified_pixels);
176 } else {
177 for (i = 0; i < piglit_height; i++) {
178 if (n == 2) {
179 glTextureSubImage2DEXT(tex,
180 target, 0,
181 0, i, piglit_width, 1,
182 GL_RGBA, GL_FLOAT,
183 &modified_pixels[piglit_width * 4 * i]);
184 } else {
185 /* Update the 1st layer of the 3D image */
186 glTextureSubImage3DEXT(tex,
187 target, 0,
188 0, i, 0, piglit_width, 1, 1,
189 GL_RGBA, GL_FLOAT,
190 &modified_pixels[piglit_width * 4 * i]);
191 /* And the 2nd layer */
192 glTextureSubImage3DEXT(tex,
193 target, 0,
194 0, i, 1, piglit_width, 1, 1,
195 GL_RGBA, GL_FLOAT,
196 &modified_pixels[piglit_width * 4 * (i + piglit_height)]);
201 if (use_display_list != GL_NONE)
202 glEndList(list);
204 got_pixels = (float*) malloc(image_size);
205 glGetTextureImageEXT(tex, target, 0, GL_RGBA, GL_FLOAT, got_pixels);
207 if (use_display_list == GL_COMPILE) {
208 /* Texture shouldn't have been modified yet */
209 pass = memcmp(original_pixels, got_pixels, image_size) == 0 && pass;
210 glCallList(list);
211 /* Re-read */
212 glGetTextureImageEXT(tex, target, 0, GL_RGBA, GL_FLOAT, got_pixels);
215 pass = memcmp(modified_pixels, got_pixels, image_size) == 0 && pass;
217 /* Verify error added by the extension:
218 "INVALID_OPERATION is generated [...] if the target parameter does
219 not match the target type of the texture object named by the texture
220 parameter."
222 if (n == 2) {
223 glTextureSubImage2DEXT(tex,
224 GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0,
225 0, 0, 4, 1,
226 GL_RGBA, GL_FLOAT,
227 modified_pixels);
228 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
231 glDeleteTextures(1, &tex);
232 free(modified_pixels);
233 free(original_pixels);
235 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
238 static enum piglit_result
239 test_CopyTextureImageNDEXT(void* data)
241 bool pass = true;
242 const int n = (int)(intptr_t) data;
243 assert(n == 1 || n == 2);
244 const GLenum target = dimension_to_target(n);
245 int image_size;
246 float* original_pixels;
247 GLuint tex = init_texture(target, &image_size, &original_pixels);
248 const int height = (target == GL_TEXTURE_1D) ? 1 : piglit_height;
249 float* got_pixels;
251 glClearColor(0.25, 0.5, 0.75, 1);
252 glClear(GL_COLOR_BUFFER_BIT);
254 if (use_display_list != GL_NONE)
255 glNewList(list, use_display_list);
257 switch (target) {
258 case GL_TEXTURE_1D:
259 glCopyTextureImage1DEXT(tex, target, 0, GL_RGBA, 0, 0, piglit_width, 0);
260 break;
261 case GL_TEXTURE_2D:
262 glCopyTextureImage2DEXT(tex, target, 0, GL_RGBA, 0, 0, piglit_width, piglit_height, 0);
263 break;
266 if (use_display_list != GL_NONE)
267 glEndList(list);
269 got_pixels = (float*) malloc(piglit_width * height * 4 * sizeof(float));
271 /* Compare glGetTextureImageEXT and on screen pixels */
272 glGetTextureImageEXT(tex, target, 0, GL_RGBA, GL_FLOAT, got_pixels);
274 if (use_display_list == GL_COMPILE) {
275 /* Texture shouldn't have been modified yet */
276 pass = memcmp(got_pixels, original_pixels, image_size) == 0;
277 glCallList(list);
278 glGetTextureImageEXT(tex, target, 0, GL_RGBA, GL_FLOAT, got_pixels);
281 pass = piglit_probe_rect_rgba(0, 0, piglit_width, height, got_pixels) && pass;
283 free(got_pixels);
284 free(original_pixels);
286 glDeleteTextures(1, &tex);
288 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
291 static enum piglit_result
292 test_CopyTextureSubImageNDEXT(void* data)
294 bool pass = true;
295 const int n = (int)(intptr_t) data;
296 const GLenum target = dimension_to_target(n);
297 int image_size;
298 float* original_pixels;
299 GLuint tex = init_texture(target, &image_size, &original_pixels);
300 const int height = (target == GL_TEXTURE_1D) ? 1 : piglit_height;
301 float* got_pixels;
303 glClearColor(0.25, 0.5, 0.75, 1);
304 glClear(GL_COLOR_BUFFER_BIT);
306 if (use_display_list != GL_NONE)
307 glNewList(list, use_display_list);
309 switch (target) {
310 case GL_TEXTURE_1D:
311 glCopyTextureSubImage1DEXT(tex, target, 0, 0, 0, 0, piglit_width);
312 break;
313 case GL_TEXTURE_2D:
314 glCopyTextureSubImage2DEXT(tex, target, 0, 0, 0, 0, 0, piglit_width, piglit_height);
315 break;
316 case GL_TEXTURE_3D:
317 glCopyTextureSubImage3DEXT(tex, target, 0, 0, 0, 0, 0, 0, piglit_width, piglit_height);
318 break;
321 if (use_display_list != GL_NONE)
322 glEndList(list);
324 got_pixels = (float*) malloc(image_size);
326 /* Compare glGetTextureImageEXT and on screen pixels */
327 glGetTextureImageEXT(tex, target, 0, GL_RGBA, GL_FLOAT, got_pixels);
329 if (use_display_list == GL_COMPILE) {
330 /* Texture shouldn't have been modified yet */
331 pass = memcmp(got_pixels, original_pixels, image_size) == 0;
332 glCallList(list);
333 glGetTextureImageEXT(tex, target, 0, GL_RGBA, GL_FLOAT, got_pixels);
336 pass = piglit_probe_rect_rgba(0, 0, piglit_width, height, got_pixels) && pass;
338 free(got_pixels);
339 free(original_pixels);
341 glDeleteTextures(1, &tex);
343 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
346 static enum piglit_result
347 test_TextureParameterEXT(void* data)
349 GLuint tex[2];
350 static const GLenum targets[] = {
351 GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
352 GL_TEXTURE_CUBE_MAP,
354 int i, j, k, value;
355 bool pass = true;
357 void (*textureParameteri_variant) (GLuint, GLenum, GLenum, GLint*) = data;
359 struct pname_value {
360 GLenum pname;
361 int value_count;
362 int values[8];
363 } tested[] = {
365 GL_TEXTURE_WRAP_S,
368 GL_CLAMP, GL_CLAMP_TO_EDGE, GL_REPEAT,
369 GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT
373 GL_TEXTURE_WRAP_R,
376 GL_CLAMP, GL_CLAMP_TO_EDGE, GL_REPEAT,
377 GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT
381 GL_TEXTURE_WRAP_T,
384 GL_CLAMP, GL_CLAMP_TO_EDGE, GL_REPEAT,
385 GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT
389 GL_TEXTURE_MIN_FILTER,
392 GL_NEAREST, GL_LINEAR,
393 GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST_MIPMAP_NEAREST,
394 GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST
398 GL_TEXTURE_MAG_FILTER,
401 GL_NEAREST, GL_LINEAR
405 GL_TEXTURE_BASE_LEVEL,
406 1, { rand() }
409 GL_TEXTURE_MAX_LEVEL,
410 1, { rand() }
413 GL_DEPTH_TEXTURE_MODE,
416 GL_RED, GL_LUMINANCE, GL_INTENSITY, GL_ALPHA
420 GL_TEXTURE_COMPARE_MODE,
423 GL_NONE, GL_COMPARE_REF_TO_TEXTURE
427 GL_TEXTURE_COMPARE_FUNC,
430 GL_LEQUAL, GL_GEQUAL, GL_LESS, GL_GREATER,
431 GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER
435 GL_GENERATE_MIPMAP,
438 GL_TRUE, GL_FALSE
443 if (!textureParameteri_variant) {
444 return PIGLIT_SKIP;
447 for (i = 0; i < ARRAY_SIZE(targets); i++) {
448 GLenum target = targets[i];
450 glGenTextures(ARRAY_SIZE(tex), tex);
452 for (j = 0; j < ARRAY_SIZE(tested); j++) {
453 for (k = 0; k < tested[j].value_count; k++) {
454 if (tested[j].values[k] == GL_RED && !piglit_is_extension_supported("GL_ARB_texture_rg"))
455 continue;
457 int original_value;
458 if (use_display_list != GL_NONE)
459 glNewList(list, use_display_list);
461 glGetTextureParameterivEXT(tex[1], target,
462 tested[j].pname, &original_value);
464 (*textureParameteri_variant)(
465 tex[1], target,
466 tested[j].pname,
467 &tested[j].values[k]);
469 if (use_display_list != GL_NONE)
470 glEndList(list);
472 if (use_display_list == GL_COMPILE) {
473 int v;
474 glGetTextureParameterivEXT(tex[1], target,
475 tested[j].pname, &v);
476 pass = (v == original_value) && pass;
477 glCallList(list);
480 glGetTextureParameterivEXT(tex[1], target, tested[j].pname, &value);
482 if (value != tested[j].values[k]) {
483 piglit_loge("TextureParameter*EXT(%s, %s, ...) failed. Expected %d but got %d\n",
484 piglit_get_gl_enum_name(target),
485 piglit_get_gl_enum_name(tested[j].pname),
486 tested[j].values[k],
487 value);
488 return PIGLIT_FAIL;
490 if (!piglit_check_gl_error(GL_NO_ERROR)) {
491 piglit_loge("TextureParameter*EXT(%s, %s, ...) failed.\n",
492 piglit_get_gl_enum_name(target),
493 piglit_get_gl_enum_name(tested[j].pname));
494 return PIGLIT_FAIL;
498 glDeleteTextures(ARRAY_SIZE(tex), tex);
500 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
503 static enum piglit_result
504 test_TextureParameterfEXT(void* data)
506 GLuint tex[2];
507 static const GLenum targets[] = {
508 GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
509 GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY,
510 GL_TEXTURE_CUBE_MAP,
512 int i, j, k, l;
513 bool pass = true;
514 float value;
516 const struct pname_value {
517 GLenum pname;
518 int value_count;
519 float values[8];
520 } tested[] = {
522 GL_TEXTURE_PRIORITY,
523 1, { (float) rand() / RAND_MAX }
526 GL_TEXTURE_MIN_LOD,
527 1, { (float)rand() }
530 GL_TEXTURE_MAX_LOD,
531 1, { (float)rand() }
534 GL_TEXTURE_LOD_BIAS,
535 1, { (float)rand() }
539 for (i = 0; i < ARRAY_SIZE(targets); i++) {
540 GLenum target = targets[i];
542 if ((target == GL_TEXTURE_1D_ARRAY || target == GL_TEXTURE_2D_ARRAY) &&
543 !piglit_is_extension_supported("GL_EXT_texture_array")) {
544 continue;
547 glGenTextures(ARRAY_SIZE(tex), tex);
549 for (j = 0; j < ARRAY_SIZE(tested); j++) {
550 for (k = 0; k < tested[j].value_count; k++) {
551 float original_values[2];
553 if (use_display_list != GL_NONE)
554 glNewList(list, use_display_list);
556 for (l = 0; l < 2; l++) {
557 glGetTextureParameterfvEXT(tex[l], target,
558 tested[j].pname, &original_values[l]);
561 glTextureParameterfEXT(
562 tex[0], target,
563 tested[j].pname,
564 tested[j].values[k]);
566 glTextureParameterfvEXT(
567 tex[1], target,
568 tested[j].pname,
569 &tested[j].values[k]);
571 if (use_display_list != GL_NONE)
572 glEndList(list);
574 if (use_display_list == GL_COMPILE) {
575 for (l = 0; l < 2; l++) {
576 float v;
577 glGetTextureParameterfvEXT(tex[l], target,
578 tested[j].pname, &v);
579 pass = v == original_values[l] && pass;
581 glCallList(list);
584 for (l = 0; l < 2; l++) {
585 glGetTextureParameterfvEXT(tex[l], target, tested[j].pname, &value);
587 if (value != tested[j].values[k]) {
588 piglit_loge("%s(%s, %s, ...) failed. Expected %f but got %f\n",
589 l == 0 ? "glTextureParameterfEXT" : "glTextureParameterfvEXT",
590 piglit_get_gl_enum_name(target),
591 piglit_get_gl_enum_name(tested[j].pname),
592 tested[j].values[k],
593 value);
594 return PIGLIT_FAIL;
596 if (!piglit_check_gl_error(GL_NO_ERROR)) {
597 piglit_loge("%s(%s, %s, ...) failed.\n",
598 l == 0 ? "glTextureParameterfEXT" : "glTextureParameterfvEXT",
599 piglit_get_gl_enum_name(target),
600 piglit_get_gl_enum_name(tested[j].pname));
601 return PIGLIT_FAIL;
606 glDeleteTextures(ARRAY_SIZE(tex), tex);
608 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
611 enum piglit_result
612 test_EnableDisableEXT(void* data)
614 /* The GL_EXT_direct_state_access spec says:
616 * The following commands (introduced by EXT_draw_buffers2):
618 * void EnableIndexedEXT(enum cap, uint index);
619 * void DisableIndexedEXT(enum cap, uint index);
621 * are equivalent (assuming no errors) to the following:
623 * ActiveTexture(TEXTURE0+index);
624 * XXX(cap);
626 * [...] when the cap parameter is one of the texture-related
627 * enable token depending on the active texture state, namely
628 * TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, TEXTURE_CUBE_MAP,
629 * TEXTURE_RECTANGLE_ARB, TEXTURE_GEN_S, TEXTURE_GEN_T,
630 * TEXTURE_GEN_R, or TEXTURE_GEN_Q.
632 static const GLenum caps[] = {
633 GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP,
634 GL_TEXTURE_GEN_S, GL_TEXTURE_GEN_T, GL_TEXTURE_GEN_R,
635 GL_TEXTURE_GEN_Q
638 int i, max_texture_units;
639 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_units);
641 for (i = 0; i < ARRAY_SIZE(caps); i++) {
642 const GLenum cap = caps[i];
644 const int index = rand() % max_texture_units;
645 const bool value = rand() % 2;
646 GLboolean got;
647 int got_i;
649 glActiveTexture(GL_TEXTURE0 + (index + 1) % max_texture_units);
651 if (use_display_list != GL_NONE)
652 glNewList(list, use_display_list);
654 if (value) {
655 glEnableIndexedEXT(cap, index);
656 } else {
657 glDisableIndexedEXT(cap, index);
660 if (use_display_list != GL_NONE)
661 glEndList(list);
663 if (use_display_list == GL_COMPILE)
664 glCallList(list);
666 /* Read back with glIsEnabledIndexedEXT */
667 if (value != glIsEnabledIndexedEXT(cap, index)) {
668 piglit_loge("gl%sIndexedEXT(%s, %d) / glIsEnabledIndexedEXT failed.\n",
669 value ? "Enable" : "Disable",
670 piglit_get_gl_enum_name(cap),
671 index);
672 return PIGLIT_FAIL;
675 /* Read back with glGetBooleanIndexedvEXT */
676 glGetBooleanIndexedvEXT(cap, index, &got);
677 if (value != got) {
678 piglit_loge("gl%sIndexedEXT(%s, %d) / glGetBooleanIndexedvEXT failed.\n",
679 value ? "Enable" : "Disable",
680 piglit_get_gl_enum_name(cap),
681 index);
682 return PIGLIT_FAIL;
685 /* Read back with glGetBooleanIndexedvEXT */
686 glGetIntegerIndexedvEXT(cap, index, &got_i);
687 if (value != got_i) {
688 piglit_loge("gl%sIndexedEXT(%s, %d) / glGetIntegerIndexedvEXT failed.\n",
689 value ? "Enable" : "Disable",
690 piglit_get_gl_enum_name(cap),
691 index);
692 return PIGLIT_FAIL;
695 return PIGLIT_PASS;
699 static enum piglit_result
700 test_TextureProxyTarget(void* data)
702 bool pass = true;
703 GLint width;
704 GLfloat height;
705 const int n = (int)(intptr_t) data;
706 const GLenum target = dimension_to_target(n);
708 GLenum proxy_target = (target == GL_TEXTURE_1D) ? GL_PROXY_TEXTURE_1D :
709 (target == GL_TEXTURE_2D ? GL_PROXY_TEXTURE_2D : GL_PROXY_TEXTURE_3D);
711 GLuint tex;
712 glGenTextures(1, &tex);
714 /* The GL_EXT_direct_state_access says:
716 * Proxy targets work with the glTex* (glTexImage*)
717 * and glGetTex* (glGetTexLevelParameter*) commands that support
718 * proxy textures BUT the texture name must be 0 to avoid a
719 * GL_INVALID_OPERATION error.
721 if (n == 1) {
722 glTextureImage1DEXT(tex, proxy_target, 0, GL_RGBA,
723 piglit_width, 0,
724 GL_RGBA, GL_FLOAT, NULL);
725 } else if (n == 2) {
726 glTextureImage2DEXT(tex, proxy_target, 0, GL_RGBA,
727 piglit_width, piglit_height, 0,
728 GL_RGBA, GL_FLOAT, NULL);
729 } else if (n == 3) {
730 glTextureImage3DEXT(tex, proxy_target, 0, GL_RGBA,
731 piglit_width, piglit_height, 1, 0,
732 GL_RGBA, GL_FLOAT, NULL);
734 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
736 if (n == 1) {
737 glTextureImage1DEXT(0, proxy_target, 0, GL_RGBA,
738 piglit_width, 0,
739 GL_RGBA, GL_FLOAT, NULL);
740 } else if (n == 2) {
741 glTextureImage2DEXT(0, proxy_target, 0, GL_RGBA,
742 piglit_width, piglit_height, 0,
743 GL_RGBA, GL_FLOAT, NULL);
744 } else if (n == 3) {
745 glTextureImage3DEXT(0, proxy_target, 0, GL_RGBA,
746 piglit_width, piglit_height, 1, 0,
747 GL_RGBA, GL_FLOAT, NULL);
749 glGetTextureLevelParameterivEXT(0, proxy_target, 0,
750 GL_TEXTURE_WIDTH, &width);
751 glGetTextureLevelParameterfvEXT(0, proxy_target, 0,
752 GL_TEXTURE_HEIGHT, &height);
753 pass = width == piglit_width && pass;
754 pass = (int)height == (n > 1 ? piglit_height : 1) && pass;
756 glDeleteTextures(1, &tex);
758 return pass && piglit_check_gl_error(GL_NO_ERROR) ? PIGLIT_PASS : PIGLIT_FAIL;
761 void TextureParameteriEXT_wrapper(GLuint texture, GLenum target, GLenum pname, GLint* value) {
762 glTextureParameteriEXT(texture, target, pname, *value);
765 void TextureParameterIuivEXT_wrapper(GLuint texture, GLenum target, GLenum pname, GLint* value) {
766 glTextureParameterIuivEXT(texture, target, pname, (GLuint*) value);
769 enum piglit_result
770 piglit_display(void)
772 int i;
773 const bool have_ext_tex_int = piglit_is_extension_supported("GL_EXT_texture_integer");
774 struct piglit_subtest tests[] = {
776 "TextureParameteriEXT",
777 NULL,
778 test_TextureParameterEXT,
779 TextureParameteriEXT_wrapper
782 "TextureParameterivEXT",
783 NULL,
784 test_TextureParameterEXT,
785 glTextureParameterivEXT
788 "TextureParameterIivEXT",
789 NULL,
790 test_TextureParameterEXT,
791 have_ext_tex_int ? glTextureParameterIivEXT : NULL
794 "TextureParameterIuivEXT",
795 NULL,
796 test_TextureParameterEXT,
797 have_ext_tex_int ? TextureParameterIuivEXT_wrapper : NULL
800 "TextureParameterfEXT",
801 NULL,
802 test_TextureParameterfEXT,
803 NULL
806 "TextureImage1DEXT",
807 NULL,
808 test_TextureImageNDEXT,
809 (void*) 1
812 "TextureImage2DEXT",
813 NULL,
814 test_TextureImageNDEXT,
815 (void*) 2
818 "TextureImage3DEXT",
819 NULL,
820 test_TextureImageNDEXT,
821 (void*) 3
824 "TextureSubImage1DEXT",
825 NULL,
826 test_TextureSubImageNDEXT,
827 (void*) 1
830 "TextureSubImage2DEXT",
831 NULL,
832 test_TextureSubImageNDEXT,
833 (void*) 2
836 "TextureSubImage3DEXT",
837 NULL,
838 test_TextureSubImageNDEXT,
839 (void*) 3
842 "CopyTextureImage1DEXT",
843 NULL,
844 test_CopyTextureImageNDEXT,
845 (void*) 1
848 "CopyTextureImage2DEXT",
849 NULL,
850 test_CopyTextureImageNDEXT,
851 (void*) 2
854 "CopyTextureSubImage1DEXT",
855 NULL,
856 test_CopyTextureSubImageNDEXT,
857 (void*) 1
860 "CopyTextureSubImage2DEXT",
861 NULL,
862 test_CopyTextureSubImageNDEXT,
863 (void*) 2
866 "CopyTextureSubImage3DEXT",
867 NULL,
868 test_CopyTextureSubImageNDEXT,
869 (void*) 3
872 "EnableDisableEXT",
873 NULL,
874 test_EnableDisableEXT
877 "GL_PROXY_TEXTURE_1D + glTex*",
878 NULL,
879 test_TextureProxyTarget,
880 (void*) 1
883 "GL_PROXY_TEXTURE_2D + glTex*",
884 NULL,
885 test_TextureProxyTarget,
886 (void*) 2
889 "GL_PROXY_TEXTURE_3D + glTex*",
890 NULL,
891 test_TextureProxyTarget,
892 (void*) 3
895 NULL
899 enum piglit_result result = piglit_run_selected_subtests(tests, NULL, 0, PIGLIT_PASS);
900 list = glGenLists(1);
902 /* Re-run the same test but using display list GL_COMPILE */
903 for (i = 0; tests[i].name; i++) {
904 char* test_name_display_list;
905 asprintf(&test_name_display_list, "%s + display list GL_COMPILE", tests[i].name);
906 tests[i].name = test_name_display_list;
908 use_display_list = GL_COMPILE;
909 result = piglit_run_selected_subtests(tests, NULL, 0, result);
911 /* Re-run the same test but using display list GL_COMPILE_AND_EXECUTE */
912 for (i = 0; tests[i].name; i++) {
913 char* test_name_display_list;
914 asprintf(&test_name_display_list, "%s_AND_EXECUTE", tests[i].name);
915 tests[i].name = test_name_display_list;
917 use_display_list = GL_COMPILE_AND_EXECUTE;
918 result = piglit_run_selected_subtests(tests, NULL, 0, result);
920 glDeleteLists(list, 1);
922 return result;