Add more structure constructor tests.
[piglit/hramrach.git] / tests / texturing / tex-swizzle.c
blob2e5c86cb66847b901c00d3e709184cc9de03281d
3 /*
4 * Copyright © 2009 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
25 * Authors:
26 * Ben Holmes <shranzel@hotmail.com>
30 * this test draws 256 quads utilizing every permutation of texture
31 * swizzling available.
34 #include "piglit-util.h"
36 #ifndef GL_TEXTURE_SWIZZLE_RGBA_EXT
37 #define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46
38 #endif
40 int piglit_width = 400, piglit_height = 300;
41 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
43 static GLuint tex[1];
45 static GLfloat verts[12] = {17.0, 1.0, 0.0,
46 17.0, 17.0, 0.0,
47 1.0, 1.0, 0.0,
48 1.0, 17.0, 0.0};
50 static GLfloat texCoords[8] = {1.0, 0.0,
51 1.0, 1.0,
52 0.0, 0.0,
53 0.0, 1.0};
55 static GLboolean
56 probes();
58 static void
59 loadTex()
61 #define height 2
62 #define width 2
63 int i, j;
65 GLfloat texData[width][height][4];
66 for (i = 0; i < width; ++i) {
67 for (j = 0; j < height; ++j) {
68 if ((i+j) & 1) {
69 texData[i][j][0] = 1.0;
70 texData[i][j][1] = 0.0;
71 texData[i][j][2] = 1.0;
72 texData[i][j][3] = 0.0;
74 else {
75 texData[i][j][0] = 0.0;
76 texData[i][j][1] = 1.0;
77 texData[i][j][2] = 0.0;
78 texData[i][j][3] = 1.0;
83 glGenTextures(1, tex);
84 glBindTexture(GL_TEXTURE_2D, tex[0]);
85 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
89 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
90 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
91 GL_FLOAT, texData);
93 #undef height
94 #undef width
99 void
100 piglit_init(int argc, char **argv)
103 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
105 piglit_require_extension("GL_EXT_texture_swizzle");
107 glEnable(GL_TEXTURE_2D);
108 glEnable(GL_BLEND);
109 glBlendFunc(GL_ONE, GL_SRC_ALPHA);
110 glClearColor(0.6, 0.6, 0.6, 1.0);
112 loadTex();
115 enum piglit_result
116 piglit_display(void)
118 GLenum rgba[4] = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
119 int i, j, k;
120 GLboolean pass = GL_TRUE;
122 glClear(GL_COLOR_BUFFER_BIT);
123 glEnableClientState(GL_VERTEX_ARRAY);
124 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
126 glVertexPointer(3, GL_FLOAT, 0, verts);
127 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
129 glBindTexture(GL_TEXTURE_2D, tex[0]);
131 glPushMatrix();
133 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA_EXT, (GLint *) rgba);
135 for(k = 0; k < 4; ++k) {
136 glPushMatrix();
137 for(j = 0; j < 4; ++j) {
138 for(i = 0; i < 4; ++i) {
139 glPushMatrix();
140 rgba[3] = GL_ALPHA;
141 glTexParameteriv(GL_TEXTURE_2D,
142 GL_TEXTURE_SWIZZLE_RGBA_EXT,
143 (GLint *) rgba);
145 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
147 glTranslatef(17.0, 0.0, 0.0);
148 rgba[3] = GL_RED;
149 glTexParameteriv(GL_TEXTURE_2D,
150 GL_TEXTURE_SWIZZLE_RGBA_EXT,
151 (GLint *) rgba);
153 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
155 glTranslatef(17.0, 0.0, 0.0);
156 rgba[3] = GL_GREEN;
157 glTexParameteriv(GL_TEXTURE_2D,
158 GL_TEXTURE_SWIZZLE_RGBA_EXT,
159 (GLint *) rgba);
161 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
163 glTranslatef(17.0, 0.0, 0.0);
164 rgba[3] = GL_BLUE;
165 glTexParameteriv(GL_TEXTURE_2D,
166 GL_TEXTURE_SWIZZLE_RGBA_EXT,
167 (GLint *) rgba);
169 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
170 glPopMatrix();
172 switch (i) {
173 case 0:
174 rgba[2] = GL_RED;
175 break;
176 case 1:
177 rgba[2] = GL_GREEN;
178 break;
179 case 2:
180 rgba[2] = GL_ALPHA;
181 break;
183 glTranslatef(0.0, 17.0, 0.0);
186 rgba[2] = GL_BLUE;
188 switch(j) {
189 case 0:
190 rgba[1] = GL_RED;
191 break;
192 case 1:
193 rgba[1] = GL_BLUE;
194 break;
195 case 2:
196 rgba[1] = GL_ALPHA;
197 break;
200 glPopMatrix();
201 glTranslatef(85.0, 0.0, 0.0);
202 rgba[1] = GL_GREEN;
204 switch (k) {
205 case 0:
206 rgba[0] = GL_GREEN;
207 break;
208 case 1:
209 rgba[0] = GL_BLUE;
210 break;
211 case 2:
212 rgba[0] = GL_ALPHA;
213 break;
218 glPopMatrix();
220 pass = probes();
222 glFinish();
223 glutSwapBuffers();
225 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
228 //probing is done left-to-right, bottom-to-top, by column
229 //and two probes are done per quad
230 static GLboolean
231 probes(void)
234 int i;
236 static const GLfloat greyGreen[3] = {0.6, 1.0, 0.6};
237 static const GLfloat green[3] = {0.0, 1.0, 0.0};
238 static const GLfloat greyPink[3] = {1.0, 0.6, 1.0};
239 static const GLfloat pink[3] = {1.0, 0.0, 1.0};
240 static const GLfloat greyBlueGreen[3] = {0.6, 1.0, 1.0};
241 static const GLfloat red[3] = {1.0, 0.0, 0.0};
242 static const GLfloat blueGreen[3] = {0.0, 1.0, 1.0};
243 static const GLfloat greyRed[3] = {1.0, 0.6, 0.6};
244 static const GLfloat grey[3] = {0.6, 0.6, 0.6};
245 static const GLfloat white[3] = {1.0, 1.0, 1.0};
246 static const GLfloat black[3] = {0.0, 0.0, 0.0};
247 static const GLfloat blue[3] = {0.0, 0.0, 1.0};
248 static const GLfloat yellow[3] = {1.0, 1.0, 0.0};
249 static const GLfloat greyYellow[3] = {1.0, 1.0, 0.6};
250 static const GLfloat greyBlue[3] = {0.6, 0.6, 1.0};
252 GLboolean pass = GL_TRUE;
254 static const struct {
255 int x, y;
256 const GLfloat *color;
257 } expect[] = {
259 //first column
260 {2,2,greyGreen},
261 {10,2,pink},
262 {20,2,green},
263 {28,2,greyPink},
264 {38,2,greyGreen},
265 {46,2,pink},
266 {56,2,green},
267 {64,2,greyPink},
269 {2,19,greyGreen},
270 {10,19,pink},
271 {20,19,green},
272 {28,19,greyPink},
273 {38,19,greyGreen},
274 {46,19,pink},
275 {56,19,green},
276 {64,19,greyPink},
278 {2,36,greyBlueGreen},
279 {10,36,red},
280 {20,36,blueGreen},
281 {28,36,greyRed},
282 {38,36,greyBlueGreen},
283 {46,36,red},
284 {56,36,blueGreen},
285 {64,36,greyRed},
287 {2,53,greyBlueGreen},
288 {10,53,red},
289 {20,53,blueGreen},
290 {28,53,greyRed},
291 {38,53,greyBlueGreen},
292 {46,53,red},
293 {56,53,blueGreen},
294 {64,53,greyRed},
296 {2,70,grey},
297 {10,70,white},
298 {20,70,black},
299 {28,70,white},
300 {38,70,grey},
301 {46,70,white},
302 {56,70,black},
303 {64,70,white},
305 {2,87,grey},
306 {10,87,white},
307 {20,87,black},
308 {28,87,white},
309 {38,87,grey},
310 {46,87,white},
311 {56,87,black},
312 {64,87,white},
314 {2,104,greyBlue},
315 {10,104,yellow},
316 {20,104,blue},
317 {28,104,greyYellow},
318 {38,104,greyBlue},
319 {46,104,yellow},
320 {56,104,blue},
321 {64,104,greyYellow},
323 {2,121,greyBlue},
324 {10,121,yellow},
325 {20,121,blue},
326 {28,121,greyYellow},
327 {38,121,greyBlue},
328 {46,121,yellow},
329 {56,121,blue},
330 {64,121,greyYellow},
332 {2,138,grey},
333 {10,138,white},
334 {20,138,black},
335 {28,138,white},
336 {38,138,grey},
337 {46,138,white},
338 {56,138,black},
339 {64,138,white},
341 {2,155,grey},
342 {10,155,white},
343 {20,155,black},
344 {28,155,white},
345 {38,155,grey},
346 {46,155,white},
347 {56,155,black},
348 {64,155,white},
350 {2,172,greyBlue},
351 {10,172,yellow},
352 {20,172,blue},
353 {28,172,greyYellow},
354 {38,172,greyBlue},
355 {46,172,yellow},
356 {56,172,blue},
357 {64,172,greyYellow},
359 {2,189,greyBlue},
360 {10,189,yellow},
361 {20,189,blue},
362 {28,189,greyYellow},
363 {38,189,greyBlue},
364 {46,189,yellow},
365 {56,189,blue},
366 {64,189,greyYellow},
368 {2,206,greyGreen},
369 {10,206,pink},
370 {20,206,green},
371 {28,206,greyPink},
372 {38,206,greyGreen},
373 {46,206,pink},
374 {56,206,green},
375 {64,206,greyPink},
377 {2,223,greyGreen},
378 {10,223,pink},
379 {20,223,green},
380 {28,223,greyPink},
381 {38,223,greyGreen},
382 {46,223,pink},
383 {56,223,green},
384 {64,223,greyPink},
386 {2,240,greyBlueGreen},
387 {10,240,red},
388 {20,240,blueGreen},
389 {28,240,greyRed},
390 {38,240,greyBlueGreen},
391 {46,240,red},
392 {56,240,blueGreen},
393 {64,240,greyRed},
395 {2,257,greyBlueGreen},
396 {10,257,red},
397 {20,257,blueGreen},
398 {28,257,greyRed},
399 {38,257,greyBlueGreen},
400 {46,257,red},
401 {56,257,blueGreen},
402 {64,257,greyRed},
404 //second column
405 {87,2,greyYellow},
406 {95,2,blue},
407 {105,2,yellow},
408 {113,2,greyBlue},
409 {123,2,greyYellow},
410 {131,2,blue},
411 {141,2,yellow},
412 {149,2,greyBlue},
414 {87,19,greyYellow},
415 {95,19,blue},
416 {105,19,yellow},
417 {113,19,greyBlue},
418 {123,19,greyYellow},
419 {131,19,blue},
420 {141,19,yellow},
421 {149,19,greyBlue},
423 {87,36,white},
424 {95,36,black},
425 {105,36,white},
426 {113,36,grey},
427 {123,36,white},
428 {131,36,black},
429 {141,36,white},
430 {149,36,grey},
432 {87,53,white},
433 {95,53,black},
434 {105,53,white},
435 {113,53,grey},
436 {123,53,white},
437 {131,53,black},
438 {141,53,white},
439 {149,53,grey},
441 {87,70,greyRed},
442 {95,70,blueGreen},
443 {105,70,red},
444 {113,70,greyBlueGreen},
445 {123,70,greyRed},
446 {131,70,blueGreen},
447 {141,70,red},
448 {149,70,greyBlueGreen},
450 {87,87,greyRed},
451 {95,87,blueGreen},
452 {105,87,red},
453 {113,87,greyBlueGreen},
454 {123,87,greyRed},
455 {131,87,blueGreen},
456 {141,87,red},
457 {149,87,greyBlueGreen},
459 {87,104,greyPink},
460 {95,104,green},
461 {105,104,pink},
462 {113,104,greyGreen},
463 {123,104,greyPink},
464 {131,104,green},
465 {141,104,pink},
466 {149,104,greyGreen},
468 {87,121,greyPink},
469 {95,121,green},
470 {105,121,pink},
471 {113,121,greyGreen},
472 {123,121,greyPink},
473 {131,121,green},
474 {141,121,pink},
475 {149,121,greyGreen},
477 {87,138,greyRed},
478 {95,138,blueGreen},
479 {105,138,red},
480 {113,138,greyBlueGreen},
481 {123,138,greyRed},
482 {131,138,blueGreen},
483 {141,138,red},
484 {149,138,greyBlueGreen},
486 {87,155,greyRed},
487 {95,155,blueGreen},
488 {105,155,red},
489 {113,155,greyBlueGreen},
490 {123,155,greyRed},
491 {131,155,blueGreen},
492 {141,155,red},
493 {149,155,greyBlueGreen},
495 {87,172,greyPink},
496 {95,172,green},
497 {105,172,pink},
498 {113,172,greyGreen},
499 {123,172,greyPink},
500 {131,172,green},
501 {141,172,pink},
502 {149,172,greyGreen},
504 {87,189,greyPink},
505 {95,189,green},
506 {105,189,pink},
507 {113,189,greyGreen},
508 {123,189,greyPink},
509 {131,189,green},
510 {141,189,pink},
511 {149,189,greyGreen},
513 {87,206,greyYellow},
514 {95,206,blue},
515 {105,206,yellow},
516 {113,206,greyBlue},
517 {123,206,greyYellow},
518 {131,206,blue},
519 {141,206,yellow},
520 {149,206,greyBlue},
522 {87,223,greyYellow},
523 {95,223,blue},
524 {105,223,yellow},
525 {113,223,greyBlue},
526 {123,223,greyYellow},
527 {131,223,blue},
528 {141,223,yellow},
529 {149,223,greyBlue},
531 {87,240,white},
532 {95,240,black},
533 {105,240,white},
534 {113,240,grey},
535 {123,240,white},
536 {131,240,black},
537 {141,240,white},
538 {149,240,grey},
540 {87,257,white},
541 {95,257,black},
542 {105,257,white},
543 {113,257,grey},
544 {123,257,white},
545 {131,257,black},
546 {141,257,white},
547 {149,257,grey},
549 //third column
550 {172,2,greyGreen},
551 {180,2,pink},
552 {190,2,green},
553 {198,2,greyPink},
554 {208,2,greyGreen},
555 {216,2,pink},
556 {226,2,green},
557 {234,2,greyPink},
559 {172,19,greyGreen},
560 {180,19,pink},
561 {190,19,green},
562 {198,19,greyPink},
563 {208,19,greyGreen},
564 {216,19,pink},
565 {226,19,green},
566 {234,19,greyPink},
568 {172,36,greyBlueGreen},
569 {180,36,red},
570 {190,36,blueGreen},
571 {198,36,greyRed},
572 {208,36,greyBlueGreen},
573 {216,36,red},
574 {226,36,blueGreen},
575 {234,36,greyRed},
577 {172,53,greyBlueGreen},
578 {180,53,red},
579 {190,53,blueGreen},
580 {198,53,greyRed},
581 {208,53,greyBlueGreen},
582 {216,53,red},
583 {226,53,blueGreen},
584 {234,53,greyRed},
586 {172,70,grey},
587 {180,70,white},
588 {190,70,black},
589 {198,70,white},
590 {208,70,grey},
591 {216,70,white},
592 {226,70,black},
593 {234,70,white},
595 {172,87,grey},
596 {180,87,white},
597 {190,87,black},
598 {198,87,white},
599 {208,87,grey},
600 {216,87,white},
601 {226,87,black},
602 {234,87,white},
604 {172,104,greyBlue},
605 {180,104,yellow},
606 {190,104,blue},
607 {198,104,greyYellow},
608 {208,104,greyBlue},
609 {216,104,yellow},
610 {226,104,blue},
611 {234,104,greyYellow},
613 {172,121,greyBlue},
614 {180,121,yellow},
615 {190,121,blue},
616 {198,121,greyYellow},
617 {208,121,greyBlue},
618 {216,121,yellow},
619 {226,121,blue},
620 {234,121,greyYellow},
622 {172,138,grey},
623 {180,138,white},
624 {190,138,black},
625 {198,138,white},
626 {208,138,grey},
627 {216,138,white},
628 {226,138,black},
629 {234,138,white},
631 {172,155,grey},
632 {180,155,white},
633 {190,155,black},
634 {198,155,white},
635 {208,155,grey},
636 {216,155,white},
637 {226,155,black},
638 {234,155,white},
640 {172,172,greyBlue},
641 {180,172,yellow},
642 {190,172,blue},
643 {198,172,greyYellow},
644 {208,172,greyBlue},
645 {216,172,yellow},
646 {226,172,blue},
647 {234,172,greyYellow},
649 {172,189,greyBlue},
650 {180,189,yellow},
651 {190,189,blue},
652 {198,189,greyYellow},
653 {208,189,greyBlue},
654 {216,189,yellow},
655 {226,189,blue},
656 {234,189,greyYellow},
658 {172,206,greyGreen},
659 {180,206,pink},
660 {190,206,green},
661 {198,206,greyPink},
662 {208,206,greyGreen},
663 {216,206,pink},
664 {226,206,green},
665 {234,206,greyPink},
667 {172,223,greyGreen},
668 {180,223,pink},
669 {190,223,green},
670 {198,223,greyPink},
671 {208,223,greyGreen},
672 {216,223,pink},
673 {226,223,green},
674 {234,223,greyPink},
676 {172,240,greyBlueGreen},
677 {180,240,red},
678 {190,240,blueGreen},
679 {198,240,greyRed},
680 {208,240,greyBlueGreen},
681 {216,240,red},
682 {226,240,blueGreen},
683 {234,240,greyRed},
685 {172,257,greyBlueGreen},
686 {180,257,red},
687 {190,257,blueGreen},
688 {198,257,greyRed},
689 {208,257,greyBlueGreen},
690 {216,257,red},
691 {226,257,blueGreen},
692 {234,257,greyRed},
694 //fourth column
695 {257,2,greyYellow},
696 {265,2,blue},
697 {275,2,yellow},
698 {283,2,greyBlue},
699 {293,2,greyYellow},
700 {301,2,blue},
701 {311,2,yellow},
702 {319,2,greyBlue},
704 {257,19,greyYellow},
705 {265,19,blue},
706 {275,19,yellow},
707 {283,19,greyBlue},
708 {293,19,greyYellow},
709 {301,19,blue},
710 {311,19,yellow},
711 {319,19,greyBlue},
713 {257,36,white},
714 {265,36,black},
715 {275,36,white},
716 {283,36,grey},
717 {293,36,white},
718 {301,36,black},
719 {311,36,white},
720 {319,36,grey},
722 {257,53,white},
723 {265,53,black},
724 {275,53,white},
725 {283,53,grey},
726 {293,53,white},
727 {301,53,black},
728 {311,53,white},
729 {319,53,grey},
731 {257,70,greyRed},
732 {265,70,blueGreen},
733 {275,70,red},
734 {283,70,greyBlueGreen},
735 {293,70,greyRed},
736 {301,70,blueGreen},
737 {311,70,red},
738 {319,70,greyBlueGreen},
740 {257,87,greyRed},
741 {265,87,blueGreen},
742 {275,87,red},
743 {283,87,greyBlueGreen},
744 {293,87,greyRed},
745 {301,87,blueGreen},
746 {311,87,red},
747 {319,87,greyBlueGreen},
749 {257,104,greyPink},
750 {265,104,green},
751 {275,104,pink},
752 {283,104,greyGreen},
753 {293,104,greyPink},
754 {301,104,green},
755 {311,104,pink},
756 {319,104,greyGreen},
758 {257,121,greyPink},
759 {265,121,green},
760 {275,121,pink},
761 {283,121,greyGreen},
762 {293,121,greyPink},
763 {301,121,green},
764 {311,121,pink},
765 {319,121,greyGreen},
767 {257,138,greyRed},
768 {265,138,blueGreen},
769 {275,138,red},
770 {283,138,greyBlueGreen},
771 {293,138,greyRed},
772 {301,138,blueGreen},
773 {311,138,red},
774 {319,138,greyBlueGreen},
776 {257,155,greyRed},
777 {265,155,blueGreen},
778 {275,155,red},
779 {283,155,greyBlueGreen},
780 {293,155,greyRed},
781 {301,155,blueGreen},
782 {311,155,red},
783 {319,155,greyBlueGreen},
785 {257,172,greyPink},
786 {265,172,green},
787 {275,172,pink},
788 {283,172,greyGreen},
789 {293,172,greyPink},
790 {301,172,green},
791 {311,172,pink},
792 {319,172,greyGreen},
794 {257,189,greyPink},
795 {265,189,green},
796 {275,189,pink},
797 {283,189,greyGreen},
798 {293,189,greyPink},
799 {301,189,green},
800 {311,189,pink},
801 {319,189,greyGreen},
803 {257,206,greyYellow},
804 {265,206,blue},
805 {275,206,yellow},
806 {283,206,greyBlue},
807 {293,206,greyYellow},
808 {301,206,blue},
809 {311,206,yellow},
810 {319,206,greyBlue},
812 {257,223,greyYellow},
813 {265,223,blue},
814 {275,223,yellow},
815 {283,223,greyBlue},
816 {293,223,greyYellow},
817 {301,223,blue},
818 {311,223,yellow},
819 {319,223,greyBlue},
821 {257,240,white},
822 {265,240,black},
823 {275,240,white},
824 {283,240,grey},
825 {293,240,white},
826 {301,240,black},
827 {311,240,white},
828 {319,240,grey},
830 {257,257,white},
831 {265,257,black},
832 {275,257,white},
833 {283,257,grey},
834 {293,257,white},
835 {301,257,black},
836 {311,257,white},
837 {319,257,grey},
838 {-1,-1,NULL}
842 for(i = 0; pass && (expect[i].color != NULL); ++i) {
843 pass = pass && piglit_probe_pixel_rgb(expect[i].x,
844 expect[i].y,
845 expect[i].color);
848 return pass;