2 * Mesa 3-D graphics library
4 * Copyright (c) 2011 VMware, Inc.
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 shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Color, depth, stencil packing functions.
27 * Used to pack basic color, depth and stencil formats to specific
30 * There are both per-pixel and per-row packing functions:
31 * - The former will be used by swrast to write values to the color, depth,
32 * stencil buffers when drawing points, lines and masked spans.
33 * - The later will be used for image-oriented functions like glDrawPixels,
34 * glAccum, and glTexImage.
39 #include "format_pack.h"
43 typedef void (*pack_ubyte_rgba_row_func
)(GLuint n
,
44 const GLubyte src
[][4], void *dst
);
46 typedef void (*pack_float_rgba_row_func
)(GLuint n
,
47 const GLfloat src
[][4], void *dst
);
50 * MESA_FORMAT_RGBA8888
54 pack_ubyte_RGBA8888(const GLubyte src
[4], void *dst
)
56 GLuint
*d
= ((GLuint
*) dst
);
57 *d
= PACK_COLOR_8888(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
61 pack_float_RGBA8888(const GLfloat src
[4], void *dst
)
64 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
65 pack_ubyte_RGBA8888(v
, dst
);
69 pack_row_ubyte_RGBA8888(GLuint n
, const GLubyte src
[][4], void *dst
)
71 GLuint
*d
= ((GLuint
*) dst
);
73 for (i
= 0; i
< n
; i
++) {
74 d
[i
] = PACK_COLOR_8888(src
[i
][RCOMP
], src
[i
][GCOMP
],
75 src
[i
][BCOMP
], src
[i
][ACOMP
]);
80 pack_row_float_RGBA8888(GLuint n
, const GLfloat src
[][4], void *dst
)
82 GLuint
*d
= ((GLuint
*) dst
);
84 for (i
= 0; i
< n
; i
++) {
86 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
87 pack_ubyte_RGBA8888(v
, d
+ i
);
94 * MESA_FORMAT_RGBA8888_REV
98 pack_ubyte_RGBA8888_REV(const GLubyte src
[4], void *dst
)
100 GLuint
*d
= ((GLuint
*) dst
);
101 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[BCOMP
], src
[GCOMP
], src
[RCOMP
]);
105 pack_float_RGBA8888_REV(const GLfloat src
[4], void *dst
)
108 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
109 pack_ubyte_RGBA8888_REV(v
, dst
);
113 pack_row_ubyte_RGBA8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
115 GLuint
*d
= ((GLuint
*) dst
);
117 for (i
= 0; i
< n
; i
++) {
118 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][BCOMP
],
119 src
[i
][GCOMP
], src
[i
][RCOMP
]);
124 pack_row_float_RGBA8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
126 GLuint
*d
= ((GLuint
*) dst
);
128 for (i
= 0; i
< n
; i
++) {
130 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
131 pack_ubyte_RGBA8888_REV(v
, d
+ i
);
137 * MESA_FORMAT_ARGB8888
141 pack_ubyte_ARGB8888(const GLubyte src
[4], void *dst
)
143 GLuint
*d
= ((GLuint
*) dst
);
144 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
148 pack_float_ARGB8888(const GLfloat src
[4], void *dst
)
151 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
152 pack_ubyte_ARGB8888(v
, dst
);
156 pack_row_ubyte_ARGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
158 GLuint
*d
= ((GLuint
*) dst
);
160 for (i
= 0; i
< n
; i
++) {
161 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][RCOMP
],
162 src
[i
][GCOMP
], src
[i
][BCOMP
]);
167 pack_row_float_ARGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
169 GLuint
*d
= ((GLuint
*) dst
);
171 for (i
= 0; i
< n
; i
++) {
173 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
174 pack_ubyte_ARGB8888(v
, d
+ i
);
180 * MESA_FORMAT_ARGB8888_REV
184 pack_ubyte_ARGB8888_REV(const GLubyte src
[4], void *dst
)
186 GLuint
*d
= ((GLuint
*) dst
);
187 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
191 pack_float_ARGB8888_REV(const GLfloat src
[4], void *dst
)
194 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
195 pack_ubyte_ARGB8888_REV(v
, dst
);
199 pack_row_ubyte_ARGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
201 GLuint
*d
= ((GLuint
*) dst
);
203 for (i
= 0; i
< n
; i
++) {
204 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
],
205 src
[i
][RCOMP
], src
[i
][ACOMP
]);
210 pack_row_float_ARGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
212 GLuint
*d
= ((GLuint
*) dst
);
214 for (i
= 0; i
< n
; i
++) {
216 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
217 pack_ubyte_ARGB8888_REV(v
, d
+ i
);
223 * MESA_FORMAT_XRGB8888
227 pack_ubyte_XRGB8888(const GLubyte src
[4], void *dst
)
229 GLuint
*d
= ((GLuint
*) dst
);
230 *d
= PACK_COLOR_8888(0x0, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
234 pack_float_XRGB8888(const GLfloat src
[4], void *dst
)
237 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
238 pack_ubyte_XRGB8888(v
, dst
);
242 pack_row_ubyte_XRGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
244 GLuint
*d
= ((GLuint
*) dst
);
246 for (i
= 0; i
< n
; i
++) {
247 d
[i
] = PACK_COLOR_8888(0, src
[i
][RCOMP
], src
[i
][GCOMP
], src
[i
][BCOMP
]);
252 pack_row_float_XRGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
254 GLuint
*d
= ((GLuint
*) dst
);
256 for (i
= 0; i
< n
; i
++) {
258 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
259 pack_ubyte_XRGB8888(v
, d
+ i
);
265 * MESA_FORMAT_XRGB8888_REV
269 pack_ubyte_XRGB8888_REV(const GLubyte src
[4], void *dst
)
271 GLuint
*d
= ((GLuint
*) dst
);
272 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], 0);
276 pack_float_XRGB8888_REV(const GLfloat src
[4], void *dst
)
279 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
280 pack_ubyte_XRGB8888_REV(v
, dst
);
284 pack_row_ubyte_XRGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
286 GLuint
*d
= ((GLuint
*) dst
);
288 for (i
= 0; i
< n
; i
++) {
289 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
], src
[i
][RCOMP
], 0);
294 pack_row_float_XRGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
296 GLuint
*d
= ((GLuint
*) dst
);
298 for (i
= 0; i
< n
; i
++) {
300 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
301 pack_ubyte_XRGB8888_REV(v
, d
+ i
);
311 pack_ubyte_RGB888(const GLubyte src
[4], void *dst
)
313 GLubyte
*d
= ((GLubyte
*) dst
);
320 pack_float_RGB888(const GLfloat src
[4], void *dst
)
322 GLubyte
*d
= ((GLubyte
*) dst
);
323 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[RCOMP
]);
324 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
325 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[BCOMP
]);
329 pack_row_ubyte_RGB888(GLuint n
, const GLubyte src
[][4], void *dst
)
331 GLubyte
*d
= ((GLubyte
*) dst
);
333 for (i
= 0; i
< n
; i
++) {
334 d
[i
*3+2] = src
[i
][RCOMP
];
335 d
[i
*3+1] = src
[i
][GCOMP
];
336 d
[i
*3+0] = src
[i
][BCOMP
];
341 pack_row_float_RGB888(GLuint n
, const GLfloat src
[][4], void *dst
)
343 GLubyte
*d
= ((GLubyte
*) dst
);
345 for (i
= 0; i
< n
; i
++) {
347 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
360 pack_ubyte_BGR888(const GLubyte src
[4], void *dst
)
362 GLubyte
*d
= ((GLubyte
*) dst
);
369 pack_float_BGR888(const GLfloat src
[4], void *dst
)
371 GLubyte
*d
= ((GLubyte
*) dst
);
372 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[BCOMP
]);
373 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
374 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
378 pack_row_ubyte_BGR888(GLuint n
, const GLubyte src
[][4], void *dst
)
380 GLubyte
*d
= ((GLubyte
*) dst
);
382 for (i
= 0; i
< n
; i
++) {
383 d
[i
*3+2] = src
[i
][BCOMP
];
384 d
[i
*3+1] = src
[i
][GCOMP
];
385 d
[i
*3+0] = src
[i
][RCOMP
];
390 pack_row_float_BGR888(GLuint n
, const GLfloat src
[][4], void *dst
)
392 GLubyte
*d
= ((GLubyte
*) dst
);
394 for (i
= 0; i
< n
; i
++) {
396 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
409 pack_ubyte_RGB565(const GLubyte src
[4], void *dst
)
411 GLushort
*d
= ((GLushort
*) dst
);
412 *d
= PACK_COLOR_565(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
416 pack_float_RGB565(const GLfloat src
[4], void *dst
)
419 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
420 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
421 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
422 pack_ubyte_RGB565(v
, dst
);
426 pack_row_ubyte_RGB565(GLuint n
, const GLubyte src
[][4], void *dst
)
428 GLushort
*d
= ((GLushort
*) dst
);
430 for (i
= 0; i
< n
; i
++) {
431 pack_ubyte_RGB565(src
[i
], d
+ i
);
436 pack_row_float_RGB565(GLuint n
, const GLfloat src
[][4], void *dst
)
438 GLushort
*d
= ((GLushort
*) dst
);
440 for (i
= 0; i
< n
; i
++) {
442 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
443 pack_ubyte_RGB565(v
, d
+ i
);
449 * MESA_FORMAT_RGB565_REV
453 pack_ubyte_RGB565_REV(const GLubyte src
[4], void *dst
)
455 GLushort
*d
= ((GLushort
*) dst
);
456 *d
= PACK_COLOR_565_REV(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
460 pack_float_RGB565_REV(const GLfloat src
[4], void *dst
)
462 GLushort
*d
= ((GLushort
*) dst
);
464 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
465 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
466 UNCLAMPED_FLOAT_TO_UBYTE(b
, src
[BCOMP
]);
467 *d
= PACK_COLOR_565_REV(r
, g
, b
);
471 pack_row_ubyte_RGB565_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
473 GLushort
*d
= ((GLushort
*) dst
);
475 for (i
= 0; i
< n
; i
++) {
476 pack_ubyte_RGB565_REV(src
[i
], d
+ i
);
481 pack_row_float_RGB565_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
483 GLushort
*d
= ((GLushort
*) dst
);
485 for (i
= 0; i
< n
; i
++) {
487 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
488 pack_ubyte_RGB565_REV(v
, d
+ i
);
494 * MESA_FORMAT_ARGB4444
498 pack_ubyte_ARGB4444(const GLubyte src
[4], void *dst
)
500 GLushort
*d
= ((GLushort
*) dst
);
501 *d
= PACK_COLOR_4444(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
505 pack_float_ARGB4444(const GLfloat src
[4], void *dst
)
508 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
509 pack_ubyte_ARGB4444(v
, dst
);
512 /* use fallback row packing functions */
516 * MESA_FORMAT_ARGB4444_REV
520 pack_ubyte_ARGB4444_REV(const GLubyte src
[4], void *dst
)
522 GLushort
*d
= ((GLushort
*) dst
);
523 *d
= PACK_COLOR_4444(src
[GCOMP
], src
[BCOMP
], src
[ACOMP
], src
[RCOMP
]);
527 pack_float_ARGB4444_REV(const GLfloat src
[4], void *dst
)
530 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
531 pack_ubyte_ARGB4444_REV(v
, dst
);
534 /* use fallback row packing functions */
538 * MESA_FORMAT_RGBA5551
542 pack_ubyte_RGBA5551(const GLubyte src
[4], void *dst
)
544 GLushort
*d
= ((GLushort
*) dst
);
545 *d
= PACK_COLOR_5551(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
549 pack_float_RGBA5551(const GLfloat src
[4], void *dst
)
552 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
553 pack_ubyte_RGBA5551(v
, dst
);
556 /* use fallback row packing functions */
560 * MESA_FORMAT_ARGB1555
564 pack_ubyte_ARGB1555(const GLubyte src
[4], void *dst
)
566 GLushort
*d
= ((GLushort
*) dst
);
567 *d
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
571 pack_float_ARGB1555(const GLfloat src
[4], void *dst
)
574 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
575 pack_ubyte_ARGB1555(v
, dst
);
579 /* MESA_FORMAT_ARGB1555_REV */
582 pack_ubyte_ARGB1555_REV(const GLubyte src
[4], void *dst
)
584 GLushort
*d
= ((GLushort
*) dst
), tmp
;
585 tmp
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
586 *d
= (tmp
>> 8) | (tmp
<< 8);
590 pack_float_ARGB1555_REV(const GLfloat src
[4], void *dst
)
593 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
594 pack_ubyte_ARGB1555_REV(v
, dst
);
598 /* MESA_FORMAT_AL44 */
601 pack_ubyte_AL44(const GLubyte src
[4], void *dst
)
603 GLubyte
*d
= ((GLubyte
*) dst
);
604 *d
= PACK_COLOR_44(src
[ACOMP
], src
[RCOMP
]);
608 pack_float_AL44(const GLfloat src
[4], void *dst
)
611 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
612 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
613 pack_ubyte_AL44(v
, dst
);
617 /* MESA_FORMAT_AL88 */
620 pack_ubyte_AL88(const GLubyte src
[4], void *dst
)
622 GLushort
*d
= ((GLushort
*) dst
);
623 *d
= PACK_COLOR_88(src
[ACOMP
], src
[RCOMP
]);
627 pack_float_AL88(const GLfloat src
[4], void *dst
)
630 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
631 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
632 pack_ubyte_AL88(v
, dst
);
636 /* MESA_FORMAT_AL88_REV */
639 pack_ubyte_AL88_REV(const GLubyte src
[4], void *dst
)
641 GLushort
*d
= ((GLushort
*) dst
);
642 *d
= PACK_COLOR_88(src
[RCOMP
], src
[ACOMP
]);
646 pack_float_AL88_REV(const GLfloat src
[4], void *dst
)
649 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
650 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
651 pack_ubyte_AL88_REV(v
, dst
);
655 /* MESA_FORMAT_AL1616 */
658 pack_ubyte_AL1616(const GLubyte src
[4], void *dst
)
660 GLuint
*d
= ((GLuint
*) dst
);
661 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
662 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
663 *d
= PACK_COLOR_1616(a
, l
);
667 pack_float_AL1616(const GLfloat src
[4], void *dst
)
669 GLuint
*d
= ((GLuint
*) dst
);
671 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
672 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
673 *d
= PACK_COLOR_1616(a
, l
);
677 /* MESA_FORMAT_AL1616_REV */
680 pack_ubyte_AL1616_REV(const GLubyte src
[4], void *dst
)
682 GLuint
*d
= ((GLuint
*) dst
);
683 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
684 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
685 *d
= PACK_COLOR_1616(l
, a
);
689 pack_float_AL1616_REV(const GLfloat src
[4], void *dst
)
691 GLuint
*d
= ((GLuint
*) dst
);
693 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
694 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
695 *d
= PACK_COLOR_1616(l
, a
);
699 /* MESA_FORMAT_RGB332 */
702 pack_ubyte_RGB332(const GLubyte src
[4], void *dst
)
704 GLubyte
*d
= ((GLubyte
*) dst
);
705 *d
= PACK_COLOR_332(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
709 pack_float_RGB332(const GLfloat src
[4], void *dst
)
712 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
713 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
714 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
715 pack_ubyte_RGB332(v
, dst
);
722 pack_ubyte_A8(const GLubyte src
[4], void *dst
)
724 GLubyte
*d
= ((GLubyte
*) dst
);
729 pack_float_A8(const GLfloat src
[4], void *dst
)
731 GLubyte
*d
= ((GLubyte
*) dst
);
732 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[ACOMP
]);
736 /* MESA_FORMAT_A16 */
739 pack_ubyte_A16(const GLubyte src
[4], void *dst
)
741 GLushort
*d
= ((GLushort
*) dst
);
742 *d
= UBYTE_TO_USHORT(src
[ACOMP
]);
746 pack_float_A16(const GLfloat src
[4], void *dst
)
748 GLushort
*d
= ((GLushort
*) dst
);
749 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[ACOMP
]);
756 pack_ubyte_L8(const GLubyte src
[4], void *dst
)
758 GLubyte
*d
= ((GLubyte
*) dst
);
763 pack_float_L8(const GLfloat src
[4], void *dst
)
765 GLubyte
*d
= ((GLubyte
*) dst
);
766 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
770 /* MESA_FORMAT_L16 */
773 pack_ubyte_L16(const GLubyte src
[4], void *dst
)
775 GLushort
*d
= ((GLushort
*) dst
);
776 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
780 pack_float_L16(const GLfloat src
[4], void *dst
)
782 GLushort
*d
= ((GLushort
*) dst
);
783 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
787 /* MESA_FORMAT_YCBCR */
790 pack_ubyte_YCBCR(const GLubyte src
[4], void *dst
)
796 pack_float_YCBCR(const GLfloat src
[4], void *dst
)
802 /* MESA_FORMAT_YCBCR_REV */
805 pack_ubyte_YCBCR_REV(const GLubyte src
[4], void *dst
)
811 pack_float_YCBCR_REV(const GLfloat src
[4], void *dst
)
817 /* MESA_FORMAT_RGBA_FLOAT32 */
820 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
822 GLfloat
*d
= ((GLfloat
*) dst
);
823 d
[0] = UBYTE_TO_FLOAT(src
[0]);
824 d
[1] = UBYTE_TO_FLOAT(src
[1]);
825 d
[2] = UBYTE_TO_FLOAT(src
[2]);
826 d
[3] = UBYTE_TO_FLOAT(src
[3]);
830 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
832 GLfloat
*d
= ((GLfloat
*) dst
);
840 /* MESA_FORMAT_RGBA_FLOAT16 */
843 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
845 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
846 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
847 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
848 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
849 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
853 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
855 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
856 d
[0] = _mesa_float_to_half(src
[0]);
857 d
[1] = _mesa_float_to_half(src
[1]);
858 d
[2] = _mesa_float_to_half(src
[2]);
859 d
[3] = _mesa_float_to_half(src
[3]);
863 /* MESA_FORMAT_RGB_FLOAT32 */
866 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
868 GLfloat
*d
= ((GLfloat
*) dst
);
869 d
[0] = UBYTE_TO_FLOAT(src
[0]);
870 d
[1] = UBYTE_TO_FLOAT(src
[1]);
871 d
[2] = UBYTE_TO_FLOAT(src
[2]);
875 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
877 GLfloat
*d
= ((GLfloat
*) dst
);
884 /* MESA_FORMAT_RGB_FLOAT16 */
887 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
889 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
890 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
891 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
892 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
896 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
898 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
899 d
[0] = _mesa_float_to_half(src
[0]);
900 d
[1] = _mesa_float_to_half(src
[1]);
901 d
[2] = _mesa_float_to_half(src
[2]);
905 /* MESA_FORMAT_ALPHA_FLOAT32 */
908 pack_ubyte_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
910 GLfloat
*d
= ((GLfloat
*) dst
);
911 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
915 pack_float_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
917 GLfloat
*d
= ((GLfloat
*) dst
);
922 /* MESA_FORMAT_ALPHA_FLOAT16 */
925 pack_ubyte_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
927 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
928 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
932 pack_float_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
934 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
935 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
939 /* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
942 pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src
[4], void *dst
)
944 GLfloat
*d
= ((GLfloat
*) dst
);
945 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
949 pack_float_LUMINANCE_FLOAT32(const GLfloat src
[4], void *dst
)
951 GLfloat
*d
= ((GLfloat
*) dst
);
956 /* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
959 pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src
[4], void *dst
)
961 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
962 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
966 pack_float_LUMINANCE_FLOAT16(const GLfloat src
[4], void *dst
)
968 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
969 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
973 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
976 pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
978 GLfloat
*d
= ((GLfloat
*) dst
);
979 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
980 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
984 pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
986 GLfloat
*d
= ((GLfloat
*) dst
);
992 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
995 pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
997 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
998 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
999 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1003 pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1005 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1006 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1007 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1011 /* MESA_FORMAT_RGBA_16 */
1014 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1016 GLushort
*d
= ((GLushort
*) dst
);
1017 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1018 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1019 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1020 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1024 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1026 GLushort
*d
= ((GLushort
*) dst
);
1027 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1028 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1029 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1030 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1034 * MESA_FORMAT_SIGNED_RGBA_16
1038 pack_float_SIGNED_RGBA_16(const GLfloat src
[4], void *dst
)
1040 GLshort
*d
= (GLshort
*) dst
;
1041 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1042 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1043 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1044 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1050 * Return a function that can pack a GLubyte rgba[4] color.
1052 gl_pack_ubyte_rgba_func
1053 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1055 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1056 static GLboolean initialized
= GL_FALSE
;
1059 memset(table
, 0, sizeof(table
));
1061 table
[MESA_FORMAT_NONE
] = NULL
;
1063 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1064 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1065 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1066 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1067 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1068 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1069 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1070 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1071 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1072 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1073 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1074 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1075 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1076 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1077 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1078 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1079 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1080 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1081 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1082 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1083 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1084 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1085 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1086 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1087 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1088 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1089 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1090 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1091 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1092 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1093 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1095 /* should never convert RGBA to these formats */
1096 table
[MESA_FORMAT_Z16
] = NULL
;
1097 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1098 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1099 table
[MESA_FORMAT_Z32
] = NULL
;
1100 table
[MESA_FORMAT_S8
] = NULL
;
1102 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1103 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1104 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1105 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1106 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1107 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1108 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1109 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1110 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1111 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1112 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1113 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1116 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1117 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1118 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1119 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1120 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1121 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1123 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1125 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1128 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1130 initialized
= GL_TRUE
;
1133 return table
[format
];
1139 * Return a function that can pack a GLfloat rgba[4] color.
1141 gl_pack_float_rgba_func
1142 _mesa_get_pack_float_rgba_function(gl_format format
)
1144 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1145 static GLboolean initialized
= GL_FALSE
;
1148 memset(table
, 0, sizeof(table
));
1150 table
[MESA_FORMAT_NONE
] = NULL
;
1152 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
1153 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
1154 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
1155 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
1156 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
1157 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
1158 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
1159 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
1160 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
1161 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
1162 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
1163 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
1164 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
1165 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
1166 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
1167 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
1168 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
1170 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
1171 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
1172 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
1173 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
1174 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
1175 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
1176 table
[MESA_FORMAT_A8
] = pack_float_A8
;
1177 table
[MESA_FORMAT_A16
] = pack_float_A16
;
1178 table
[MESA_FORMAT_L8
] = pack_float_L8
;
1179 table
[MESA_FORMAT_L16
] = pack_float_L16
;
1180 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
1181 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
1182 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
1183 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
1185 /* should never convert RGBA to these formats */
1186 table
[MESA_FORMAT_Z16
] = NULL
;
1187 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1188 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1189 table
[MESA_FORMAT_Z32
] = NULL
;
1190 table
[MESA_FORMAT_S8
] = NULL
;
1192 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
1193 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
1194 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
1195 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
1196 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
1197 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
1198 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1199 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1200 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
1201 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
1203 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1204 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1207 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
1208 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
1209 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
1210 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
1211 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
1212 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
1214 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
1216 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
1219 initialized
= GL_TRUE
;
1222 return table
[format
];
1227 static pack_float_rgba_row_func
1228 get_pack_float_rgba_row_function(gl_format format
)
1230 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
1231 static GLboolean initialized
= GL_FALSE
;
1234 /* We don't need a special row packing function for each format.
1235 * There's a generic fallback which uses a per-pixel packing function.
1237 memset(table
, 0, sizeof(table
));
1239 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
1240 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
1241 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
1242 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
1243 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
1244 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
1245 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
1246 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
1247 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
1248 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
1249 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
1250 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
1252 initialized
= GL_TRUE
;
1255 return table
[format
];
1260 static pack_ubyte_rgba_row_func
1261 get_pack_ubyte_rgba_row_function(gl_format format
)
1263 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
1264 static GLboolean initialized
= GL_FALSE
;
1267 /* We don't need a special row packing function for each format.
1268 * There's a generic fallback which uses a per-pixel packing function.
1270 memset(table
, 0, sizeof(table
));
1272 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
1273 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
1274 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
1275 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
1276 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
1277 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
1278 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
1279 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
1280 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
1281 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
1282 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
1283 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
1285 initialized
= GL_TRUE
;
1288 return table
[format
];
1294 * Pack a row of GLfloat rgba[4] values to the destination.
1297 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
1298 const GLfloat src
[][4], void *dst
)
1300 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
1302 /* use "fast" function */
1303 packrow(n
, src
, dst
);
1306 /* slower fallback */
1307 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
1308 GLuint dstStride
= _mesa_get_format_bytes(format
);
1309 GLubyte
*dstPtr
= (GLubyte
*) dst
;
1316 for (i
= 0; i
< n
; i
++) {
1317 pack(src
[i
], dstPtr
);
1318 dstPtr
+= dstStride
;
1325 * Pack a row of GLubyte rgba[4] values to the destination.
1328 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
1329 const GLubyte src
[][4], void *dst
)
1331 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
1333 /* use "fast" function */
1334 packrow(n
, src
, dst
);
1337 /* slower fallback */
1338 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
1339 const GLuint stride
= _mesa_get_format_bytes(format
);
1340 GLubyte
*d
= ((GLubyte
*) dst
);
1347 for (i
= 0; i
< n
; i
++) {
1356 ** Pack float Z pixels
1360 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
1362 /* don't disturb the stencil values */
1363 GLuint
*d
= ((GLuint
*) dst
);
1364 const GLdouble scale
= (GLdouble
) 0xffffff;
1365 GLuint s
= *d
& 0xff;
1366 GLuint z
= (GLuint
) (*src
* scale
);
1367 assert(z
<= 0xffffff);
1372 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
1374 /* don't disturb the stencil values */
1375 GLuint
*d
= ((GLuint
*) dst
);
1376 const GLdouble scale
= (GLdouble
) 0xffffff;
1377 GLuint s
= *d
& 0xff000000;
1378 GLuint z
= (GLuint
) (*src
* scale
);
1379 assert(z
<= 0xffffff);
1384 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
1386 GLushort
*d
= ((GLushort
*) dst
);
1387 const GLfloat scale
= (GLfloat
) 0xffff;
1388 *d
= (GLushort
) (*src
* scale
);
1392 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
1394 GLuint
*d
= ((GLuint
*) dst
);
1395 const GLdouble scale
= (GLdouble
) 0xffffffff;
1396 *d
= (GLuint
) (*src
* scale
);
1399 gl_pack_float_z_func
1400 _mesa_get_pack_float_z_func(gl_format format
)
1403 case MESA_FORMAT_Z24_X8
:
1404 return pack_float_z_Z24_S8
;
1405 case MESA_FORMAT_X8_Z24
:
1406 return pack_float_z_S8_Z24
;
1407 case MESA_FORMAT_Z16
:
1408 return pack_float_z_Z16
;
1409 case MESA_FORMAT_Z32
:
1410 return pack_float_z_Z32
;
1413 "unexpected format in _mesa_get_pack_float_z_func()");
1421 ** Pack uint Z pixels. The incoming src value is always in
1422 ** the range [0, 2^32-1].
1426 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
1428 /* don't disturb the stencil values */
1429 GLuint
*d
= ((GLuint
*) dst
);
1430 GLuint s
= *d
& 0xff;
1431 GLuint z
= *src
& 0xffffff00;
1436 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
1438 /* don't disturb the stencil values */
1439 GLuint
*d
= ((GLuint
*) dst
);
1440 GLuint s
= *d
& 0xff000000;
1441 GLuint z
= *src
>> 8;
1446 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
1448 GLushort
*d
= ((GLushort
*) dst
);
1453 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
1455 GLuint
*d
= ((GLuint
*) dst
);
1460 _mesa_get_pack_uint_z_func(gl_format format
)
1463 case MESA_FORMAT_Z24_X8
:
1464 return pack_uint_z_Z24_S8
;
1465 case MESA_FORMAT_X8_Z24
:
1466 return pack_uint_z_S8_Z24
;
1467 case MESA_FORMAT_Z16
:
1468 return pack_uint_z_Z16
;
1469 case MESA_FORMAT_Z32
:
1470 return pack_uint_z_Z32
;
1472 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
1479 ** Pack ubyte stencil pixels
1483 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
1485 GLubyte
*d
= (GLubyte
*) dst
;
1490 gl_pack_ubyte_stencil_func
1491 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
1493 return pack_ubyte_stencil_S8
;
1499 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
1500 const GLfloat
*src
, void *dst
)
1503 case MESA_FORMAT_Z24_X8
:
1505 /* don't disturb the stencil values */
1506 GLuint
*d
= ((GLuint
*) dst
);
1507 const GLdouble scale
= (GLdouble
) 0xffffff;
1509 for (i
= 0; i
< n
; i
++) {
1510 GLuint s
= d
[i
] & 0xff;
1511 GLuint z
= (GLuint
) (src
[i
] * scale
);
1512 assert(z
<= 0xffffff);
1513 d
[i
] = (z
<< 8) | s
;
1517 case MESA_FORMAT_X8_Z24
:
1519 /* don't disturb the stencil values */
1520 GLuint
*d
= ((GLuint
*) dst
);
1521 const GLdouble scale
= (GLdouble
) 0xffffff;
1523 for (i
= 0; i
< n
; i
++) {
1524 GLuint s
= d
[i
] & 0xff000000;
1525 GLuint z
= (GLuint
) (src
[i
] * scale
);
1526 assert(z
<= 0xffffff);
1531 case MESA_FORMAT_Z16
:
1533 GLushort
*d
= ((GLushort
*) dst
);
1534 const GLfloat scale
= (GLfloat
) 0xffff;
1536 for (i
= 0; i
< n
; i
++) {
1537 d
[i
] = (GLushort
) (src
[i
] * scale
);
1541 case MESA_FORMAT_Z32
:
1543 GLuint
*d
= ((GLuint
*) dst
);
1544 const GLdouble scale
= (GLdouble
) 0xffffffff;
1546 for (i
= 0; i
< n
; i
++) {
1547 d
[i
] = (GLuint
) (src
[i
] * scale
);
1552 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
1558 * The incoming Z values are always in the range [0, 0xffffffff].
1561 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
1562 const GLuint
*src
, void *dst
)
1565 case MESA_FORMAT_Z24_X8
:
1567 /* don't disturb the stencil values */
1568 GLuint
*d
= ((GLuint
*) dst
);
1570 for (i
= 0; i
< n
; i
++) {
1571 GLuint s
= d
[i
] & 0xff;
1572 GLuint z
= src
[i
] & 0xffffff00;
1577 case MESA_FORMAT_X8_Z24
:
1579 /* don't disturb the stencil values */
1580 GLuint
*d
= ((GLuint
*) dst
);
1582 for (i
= 0; i
< n
; i
++) {
1583 GLuint s
= d
[i
] & 0xff000000;
1584 GLuint z
= src
[i
] >> 8;
1589 case MESA_FORMAT_Z16
:
1591 GLushort
*d
= ((GLushort
*) dst
);
1593 for (i
= 0; i
< n
; i
++) {
1594 d
[i
] = src
[i
] >> 16;
1598 case MESA_FORMAT_Z32
:
1599 memcpy(dst
, src
, n
* sizeof(GLfloat
));
1602 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
1608 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
1609 const GLubyte
*src
, void *dst
)
1611 memcpy(dst
, src
, n
* sizeof(GLubyte
));
1616 * Convert a boolean color mask to a packed color where each channel of
1617 * the packed value at dst will be 0 or ~0 depending on the colorMask.
1620 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
1622 GLfloat maskColor
[4];
1624 switch (_mesa_get_format_datatype(format
)) {
1625 case GL_UNSIGNED_NORMALIZED
:
1626 /* simple: 1.0 will convert to ~0 in the right bit positions */
1627 maskColor
[0] = colorMask
[0] ? 1.0 : 0.0;
1628 maskColor
[1] = colorMask
[1] ? 1.0 : 0.0;
1629 maskColor
[2] = colorMask
[2] ? 1.0 : 0.0;
1630 maskColor
[3] = colorMask
[3] ? 1.0 : 0.0;
1631 _mesa_pack_float_rgba_row(format
, 1,
1632 (const GLfloat (*)[4]) maskColor
, dst
);
1634 case GL_SIGNED_NORMALIZED
:
1636 /* These formats are harder because it's hard to know the floating
1637 * point values that will convert to ~0 for each color channel's bits.
1638 * This solution just generates a non-zero value for each color channel
1639 * then fixes up the non-zero values to be ~0.
1640 * Note: we'll need to add special case code if we ever have to deal
1641 * with formats with unequal color channel sizes, like R11_G11_B10.
1642 * We issue a warning below for channel sizes other than 8,16,32.
1645 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
1646 GLuint bytes
= _mesa_get_format_bytes(format
);
1649 /* this should put non-zero values into the channels of dst */
1650 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
1651 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
1652 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
1653 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
1654 _mesa_pack_float_rgba_row(format
, 1,
1655 (const GLfloat (*)[4]) maskColor
, dst
);
1657 /* fix-up the dst channels by converting non-zero values to ~0 */
1659 GLubyte
*d
= (GLubyte
*) dst
;
1660 for (i
= 0; i
< bytes
; i
++) {
1661 d
[i
] = d
[i
] ? 0xffff : 0x0;
1664 else if (bits
== 16) {
1665 GLushort
*d
= (GLushort
*) dst
;
1666 for (i
= 0; i
< bytes
/ 2; i
++) {
1667 d
[i
] = d
[i
] ? 0xffff : 0x0;
1670 else if (bits
== 32) {
1671 GLuint
*d
= (GLuint
*) dst
;
1672 for (i
= 0; i
< bytes
/ 4; i
++) {
1673 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
1677 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
1683 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");