2 * Copyright 2012 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
27 * Test to verify functionality of glDrawPixels() with various pixel formats
33 #include "piglit-util-gl.h"
35 /* Data conversions as used in mesa */
36 /** Convert GLubyte in [0,255] to GLfloat in [0.0,1.0] */
37 #define UBYTE_TO_FLOAT(u) ((float) u / 255.0F)
39 /** Convert GLbyte in [-128,127] to GLfloat in [-1.0,1.0] */
40 #define BYTE_TO_FLOAT(B) ((B) == -128 ? -1.0F : (B) * (1.0F/127.0F))
42 /** Convert GLushort in [0,65535] to GLfloat in [0.0,1.0] */
43 #define USHORT_TO_FLOAT(S) ((GLfloat) (S) * (1.0F / 65535.0F))
45 /** Convert GLshort in [-32768,32767] to GLfloat in [-1.0,1.0] */
46 #define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
48 /** Convert GLuint in [0,4294967295] to GLfloat in [0.0,1.0] */
49 #define UINT_TO_FLOAT(U) ((GLfloat) ((U) * (1.0F / 4294967295.0)))
51 /** Convert GLint in [-2147483648,2147483647] to GLfloat in [-1.0,1.0] */
52 #define INT_TO_FLOAT(I) ((GLfloat) ((2.0F * (I) + 1.0F) * (1.0F/4294967294.0)))
54 PIGLIT_GL_TEST_CONFIG_BEGIN
56 config
.supports_gl_compat_version
= 10;
58 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_STENCIL
;
60 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
62 PIGLIT_GL_TEST_CONFIG_END
64 const GLuint idx0
= 0, idx1
= 1, idx2
= 2, idx3
= 3;
65 static GLfloat expected
[100][4];
67 /*As per OpenGL 3.0 specification integer formats are not allowed in
70 static GLenum pixel_formats
[] = {
85 static GLenum data_types
[] = {
93 GL_UNSIGNED_BYTE_3_3_2
,
94 GL_UNSIGNED_BYTE_2_3_3_REV
,
95 GL_UNSIGNED_SHORT_5_6_5
,
96 GL_UNSIGNED_SHORT_5_6_5_REV
,
97 GL_UNSIGNED_SHORT_4_4_4_4
,
98 GL_UNSIGNED_SHORT_4_4_4_4_REV
,
99 GL_UNSIGNED_SHORT_5_5_5_1
,
100 GL_UNSIGNED_SHORT_1_5_5_5_REV
,
101 GL_UNSIGNED_INT_8_8_8_8
,
102 GL_UNSIGNED_INT_8_8_8_8_REV
,
103 GL_UNSIGNED_INT_10_10_10_2
,
104 GL_UNSIGNED_INT_2_10_10_10_REV
};
106 typedef struct p_ops
{
111 static const p_ops pixel_ops
[] = {
112 { GL_UNPACK_SWAP_BYTES
, 0 },
113 { GL_UNPACK_SWAP_BYTES
, 1 } };
116 void Swap2Byte(void *value
)
118 GLubyte
*bytes
= (GLubyte
*) value
;
119 GLubyte tmp
= bytes
[0];
124 void Swap4Byte(void *value
)
126 GLubyte
*bytes
= (GLubyte
*) value
;
127 GLubyte tmp
= bytes
[0];
135 bool is_format_type_mismatch(GLenum format
, GLenum type
)
137 if (((type
== GL_UNSIGNED_BYTE_3_3_2
||
138 type
== GL_UNSIGNED_BYTE_2_3_3_REV
||
139 type
== GL_UNSIGNED_SHORT_5_6_5
||
140 type
== GL_UNSIGNED_SHORT_5_6_5_REV
) &&
141 (format
!= GL_RGB
)) ||
143 ((type
== GL_UNSIGNED_SHORT_4_4_4_4
||
144 type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
||
145 type
== GL_UNSIGNED_SHORT_5_5_5_1
||
146 type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
||
147 type
== GL_UNSIGNED_INT_8_8_8_8
||
148 type
== GL_UNSIGNED_INT_8_8_8_8_REV
||
149 type
== GL_UNSIGNED_INT_10_10_10_2
||
150 type
== GL_UNSIGNED_INT_2_10_10_10_REV
) &&
151 (format
!= GL_RGBA
&&
159 allocPixels(GLenum format
, GLenum type
, GLuint components
)
163 GLuint npixels
= piglit_width
* piglit_height
;
167 pixels
= calloc(npixels
* components
, sizeof(GLbyte
));
168 for (i
= 0; i
< npixels
; i
++) {
169 for (j
= 0; j
< components
; j
++)
170 ((GLbyte
*)pixels
)[i
* components
+ j
] = 50 + j
* 4;
174 case GL_UNSIGNED_BYTE
:
175 pixels
= calloc(npixels
* components
, sizeof(GLubyte
));
176 for (i
= 0; i
< npixels
; i
++) {
177 for (j
= 0; j
< components
; j
++)
178 ((GLubyte
*)pixels
)[i
* components
+ j
] = 100 + j
* 4;
182 case GL_UNSIGNED_BYTE_3_3_2
:
183 case GL_UNSIGNED_BYTE_2_3_3_REV
:
184 pixels
= calloc(npixels
, sizeof(GLubyte
));
185 for (i
= 0; i
< npixels
; i
++) {
186 ((GLubyte
*)pixels
)[i
] = 0x99;
191 pixels
= calloc(npixels
* components
, sizeof(GLshort
));
192 for (i
= 0; i
< npixels
; i
++) {
193 for (j
= 0; j
< components
; j
++) {
194 ((GLshort
*)pixels
)[i
* components
+ j
] = 0x1234;
199 case GL_UNSIGNED_SHORT
:
200 pixels
= calloc(npixels
* components
, sizeof(GLushort
));
201 for (i
= 0; i
< npixels
; i
++) {
202 for (j
= 0; j
< components
; j
++) {
203 ((GLushort
*)pixels
)[i
* components
+ j
] = 0x4321;
208 case GL_UNSIGNED_SHORT_5_6_5
:
209 case GL_UNSIGNED_SHORT_5_6_5_REV
:
210 case GL_UNSIGNED_SHORT_4_4_4_4
:
211 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
212 case GL_UNSIGNED_SHORT_5_5_5_1
:
213 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
214 pixels
= calloc(npixels
, sizeof(GLushort
));
215 for (i
= 0; i
< npixels
; i
++)
216 ((GLushort
*)pixels
)[i
] = 0x9b59;
220 pixels
= calloc(npixels
* components
, sizeof(GLint
));
221 for (i
= 0; i
< npixels
; i
++) {
222 for (j
= 0; j
< components
; j
++) {
223 ((GLint
*)pixels
)[i
* components
+ j
] = 0x12345678;
228 case GL_UNSIGNED_INT
:
229 pixels
= calloc(npixels
* components
, sizeof(GLuint
));
230 for (i
= 0; i
< npixels
; i
++) {
231 for (j
= 0; j
< components
; j
++) {
232 ((GLuint
*)pixels
)[i
* components
+ j
] = 0x87654321;
237 case GL_UNSIGNED_INT_8_8_8_8
:
238 case GL_UNSIGNED_INT_8_8_8_8_REV
:
239 case GL_UNSIGNED_INT_10_10_10_2
:
240 case GL_UNSIGNED_INT_2_10_10_10_REV
:
241 pixels
= calloc(npixels
, sizeof(GLuint
));
242 for (i
= 0; i
< npixels
; i
++)
243 ((GLuint
*)pixels
)[i
] = 0x1a4b5a4b;
247 pixels
= calloc(npixels
* components
, sizeof(GLfloat
));
248 for (i
= 0; i
< npixels
; i
++) {
249 for (j
= 0; j
< components
; j
++) {
250 if (format
== GL_STENCIL_INDEX
)
251 ((GLfloat
*)pixels
)[i
* components
+ j
] =
254 ((GLfloat
*)pixels
)[i
* components
+ j
] =
261 assert(!"Unexpected data type");
269 pixelsInit(GLenum format
, GLenum type
)
277 case GL_DEPTH_COMPONENT
:
278 case GL_STENCIL_INDEX
:
279 return (allocPixels(format
, type
, 1));
280 case GL_LUMINANCE_ALPHA
:
282 return (allocPixels(format
, type
, 2));
285 return (allocPixels(format
, type
, 3));
288 return (allocPixels(format
, type
, 4));
290 printf("format = %s not allowed in glDrawPixels()\n",
291 piglit_get_gl_enum_name(format
));
292 piglit_report_result(PIGLIT_FAIL
);
298 typeToFloat(GLenum format
, GLenum type
, GLvoid
*src
,
299 GLuint index
, p_ops pixelops
)
302 GLuint pi
, pui
, mask
; GLushort pus
; GLshort ps
;
303 GLfloat pf
; GLint stencil_bits
; GLbyte pb
; GLubyte pub
;
304 const GLuint
*uisrc
; const GLushort
*ussrc
; const GLubyte
*ubsrc
;
305 GLfloat rs
= 1.0f
, gs
= 1.0f
, bs
= 1.0f
, as
= 1.0f
;
307 GLboolean swap
= (pixelops
.pname
== GL_UNPACK_SWAP_BYTES
) ?
308 pixelops
.param
: false;
310 if (format
== GL_STENCIL_INDEX
) {
312 glGetIntegerv(GL_STENCIL_BITS
, &stencil_bits
);
313 /* Clamp the return value to the size of stencil buffer */
314 mask
= 0xffffffff >> (sizeof(GLuint
) * 8 - stencil_bits
);
318 pb
= ((GLbyte
*)src
)[index
];
320 case GL_UNSIGNED_BYTE
:
321 pub
= ((GLubyte
*)src
)[index
];
324 ps
= ((GLshort
*)src
)[index
];
328 case GL_UNSIGNED_SHORT
:
329 pus
= ((GLushort
*)src
)[index
];
334 pi
= ((GLint
*)src
)[index
];
338 case GL_UNSIGNED_INT
:
339 pui
= ((GLuint
*)src
)[index
];
344 pf
= ((GLfloat
*)src
)[index
];
347 return (GLfloat
)((GLuint
)pf
& mask
);
349 printf("type = %s not allowed in glDrawPixels()\n",
350 piglit_get_gl_enum_name(type
));
351 piglit_report_result(PIGLIT_FAIL
);
357 return BYTE_TO_FLOAT(((GLbyte
*)src
)[index
]);
359 case GL_UNSIGNED_BYTE
:
360 return UBYTE_TO_FLOAT(((GLubyte
*)src
)[index
]);
362 case GL_UNSIGNED_BYTE_3_3_2
:
363 ubsrc
= (const GLubyte
*) src
;
369 return (((pub
>> 5) ) * rs
);
370 else if (index
== idx1
)
371 return (((pub
>> 2) & 0x7) * gs
);
372 else if (index
== idx2
)
373 return (((pub
) & 0x3) * bs
);
377 case GL_UNSIGNED_BYTE_2_3_3_REV
:
378 ubsrc
= (const GLubyte
*) src
;
384 return (((pub
) & 0x7) * rs
);
385 else if (index
== idx1
)
386 return (((pub
>> 3) & 0x7) * gs
);
387 else if (index
== idx2
)
388 return (((pub
>> 6) ) * bs
);
393 ps
= ((GLshort
*)src
)[index
];
396 return (SHORT_TO_FLOAT(ps
));
398 case GL_UNSIGNED_SHORT
:
399 pus
= ((GLushort
*)src
)[index
];
402 return (USHORT_TO_FLOAT(pus
));
404 case GL_UNSIGNED_SHORT_5_6_5
:
405 ussrc
= (const GLushort
*) src
;
413 return (((pus
>> 11) ) * rs
);
414 else if (index
== idx1
)
415 return (((pus
>> 5) & 0x3f) * gs
);
416 else if (index
== idx2
)
417 return (((pus
) & 0x1f) * bs
);
421 case GL_UNSIGNED_SHORT_5_6_5_REV
:
422 ussrc
= (const GLushort
*) src
;
430 return (((pus
) & 0x1f) * rs
);
431 else if (index
== idx1
)
432 return (((pus
>> 5) & 0x3f) * gs
);
433 else if (index
== idx2
)
434 return (((pus
>> 11) ) * bs
);
438 case GL_UNSIGNED_SHORT_4_4_4_4
:
439 ussrc
= (const GLushort
*) src
;
440 rs
= gs
= bs
= as
= 1.0F
/ 15.0F
;
445 return (((pus
>> 12) ) * rs
);
446 else if (index
== idx1
)
447 return (((pus
>> 8) & 0xf ) * gs
);
448 else if (index
== idx2
)
449 return (((pus
>> 4) & 0xf ) * bs
);
451 return (((pus
) & 0xf ) * as
);
453 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
454 ussrc
= (const GLushort
*) src
;
455 rs
= gs
= bs
= as
= 1.0F
/ 15.0F
;
460 return (((pus
) & 0xf ) * rs
);
461 else if (index
== idx1
)
462 return (((pus
>> 4) & 0xf ) * gs
);
463 else if (index
== idx2
)
464 return (((pus
>> 8) & 0xf ) * bs
);
466 return (((pus
>> 12) ) * as
);
468 case GL_UNSIGNED_SHORT_5_5_5_1
:
469 ussrc
= (const GLushort
*) src
;
470 rs
= gs
= bs
= 1.0F
/ 31.0F
;
475 return (((pus
>> 11) ) * rs
);
476 else if (index
== idx1
)
477 return (((pus
>> 6) & 0x1f) * gs
);
478 else if (index
== idx2
)
479 return (((pus
>> 1) & 0x1f) * bs
);
481 return (((pus
) & 0x1) * as
);
483 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
484 ussrc
= (const GLushort
*) src
;
485 rs
= gs
= bs
= 1.0F
/ 31.0F
;
490 return (((pus
) & 0x1f) * rs
);
491 else if (index
== idx1
)
492 return (((pus
>> 5) & 0x1f) * gs
);
493 else if (index
== idx2
)
494 return (((pus
>> 10) & 0x1f) * bs
);
496 return (((pus
>> 15) ) * as
);
499 pi
= ((GLint
*)src
)[index
];
502 return INT_TO_FLOAT(pi
);
504 case GL_UNSIGNED_INT
:
505 pui
= ((GLuint
*)src
)[index
];
508 return UINT_TO_FLOAT(pui
);
510 case GL_UNSIGNED_INT_8_8_8_8
:
511 uisrc
= (const GLuint
*) src
;
516 return UBYTE_TO_FLOAT(((pui
>> 24) ));
517 else if (index
== idx1
)
518 return UBYTE_TO_FLOAT(((pui
>> 16) & 0xff));
519 else if (index
== idx2
)
520 return UBYTE_TO_FLOAT(((pui
>> 8) & 0xff));
522 return UBYTE_TO_FLOAT(((pui
) & 0xff));
524 case GL_UNSIGNED_INT_8_8_8_8_REV
:
525 uisrc
= (const GLuint
*) src
;
530 return UBYTE_TO_FLOAT(((pui
) & 0xff));
531 else if (index
== idx1
)
532 return UBYTE_TO_FLOAT(((pui
>> 8) & 0xff));
533 else if (index
== idx2
)
534 return UBYTE_TO_FLOAT(((pui
>> 16) & 0xff));
536 return UBYTE_TO_FLOAT(((pui
>> 24) ));
538 case GL_UNSIGNED_INT_10_10_10_2
:
539 uisrc
= (const GLuint
*) src
;
548 return (((pui
>> 22) ) * rs
);
549 else if (index
== idx1
)
550 return (((pui
>> 12) & 0x3ff) * gs
);
551 else if (index
== idx2
)
552 return (((pui
>> 2) & 0x3ff) * bs
);
554 return (((pui
) & 0x3 ) * as
);
556 case GL_UNSIGNED_INT_2_10_10_10_REV
:
557 uisrc
= (const GLuint
*) src
;
566 return (((pui
) & 0x3ff) * rs
);
567 else if (index
== idx1
)
568 return (((pui
>> 10) & 0x3ff) * gs
);
569 else if (index
== idx2
)
570 return (((pui
>> 20) & 0x3ff) * bs
);
572 return (((pui
>> 30) ) * as
);
575 pf
= ((GLfloat
*)src
)[index
];
580 printf("type = %s not supported in glDrawPixels()\n",
581 piglit_get_gl_enum_name(format
));
582 piglit_report_result(PIGLIT_FAIL
);
591 return ((f
> 1.0f
) ? 1.0f
: ((f
< 0.0f
? 0.0f
: f
)));
595 computeExpected(GLenum format
, GLenum type
, GLuint index
,
596 p_ops pixelops
, GLvoid
*pixels
)
599 GLvoid
* src
= pixels
;
604 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
605 expected
[j
][0] = clampColor(fval
);
606 expected
[j
][1] = 0.0;
607 expected
[j
][2] = 0.0;
608 expected
[j
][3] = 1.0;
611 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
612 expected
[j
][0] = 0.0;
613 expected
[j
][1] = clampColor(fval
);
614 expected
[j
][2] = 0.0;
615 expected
[j
][3] = 1.0;
618 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
619 expected
[j
][0] = 0.0;
620 expected
[j
][1] = 0.0;
621 expected
[j
][2] = clampColor(fval
);
622 expected
[j
][3] = 1.0;
626 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
627 expected
[j
][0] = 0.0;
628 expected
[j
][1] = 0.0;
629 expected
[j
][2] = 0.0;
630 expected
[j
][3] = clampColor(fval
);
634 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
635 expected
[j
][0] = clampColor(fval
);
636 expected
[j
][1] = clampColor(fval
);
637 expected
[j
][2] = clampColor(fval
);
638 expected
[j
][3] = 1.0;
641 case GL_LUMINANCE_ALPHA
:
642 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
643 expected
[j
][0] = clampColor(fval
);
644 expected
[j
][1] = clampColor(fval
);
645 expected
[j
][2] = clampColor(fval
);
646 fval
= typeToFloat(format
, type
, src
, idx1
, pixelops
);
647 expected
[j
][3] = clampColor(fval
);
651 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
652 expected
[j
][0] = clampColor(fval
);
653 fval
= typeToFloat(format
, type
, src
, idx1
, pixelops
);
654 expected
[j
][1] = clampColor(fval
);
655 expected
[j
][2] = 0.0;
656 expected
[j
][3] = 1.0;
660 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
661 expected
[j
][0] = clampColor(fval
);
662 fval
= typeToFloat(format
, type
, src
, idx1
, pixelops
);
663 expected
[j
][1] = clampColor(fval
);
664 fval
= typeToFloat(format
, type
, src
, idx2
, pixelops
);
665 expected
[j
][2] = clampColor(fval
);
666 expected
[j
][3] = 1.0;
670 fval
= typeToFloat(format
, type
, src
, idx2
, pixelops
);
671 expected
[j
][0] = clampColor(fval
);
672 fval
= typeToFloat(format
, type
, src
, idx1
, pixelops
);
673 expected
[j
][1] = clampColor(fval
);
674 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
675 expected
[j
][2] = clampColor(fval
);
676 expected
[j
][3] = 1.0;
680 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
681 expected
[j
][0] = clampColor(fval
);
682 fval
= typeToFloat(format
, type
, src
, idx1
, pixelops
);
683 expected
[j
][1] = clampColor(fval
);
684 fval
= typeToFloat(format
, type
, src
, idx2
, pixelops
);
685 expected
[j
][2] = clampColor(fval
);
686 fval
= typeToFloat(format
, type
, src
, idx3
, pixelops
);
687 expected
[j
][3] = clampColor(fval
);
691 fval
= typeToFloat(format
, type
, src
, idx2
, pixelops
);
692 expected
[j
][0] = clampColor(fval
);
693 fval
= typeToFloat(format
, type
, src
, idx1
, pixelops
);
694 expected
[j
][1] = clampColor(fval
);
695 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
696 expected
[j
][2] = clampColor(fval
);
697 fval
= typeToFloat(format
, type
, src
, idx3
, pixelops
);
698 expected
[j
][3] = clampColor(fval
);
701 case GL_DEPTH_COMPONENT
:
702 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
703 expected
[j
][0] = clampColor(fval
);
706 case GL_STENCIL_INDEX
:
707 fval
= typeToFloat(format
, type
, src
, idx0
, pixelops
);
708 expected
[j
][0] = fval
;
714 report_failure(GLenum format
, GLenum type
)
716 printf(" Failed with format %s, type %s\n",
717 piglit_get_gl_enum_name(format
),
718 piglit_get_gl_enum_name(type
));
726 GLvoid
*pixels
= NULL
;
728 GLfloat black
[4] = {0.0, 0.0, 0.0, 1.0};
729 GLfloat red
[4] = {1.0, 0.0, 0.0, 1.0};
731 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
733 for (i
= 0; i
< ARRAY_SIZE(data_types
); i
++) {
734 for (k
= 0; k
< ARRAY_SIZE(pixel_ops
); k
++) {
735 for (j
= 0; j
< ARRAY_SIZE(pixel_formats
); j
++) {
737 format
= pixel_formats
[j
];
738 type
= data_types
[i
];
740 if (is_format_type_mismatch(format
, type
)) {
741 if (piglit_khr_no_error
)
744 glDrawPixels(piglit_width
, piglit_height
,
745 format
, type
, pixels
);
746 /* Here GL_INVALID_OPERATION is an
749 pass
= piglit_check_gl_error(
750 GL_INVALID_OPERATION
)
755 if (type
== GL_UNSIGNED_BYTE_3_3_2
||
756 type
== GL_UNSIGNED_BYTE_2_3_3_REV
)
757 piglit_set_tolerance_for_bits(7, 7, 7, 7);
759 piglit_set_tolerance_for_bits(8, 8, 8, 8);
761 if (!piglit_automatic
)
762 printf("Format = %s, Type = %s,"
763 " Swap Bytes = %d\n",
764 piglit_get_gl_enum_name(format
),
765 piglit_get_gl_enum_name(type
),
768 pixels
= pixelsInit(format
, type
);
769 computeExpected(format
, type
, j
, pixel_ops
[k
], pixels
);
771 glClear(GL_COLOR_BUFFER_BIT
);
772 /* Enable/Disable byte swap while unpacking pixels */
773 glPixelStorei(pixel_ops
[k
].pname
, pixel_ops
[k
].param
);
778 if (!piglit_is_extension_supported(
779 "GL_ARB_texture_rg")) {
780 if (!piglit_automatic
)
781 printf("GL_RG skipped\n");
790 case GL_LUMINANCE_ALPHA
:
795 glDrawPixels(piglit_width
, piglit_height
,
796 format
, type
, pixels
);
798 pass
= piglit_check_gl_error(GL_NO_ERROR
)
800 p
= piglit_probe_rect_rgba(0, 0,
801 piglit_width
, piglit_height
,
804 report_failure(format
, type
);
809 case GL_DEPTH_COMPONENT
:
810 glEnable(GL_DEPTH_TEST
);
812 glDepthFunc(GL_ALWAYS
);
813 glClear(GL_DEPTH_BUFFER_BIT
);
814 glDrawPixels(piglit_width
, piglit_height
,
815 format
, type
, pixels
);
817 pass
= piglit_check_gl_error(GL_NO_ERROR
)
819 p
= piglit_probe_rect_depth(0, 0,
820 piglit_width
, piglit_height
,
823 report_failure(format
, type
);
826 glDisable(GL_DEPTH_TEST
);
829 case GL_STENCIL_INDEX
:
831 glClear(GL_STENCIL_BUFFER_BIT
);
832 glDrawPixels(piglit_width
, piglit_height
,
833 format
, type
, pixels
);
835 pass
= piglit_check_gl_error(GL_NO_ERROR
)
837 /* Probe stencil buffer */
838 p
= piglit_probe_rect_stencil(0, 0,
843 report_failure(format
, type
);
847 glEnable(GL_STENCIL_TEST
);
848 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
849 glStencilFunc(GL_EQUAL
, 1, ~0);
850 glColor4f(1.0, 0.0, 0.0, 1.0);
851 piglit_draw_rect(0, 0, piglit_width
,
854 /* Probe color buffer. Color buffer will
855 * stay unaffected by piglit_draw_rect()
857 p
= piglit_probe_rect_rgba(0, 0,
858 piglit_width
, piglit_height
,
861 report_failure(format
, type
);
865 glStencilFunc(GL_EQUAL
, expected
[j
][0], ~0);
866 piglit_draw_rect(0, 0, piglit_width
,
868 p
= piglit_probe_rect_rgba(0, 0,
869 piglit_width
, piglit_height
,
872 report_failure(format
, type
);
876 glDisable(GL_STENCIL_TEST
);
883 piglit_present_results();
888 return (pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
892 piglit_init(int argc
, char **argv
)
894 glClearColor(0.0, 0.0, 0.0, 1.0);
895 piglit_ortho_projection(piglit_width
, piglit_height
, GL_TRUE
);