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"
42 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
43 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
45 #include "u_format_rgb9e5.h"
46 #include "u_format_r11g11b10f.h"
50 typedef void (*pack_ubyte_rgba_row_func
)(GLuint n
,
51 const GLubyte src
[][4], void *dst
);
53 typedef void (*pack_float_rgba_row_func
)(GLuint n
,
54 const GLfloat src
[][4], void *dst
);
59 linear_to_srgb(GLfloat cl
)
63 else if (cl
< 0.0031308f
)
66 return 1.055f
* powf(cl
, 0.41666f
) - 0.055f
;
73 linear_float_to_srgb_ubyte(GLfloat cl
)
75 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
));
81 linear_ubyte_to_srgb_ubyte(GLubyte cl
)
83 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
/ 255.0f
));
91 * MESA_FORMAT_RGBA8888
95 pack_ubyte_RGBA8888(const GLubyte src
[4], void *dst
)
97 GLuint
*d
= ((GLuint
*) dst
);
98 *d
= PACK_COLOR_8888(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
102 pack_float_RGBA8888(const GLfloat src
[4], void *dst
)
105 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
106 pack_ubyte_RGBA8888(v
, dst
);
110 pack_row_ubyte_RGBA8888(GLuint n
, const GLubyte src
[][4], void *dst
)
112 GLuint
*d
= ((GLuint
*) dst
);
114 for (i
= 0; i
< n
; i
++) {
115 d
[i
] = PACK_COLOR_8888(src
[i
][RCOMP
], src
[i
][GCOMP
],
116 src
[i
][BCOMP
], src
[i
][ACOMP
]);
121 pack_row_float_RGBA8888(GLuint n
, const GLfloat src
[][4], void *dst
)
123 GLuint
*d
= ((GLuint
*) dst
);
125 for (i
= 0; i
< n
; i
++) {
127 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
128 pack_ubyte_RGBA8888(v
, d
+ i
);
135 * MESA_FORMAT_RGBA8888_REV
139 pack_ubyte_RGBA8888_REV(const GLubyte src
[4], void *dst
)
141 GLuint
*d
= ((GLuint
*) dst
);
142 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[BCOMP
], src
[GCOMP
], src
[RCOMP
]);
146 pack_float_RGBA8888_REV(const GLfloat src
[4], void *dst
)
149 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
150 pack_ubyte_RGBA8888_REV(v
, dst
);
154 pack_row_ubyte_RGBA8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
156 GLuint
*d
= ((GLuint
*) dst
);
158 for (i
= 0; i
< n
; i
++) {
159 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][BCOMP
],
160 src
[i
][GCOMP
], src
[i
][RCOMP
]);
165 pack_row_float_RGBA8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
167 GLuint
*d
= ((GLuint
*) dst
);
169 for (i
= 0; i
< n
; i
++) {
171 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
172 pack_ubyte_RGBA8888_REV(v
, d
+ i
);
178 * MESA_FORMAT_ARGB8888
182 pack_ubyte_ARGB8888(const GLubyte src
[4], void *dst
)
184 GLuint
*d
= ((GLuint
*) dst
);
185 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
189 pack_float_ARGB8888(const GLfloat src
[4], void *dst
)
192 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
193 pack_ubyte_ARGB8888(v
, dst
);
197 pack_row_ubyte_ARGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
199 GLuint
*d
= ((GLuint
*) dst
);
201 for (i
= 0; i
< n
; i
++) {
202 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][RCOMP
],
203 src
[i
][GCOMP
], src
[i
][BCOMP
]);
208 pack_row_float_ARGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
210 GLuint
*d
= ((GLuint
*) dst
);
212 for (i
= 0; i
< n
; i
++) {
214 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
215 pack_ubyte_ARGB8888(v
, d
+ i
);
221 * MESA_FORMAT_ARGB8888_REV
225 pack_ubyte_ARGB8888_REV(const GLubyte src
[4], void *dst
)
227 GLuint
*d
= ((GLuint
*) dst
);
228 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
232 pack_float_ARGB8888_REV(const GLfloat src
[4], void *dst
)
235 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
236 pack_ubyte_ARGB8888_REV(v
, dst
);
240 pack_row_ubyte_ARGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
242 GLuint
*d
= ((GLuint
*) dst
);
244 for (i
= 0; i
< n
; i
++) {
245 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
],
246 src
[i
][RCOMP
], src
[i
][ACOMP
]);
251 pack_row_float_ARGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
253 GLuint
*d
= ((GLuint
*) dst
);
255 for (i
= 0; i
< n
; i
++) {
257 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
258 pack_ubyte_ARGB8888_REV(v
, d
+ i
);
264 * MESA_FORMAT_XRGB8888
268 pack_ubyte_XRGB8888(const GLubyte src
[4], void *dst
)
270 GLuint
*d
= ((GLuint
*) dst
);
271 *d
= PACK_COLOR_8888(0x0, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
275 pack_float_XRGB8888(const GLfloat src
[4], void *dst
)
278 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
279 pack_ubyte_XRGB8888(v
, dst
);
283 pack_row_ubyte_XRGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
285 GLuint
*d
= ((GLuint
*) dst
);
287 for (i
= 0; i
< n
; i
++) {
288 d
[i
] = PACK_COLOR_8888(0, src
[i
][RCOMP
], src
[i
][GCOMP
], src
[i
][BCOMP
]);
293 pack_row_float_XRGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
295 GLuint
*d
= ((GLuint
*) dst
);
297 for (i
= 0; i
< n
; i
++) {
299 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
300 pack_ubyte_XRGB8888(v
, d
+ i
);
306 * MESA_FORMAT_XRGB8888_REV
310 pack_ubyte_XRGB8888_REV(const GLubyte src
[4], void *dst
)
312 GLuint
*d
= ((GLuint
*) dst
);
313 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], 0);
317 pack_float_XRGB8888_REV(const GLfloat src
[4], void *dst
)
320 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
321 pack_ubyte_XRGB8888_REV(v
, dst
);
325 pack_row_ubyte_XRGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
327 GLuint
*d
= ((GLuint
*) dst
);
329 for (i
= 0; i
< n
; i
++) {
330 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
], src
[i
][RCOMP
], 0);
335 pack_row_float_XRGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
337 GLuint
*d
= ((GLuint
*) dst
);
339 for (i
= 0; i
< n
; i
++) {
341 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
342 pack_ubyte_XRGB8888_REV(v
, d
+ i
);
352 pack_ubyte_RGB888(const GLubyte src
[4], void *dst
)
354 GLubyte
*d
= ((GLubyte
*) dst
);
361 pack_float_RGB888(const GLfloat src
[4], void *dst
)
363 GLubyte
*d
= ((GLubyte
*) dst
);
364 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[RCOMP
]);
365 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
366 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[BCOMP
]);
370 pack_row_ubyte_RGB888(GLuint n
, const GLubyte src
[][4], void *dst
)
372 GLubyte
*d
= ((GLubyte
*) dst
);
374 for (i
= 0; i
< n
; i
++) {
375 d
[i
*3+2] = src
[i
][RCOMP
];
376 d
[i
*3+1] = src
[i
][GCOMP
];
377 d
[i
*3+0] = src
[i
][BCOMP
];
382 pack_row_float_RGB888(GLuint n
, const GLfloat src
[][4], void *dst
)
384 GLubyte
*d
= ((GLubyte
*) dst
);
386 for (i
= 0; i
< n
; i
++) {
388 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
401 pack_ubyte_BGR888(const GLubyte src
[4], void *dst
)
403 GLubyte
*d
= ((GLubyte
*) dst
);
410 pack_float_BGR888(const GLfloat src
[4], void *dst
)
412 GLubyte
*d
= ((GLubyte
*) dst
);
413 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[BCOMP
]);
414 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
415 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
419 pack_row_ubyte_BGR888(GLuint n
, const GLubyte src
[][4], void *dst
)
421 GLubyte
*d
= ((GLubyte
*) dst
);
423 for (i
= 0; i
< n
; i
++) {
424 d
[i
*3+2] = src
[i
][BCOMP
];
425 d
[i
*3+1] = src
[i
][GCOMP
];
426 d
[i
*3+0] = src
[i
][RCOMP
];
431 pack_row_float_BGR888(GLuint n
, const GLfloat src
[][4], void *dst
)
433 GLubyte
*d
= ((GLubyte
*) dst
);
435 for (i
= 0; i
< n
; i
++) {
437 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
450 pack_ubyte_RGB565(const GLubyte src
[4], void *dst
)
452 GLushort
*d
= ((GLushort
*) dst
);
453 *d
= PACK_COLOR_565(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
457 pack_float_RGB565(const GLfloat src
[4], void *dst
)
460 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
461 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
462 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
463 pack_ubyte_RGB565(v
, dst
);
467 pack_row_ubyte_RGB565(GLuint n
, const GLubyte src
[][4], void *dst
)
469 GLushort
*d
= ((GLushort
*) dst
);
471 for (i
= 0; i
< n
; i
++) {
472 pack_ubyte_RGB565(src
[i
], d
+ i
);
477 pack_row_float_RGB565(GLuint n
, const GLfloat src
[][4], void *dst
)
479 GLushort
*d
= ((GLushort
*) dst
);
481 for (i
= 0; i
< n
; i
++) {
483 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
484 pack_ubyte_RGB565(v
, d
+ i
);
490 * MESA_FORMAT_RGB565_REV
494 pack_ubyte_RGB565_REV(const GLubyte src
[4], void *dst
)
496 GLushort
*d
= ((GLushort
*) dst
);
497 *d
= PACK_COLOR_565_REV(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
501 pack_float_RGB565_REV(const GLfloat src
[4], void *dst
)
503 GLushort
*d
= ((GLushort
*) dst
);
505 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
506 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
507 UNCLAMPED_FLOAT_TO_UBYTE(b
, src
[BCOMP
]);
508 *d
= PACK_COLOR_565_REV(r
, g
, b
);
512 pack_row_ubyte_RGB565_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
514 GLushort
*d
= ((GLushort
*) dst
);
516 for (i
= 0; i
< n
; i
++) {
517 pack_ubyte_RGB565_REV(src
[i
], d
+ i
);
522 pack_row_float_RGB565_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
524 GLushort
*d
= ((GLushort
*) dst
);
526 for (i
= 0; i
< n
; i
++) {
528 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
529 pack_ubyte_RGB565_REV(v
, d
+ i
);
535 * MESA_FORMAT_ARGB4444
539 pack_ubyte_ARGB4444(const GLubyte src
[4], void *dst
)
541 GLushort
*d
= ((GLushort
*) dst
);
542 *d
= PACK_COLOR_4444(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
546 pack_float_ARGB4444(const GLfloat src
[4], void *dst
)
549 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
550 pack_ubyte_ARGB4444(v
, dst
);
553 /* use fallback row packing functions */
557 * MESA_FORMAT_ARGB4444_REV
561 pack_ubyte_ARGB4444_REV(const GLubyte src
[4], void *dst
)
563 GLushort
*d
= ((GLushort
*) dst
);
564 *d
= PACK_COLOR_4444(src
[GCOMP
], src
[BCOMP
], src
[ACOMP
], src
[RCOMP
]);
568 pack_float_ARGB4444_REV(const GLfloat src
[4], void *dst
)
571 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
572 pack_ubyte_ARGB4444_REV(v
, dst
);
575 /* use fallback row packing functions */
579 * MESA_FORMAT_RGBA5551
583 pack_ubyte_RGBA5551(const GLubyte src
[4], void *dst
)
585 GLushort
*d
= ((GLushort
*) dst
);
586 *d
= PACK_COLOR_5551(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
590 pack_float_RGBA5551(const GLfloat src
[4], void *dst
)
593 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
594 pack_ubyte_RGBA5551(v
, dst
);
597 /* use fallback row packing functions */
601 * MESA_FORMAT_ARGB1555
605 pack_ubyte_ARGB1555(const GLubyte src
[4], void *dst
)
607 GLushort
*d
= ((GLushort
*) dst
);
608 *d
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
612 pack_float_ARGB1555(const GLfloat src
[4], void *dst
)
615 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
616 pack_ubyte_ARGB1555(v
, dst
);
620 /* MESA_FORMAT_ARGB1555_REV */
623 pack_ubyte_ARGB1555_REV(const GLubyte src
[4], void *dst
)
625 GLushort
*d
= ((GLushort
*) dst
), tmp
;
626 tmp
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
627 *d
= (tmp
>> 8) | (tmp
<< 8);
631 pack_float_ARGB1555_REV(const GLfloat src
[4], void *dst
)
634 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
635 pack_ubyte_ARGB1555_REV(v
, dst
);
639 /* MESA_FORMAT_AL44 */
642 pack_ubyte_AL44(const GLubyte src
[4], void *dst
)
644 GLubyte
*d
= ((GLubyte
*) dst
);
645 *d
= PACK_COLOR_44(src
[ACOMP
], src
[RCOMP
]);
649 pack_float_AL44(const GLfloat src
[4], void *dst
)
652 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
653 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
654 pack_ubyte_AL44(v
, dst
);
658 /* MESA_FORMAT_AL88 */
661 pack_ubyte_AL88(const GLubyte src
[4], void *dst
)
663 GLushort
*d
= ((GLushort
*) dst
);
664 *d
= PACK_COLOR_88(src
[ACOMP
], src
[RCOMP
]);
668 pack_float_AL88(const GLfloat src
[4], void *dst
)
671 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
672 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
673 pack_ubyte_AL88(v
, dst
);
677 /* MESA_FORMAT_AL88_REV */
680 pack_ubyte_AL88_REV(const GLubyte src
[4], void *dst
)
682 GLushort
*d
= ((GLushort
*) dst
);
683 *d
= PACK_COLOR_88(src
[RCOMP
], src
[ACOMP
]);
687 pack_float_AL88_REV(const GLfloat src
[4], void *dst
)
690 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
691 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
692 pack_ubyte_AL88_REV(v
, dst
);
696 /* MESA_FORMAT_AL1616 */
699 pack_ubyte_AL1616(const GLubyte src
[4], void *dst
)
701 GLuint
*d
= ((GLuint
*) dst
);
702 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
703 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
704 *d
= PACK_COLOR_1616(a
, l
);
708 pack_float_AL1616(const GLfloat src
[4], void *dst
)
710 GLuint
*d
= ((GLuint
*) dst
);
712 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
713 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
714 *d
= PACK_COLOR_1616(a
, l
);
718 /* MESA_FORMAT_AL1616_REV */
721 pack_ubyte_AL1616_REV(const GLubyte src
[4], void *dst
)
723 GLuint
*d
= ((GLuint
*) dst
);
724 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
725 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
726 *d
= PACK_COLOR_1616(l
, a
);
730 pack_float_AL1616_REV(const GLfloat src
[4], void *dst
)
732 GLuint
*d
= ((GLuint
*) dst
);
734 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
735 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
736 *d
= PACK_COLOR_1616(l
, a
);
740 /* MESA_FORMAT_RGB332 */
743 pack_ubyte_RGB332(const GLubyte src
[4], void *dst
)
745 GLubyte
*d
= ((GLubyte
*) dst
);
746 *d
= PACK_COLOR_332(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
750 pack_float_RGB332(const GLfloat src
[4], void *dst
)
753 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
754 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
755 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
756 pack_ubyte_RGB332(v
, dst
);
763 pack_ubyte_A8(const GLubyte src
[4], void *dst
)
765 GLubyte
*d
= ((GLubyte
*) dst
);
770 pack_float_A8(const GLfloat src
[4], void *dst
)
772 GLubyte
*d
= ((GLubyte
*) dst
);
773 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[ACOMP
]);
777 /* MESA_FORMAT_A16 */
780 pack_ubyte_A16(const GLubyte src
[4], void *dst
)
782 GLushort
*d
= ((GLushort
*) dst
);
783 *d
= UBYTE_TO_USHORT(src
[ACOMP
]);
787 pack_float_A16(const GLfloat src
[4], void *dst
)
789 GLushort
*d
= ((GLushort
*) dst
);
790 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[ACOMP
]);
797 pack_ubyte_L8(const GLubyte src
[4], void *dst
)
799 GLubyte
*d
= ((GLubyte
*) dst
);
804 pack_float_L8(const GLfloat src
[4], void *dst
)
806 GLubyte
*d
= ((GLubyte
*) dst
);
807 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
811 /* MESA_FORMAT_L16 */
814 pack_ubyte_L16(const GLubyte src
[4], void *dst
)
816 GLushort
*d
= ((GLushort
*) dst
);
817 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
821 pack_float_L16(const GLfloat src
[4], void *dst
)
823 GLushort
*d
= ((GLushort
*) dst
);
824 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
828 /* MESA_FORMAT_YCBCR */
831 pack_ubyte_YCBCR(const GLubyte src
[4], void *dst
)
837 pack_float_YCBCR(const GLfloat src
[4], void *dst
)
843 /* MESA_FORMAT_YCBCR_REV */
846 pack_ubyte_YCBCR_REV(const GLubyte src
[4], void *dst
)
852 pack_float_YCBCR_REV(const GLfloat src
[4], void *dst
)
861 pack_ubyte_R8(const GLubyte src
[4], void *dst
)
863 GLubyte
*d
= ((GLubyte
*) dst
);
868 pack_float_R8(const GLfloat src
[4], void *dst
)
870 GLubyte
*d
= ((GLubyte
*) dst
);
872 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
877 /* MESA_FORMAT_GR88 */
880 pack_ubyte_GR88(const GLubyte src
[4], void *dst
)
882 GLubyte
*d
= ((GLubyte
*) dst
);
883 *d
= PACK_COLOR_88(src
[GCOMP
], src
[RCOMP
]);
887 pack_float_GR88(const GLfloat src
[4], void *dst
)
889 GLushort
*d
= ((GLushort
*) dst
);
891 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
892 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
893 *d
= PACK_COLOR_88(g
, r
);
897 /* MESA_FORMAT_RG88 */
900 pack_ubyte_RG88(const GLubyte src
[4], void *dst
)
902 GLubyte
*d
= ((GLubyte
*) dst
);
903 *d
= PACK_COLOR_88(src
[RCOMP
], src
[GCOMP
]);
907 pack_float_RG88(const GLfloat src
[4], void *dst
)
909 GLushort
*d
= ((GLushort
*) dst
);
911 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
912 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
913 *d
= PACK_COLOR_88(r
, g
);
917 /* MESA_FORMAT_R16 */
920 pack_ubyte_R16(const GLubyte src
[4], void *dst
)
922 GLushort
*d
= ((GLushort
*) dst
);
923 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
927 pack_float_R16(const GLfloat src
[4], void *dst
)
929 GLushort
*d
= ((GLushort
*) dst
);
930 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
934 /* MESA_FORMAT_RG1616 */
937 pack_ubyte_RG1616(const GLubyte src
[4], void *dst
)
939 GLuint
*d
= ((GLuint
*) dst
);
940 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
941 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
942 *d
= PACK_COLOR_1616(g
, r
);
946 pack_float_RG1616(const GLfloat src
[4], void *dst
)
948 GLuint
*d
= ((GLuint
*) dst
);
950 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
951 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
952 *d
= PACK_COLOR_1616(g
, r
);
956 /* MESA_FORMAT_RG1616_REV */
959 pack_ubyte_RG1616_REV(const GLubyte src
[4], void *dst
)
961 GLuint
*d
= ((GLuint
*) dst
);
962 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
963 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
964 *d
= PACK_COLOR_1616(r
, g
);
969 pack_float_RG1616_REV(const GLfloat src
[4], void *dst
)
971 GLuint
*d
= ((GLuint
*) dst
);
973 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
974 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
975 *d
= PACK_COLOR_1616(r
, g
);
979 /* MESA_FORMAT_ARGB2101010 */
982 pack_ubyte_ARGB2101010(const GLubyte src
[4], void *dst
)
984 GLuint
*d
= ((GLuint
*) dst
);
985 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
986 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
987 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
988 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
989 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
993 pack_float_ARGB2101010(const GLfloat src
[4], void *dst
)
995 GLuint
*d
= ((GLuint
*) dst
);
997 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
998 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
999 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1000 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1001 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
1005 /* MESA_FORMAT_SRGB8 */
1008 pack_ubyte_SRGB8(const GLubyte src
[4], void *dst
)
1010 GLubyte
*d
= ((GLubyte
*) dst
);
1011 d
[2] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1012 d
[1] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1013 d
[0] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1017 pack_float_SRGB8(const GLfloat src
[4], void *dst
)
1019 GLubyte
*d
= ((GLubyte
*) dst
);
1020 d
[2] = linear_float_to_srgb_ubyte(src
[RCOMP
]);
1021 d
[1] = linear_float_to_srgb_ubyte(src
[GCOMP
]);
1022 d
[0] = linear_float_to_srgb_ubyte(src
[BCOMP
]);
1026 /* MESA_FORMAT_SRGBA8 */
1029 pack_ubyte_SRGBA8(const GLubyte src
[4], void *dst
)
1031 GLuint
*d
= ((GLuint
*) dst
);
1032 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1033 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[GCOMP
]);
1034 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[BCOMP
]);
1035 *d
= PACK_COLOR_8888(r
, g
, b
, src
[ACOMP
]);
1039 pack_float_SRGBA8(const GLfloat src
[4], void *dst
)
1041 GLuint
*d
= ((GLuint
*) dst
);
1043 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1044 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1045 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1046 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1047 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1051 /* MESA_FORMAT_SARGB8 */
1054 pack_ubyte_SARGB8(const GLubyte src
[4], void *dst
)
1056 GLuint
*d
= ((GLuint
*) dst
);
1057 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1058 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1059 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1060 *d
= PACK_COLOR_8888(src
[ACOMP
], r
, g
, b
);
1064 pack_float_SARGB8(const GLfloat src
[4], void *dst
)
1066 GLuint
*d
= ((GLuint
*) dst
);
1068 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1069 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1070 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1071 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1072 *d
= PACK_COLOR_8888(a
, r
, g
, b
);
1076 /* MESA_FORMAT_SL8 */
1079 pack_ubyte_SL8(const GLubyte src
[4], void *dst
)
1081 GLubyte
*d
= ((GLubyte
*) dst
);
1082 *d
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1086 pack_float_SL8(const GLfloat src
[4], void *dst
)
1088 GLubyte
*d
= ((GLubyte
*) dst
);
1089 GLubyte l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1094 /* MESA_FORMAT_SLA8 */
1097 pack_ubyte_SLA8(const GLubyte src
[4], void *dst
)
1099 GLushort
*d
= ((GLushort
*) dst
);
1100 GLubyte l
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1101 *d
= PACK_COLOR_88(src
[ACOMP
], l
);
1105 pack_float_SLA8(const GLfloat src
[4], void *dst
)
1107 GLushort
*d
= ((GLushort
*) dst
);
1108 GLubyte a
, l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1109 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1110 *d
= PACK_COLOR_88(a
, l
);
1114 /* MESA_FORMAT_RGBA_FLOAT32 */
1117 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
1119 GLfloat
*d
= ((GLfloat
*) dst
);
1120 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1121 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1122 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1123 d
[3] = UBYTE_TO_FLOAT(src
[3]);
1127 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
1129 GLfloat
*d
= ((GLfloat
*) dst
);
1137 /* MESA_FORMAT_RGBA_FLOAT16 */
1140 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
1142 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1143 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1144 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1145 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1146 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
1150 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
1152 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1153 d
[0] = _mesa_float_to_half(src
[0]);
1154 d
[1] = _mesa_float_to_half(src
[1]);
1155 d
[2] = _mesa_float_to_half(src
[2]);
1156 d
[3] = _mesa_float_to_half(src
[3]);
1160 /* MESA_FORMAT_RGB_FLOAT32 */
1163 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
1165 GLfloat
*d
= ((GLfloat
*) dst
);
1166 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1167 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1168 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1172 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
1174 GLfloat
*d
= ((GLfloat
*) dst
);
1181 /* MESA_FORMAT_RGB_FLOAT16 */
1184 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
1186 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1187 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1188 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1189 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1193 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
1195 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1196 d
[0] = _mesa_float_to_half(src
[0]);
1197 d
[1] = _mesa_float_to_half(src
[1]);
1198 d
[2] = _mesa_float_to_half(src
[2]);
1202 /* MESA_FORMAT_ALPHA_FLOAT32 */
1205 pack_ubyte_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1207 GLfloat
*d
= ((GLfloat
*) dst
);
1208 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1212 pack_float_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1214 GLfloat
*d
= ((GLfloat
*) dst
);
1219 /* MESA_FORMAT_ALPHA_FLOAT16 */
1222 pack_ubyte_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1224 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1225 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1229 pack_float_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1231 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1232 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
1236 /* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
1239 pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src
[4], void *dst
)
1241 GLfloat
*d
= ((GLfloat
*) dst
);
1242 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1246 pack_float_LUMINANCE_FLOAT32(const GLfloat src
[4], void *dst
)
1248 GLfloat
*d
= ((GLfloat
*) dst
);
1253 /* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
1256 pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src
[4], void *dst
)
1258 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1259 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1263 pack_float_LUMINANCE_FLOAT16(const GLfloat src
[4], void *dst
)
1265 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1266 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1270 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
1273 pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1275 GLfloat
*d
= ((GLfloat
*) dst
);
1276 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1277 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1281 pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1283 GLfloat
*d
= ((GLfloat
*) dst
);
1289 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
1292 pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1294 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1295 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1296 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1300 pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1302 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1303 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1304 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1308 /* MESA_FORMAT_RG_FLOAT32 */
1311 pack_ubyte_RG_FLOAT32(const GLubyte src
[4], void *dst
)
1313 GLfloat
*d
= ((GLfloat
*) dst
);
1314 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1315 d
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1319 pack_float_RG_FLOAT32(const GLfloat src
[4], void *dst
)
1321 GLfloat
*d
= ((GLfloat
*) dst
);
1327 /* MESA_FORMAT_RG_FLOAT16 */
1330 pack_ubyte_RG_FLOAT16(const GLubyte src
[4], void *dst
)
1332 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1333 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1334 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[GCOMP
]));
1338 pack_float_RG_FLOAT16(const GLfloat src
[4], void *dst
)
1340 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1341 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1342 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1346 /* MESA_FORMAT_DUDV8 */
1349 pack_ubyte_DUDV8(const GLubyte src
[4], void *dst
)
1351 /* XXX is this ever used? */
1352 GLushort
*d
= ((GLushort
*) dst
);
1353 *d
= PACK_COLOR_88(src
[0], src
[1]);
1357 pack_float_DUDV8(const GLfloat src
[4], void *dst
)
1359 GLushort
*d
= ((GLushort
*) dst
);
1361 du
= FLOAT_TO_BYTE(CLAMP(src
[0], 0.0F
, 1.0F
));
1362 dv
= FLOAT_TO_BYTE(CLAMP(src
[1], 0.0F
, 1.0F
));
1363 *d
= PACK_COLOR_88(du
, dv
);
1367 /* MESA_FORMAT_RGBA_16 */
1370 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1372 GLushort
*d
= ((GLushort
*) dst
);
1373 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1374 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1375 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1376 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1380 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1382 GLushort
*d
= ((GLushort
*) dst
);
1383 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1384 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1385 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1386 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1392 * MESA_FORMAT_SIGNED_R8
1396 pack_float_SIGNED_R8(const GLfloat src
[4], void *dst
)
1398 GLbyte
*d
= (GLbyte
*) dst
;
1399 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1404 * MESA_FORMAT_SIGNED_RG88_REV
1408 pack_float_SIGNED_RG88_REV(const GLfloat src
[4], void *dst
)
1410 GLushort
*d
= (GLushort
*) dst
;
1411 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1412 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1418 * MESA_FORMAT_SIGNED_RGBX8888
1422 pack_float_SIGNED_RGBX8888(const GLfloat src
[4], void *dst
)
1424 GLuint
*d
= (GLuint
*) dst
;
1425 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1426 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1427 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1429 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1434 * MESA_FORMAT_SIGNED_RGBA8888
1438 pack_float_SIGNED_RGBA8888(const GLfloat src
[4], void *dst
)
1440 GLuint
*d
= (GLuint
*) dst
;
1441 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1442 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1443 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1444 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1445 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1450 * MESA_FORMAT_SIGNED_RGBA8888_REV
1454 pack_float_SIGNED_RGBA8888_REV(const GLfloat src
[4], void *dst
)
1456 GLuint
*d
= (GLuint
*) dst
;
1457 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1458 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1459 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1460 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1461 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1466 * MESA_FORMAT_SIGNED_R16
1470 pack_float_SIGNED_R16(const GLfloat src
[4], void *dst
)
1472 GLshort
*d
= (GLshort
*) dst
;
1473 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1478 * MESA_FORMAT_SIGNED_GR1616
1482 pack_float_SIGNED_GR1616(const GLfloat src
[4], void *dst
)
1484 GLuint
*d
= (GLuint
*) dst
;
1485 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1486 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1487 *d
= (g
<< 16) | (r
& 0xffff);
1492 * MESA_FORMAT_SIGNED_RGB_16
1496 pack_float_SIGNED_RGB_16(const GLfloat src
[4], void *dst
)
1498 GLshort
*d
= (GLshort
*) dst
;
1499 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1500 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1501 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1506 * MESA_FORMAT_SIGNED_RGBA_16
1510 pack_float_SIGNED_RGBA_16(const GLfloat src
[4], void *dst
)
1512 GLshort
*d
= (GLshort
*) dst
;
1513 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1514 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1515 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1516 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1521 * MESA_FORMAT_SIGNED_A8
1525 pack_float_SIGNED_A8(const GLfloat src
[4], void *dst
)
1527 GLbyte
*d
= (GLbyte
*) dst
;
1528 *d
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1533 * MESA_FORMAT_SIGNED_L8
1537 pack_float_SIGNED_L8(const GLfloat src
[4], void *dst
)
1539 GLbyte
*d
= (GLbyte
*) dst
;
1540 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1545 * MESA_FORMAT_SIGNED_AL88
1549 pack_float_SIGNED_AL88(const GLfloat src
[4], void *dst
)
1551 GLushort
*d
= (GLushort
*) dst
;
1552 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1553 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1559 * MESA_FORMAT_SIGNED_A16
1563 pack_float_SIGNED_A16(const GLfloat src
[4], void *dst
)
1565 GLshort
*d
= (GLshort
*) dst
;
1566 *d
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1571 * MESA_FORMAT_SIGNED_L16
1575 pack_float_SIGNED_L16(const GLfloat src
[4], void *dst
)
1577 GLshort
*d
= (GLshort
*) dst
;
1578 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1583 * MESA_FORMAT_SIGNED_AL1616
1587 pack_float_SIGNED_AL1616(const GLfloat src
[4], void *dst
)
1589 GLuint
*d
= (GLuint
*) dst
;
1590 GLshort l
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1591 GLshort a
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1592 *d
= PACK_COLOR_1616(a
, l
);
1597 * MESA_FORMAT_RGB9_E5_FLOAT;
1601 pack_float_RGB9_E5_FLOAT(const GLfloat src
[4], void *dst
)
1603 GLuint
*d
= (GLuint
*) dst
;
1604 *d
= float3_to_rgb9e5(src
);
1608 pack_ubyte_RGB9_E5_FLOAT(const GLubyte src
[4], void *dst
)
1610 GLuint
*d
= (GLuint
*) dst
;
1612 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1613 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1614 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1615 *d
= float3_to_rgb9e5(rgb
);
1621 * MESA_FORMAT_R11_G11_B10_FLOAT;
1625 pack_ubyte_R11_G11_B10_FLOAT(const GLubyte src
[4], void *dst
)
1627 GLuint
*d
= (GLuint
*) dst
;
1629 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1630 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1631 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1632 *d
= float3_to_r11g11b10f(rgb
);
1636 pack_float_R11_G11_B10_FLOAT(const GLfloat src
[4], void *dst
)
1638 GLuint
*d
= (GLuint
*) dst
;
1639 *d
= float3_to_r11g11b10f(src
);
1645 * Return a function that can pack a GLubyte rgba[4] color.
1647 gl_pack_ubyte_rgba_func
1648 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1650 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1651 static GLboolean initialized
= GL_FALSE
;
1654 memset(table
, 0, sizeof(table
));
1656 table
[MESA_FORMAT_NONE
] = NULL
;
1658 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1659 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1660 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1661 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1662 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1663 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1664 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1665 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1666 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1667 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1668 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1669 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1670 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1671 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1672 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1673 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1674 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1675 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1676 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1677 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1678 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1679 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1680 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1681 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1682 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1683 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1684 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1685 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1686 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1687 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1688 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1689 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1690 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1691 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1692 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1693 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1694 table
[MESA_FORMAT_RG1616_REV
] = pack_ubyte_RG1616_REV
;
1695 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1697 /* should never convert RGBA to these formats */
1698 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1699 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1700 table
[MESA_FORMAT_Z16
] = NULL
;
1701 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1702 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1703 table
[MESA_FORMAT_Z32
] = NULL
;
1704 table
[MESA_FORMAT_S8
] = NULL
;
1707 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1708 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1709 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1710 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1711 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1714 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1715 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1716 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1717 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1719 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1720 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1721 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1722 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1723 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1724 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1726 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1727 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1728 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1729 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1730 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1731 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1732 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1733 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1734 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1735 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1736 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1737 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1738 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1739 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1740 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1741 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1744 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1745 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1746 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1747 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1748 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1749 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1751 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1753 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1756 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1757 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1758 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1759 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1760 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1761 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1762 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1763 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1764 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1765 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1766 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1767 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1768 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1769 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1770 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1771 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1772 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1775 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1777 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
1778 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
1780 initialized
= GL_TRUE
;
1783 return table
[format
];
1789 * Return a function that can pack a GLfloat rgba[4] color.
1791 gl_pack_float_rgba_func
1792 _mesa_get_pack_float_rgba_function(gl_format format
)
1794 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1795 static GLboolean initialized
= GL_FALSE
;
1798 memset(table
, 0, sizeof(table
));
1800 table
[MESA_FORMAT_NONE
] = NULL
;
1802 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
1803 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
1804 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
1805 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
1806 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
1807 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
1808 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
1809 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
1810 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
1811 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
1812 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
1813 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
1814 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
1815 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
1816 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
1817 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
1818 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
1820 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
1821 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
1822 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
1823 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
1824 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
1825 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
1826 table
[MESA_FORMAT_A8
] = pack_float_A8
;
1827 table
[MESA_FORMAT_A16
] = pack_float_A16
;
1828 table
[MESA_FORMAT_L8
] = pack_float_L8
;
1829 table
[MESA_FORMAT_L16
] = pack_float_L16
;
1830 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
1831 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
1832 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
1833 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
1834 table
[MESA_FORMAT_R8
] = pack_float_R8
;
1835 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
1836 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
1837 table
[MESA_FORMAT_R16
] = pack_float_R16
;
1838 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
1839 table
[MESA_FORMAT_RG1616_REV
] = pack_float_RG1616_REV
;
1840 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
1842 /* should never convert RGBA to these formats */
1843 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1844 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1845 table
[MESA_FORMAT_Z16
] = NULL
;
1846 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1847 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1848 table
[MESA_FORMAT_Z32
] = NULL
;
1849 table
[MESA_FORMAT_S8
] = NULL
;
1851 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
1852 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
1853 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
1854 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
1855 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
1858 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
1859 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
1860 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
1861 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
1863 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
1864 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
1865 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
1866 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
1867 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
1868 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
1870 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
1871 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
1872 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
1873 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
1874 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
1875 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
1876 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1877 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1878 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
1879 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
1881 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1882 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1883 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1884 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1885 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
1886 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
1889 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
1890 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
1891 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
1892 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
1893 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
1894 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
1896 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
1898 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
1900 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
1901 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
1902 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
1903 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
1904 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
1905 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
1906 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
1907 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
1908 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
1909 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
1910 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
1911 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
1912 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
1913 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
1914 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
1915 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
1916 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
1918 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
1919 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
1921 initialized
= GL_TRUE
;
1924 return table
[format
];
1929 static pack_float_rgba_row_func
1930 get_pack_float_rgba_row_function(gl_format format
)
1932 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
1933 static GLboolean initialized
= GL_FALSE
;
1936 /* We don't need a special row packing function for each format.
1937 * There's a generic fallback which uses a per-pixel packing function.
1939 memset(table
, 0, sizeof(table
));
1941 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
1942 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
1943 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
1944 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
1945 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
1946 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
1947 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
1948 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
1949 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
1950 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
1951 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
1952 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
1954 initialized
= GL_TRUE
;
1957 return table
[format
];
1962 static pack_ubyte_rgba_row_func
1963 get_pack_ubyte_rgba_row_function(gl_format format
)
1965 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
1966 static GLboolean initialized
= GL_FALSE
;
1969 /* We don't need a special row packing function for each format.
1970 * There's a generic fallback which uses a per-pixel packing function.
1972 memset(table
, 0, sizeof(table
));
1974 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
1975 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
1976 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
1977 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
1978 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
1979 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
1980 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
1981 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
1982 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
1983 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
1984 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
1985 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
1987 initialized
= GL_TRUE
;
1990 return table
[format
];
1996 * Pack a row of GLfloat rgba[4] values to the destination.
1999 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
2000 const GLfloat src
[][4], void *dst
)
2002 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2004 /* use "fast" function */
2005 packrow(n
, src
, dst
);
2008 /* slower fallback */
2009 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2010 GLuint dstStride
= _mesa_get_format_bytes(format
);
2011 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2018 for (i
= 0; i
< n
; i
++) {
2019 pack(src
[i
], dstPtr
);
2020 dstPtr
+= dstStride
;
2027 * Pack a row of GLubyte rgba[4] values to the destination.
2030 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2031 const GLubyte src
[][4], void *dst
)
2033 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2035 /* use "fast" function */
2036 packrow(n
, src
, dst
);
2039 /* slower fallback */
2040 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2041 const GLuint stride
= _mesa_get_format_bytes(format
);
2042 GLubyte
*d
= ((GLubyte
*) dst
);
2049 for (i
= 0; i
< n
; i
++) {
2058 ** Pack float Z pixels
2062 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2064 /* don't disturb the stencil values */
2065 GLuint
*d
= ((GLuint
*) dst
);
2066 const GLdouble scale
= (GLdouble
) 0xffffff;
2067 GLuint s
= *d
& 0xff;
2068 GLuint z
= (GLuint
) (*src
* scale
);
2069 assert(z
<= 0xffffff);
2074 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2076 /* don't disturb the stencil values */
2077 GLuint
*d
= ((GLuint
*) dst
);
2078 const GLdouble scale
= (GLdouble
) 0xffffff;
2079 GLuint s
= *d
& 0xff000000;
2080 GLuint z
= (GLuint
) (*src
* scale
);
2081 assert(z
<= 0xffffff);
2086 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2088 GLushort
*d
= ((GLushort
*) dst
);
2089 const GLfloat scale
= (GLfloat
) 0xffff;
2090 *d
= (GLushort
) (*src
* scale
);
2094 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2096 GLuint
*d
= ((GLuint
*) dst
);
2097 const GLdouble scale
= (GLdouble
) 0xffffffff;
2098 *d
= (GLuint
) (*src
* scale
);
2102 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2104 GLfloat
*d
= (GLfloat
*) dst
;
2108 gl_pack_float_z_func
2109 _mesa_get_pack_float_z_func(gl_format format
)
2112 case MESA_FORMAT_Z24_S8
:
2113 case MESA_FORMAT_Z24_X8
:
2114 return pack_float_z_Z24_S8
;
2115 case MESA_FORMAT_S8_Z24
:
2116 case MESA_FORMAT_X8_Z24
:
2117 return pack_float_z_S8_Z24
;
2118 case MESA_FORMAT_Z16
:
2119 return pack_float_z_Z16
;
2120 case MESA_FORMAT_Z32
:
2121 return pack_float_z_Z32
;
2122 case MESA_FORMAT_Z32_FLOAT
:
2123 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2124 return pack_float_z_Z32_FLOAT
;
2127 "unexpected format in _mesa_get_pack_float_z_func()");
2135 ** Pack uint Z pixels. The incoming src value is always in
2136 ** the range [0, 2^32-1].
2140 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2142 /* don't disturb the stencil values */
2143 GLuint
*d
= ((GLuint
*) dst
);
2144 GLuint s
= *d
& 0xff;
2145 GLuint z
= *src
& 0xffffff00;
2150 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2152 /* don't disturb the stencil values */
2153 GLuint
*d
= ((GLuint
*) dst
);
2154 GLuint s
= *d
& 0xff000000;
2155 GLuint z
= *src
>> 8;
2160 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2162 GLushort
*d
= ((GLushort
*) dst
);
2167 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2169 GLuint
*d
= ((GLuint
*) dst
);
2174 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2176 GLuint
*d
= ((GLuint
*) dst
);
2177 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2184 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2186 GLfloat
*d
= ((GLfloat
*) dst
);
2187 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2194 _mesa_get_pack_uint_z_func(gl_format format
)
2197 case MESA_FORMAT_Z24_S8
:
2198 case MESA_FORMAT_Z24_X8
:
2199 return pack_uint_z_Z24_S8
;
2200 case MESA_FORMAT_S8_Z24
:
2201 case MESA_FORMAT_X8_Z24
:
2202 return pack_uint_z_S8_Z24
;
2203 case MESA_FORMAT_Z16
:
2204 return pack_uint_z_Z16
;
2205 case MESA_FORMAT_Z32
:
2206 return pack_uint_z_Z32
;
2207 case MESA_FORMAT_Z32_FLOAT
:
2208 return pack_uint_z_Z32_FLOAT
;
2209 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2210 return pack_uint_z_Z32_FLOAT_X24S8
;
2212 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2219 ** Pack ubyte stencil pixels
2223 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2225 /* don't disturb the Z values */
2226 GLuint
*d
= ((GLuint
*) dst
);
2228 GLuint z
= *d
& 0xffffff00;
2233 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2235 /* don't disturb the Z values */
2236 GLuint
*d
= ((GLuint
*) dst
);
2237 GLuint s
= *src
<< 24;
2238 GLuint z
= *d
& 0xffffff;
2243 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2245 GLubyte
*d
= (GLubyte
*) dst
;
2250 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2252 GLfloat
*d
= ((GLfloat
*) dst
);
2257 gl_pack_ubyte_stencil_func
2258 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2261 case MESA_FORMAT_Z24_S8
:
2262 return pack_ubyte_stencil_Z24_S8
;
2263 case MESA_FORMAT_S8_Z24
:
2264 return pack_ubyte_stencil_S8_Z24
;
2265 case MESA_FORMAT_S8
:
2266 return pack_ubyte_stencil_S8
;
2267 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2268 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2271 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2279 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2280 const GLfloat
*src
, void *dst
)
2283 case MESA_FORMAT_Z24_S8
:
2284 case MESA_FORMAT_Z24_X8
:
2286 /* don't disturb the stencil values */
2287 GLuint
*d
= ((GLuint
*) dst
);
2288 const GLdouble scale
= (GLdouble
) 0xffffff;
2290 for (i
= 0; i
< n
; i
++) {
2291 GLuint s
= d
[i
] & 0xff;
2292 GLuint z
= (GLuint
) (src
[i
] * scale
);
2293 assert(z
<= 0xffffff);
2294 d
[i
] = (z
<< 8) | s
;
2298 case MESA_FORMAT_S8_Z24
:
2299 case MESA_FORMAT_X8_Z24
:
2301 /* don't disturb the stencil values */
2302 GLuint
*d
= ((GLuint
*) dst
);
2303 const GLdouble scale
= (GLdouble
) 0xffffff;
2305 for (i
= 0; i
< n
; i
++) {
2306 GLuint s
= d
[i
] & 0xff000000;
2307 GLuint z
= (GLuint
) (src
[i
] * scale
);
2308 assert(z
<= 0xffffff);
2313 case MESA_FORMAT_Z16
:
2315 GLushort
*d
= ((GLushort
*) dst
);
2316 const GLfloat scale
= (GLfloat
) 0xffff;
2318 for (i
= 0; i
< n
; i
++) {
2319 d
[i
] = (GLushort
) (src
[i
] * scale
);
2323 case MESA_FORMAT_Z32
:
2325 GLuint
*d
= ((GLuint
*) dst
);
2326 const GLdouble scale
= (GLdouble
) 0xffffffff;
2328 for (i
= 0; i
< n
; i
++) {
2329 d
[i
] = (GLuint
) (src
[i
] * scale
);
2333 case MESA_FORMAT_Z32_FLOAT
:
2334 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2336 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2338 GLfloat
*d
= ((GLfloat
*) dst
);
2340 for (i
= 0; i
< n
; i
++) {
2346 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2352 * The incoming Z values are always in the range [0, 0xffffffff].
2355 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2356 const GLuint
*src
, void *dst
)
2359 case MESA_FORMAT_Z24_S8
:
2360 case MESA_FORMAT_Z24_X8
:
2362 /* don't disturb the stencil values */
2363 GLuint
*d
= ((GLuint
*) dst
);
2365 for (i
= 0; i
< n
; i
++) {
2366 GLuint s
= d
[i
] & 0xff;
2367 GLuint z
= src
[i
] & 0xffffff00;
2372 case MESA_FORMAT_S8_Z24
:
2373 case MESA_FORMAT_X8_Z24
:
2375 /* don't disturb the stencil values */
2376 GLuint
*d
= ((GLuint
*) dst
);
2378 for (i
= 0; i
< n
; i
++) {
2379 GLuint s
= d
[i
] & 0xff000000;
2380 GLuint z
= src
[i
] >> 8;
2385 case MESA_FORMAT_Z16
:
2387 GLushort
*d
= ((GLushort
*) dst
);
2389 for (i
= 0; i
< n
; i
++) {
2390 d
[i
] = src
[i
] >> 16;
2394 case MESA_FORMAT_Z32
:
2395 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2397 case MESA_FORMAT_Z32_FLOAT
:
2399 GLuint
*d
= ((GLuint
*) dst
);
2400 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2402 for (i
= 0; i
< n
; i
++) {
2403 d
[i
] = src
[i
] * scale
;
2404 assert(d
[i
] >= 0.0f
);
2405 assert(d
[i
] <= 1.0f
);
2409 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2411 GLfloat
*d
= ((GLfloat
*) dst
);
2412 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2414 for (i
= 0; i
< n
; i
++) {
2415 d
[i
* 2] = src
[i
] * scale
;
2416 assert(d
[i
* 2] >= 0.0f
);
2417 assert(d
[i
* 2] <= 1.0f
);
2422 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2428 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2429 const GLubyte
*src
, void *dst
)
2432 case MESA_FORMAT_Z24_S8
:
2434 /* don't disturb the Z values */
2435 GLuint
*d
= ((GLuint
*) dst
);
2437 for (i
= 0; i
< n
; i
++) {
2439 GLuint z
= d
[i
] & 0xffffff00;
2444 case MESA_FORMAT_S8_Z24
:
2446 /* don't disturb the Z values */
2447 GLuint
*d
= ((GLuint
*) dst
);
2449 for (i
= 0; i
< n
; i
++) {
2450 GLuint s
= src
[i
] << 24;
2451 GLuint z
= d
[i
] & 0xffffff;
2456 case MESA_FORMAT_S8
:
2457 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2459 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2463 for (i
= 0; i
< n
; i
++) {
2464 d
[i
* 2 + 1] = src
[i
];
2469 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2475 * Incoming Z/stencil values are always in uint_24_8 format.
2478 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2479 const GLuint
*src
, void *dst
)
2482 case MESA_FORMAT_Z24_S8
:
2483 memcpy(dst
, src
, n
* sizeof(GLuint
));
2485 case MESA_FORMAT_S8_Z24
:
2487 GLuint
*d
= ((GLuint
*) dst
);
2489 for (i
= 0; i
< n
; i
++) {
2490 GLuint s
= src
[i
] << 24;
2491 GLuint z
= src
[i
] >> 8;
2497 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2498 _mesa_get_format_name(format
));
2506 * Convert a boolean color mask to a packed color where each channel of
2507 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2510 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2512 GLfloat maskColor
[4];
2514 switch (_mesa_get_format_datatype(format
)) {
2515 case GL_UNSIGNED_NORMALIZED
:
2516 /* simple: 1.0 will convert to ~0 in the right bit positions */
2517 maskColor
[0] = colorMask
[0] ? 1.0 : 0.0;
2518 maskColor
[1] = colorMask
[1] ? 1.0 : 0.0;
2519 maskColor
[2] = colorMask
[2] ? 1.0 : 0.0;
2520 maskColor
[3] = colorMask
[3] ? 1.0 : 0.0;
2521 _mesa_pack_float_rgba_row(format
, 1,
2522 (const GLfloat (*)[4]) maskColor
, dst
);
2524 case GL_SIGNED_NORMALIZED
:
2526 /* These formats are harder because it's hard to know the floating
2527 * point values that will convert to ~0 for each color channel's bits.
2528 * This solution just generates a non-zero value for each color channel
2529 * then fixes up the non-zero values to be ~0.
2530 * Note: we'll need to add special case code if we ever have to deal
2531 * with formats with unequal color channel sizes, like R11_G11_B10.
2532 * We issue a warning below for channel sizes other than 8,16,32.
2535 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2536 GLuint bytes
= _mesa_get_format_bytes(format
);
2539 /* this should put non-zero values into the channels of dst */
2540 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2541 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2542 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2543 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2544 _mesa_pack_float_rgba_row(format
, 1,
2545 (const GLfloat (*)[4]) maskColor
, dst
);
2547 /* fix-up the dst channels by converting non-zero values to ~0 */
2549 GLubyte
*d
= (GLubyte
*) dst
;
2550 for (i
= 0; i
< bytes
; i
++) {
2551 d
[i
] = d
[i
] ? 0xffff : 0x0;
2554 else if (bits
== 16) {
2555 GLushort
*d
= (GLushort
*) dst
;
2556 for (i
= 0; i
< bytes
/ 2; i
++) {
2557 d
[i
] = d
[i
] ? 0xffff : 0x0;
2560 else if (bits
== 32) {
2561 GLuint
*d
= (GLuint
*) dst
;
2562 for (i
= 0; i
< bytes
/ 4; i
++) {
2563 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2567 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2573 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");