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
);
52 linear_to_srgb(GLfloat cl
)
56 else if (cl
< 0.0031308f
)
59 return 1.055f
* powf(cl
, 0.41666f
) - 0.055f
;
66 linear_float_to_srgb_ubyte(GLfloat cl
)
68 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
));
74 linear_ubyte_to_srgb_ubyte(GLubyte cl
)
76 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
/ 255.0f
));
84 * MESA_FORMAT_RGBA8888
88 pack_ubyte_RGBA8888(const GLubyte src
[4], void *dst
)
90 GLuint
*d
= ((GLuint
*) dst
);
91 *d
= PACK_COLOR_8888(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
95 pack_float_RGBA8888(const GLfloat src
[4], void *dst
)
98 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
99 pack_ubyte_RGBA8888(v
, dst
);
103 pack_row_ubyte_RGBA8888(GLuint n
, const GLubyte src
[][4], void *dst
)
105 GLuint
*d
= ((GLuint
*) dst
);
107 for (i
= 0; i
< n
; i
++) {
108 d
[i
] = PACK_COLOR_8888(src
[i
][RCOMP
], src
[i
][GCOMP
],
109 src
[i
][BCOMP
], src
[i
][ACOMP
]);
114 pack_row_float_RGBA8888(GLuint n
, const GLfloat src
[][4], void *dst
)
116 GLuint
*d
= ((GLuint
*) dst
);
118 for (i
= 0; i
< n
; i
++) {
120 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
121 pack_ubyte_RGBA8888(v
, d
+ i
);
128 * MESA_FORMAT_RGBA8888_REV
132 pack_ubyte_RGBA8888_REV(const GLubyte src
[4], void *dst
)
134 GLuint
*d
= ((GLuint
*) dst
);
135 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[BCOMP
], src
[GCOMP
], src
[RCOMP
]);
139 pack_float_RGBA8888_REV(const GLfloat src
[4], void *dst
)
142 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
143 pack_ubyte_RGBA8888_REV(v
, dst
);
147 pack_row_ubyte_RGBA8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
149 GLuint
*d
= ((GLuint
*) dst
);
151 for (i
= 0; i
< n
; i
++) {
152 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][BCOMP
],
153 src
[i
][GCOMP
], src
[i
][RCOMP
]);
158 pack_row_float_RGBA8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
160 GLuint
*d
= ((GLuint
*) dst
);
162 for (i
= 0; i
< n
; i
++) {
164 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
165 pack_ubyte_RGBA8888_REV(v
, d
+ i
);
171 * MESA_FORMAT_ARGB8888
175 pack_ubyte_ARGB8888(const GLubyte src
[4], void *dst
)
177 GLuint
*d
= ((GLuint
*) dst
);
178 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
182 pack_float_ARGB8888(const GLfloat src
[4], void *dst
)
185 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
186 pack_ubyte_ARGB8888(v
, dst
);
190 pack_row_ubyte_ARGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
192 GLuint
*d
= ((GLuint
*) dst
);
194 for (i
= 0; i
< n
; i
++) {
195 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][RCOMP
],
196 src
[i
][GCOMP
], src
[i
][BCOMP
]);
201 pack_row_float_ARGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
203 GLuint
*d
= ((GLuint
*) dst
);
205 for (i
= 0; i
< n
; i
++) {
207 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
208 pack_ubyte_ARGB8888(v
, d
+ i
);
214 * MESA_FORMAT_ARGB8888_REV
218 pack_ubyte_ARGB8888_REV(const GLubyte src
[4], void *dst
)
220 GLuint
*d
= ((GLuint
*) dst
);
221 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
225 pack_float_ARGB8888_REV(const GLfloat src
[4], void *dst
)
228 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
229 pack_ubyte_ARGB8888_REV(v
, dst
);
233 pack_row_ubyte_ARGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
235 GLuint
*d
= ((GLuint
*) dst
);
237 for (i
= 0; i
< n
; i
++) {
238 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
],
239 src
[i
][RCOMP
], src
[i
][ACOMP
]);
244 pack_row_float_ARGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
246 GLuint
*d
= ((GLuint
*) dst
);
248 for (i
= 0; i
< n
; i
++) {
250 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
251 pack_ubyte_ARGB8888_REV(v
, d
+ i
);
257 * MESA_FORMAT_XRGB8888
261 pack_ubyte_XRGB8888(const GLubyte src
[4], void *dst
)
263 GLuint
*d
= ((GLuint
*) dst
);
264 *d
= PACK_COLOR_8888(0x0, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
268 pack_float_XRGB8888(const GLfloat src
[4], void *dst
)
271 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
272 pack_ubyte_XRGB8888(v
, dst
);
276 pack_row_ubyte_XRGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
278 GLuint
*d
= ((GLuint
*) dst
);
280 for (i
= 0; i
< n
; i
++) {
281 d
[i
] = PACK_COLOR_8888(0, src
[i
][RCOMP
], src
[i
][GCOMP
], src
[i
][BCOMP
]);
286 pack_row_float_XRGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
288 GLuint
*d
= ((GLuint
*) dst
);
290 for (i
= 0; i
< n
; i
++) {
292 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
293 pack_ubyte_XRGB8888(v
, d
+ i
);
299 * MESA_FORMAT_XRGB8888_REV
303 pack_ubyte_XRGB8888_REV(const GLubyte src
[4], void *dst
)
305 GLuint
*d
= ((GLuint
*) dst
);
306 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], 0);
310 pack_float_XRGB8888_REV(const GLfloat src
[4], void *dst
)
313 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
314 pack_ubyte_XRGB8888_REV(v
, dst
);
318 pack_row_ubyte_XRGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
320 GLuint
*d
= ((GLuint
*) dst
);
322 for (i
= 0; i
< n
; i
++) {
323 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
], src
[i
][RCOMP
], 0);
328 pack_row_float_XRGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
330 GLuint
*d
= ((GLuint
*) dst
);
332 for (i
= 0; i
< n
; i
++) {
334 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
335 pack_ubyte_XRGB8888_REV(v
, d
+ i
);
345 pack_ubyte_RGB888(const GLubyte src
[4], void *dst
)
347 GLubyte
*d
= ((GLubyte
*) dst
);
354 pack_float_RGB888(const GLfloat src
[4], void *dst
)
356 GLubyte
*d
= ((GLubyte
*) dst
);
357 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[RCOMP
]);
358 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
359 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[BCOMP
]);
363 pack_row_ubyte_RGB888(GLuint n
, const GLubyte src
[][4], void *dst
)
365 GLubyte
*d
= ((GLubyte
*) dst
);
367 for (i
= 0; i
< n
; i
++) {
368 d
[i
*3+2] = src
[i
][RCOMP
];
369 d
[i
*3+1] = src
[i
][GCOMP
];
370 d
[i
*3+0] = src
[i
][BCOMP
];
375 pack_row_float_RGB888(GLuint n
, const GLfloat src
[][4], void *dst
)
377 GLubyte
*d
= ((GLubyte
*) dst
);
379 for (i
= 0; i
< n
; i
++) {
381 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
394 pack_ubyte_BGR888(const GLubyte src
[4], void *dst
)
396 GLubyte
*d
= ((GLubyte
*) dst
);
403 pack_float_BGR888(const GLfloat src
[4], void *dst
)
405 GLubyte
*d
= ((GLubyte
*) dst
);
406 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[BCOMP
]);
407 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
408 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
412 pack_row_ubyte_BGR888(GLuint n
, const GLubyte src
[][4], void *dst
)
414 GLubyte
*d
= ((GLubyte
*) dst
);
416 for (i
= 0; i
< n
; i
++) {
417 d
[i
*3+2] = src
[i
][BCOMP
];
418 d
[i
*3+1] = src
[i
][GCOMP
];
419 d
[i
*3+0] = src
[i
][RCOMP
];
424 pack_row_float_BGR888(GLuint n
, const GLfloat src
[][4], void *dst
)
426 GLubyte
*d
= ((GLubyte
*) dst
);
428 for (i
= 0; i
< n
; i
++) {
430 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
443 pack_ubyte_RGB565(const GLubyte src
[4], void *dst
)
445 GLushort
*d
= ((GLushort
*) dst
);
446 *d
= PACK_COLOR_565(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
450 pack_float_RGB565(const GLfloat src
[4], void *dst
)
453 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
454 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
455 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
456 pack_ubyte_RGB565(v
, dst
);
460 pack_row_ubyte_RGB565(GLuint n
, const GLubyte src
[][4], void *dst
)
462 GLushort
*d
= ((GLushort
*) dst
);
464 for (i
= 0; i
< n
; i
++) {
465 pack_ubyte_RGB565(src
[i
], d
+ i
);
470 pack_row_float_RGB565(GLuint n
, const GLfloat src
[][4], void *dst
)
472 GLushort
*d
= ((GLushort
*) dst
);
474 for (i
= 0; i
< n
; i
++) {
476 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
477 pack_ubyte_RGB565(v
, d
+ i
);
483 * MESA_FORMAT_RGB565_REV
487 pack_ubyte_RGB565_REV(const GLubyte src
[4], void *dst
)
489 GLushort
*d
= ((GLushort
*) dst
);
490 *d
= PACK_COLOR_565_REV(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
494 pack_float_RGB565_REV(const GLfloat src
[4], void *dst
)
496 GLushort
*d
= ((GLushort
*) dst
);
498 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
499 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
500 UNCLAMPED_FLOAT_TO_UBYTE(b
, src
[BCOMP
]);
501 *d
= PACK_COLOR_565_REV(r
, g
, b
);
505 pack_row_ubyte_RGB565_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
507 GLushort
*d
= ((GLushort
*) dst
);
509 for (i
= 0; i
< n
; i
++) {
510 pack_ubyte_RGB565_REV(src
[i
], d
+ i
);
515 pack_row_float_RGB565_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
517 GLushort
*d
= ((GLushort
*) dst
);
519 for (i
= 0; i
< n
; i
++) {
521 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
522 pack_ubyte_RGB565_REV(v
, d
+ i
);
528 * MESA_FORMAT_ARGB4444
532 pack_ubyte_ARGB4444(const GLubyte src
[4], void *dst
)
534 GLushort
*d
= ((GLushort
*) dst
);
535 *d
= PACK_COLOR_4444(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
539 pack_float_ARGB4444(const GLfloat src
[4], void *dst
)
542 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
543 pack_ubyte_ARGB4444(v
, dst
);
546 /* use fallback row packing functions */
550 * MESA_FORMAT_ARGB4444_REV
554 pack_ubyte_ARGB4444_REV(const GLubyte src
[4], void *dst
)
556 GLushort
*d
= ((GLushort
*) dst
);
557 *d
= PACK_COLOR_4444(src
[GCOMP
], src
[BCOMP
], src
[ACOMP
], src
[RCOMP
]);
561 pack_float_ARGB4444_REV(const GLfloat src
[4], void *dst
)
564 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
565 pack_ubyte_ARGB4444_REV(v
, dst
);
568 /* use fallback row packing functions */
572 * MESA_FORMAT_RGBA5551
576 pack_ubyte_RGBA5551(const GLubyte src
[4], void *dst
)
578 GLushort
*d
= ((GLushort
*) dst
);
579 *d
= PACK_COLOR_5551(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
583 pack_float_RGBA5551(const GLfloat src
[4], void *dst
)
586 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
587 pack_ubyte_RGBA5551(v
, dst
);
590 /* use fallback row packing functions */
594 * MESA_FORMAT_ARGB1555
598 pack_ubyte_ARGB1555(const GLubyte src
[4], void *dst
)
600 GLushort
*d
= ((GLushort
*) dst
);
601 *d
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
605 pack_float_ARGB1555(const GLfloat src
[4], void *dst
)
608 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
609 pack_ubyte_ARGB1555(v
, dst
);
613 /* MESA_FORMAT_ARGB1555_REV */
616 pack_ubyte_ARGB1555_REV(const GLubyte src
[4], void *dst
)
618 GLushort
*d
= ((GLushort
*) dst
), tmp
;
619 tmp
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
620 *d
= (tmp
>> 8) | (tmp
<< 8);
624 pack_float_ARGB1555_REV(const GLfloat src
[4], void *dst
)
627 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
628 pack_ubyte_ARGB1555_REV(v
, dst
);
632 /* MESA_FORMAT_AL44 */
635 pack_ubyte_AL44(const GLubyte src
[4], void *dst
)
637 GLubyte
*d
= ((GLubyte
*) dst
);
638 *d
= PACK_COLOR_44(src
[ACOMP
], src
[RCOMP
]);
642 pack_float_AL44(const GLfloat src
[4], void *dst
)
645 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
646 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
647 pack_ubyte_AL44(v
, dst
);
651 /* MESA_FORMAT_AL88 */
654 pack_ubyte_AL88(const GLubyte src
[4], void *dst
)
656 GLushort
*d
= ((GLushort
*) dst
);
657 *d
= PACK_COLOR_88(src
[ACOMP
], src
[RCOMP
]);
661 pack_float_AL88(const GLfloat src
[4], void *dst
)
664 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
665 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
666 pack_ubyte_AL88(v
, dst
);
670 /* MESA_FORMAT_AL88_REV */
673 pack_ubyte_AL88_REV(const GLubyte src
[4], void *dst
)
675 GLushort
*d
= ((GLushort
*) dst
);
676 *d
= PACK_COLOR_88(src
[RCOMP
], src
[ACOMP
]);
680 pack_float_AL88_REV(const GLfloat src
[4], void *dst
)
683 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
684 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
685 pack_ubyte_AL88_REV(v
, dst
);
689 /* MESA_FORMAT_AL1616 */
692 pack_ubyte_AL1616(const GLubyte src
[4], void *dst
)
694 GLuint
*d
= ((GLuint
*) dst
);
695 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
696 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
697 *d
= PACK_COLOR_1616(a
, l
);
701 pack_float_AL1616(const GLfloat src
[4], void *dst
)
703 GLuint
*d
= ((GLuint
*) dst
);
705 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
706 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
707 *d
= PACK_COLOR_1616(a
, l
);
711 /* MESA_FORMAT_AL1616_REV */
714 pack_ubyte_AL1616_REV(const GLubyte src
[4], void *dst
)
716 GLuint
*d
= ((GLuint
*) dst
);
717 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
718 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
719 *d
= PACK_COLOR_1616(l
, a
);
723 pack_float_AL1616_REV(const GLfloat src
[4], void *dst
)
725 GLuint
*d
= ((GLuint
*) dst
);
727 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
728 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
729 *d
= PACK_COLOR_1616(l
, a
);
733 /* MESA_FORMAT_RGB332 */
736 pack_ubyte_RGB332(const GLubyte src
[4], void *dst
)
738 GLubyte
*d
= ((GLubyte
*) dst
);
739 *d
= PACK_COLOR_332(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
743 pack_float_RGB332(const GLfloat src
[4], void *dst
)
746 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
747 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
748 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
749 pack_ubyte_RGB332(v
, dst
);
756 pack_ubyte_A8(const GLubyte src
[4], void *dst
)
758 GLubyte
*d
= ((GLubyte
*) dst
);
763 pack_float_A8(const GLfloat src
[4], void *dst
)
765 GLubyte
*d
= ((GLubyte
*) dst
);
766 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[ACOMP
]);
770 /* MESA_FORMAT_A16 */
773 pack_ubyte_A16(const GLubyte src
[4], void *dst
)
775 GLushort
*d
= ((GLushort
*) dst
);
776 *d
= UBYTE_TO_USHORT(src
[ACOMP
]);
780 pack_float_A16(const GLfloat src
[4], void *dst
)
782 GLushort
*d
= ((GLushort
*) dst
);
783 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[ACOMP
]);
790 pack_ubyte_L8(const GLubyte src
[4], void *dst
)
792 GLubyte
*d
= ((GLubyte
*) dst
);
797 pack_float_L8(const GLfloat src
[4], void *dst
)
799 GLubyte
*d
= ((GLubyte
*) dst
);
800 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
804 /* MESA_FORMAT_L16 */
807 pack_ubyte_L16(const GLubyte src
[4], void *dst
)
809 GLushort
*d
= ((GLushort
*) dst
);
810 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
814 pack_float_L16(const GLfloat src
[4], void *dst
)
816 GLushort
*d
= ((GLushort
*) dst
);
817 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
821 /* MESA_FORMAT_YCBCR */
824 pack_ubyte_YCBCR(const GLubyte src
[4], void *dst
)
830 pack_float_YCBCR(const GLfloat src
[4], void *dst
)
836 /* MESA_FORMAT_YCBCR_REV */
839 pack_ubyte_YCBCR_REV(const GLubyte src
[4], void *dst
)
845 pack_float_YCBCR_REV(const GLfloat src
[4], void *dst
)
854 pack_ubyte_R8(const GLubyte src
[4], void *dst
)
856 GLubyte
*d
= ((GLubyte
*) dst
);
861 pack_float_R8(const GLfloat src
[4], void *dst
)
863 GLubyte
*d
= ((GLubyte
*) dst
);
865 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
870 /* MESA_FORMAT_GR88 */
873 pack_ubyte_GR88(const GLubyte src
[4], void *dst
)
875 GLubyte
*d
= ((GLubyte
*) dst
);
876 *d
= PACK_COLOR_88(src
[GCOMP
], src
[RCOMP
]);
880 pack_float_GR88(const GLfloat src
[4], void *dst
)
882 GLushort
*d
= ((GLushort
*) dst
);
884 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
885 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
886 *d
= PACK_COLOR_88(g
, r
);
890 /* MESA_FORMAT_RG88 */
893 pack_ubyte_RG88(const GLubyte src
[4], void *dst
)
895 GLubyte
*d
= ((GLubyte
*) dst
);
896 *d
= PACK_COLOR_88(src
[RCOMP
], src
[GCOMP
]);
900 pack_float_RG88(const GLfloat src
[4], void *dst
)
902 GLushort
*d
= ((GLushort
*) dst
);
904 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
905 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
906 *d
= PACK_COLOR_88(r
, g
);
910 /* MESA_FORMAT_R16 */
913 pack_ubyte_R16(const GLubyte src
[4], void *dst
)
915 GLushort
*d
= ((GLushort
*) dst
);
916 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
920 pack_float_R16(const GLfloat src
[4], void *dst
)
922 GLushort
*d
= ((GLushort
*) dst
);
923 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
927 /* MESA_FORMAT_RG1616 */
930 pack_ubyte_RG1616(const GLubyte src
[4], void *dst
)
932 GLuint
*d
= ((GLuint
*) dst
);
933 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
934 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
935 *d
= PACK_COLOR_1616(g
, r
);
939 pack_float_RG1616(const GLfloat src
[4], void *dst
)
941 GLuint
*d
= ((GLuint
*) dst
);
943 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
944 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
945 *d
= PACK_COLOR_1616(g
, r
);
949 /* MESA_FORMAT_RG1616_REV */
952 pack_ubyte_RG1616_REV(const GLubyte src
[4], void *dst
)
954 GLuint
*d
= ((GLuint
*) dst
);
955 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
956 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
957 *d
= PACK_COLOR_1616(r
, g
);
962 pack_float_RG1616_REV(const GLfloat src
[4], void *dst
)
964 GLuint
*d
= ((GLuint
*) dst
);
966 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
967 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
968 *d
= PACK_COLOR_1616(r
, g
);
972 /* MESA_FORMAT_ARGB2101010 */
975 pack_ubyte_ARGB2101010(const GLubyte src
[4], void *dst
)
977 GLuint
*d
= ((GLuint
*) dst
);
978 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
979 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
980 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
981 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
982 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
986 pack_float_ARGB2101010(const GLfloat src
[4], void *dst
)
988 GLuint
*d
= ((GLuint
*) dst
);
990 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
991 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
992 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
993 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
994 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
998 /* MESA_FORMAT_SRGB8 */
1001 pack_ubyte_SRGB8(const GLubyte src
[4], void *dst
)
1003 GLubyte
*d
= ((GLubyte
*) dst
);
1004 d
[2] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1005 d
[1] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1006 d
[0] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1010 pack_float_SRGB8(const GLfloat src
[4], void *dst
)
1012 GLubyte
*d
= ((GLubyte
*) dst
);
1013 d
[2] = linear_float_to_srgb_ubyte(src
[RCOMP
]);
1014 d
[1] = linear_float_to_srgb_ubyte(src
[GCOMP
]);
1015 d
[0] = linear_float_to_srgb_ubyte(src
[BCOMP
]);
1019 /* MESA_FORMAT_SRGBA8 */
1022 pack_ubyte_SRGBA8(const GLubyte src
[4], void *dst
)
1024 GLuint
*d
= ((GLuint
*) dst
);
1025 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1026 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[GCOMP
]);
1027 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[BCOMP
]);
1028 *d
= PACK_COLOR_8888(r
, g
, b
, src
[ACOMP
]);
1032 pack_float_SRGBA8(const GLfloat src
[4], void *dst
)
1034 GLuint
*d
= ((GLuint
*) dst
);
1036 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1037 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1038 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1039 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1040 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1044 /* MESA_FORMAT_SARGB8 */
1047 pack_ubyte_SARGB8(const GLubyte src
[4], void *dst
)
1049 GLuint
*d
= ((GLuint
*) dst
);
1050 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1051 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1052 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1053 *d
= PACK_COLOR_8888(src
[ACOMP
], r
, g
, b
);
1057 pack_float_SARGB8(const GLfloat src
[4], void *dst
)
1059 GLuint
*d
= ((GLuint
*) dst
);
1061 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1062 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1063 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1064 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1065 *d
= PACK_COLOR_8888(a
, r
, g
, b
);
1069 /* MESA_FORMAT_SL8 */
1072 pack_ubyte_SL8(const GLubyte src
[4], void *dst
)
1074 GLubyte
*d
= ((GLubyte
*) dst
);
1075 *d
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1079 pack_float_SL8(const GLfloat src
[4], void *dst
)
1081 GLubyte
*d
= ((GLubyte
*) dst
);
1082 GLubyte l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1087 /* MESA_FORMAT_SLA8 */
1090 pack_ubyte_SLA8(const GLubyte src
[4], void *dst
)
1092 GLushort
*d
= ((GLushort
*) dst
);
1093 GLubyte l
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1094 *d
= PACK_COLOR_88(src
[ACOMP
], l
);
1098 pack_float_SLA8(const GLfloat src
[4], void *dst
)
1100 GLushort
*d
= ((GLushort
*) dst
);
1101 GLubyte a
, l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1102 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1103 *d
= PACK_COLOR_88(a
, l
);
1107 /* MESA_FORMAT_RGBA_FLOAT32 */
1110 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
1112 GLfloat
*d
= ((GLfloat
*) dst
);
1113 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1114 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1115 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1116 d
[3] = UBYTE_TO_FLOAT(src
[3]);
1120 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
1122 GLfloat
*d
= ((GLfloat
*) dst
);
1130 /* MESA_FORMAT_RGBA_FLOAT16 */
1133 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
1135 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1136 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1137 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1138 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1139 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
1143 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
1145 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1146 d
[0] = _mesa_float_to_half(src
[0]);
1147 d
[1] = _mesa_float_to_half(src
[1]);
1148 d
[2] = _mesa_float_to_half(src
[2]);
1149 d
[3] = _mesa_float_to_half(src
[3]);
1153 /* MESA_FORMAT_RGB_FLOAT32 */
1156 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
1158 GLfloat
*d
= ((GLfloat
*) dst
);
1159 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1160 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1161 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1165 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
1167 GLfloat
*d
= ((GLfloat
*) dst
);
1174 /* MESA_FORMAT_RGB_FLOAT16 */
1177 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
1179 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1180 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1181 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1182 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1186 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
1188 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1189 d
[0] = _mesa_float_to_half(src
[0]);
1190 d
[1] = _mesa_float_to_half(src
[1]);
1191 d
[2] = _mesa_float_to_half(src
[2]);
1195 /* MESA_FORMAT_ALPHA_FLOAT32 */
1198 pack_ubyte_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1200 GLfloat
*d
= ((GLfloat
*) dst
);
1201 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1205 pack_float_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1207 GLfloat
*d
= ((GLfloat
*) dst
);
1212 /* MESA_FORMAT_ALPHA_FLOAT16 */
1215 pack_ubyte_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1217 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1218 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1222 pack_float_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1224 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1225 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
1229 /* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
1232 pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src
[4], void *dst
)
1234 GLfloat
*d
= ((GLfloat
*) dst
);
1235 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1239 pack_float_LUMINANCE_FLOAT32(const GLfloat src
[4], void *dst
)
1241 GLfloat
*d
= ((GLfloat
*) dst
);
1246 /* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
1249 pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src
[4], void *dst
)
1251 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1252 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1256 pack_float_LUMINANCE_FLOAT16(const GLfloat src
[4], void *dst
)
1258 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1259 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1263 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
1266 pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1268 GLfloat
*d
= ((GLfloat
*) dst
);
1269 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1270 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1274 pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1276 GLfloat
*d
= ((GLfloat
*) dst
);
1282 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
1285 pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1287 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1288 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1289 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1293 pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1295 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1296 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1297 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1301 /* MESA_FORMAT_RG_FLOAT32 */
1304 pack_ubyte_RG_FLOAT32(const GLubyte src
[4], void *dst
)
1306 GLfloat
*d
= ((GLfloat
*) dst
);
1307 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1308 d
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1312 pack_float_RG_FLOAT32(const GLfloat src
[4], void *dst
)
1314 GLfloat
*d
= ((GLfloat
*) dst
);
1320 /* MESA_FORMAT_RG_FLOAT16 */
1323 pack_ubyte_RG_FLOAT16(const GLubyte src
[4], void *dst
)
1325 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1326 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1327 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[GCOMP
]));
1331 pack_float_RG_FLOAT16(const GLfloat src
[4], void *dst
)
1333 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1334 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1335 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1339 /* MESA_FORMAT_DUDV8 */
1342 pack_ubyte_DUDV8(const GLubyte src
[4], void *dst
)
1344 /* XXX is this ever used? */
1345 GLushort
*d
= ((GLushort
*) dst
);
1346 *d
= PACK_COLOR_88(src
[0], src
[1]);
1350 pack_float_DUDV8(const GLfloat src
[4], void *dst
)
1352 GLushort
*d
= ((GLushort
*) dst
);
1354 du
= FLOAT_TO_BYTE(CLAMP(src
[0], 0.0F
, 1.0F
));
1355 dv
= FLOAT_TO_BYTE(CLAMP(src
[1], 0.0F
, 1.0F
));
1356 *d
= PACK_COLOR_88(du
, dv
);
1360 /* MESA_FORMAT_RGBA_16 */
1363 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1365 GLushort
*d
= ((GLushort
*) dst
);
1366 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1367 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1368 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1369 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1373 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1375 GLushort
*d
= ((GLushort
*) dst
);
1376 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1377 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1378 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1379 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1385 * MESA_FORMAT_SIGNED_R8
1389 pack_float_SIGNED_R8(const GLfloat src
[4], void *dst
)
1391 GLbyte
*d
= (GLbyte
*) dst
;
1392 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1397 * MESA_FORMAT_SIGNED_RG88_REV
1401 pack_float_SIGNED_RG88_REV(const GLfloat src
[4], void *dst
)
1403 GLushort
*d
= (GLushort
*) dst
;
1404 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1405 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1411 * MESA_FORMAT_SIGNED_RGBX8888
1415 pack_float_SIGNED_RGBX8888(const GLfloat src
[4], void *dst
)
1417 GLuint
*d
= (GLuint
*) dst
;
1418 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1419 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1420 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1422 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1427 * MESA_FORMAT_SIGNED_RGBA8888
1431 pack_float_SIGNED_RGBA8888(const GLfloat src
[4], void *dst
)
1433 GLuint
*d
= (GLuint
*) dst
;
1434 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1435 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1436 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1437 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1438 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1443 * MESA_FORMAT_SIGNED_RGBA8888_REV
1447 pack_float_SIGNED_RGBA8888_REV(const GLfloat src
[4], void *dst
)
1449 GLuint
*d
= (GLuint
*) dst
;
1450 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1451 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1452 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1453 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1454 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1459 * MESA_FORMAT_SIGNED_R16
1463 pack_float_SIGNED_R16(const GLfloat src
[4], void *dst
)
1465 GLshort
*d
= (GLshort
*) dst
;
1466 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1471 * MESA_FORMAT_SIGNED_GR1616
1475 pack_float_SIGNED_GR1616(const GLfloat src
[4], void *dst
)
1477 GLuint
*d
= (GLuint
*) dst
;
1478 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1479 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1480 *d
= (g
<< 16) | (r
& 0xffff);
1485 * MESA_FORMAT_SIGNED_RGB_16
1489 pack_float_SIGNED_RGB_16(const GLfloat src
[4], void *dst
)
1491 GLshort
*d
= (GLshort
*) dst
;
1492 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1493 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1494 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1499 * MESA_FORMAT_SIGNED_RGBA_16
1503 pack_float_SIGNED_RGBA_16(const GLfloat src
[4], void *dst
)
1505 GLshort
*d
= (GLshort
*) dst
;
1506 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1507 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1508 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1509 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1514 * MESA_FORMAT_SIGNED_A8
1518 pack_float_SIGNED_A8(const GLfloat src
[4], void *dst
)
1520 GLbyte
*d
= (GLbyte
*) dst
;
1521 *d
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1526 * MESA_FORMAT_SIGNED_L8
1530 pack_float_SIGNED_L8(const GLfloat src
[4], void *dst
)
1532 GLbyte
*d
= (GLbyte
*) dst
;
1533 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1538 * MESA_FORMAT_SIGNED_AL88
1542 pack_float_SIGNED_AL88(const GLfloat src
[4], void *dst
)
1544 GLushort
*d
= (GLushort
*) dst
;
1545 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1546 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1552 * MESA_FORMAT_SIGNED_A16
1556 pack_float_SIGNED_A16(const GLfloat src
[4], void *dst
)
1558 GLshort
*d
= (GLshort
*) dst
;
1559 *d
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1564 * MESA_FORMAT_SIGNED_L16
1568 pack_float_SIGNED_L16(const GLfloat src
[4], void *dst
)
1570 GLshort
*d
= (GLshort
*) dst
;
1571 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1576 * MESA_FORMAT_SIGNED_AL1616
1580 pack_float_SIGNED_AL1616(const GLfloat src
[4], void *dst
)
1582 GLuint
*d
= (GLuint
*) dst
;
1583 GLshort l
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1584 GLshort a
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1585 *d
= PACK_COLOR_1616(a
, l
);
1591 * Return a function that can pack a GLubyte rgba[4] color.
1593 gl_pack_ubyte_rgba_func
1594 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1596 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1597 static GLboolean initialized
= GL_FALSE
;
1600 memset(table
, 0, sizeof(table
));
1602 table
[MESA_FORMAT_NONE
] = NULL
;
1604 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1605 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1606 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1607 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1608 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1609 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1610 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1611 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1612 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1613 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1614 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1615 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1616 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1617 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1618 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1619 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1620 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1621 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1622 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1623 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1624 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1625 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1626 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1627 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1628 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1629 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1630 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1631 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1632 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1633 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1634 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1635 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1636 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1637 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1638 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1639 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1640 table
[MESA_FORMAT_RG1616_REV
] = pack_ubyte_RG1616_REV
;
1641 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1643 /* should never convert RGBA to these formats */
1644 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1645 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1646 table
[MESA_FORMAT_Z16
] = NULL
;
1647 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1648 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1649 table
[MESA_FORMAT_Z32
] = NULL
;
1650 table
[MESA_FORMAT_S8
] = NULL
;
1653 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1654 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1655 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1656 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1657 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1660 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1661 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1662 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1663 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1665 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1666 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1667 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1668 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1669 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1670 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1672 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1673 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1674 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1675 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1676 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1677 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1678 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1679 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1680 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1681 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1682 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1683 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1684 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1685 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1686 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1687 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1690 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1691 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1692 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1693 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1694 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1695 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1697 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1699 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1702 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1703 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1704 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1705 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1706 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1707 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1708 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1709 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1710 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1711 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1712 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1713 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1714 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1715 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1716 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1717 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1718 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1721 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1723 initialized
= GL_TRUE
;
1726 return table
[format
];
1732 * Return a function that can pack a GLfloat rgba[4] color.
1734 gl_pack_float_rgba_func
1735 _mesa_get_pack_float_rgba_function(gl_format format
)
1737 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1738 static GLboolean initialized
= GL_FALSE
;
1741 memset(table
, 0, sizeof(table
));
1743 table
[MESA_FORMAT_NONE
] = NULL
;
1745 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
1746 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
1747 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
1748 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
1749 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
1750 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
1751 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
1752 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
1753 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
1754 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
1755 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
1756 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
1757 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
1758 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
1759 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
1760 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
1761 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
1763 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
1764 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
1765 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
1766 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
1767 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
1768 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
1769 table
[MESA_FORMAT_A8
] = pack_float_A8
;
1770 table
[MESA_FORMAT_A16
] = pack_float_A16
;
1771 table
[MESA_FORMAT_L8
] = pack_float_L8
;
1772 table
[MESA_FORMAT_L16
] = pack_float_L16
;
1773 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
1774 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
1775 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
1776 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
1777 table
[MESA_FORMAT_R8
] = pack_float_R8
;
1778 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
1779 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
1780 table
[MESA_FORMAT_R16
] = pack_float_R16
;
1781 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
1782 table
[MESA_FORMAT_RG1616_REV
] = pack_float_RG1616_REV
;
1783 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
1785 /* should never convert RGBA to these formats */
1786 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1787 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1788 table
[MESA_FORMAT_Z16
] = NULL
;
1789 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1790 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1791 table
[MESA_FORMAT_Z32
] = NULL
;
1792 table
[MESA_FORMAT_S8
] = NULL
;
1794 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
1795 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
1796 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
1797 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
1798 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
1801 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
1802 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
1803 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
1804 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
1806 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
1807 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
1808 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
1809 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
1810 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
1811 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
1813 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
1814 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
1815 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
1816 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
1817 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
1818 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
1819 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1820 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1821 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
1822 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
1824 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1825 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1826 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1827 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1828 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
1829 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
1832 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
1833 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
1834 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
1835 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
1836 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
1837 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
1839 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
1841 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
1843 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
1844 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
1845 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
1846 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
1847 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
1848 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
1849 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
1850 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
1851 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
1852 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
1853 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
1854 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
1855 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
1856 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
1857 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
1858 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
1859 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
1862 initialized
= GL_TRUE
;
1865 return table
[format
];
1870 static pack_float_rgba_row_func
1871 get_pack_float_rgba_row_function(gl_format format
)
1873 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
1874 static GLboolean initialized
= GL_FALSE
;
1877 /* We don't need a special row packing function for each format.
1878 * There's a generic fallback which uses a per-pixel packing function.
1880 memset(table
, 0, sizeof(table
));
1882 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
1883 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
1884 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
1885 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
1886 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
1887 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
1888 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
1889 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
1890 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
1891 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
1892 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
1893 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
1895 initialized
= GL_TRUE
;
1898 return table
[format
];
1903 static pack_ubyte_rgba_row_func
1904 get_pack_ubyte_rgba_row_function(gl_format format
)
1906 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
1907 static GLboolean initialized
= GL_FALSE
;
1910 /* We don't need a special row packing function for each format.
1911 * There's a generic fallback which uses a per-pixel packing function.
1913 memset(table
, 0, sizeof(table
));
1915 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
1916 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
1917 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
1918 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
1919 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
1920 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
1921 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
1922 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
1923 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
1924 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
1925 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
1926 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
1928 initialized
= GL_TRUE
;
1931 return table
[format
];
1937 * Pack a row of GLfloat rgba[4] values to the destination.
1940 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
1941 const GLfloat src
[][4], void *dst
)
1943 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
1945 /* use "fast" function */
1946 packrow(n
, src
, dst
);
1949 /* slower fallback */
1950 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
1951 GLuint dstStride
= _mesa_get_format_bytes(format
);
1952 GLubyte
*dstPtr
= (GLubyte
*) dst
;
1959 for (i
= 0; i
< n
; i
++) {
1960 pack(src
[i
], dstPtr
);
1961 dstPtr
+= dstStride
;
1968 * Pack a row of GLubyte rgba[4] values to the destination.
1971 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
1972 const GLubyte src
[][4], void *dst
)
1974 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
1976 /* use "fast" function */
1977 packrow(n
, src
, dst
);
1980 /* slower fallback */
1981 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
1982 const GLuint stride
= _mesa_get_format_bytes(format
);
1983 GLubyte
*d
= ((GLubyte
*) dst
);
1990 for (i
= 0; i
< n
; i
++) {
1999 ** Pack float Z pixels
2003 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2005 /* don't disturb the stencil values */
2006 GLuint
*d
= ((GLuint
*) dst
);
2007 const GLdouble scale
= (GLdouble
) 0xffffff;
2008 GLuint s
= *d
& 0xff;
2009 GLuint z
= (GLuint
) (*src
* scale
);
2010 assert(z
<= 0xffffff);
2015 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2017 /* don't disturb the stencil values */
2018 GLuint
*d
= ((GLuint
*) dst
);
2019 const GLdouble scale
= (GLdouble
) 0xffffff;
2020 GLuint s
= *d
& 0xff000000;
2021 GLuint z
= (GLuint
) (*src
* scale
);
2022 assert(z
<= 0xffffff);
2027 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2029 GLushort
*d
= ((GLushort
*) dst
);
2030 const GLfloat scale
= (GLfloat
) 0xffff;
2031 *d
= (GLushort
) (*src
* scale
);
2035 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2037 GLuint
*d
= ((GLuint
*) dst
);
2038 const GLdouble scale
= (GLdouble
) 0xffffffff;
2039 *d
= (GLuint
) (*src
* scale
);
2043 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2045 GLfloat
*d
= (GLfloat
*) dst
;
2049 gl_pack_float_z_func
2050 _mesa_get_pack_float_z_func(gl_format format
)
2053 case MESA_FORMAT_Z24_S8
:
2054 case MESA_FORMAT_Z24_X8
:
2055 return pack_float_z_Z24_S8
;
2056 case MESA_FORMAT_S8_Z24
:
2057 case MESA_FORMAT_X8_Z24
:
2058 return pack_float_z_S8_Z24
;
2059 case MESA_FORMAT_Z16
:
2060 return pack_float_z_Z16
;
2061 case MESA_FORMAT_Z32
:
2062 return pack_float_z_Z32
;
2063 case MESA_FORMAT_Z32_FLOAT
:
2064 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2065 return pack_float_z_Z32_FLOAT
;
2068 "unexpected format in _mesa_get_pack_float_z_func()");
2076 ** Pack uint Z pixels. The incoming src value is always in
2077 ** the range [0, 2^32-1].
2081 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2083 /* don't disturb the stencil values */
2084 GLuint
*d
= ((GLuint
*) dst
);
2085 GLuint s
= *d
& 0xff;
2086 GLuint z
= *src
& 0xffffff00;
2091 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2093 /* don't disturb the stencil values */
2094 GLuint
*d
= ((GLuint
*) dst
);
2095 GLuint s
= *d
& 0xff000000;
2096 GLuint z
= *src
>> 8;
2101 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2103 GLushort
*d
= ((GLushort
*) dst
);
2108 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2110 GLuint
*d
= ((GLuint
*) dst
);
2115 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2117 GLuint
*d
= ((GLuint
*) dst
);
2118 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2125 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2127 GLfloat
*d
= ((GLfloat
*) dst
);
2128 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2135 _mesa_get_pack_uint_z_func(gl_format format
)
2138 case MESA_FORMAT_Z24_S8
:
2139 case MESA_FORMAT_Z24_X8
:
2140 return pack_uint_z_Z24_S8
;
2141 case MESA_FORMAT_S8_Z24
:
2142 case MESA_FORMAT_X8_Z24
:
2143 return pack_uint_z_S8_Z24
;
2144 case MESA_FORMAT_Z16
:
2145 return pack_uint_z_Z16
;
2146 case MESA_FORMAT_Z32
:
2147 return pack_uint_z_Z32
;
2148 case MESA_FORMAT_Z32_FLOAT
:
2149 return pack_uint_z_Z32_FLOAT
;
2150 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2151 return pack_uint_z_Z32_FLOAT_X24S8
;
2153 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2160 ** Pack ubyte stencil pixels
2164 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2166 /* don't disturb the Z values */
2167 GLuint
*d
= ((GLuint
*) dst
);
2169 GLuint z
= *d
& 0xffffff00;
2174 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2176 /* don't disturb the Z values */
2177 GLuint
*d
= ((GLuint
*) dst
);
2178 GLuint s
= *src
<< 24;
2179 GLuint z
= *d
& 0xffffff;
2184 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2186 GLubyte
*d
= (GLubyte
*) dst
;
2191 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2193 GLfloat
*d
= ((GLfloat
*) dst
);
2198 gl_pack_ubyte_stencil_func
2199 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2202 case MESA_FORMAT_Z24_S8
:
2203 return pack_ubyte_stencil_Z24_S8
;
2204 case MESA_FORMAT_S8_Z24
:
2205 return pack_ubyte_stencil_S8_Z24
;
2206 case MESA_FORMAT_S8
:
2207 return pack_ubyte_stencil_S8
;
2208 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2209 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2212 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2220 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2221 const GLfloat
*src
, void *dst
)
2224 case MESA_FORMAT_Z24_S8
:
2225 case MESA_FORMAT_Z24_X8
:
2227 /* don't disturb the stencil values */
2228 GLuint
*d
= ((GLuint
*) dst
);
2229 const GLdouble scale
= (GLdouble
) 0xffffff;
2231 for (i
= 0; i
< n
; i
++) {
2232 GLuint s
= d
[i
] & 0xff;
2233 GLuint z
= (GLuint
) (src
[i
] * scale
);
2234 assert(z
<= 0xffffff);
2235 d
[i
] = (z
<< 8) | s
;
2239 case MESA_FORMAT_S8_Z24
:
2240 case MESA_FORMAT_X8_Z24
:
2242 /* don't disturb the stencil values */
2243 GLuint
*d
= ((GLuint
*) dst
);
2244 const GLdouble scale
= (GLdouble
) 0xffffff;
2246 for (i
= 0; i
< n
; i
++) {
2247 GLuint s
= d
[i
] & 0xff000000;
2248 GLuint z
= (GLuint
) (src
[i
] * scale
);
2249 assert(z
<= 0xffffff);
2254 case MESA_FORMAT_Z16
:
2256 GLushort
*d
= ((GLushort
*) dst
);
2257 const GLfloat scale
= (GLfloat
) 0xffff;
2259 for (i
= 0; i
< n
; i
++) {
2260 d
[i
] = (GLushort
) (src
[i
] * scale
);
2264 case MESA_FORMAT_Z32
:
2266 GLuint
*d
= ((GLuint
*) dst
);
2267 const GLdouble scale
= (GLdouble
) 0xffffffff;
2269 for (i
= 0; i
< n
; i
++) {
2270 d
[i
] = (GLuint
) (src
[i
] * scale
);
2274 case MESA_FORMAT_Z32_FLOAT
:
2275 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2277 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2279 GLfloat
*d
= ((GLfloat
*) dst
);
2281 for (i
= 0; i
< n
; i
++) {
2287 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2293 * The incoming Z values are always in the range [0, 0xffffffff].
2296 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2297 const GLuint
*src
, void *dst
)
2300 case MESA_FORMAT_Z24_S8
:
2301 case MESA_FORMAT_Z24_X8
:
2303 /* don't disturb the stencil values */
2304 GLuint
*d
= ((GLuint
*) dst
);
2306 for (i
= 0; i
< n
; i
++) {
2307 GLuint s
= d
[i
] & 0xff;
2308 GLuint z
= src
[i
] & 0xffffff00;
2313 case MESA_FORMAT_S8_Z24
:
2314 case MESA_FORMAT_X8_Z24
:
2316 /* don't disturb the stencil values */
2317 GLuint
*d
= ((GLuint
*) dst
);
2319 for (i
= 0; i
< n
; i
++) {
2320 GLuint s
= d
[i
] & 0xff000000;
2321 GLuint z
= src
[i
] >> 8;
2326 case MESA_FORMAT_Z16
:
2328 GLushort
*d
= ((GLushort
*) dst
);
2330 for (i
= 0; i
< n
; i
++) {
2331 d
[i
] = src
[i
] >> 16;
2335 case MESA_FORMAT_Z32
:
2336 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2338 case MESA_FORMAT_Z32_FLOAT
:
2340 GLuint
*d
= ((GLuint
*) dst
);
2341 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2343 for (i
= 0; i
< n
; i
++) {
2344 d
[i
] = src
[i
] * scale
;
2345 assert(d
[i
] >= 0.0f
);
2346 assert(d
[i
] <= 1.0f
);
2350 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2352 GLfloat
*d
= ((GLfloat
*) dst
);
2353 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2355 for (i
= 0; i
< n
; i
++) {
2356 d
[i
* 2] = src
[i
] * scale
;
2357 assert(d
[i
* 2] >= 0.0f
);
2358 assert(d
[i
* 2] <= 1.0f
);
2363 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2369 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2370 const GLubyte
*src
, void *dst
)
2373 case MESA_FORMAT_Z24_S8
:
2375 /* don't disturb the Z values */
2376 GLuint
*d
= ((GLuint
*) dst
);
2378 for (i
= 0; i
< n
; i
++) {
2380 GLuint z
= d
[i
] & 0xffffff00;
2385 case MESA_FORMAT_S8_Z24
:
2387 /* don't disturb the Z values */
2388 GLuint
*d
= ((GLuint
*) dst
);
2390 for (i
= 0; i
< n
; i
++) {
2391 GLuint s
= src
[i
] << 24;
2392 GLuint z
= d
[i
] & 0xffffff;
2397 case MESA_FORMAT_S8
:
2398 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2400 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2404 for (i
= 0; i
< n
; i
++) {
2405 d
[i
* 2 + 1] = src
[i
];
2410 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2416 * Incoming Z/stencil values are always in uint_24_8 format.
2419 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2420 const GLuint
*src
, void *dst
)
2423 case MESA_FORMAT_Z24_S8
:
2424 memcpy(dst
, src
, n
* sizeof(GLuint
));
2426 case MESA_FORMAT_S8_Z24
:
2428 GLuint
*d
= ((GLuint
*) dst
);
2430 for (i
= 0; i
< n
; i
++) {
2431 GLuint s
= src
[i
] << 24;
2432 GLuint z
= src
[i
] >> 8;
2438 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2439 _mesa_get_format_name(format
));
2447 * Convert a boolean color mask to a packed color where each channel of
2448 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2451 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2453 GLfloat maskColor
[4];
2455 switch (_mesa_get_format_datatype(format
)) {
2456 case GL_UNSIGNED_NORMALIZED
:
2457 /* simple: 1.0 will convert to ~0 in the right bit positions */
2458 maskColor
[0] = colorMask
[0] ? 1.0 : 0.0;
2459 maskColor
[1] = colorMask
[1] ? 1.0 : 0.0;
2460 maskColor
[2] = colorMask
[2] ? 1.0 : 0.0;
2461 maskColor
[3] = colorMask
[3] ? 1.0 : 0.0;
2462 _mesa_pack_float_rgba_row(format
, 1,
2463 (const GLfloat (*)[4]) maskColor
, dst
);
2465 case GL_SIGNED_NORMALIZED
:
2467 /* These formats are harder because it's hard to know the floating
2468 * point values that will convert to ~0 for each color channel's bits.
2469 * This solution just generates a non-zero value for each color channel
2470 * then fixes up the non-zero values to be ~0.
2471 * Note: we'll need to add special case code if we ever have to deal
2472 * with formats with unequal color channel sizes, like R11_G11_B10.
2473 * We issue a warning below for channel sizes other than 8,16,32.
2476 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2477 GLuint bytes
= _mesa_get_format_bytes(format
);
2480 /* this should put non-zero values into the channels of dst */
2481 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2482 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2483 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2484 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2485 _mesa_pack_float_rgba_row(format
, 1,
2486 (const GLfloat (*)[4]) maskColor
, dst
);
2488 /* fix-up the dst channels by converting non-zero values to ~0 */
2490 GLubyte
*d
= (GLubyte
*) dst
;
2491 for (i
= 0; i
< bytes
; i
++) {
2492 d
[i
] = d
[i
] ? 0xffff : 0x0;
2495 else if (bits
== 16) {
2496 GLushort
*d
= (GLushort
*) dst
;
2497 for (i
= 0; i
< bytes
/ 2; i
++) {
2498 d
[i
] = d
[i
] ? 0xffff : 0x0;
2501 else if (bits
== 32) {
2502 GLuint
*d
= (GLuint
*) dst
;
2503 for (i
= 0; i
< bytes
/ 4; i
++) {
2504 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2508 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2514 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");