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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
27 * Color, depth, stencil packing functions.
28 * Used to pack basic color, depth and stencil formats to specific
31 * There are both per-pixel and per-row packing functions:
32 * - The former will be used by swrast to write values to the color, depth,
33 * stencil buffers when drawing points, lines and masked spans.
34 * - The later will be used for image-oriented functions like glDrawPixels,
35 * glAccum, and glTexImage.
40 #include "format_pack.h"
42 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
43 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
46 /** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */
54 typedef void (*pack_ubyte_rgba_row_func
)(GLuint n
,
55 const GLubyte src
[][4], void *dst
);
57 typedef void (*pack_float_rgba_row_func
)(GLuint n
,
58 const GLfloat src
[][4], void *dst
);
63 linear_to_srgb(GLfloat cl
)
67 else if (cl
< 0.0031308f
)
70 return 1.055f
* powf(cl
, 0.41666f
) - 0.055f
;
77 linear_float_to_srgb_ubyte(GLfloat cl
)
79 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
));
85 linear_ubyte_to_srgb_ubyte(GLubyte cl
)
87 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
/ 255.0f
));
95 * MESA_FORMAT_RGBA8888
99 pack_ubyte_RGBA8888(const GLubyte src
[4], void *dst
)
101 GLuint
*d
= ((GLuint
*) dst
);
102 *d
= PACK_COLOR_8888(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
106 pack_float_RGBA8888(const GLfloat src
[4], void *dst
)
109 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
110 pack_ubyte_RGBA8888(v
, dst
);
114 pack_row_ubyte_RGBA8888(GLuint n
, const GLubyte src
[][4], void *dst
)
116 GLuint
*d
= ((GLuint
*) dst
);
118 for (i
= 0; i
< n
; i
++) {
119 d
[i
] = PACK_COLOR_8888(src
[i
][RCOMP
], src
[i
][GCOMP
],
120 src
[i
][BCOMP
], src
[i
][ACOMP
]);
125 pack_row_float_RGBA8888(GLuint n
, const GLfloat src
[][4], void *dst
)
127 GLuint
*d
= ((GLuint
*) dst
);
129 for (i
= 0; i
< n
; i
++) {
131 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
132 pack_ubyte_RGBA8888(v
, d
+ i
);
139 * MESA_FORMAT_RGBA8888_REV
143 pack_ubyte_RGBA8888_REV(const GLubyte src
[4], void *dst
)
145 GLuint
*d
= ((GLuint
*) dst
);
146 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[BCOMP
], src
[GCOMP
], src
[RCOMP
]);
150 pack_float_RGBA8888_REV(const GLfloat src
[4], void *dst
)
153 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
154 pack_ubyte_RGBA8888_REV(v
, dst
);
158 pack_row_ubyte_RGBA8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
160 GLuint
*d
= ((GLuint
*) dst
);
162 for (i
= 0; i
< n
; i
++) {
163 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][BCOMP
],
164 src
[i
][GCOMP
], src
[i
][RCOMP
]);
169 pack_row_float_RGBA8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
171 GLuint
*d
= ((GLuint
*) dst
);
173 for (i
= 0; i
< n
; i
++) {
175 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
176 pack_ubyte_RGBA8888_REV(v
, d
+ i
);
182 * MESA_FORMAT_ARGB8888
186 pack_ubyte_ARGB8888(const GLubyte src
[4], void *dst
)
188 GLuint
*d
= ((GLuint
*) dst
);
189 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
193 pack_float_ARGB8888(const GLfloat src
[4], void *dst
)
196 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
197 pack_ubyte_ARGB8888(v
, dst
);
201 pack_row_ubyte_ARGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
203 GLuint
*d
= ((GLuint
*) dst
);
205 for (i
= 0; i
< n
; i
++) {
206 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][RCOMP
],
207 src
[i
][GCOMP
], src
[i
][BCOMP
]);
212 pack_row_float_ARGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
214 GLuint
*d
= ((GLuint
*) dst
);
216 for (i
= 0; i
< n
; i
++) {
218 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
219 pack_ubyte_ARGB8888(v
, d
+ i
);
225 * MESA_FORMAT_ARGB8888_REV
229 pack_ubyte_ARGB8888_REV(const GLubyte src
[4], void *dst
)
231 GLuint
*d
= ((GLuint
*) dst
);
232 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
236 pack_float_ARGB8888_REV(const GLfloat src
[4], void *dst
)
239 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
240 pack_ubyte_ARGB8888_REV(v
, dst
);
244 pack_row_ubyte_ARGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
246 GLuint
*d
= ((GLuint
*) dst
);
248 for (i
= 0; i
< n
; i
++) {
249 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
],
250 src
[i
][RCOMP
], src
[i
][ACOMP
]);
255 pack_row_float_ARGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
257 GLuint
*d
= ((GLuint
*) dst
);
259 for (i
= 0; i
< n
; i
++) {
261 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
262 pack_ubyte_ARGB8888_REV(v
, d
+ i
);
268 * MESA_FORMAT_XRGB8888
272 pack_ubyte_XRGB8888(const GLubyte src
[4], void *dst
)
274 GLuint
*d
= ((GLuint
*) dst
);
275 *d
= PACK_COLOR_8888(0x0, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
279 pack_float_XRGB8888(const GLfloat src
[4], void *dst
)
282 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
283 pack_ubyte_XRGB8888(v
, dst
);
287 pack_row_ubyte_XRGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
289 GLuint
*d
= ((GLuint
*) dst
);
291 for (i
= 0; i
< n
; i
++) {
292 d
[i
] = PACK_COLOR_8888(0, src
[i
][RCOMP
], src
[i
][GCOMP
], src
[i
][BCOMP
]);
297 pack_row_float_XRGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
299 GLuint
*d
= ((GLuint
*) dst
);
301 for (i
= 0; i
< n
; i
++) {
303 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
304 pack_ubyte_XRGB8888(v
, d
+ i
);
310 * MESA_FORMAT_XRGB8888_REV
314 pack_ubyte_XRGB8888_REV(const GLubyte src
[4], void *dst
)
316 GLuint
*d
= ((GLuint
*) dst
);
317 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], 0);
321 pack_float_XRGB8888_REV(const GLfloat src
[4], void *dst
)
324 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
325 pack_ubyte_XRGB8888_REV(v
, dst
);
329 pack_row_ubyte_XRGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
331 GLuint
*d
= ((GLuint
*) dst
);
333 for (i
= 0; i
< n
; i
++) {
334 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
], src
[i
][RCOMP
], 0);
339 pack_row_float_XRGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
341 GLuint
*d
= ((GLuint
*) dst
);
343 for (i
= 0; i
< n
; i
++) {
345 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
346 pack_ubyte_XRGB8888_REV(v
, d
+ i
);
356 pack_ubyte_RGB888(const GLubyte src
[4], void *dst
)
358 GLubyte
*d
= ((GLubyte
*) dst
);
365 pack_float_RGB888(const GLfloat src
[4], void *dst
)
367 GLubyte
*d
= ((GLubyte
*) dst
);
368 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[RCOMP
]);
369 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
370 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[BCOMP
]);
374 pack_row_ubyte_RGB888(GLuint n
, const GLubyte src
[][4], void *dst
)
376 GLubyte
*d
= ((GLubyte
*) dst
);
378 for (i
= 0; i
< n
; i
++) {
379 d
[i
*3+2] = src
[i
][RCOMP
];
380 d
[i
*3+1] = src
[i
][GCOMP
];
381 d
[i
*3+0] = src
[i
][BCOMP
];
386 pack_row_float_RGB888(GLuint n
, const GLfloat src
[][4], void *dst
)
388 GLubyte
*d
= ((GLubyte
*) dst
);
390 for (i
= 0; i
< n
; i
++) {
392 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
405 pack_ubyte_BGR888(const GLubyte src
[4], void *dst
)
407 GLubyte
*d
= ((GLubyte
*) dst
);
414 pack_float_BGR888(const GLfloat src
[4], void *dst
)
416 GLubyte
*d
= ((GLubyte
*) dst
);
417 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[BCOMP
]);
418 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
419 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
423 pack_row_ubyte_BGR888(GLuint n
, const GLubyte src
[][4], void *dst
)
425 GLubyte
*d
= ((GLubyte
*) dst
);
427 for (i
= 0; i
< n
; i
++) {
428 d
[i
*3+2] = src
[i
][BCOMP
];
429 d
[i
*3+1] = src
[i
][GCOMP
];
430 d
[i
*3+0] = src
[i
][RCOMP
];
435 pack_row_float_BGR888(GLuint n
, const GLfloat src
[][4], void *dst
)
437 GLubyte
*d
= ((GLubyte
*) dst
);
439 for (i
= 0; i
< n
; i
++) {
441 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
454 pack_ubyte_RGB565(const GLubyte src
[4], void *dst
)
456 GLushort
*d
= ((GLushort
*) dst
);
457 *d
= PACK_COLOR_565(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
461 pack_float_RGB565(const GLfloat src
[4], void *dst
)
464 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
465 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
466 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
467 pack_ubyte_RGB565(v
, dst
);
471 pack_row_ubyte_RGB565(GLuint n
, const GLubyte src
[][4], void *dst
)
473 GLushort
*d
= ((GLushort
*) dst
);
475 for (i
= 0; i
< n
; i
++) {
476 pack_ubyte_RGB565(src
[i
], d
+ i
);
481 pack_row_float_RGB565(GLuint n
, const GLfloat src
[][4], void *dst
)
483 GLushort
*d
= ((GLushort
*) dst
);
485 for (i
= 0; i
< n
; i
++) {
487 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
488 pack_ubyte_RGB565(v
, d
+ i
);
494 * MESA_FORMAT_RGB565_REV
498 pack_ubyte_RGB565_REV(const GLubyte src
[4], void *dst
)
500 GLushort
*d
= ((GLushort
*) dst
);
501 *d
= PACK_COLOR_565_REV(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
505 pack_float_RGB565_REV(const GLfloat src
[4], void *dst
)
507 GLushort
*d
= ((GLushort
*) dst
);
509 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
510 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
511 UNCLAMPED_FLOAT_TO_UBYTE(b
, src
[BCOMP
]);
512 *d
= PACK_COLOR_565_REV(r
, g
, b
);
516 pack_row_ubyte_RGB565_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
518 GLushort
*d
= ((GLushort
*) dst
);
520 for (i
= 0; i
< n
; i
++) {
521 pack_ubyte_RGB565_REV(src
[i
], d
+ i
);
526 pack_row_float_RGB565_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
528 GLushort
*d
= ((GLushort
*) dst
);
530 for (i
= 0; i
< n
; i
++) {
532 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
533 pack_ubyte_RGB565_REV(v
, d
+ i
);
539 * MESA_FORMAT_ARGB4444
543 pack_ubyte_ARGB4444(const GLubyte src
[4], void *dst
)
545 GLushort
*d
= ((GLushort
*) dst
);
546 *d
= PACK_COLOR_4444(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
550 pack_float_ARGB4444(const GLfloat src
[4], void *dst
)
553 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
554 pack_ubyte_ARGB4444(v
, dst
);
557 /* use fallback row packing functions */
561 * MESA_FORMAT_ARGB4444_REV
565 pack_ubyte_ARGB4444_REV(const GLubyte src
[4], void *dst
)
567 GLushort
*d
= ((GLushort
*) dst
);
568 *d
= PACK_COLOR_4444(src
[GCOMP
], src
[BCOMP
], src
[ACOMP
], src
[RCOMP
]);
572 pack_float_ARGB4444_REV(const GLfloat src
[4], void *dst
)
575 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
576 pack_ubyte_ARGB4444_REV(v
, dst
);
579 /* use fallback row packing functions */
583 * MESA_FORMAT_RGBA5551
587 pack_ubyte_RGBA5551(const GLubyte src
[4], void *dst
)
589 GLushort
*d
= ((GLushort
*) dst
);
590 *d
= PACK_COLOR_5551(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
594 pack_float_RGBA5551(const GLfloat src
[4], void *dst
)
597 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
598 pack_ubyte_RGBA5551(v
, dst
);
601 /* use fallback row packing functions */
605 * MESA_FORMAT_ARGB1555
609 pack_ubyte_ARGB1555(const GLubyte src
[4], void *dst
)
611 GLushort
*d
= ((GLushort
*) dst
);
612 *d
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
616 pack_float_ARGB1555(const GLfloat src
[4], void *dst
)
619 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
620 pack_ubyte_ARGB1555(v
, dst
);
624 /* MESA_FORMAT_ARGB1555_REV */
627 pack_ubyte_ARGB1555_REV(const GLubyte src
[4], void *dst
)
629 GLushort
*d
= ((GLushort
*) dst
), tmp
;
630 tmp
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
631 *d
= (tmp
>> 8) | (tmp
<< 8);
635 pack_float_ARGB1555_REV(const GLfloat src
[4], void *dst
)
638 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
639 pack_ubyte_ARGB1555_REV(v
, dst
);
643 /* MESA_FORMAT_AL44 */
646 pack_ubyte_AL44(const GLubyte src
[4], void *dst
)
648 GLubyte
*d
= ((GLubyte
*) dst
);
649 *d
= PACK_COLOR_44(src
[ACOMP
], src
[RCOMP
]);
653 pack_float_AL44(const GLfloat src
[4], void *dst
)
656 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
657 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
658 pack_ubyte_AL44(v
, dst
);
662 /* MESA_FORMAT_AL88 */
665 pack_ubyte_AL88(const GLubyte src
[4], void *dst
)
667 GLushort
*d
= ((GLushort
*) dst
);
668 *d
= PACK_COLOR_88(src
[ACOMP
], src
[RCOMP
]);
672 pack_float_AL88(const GLfloat src
[4], void *dst
)
675 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
676 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
677 pack_ubyte_AL88(v
, dst
);
681 /* MESA_FORMAT_AL88_REV */
684 pack_ubyte_AL88_REV(const GLubyte src
[4], void *dst
)
686 GLushort
*d
= ((GLushort
*) dst
);
687 *d
= PACK_COLOR_88(src
[RCOMP
], src
[ACOMP
]);
691 pack_float_AL88_REV(const GLfloat src
[4], void *dst
)
694 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
695 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
696 pack_ubyte_AL88_REV(v
, dst
);
700 /* MESA_FORMAT_AL1616 */
703 pack_ubyte_AL1616(const GLubyte src
[4], void *dst
)
705 GLuint
*d
= ((GLuint
*) dst
);
706 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
707 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
708 *d
= PACK_COLOR_1616(a
, l
);
712 pack_float_AL1616(const GLfloat src
[4], void *dst
)
714 GLuint
*d
= ((GLuint
*) dst
);
716 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
717 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
718 *d
= PACK_COLOR_1616(a
, l
);
722 /* MESA_FORMAT_AL1616_REV */
725 pack_ubyte_AL1616_REV(const GLubyte src
[4], void *dst
)
727 GLuint
*d
= ((GLuint
*) dst
);
728 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
729 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
730 *d
= PACK_COLOR_1616(l
, a
);
734 pack_float_AL1616_REV(const GLfloat src
[4], void *dst
)
736 GLuint
*d
= ((GLuint
*) dst
);
738 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
739 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
740 *d
= PACK_COLOR_1616(l
, a
);
744 /* MESA_FORMAT_RGB332 */
747 pack_ubyte_RGB332(const GLubyte src
[4], void *dst
)
749 GLubyte
*d
= ((GLubyte
*) dst
);
750 *d
= PACK_COLOR_332(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
754 pack_float_RGB332(const GLfloat src
[4], void *dst
)
757 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
758 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
759 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
760 pack_ubyte_RGB332(v
, dst
);
767 pack_ubyte_A8(const GLubyte src
[4], void *dst
)
769 GLubyte
*d
= ((GLubyte
*) dst
);
774 pack_float_A8(const GLfloat src
[4], void *dst
)
776 GLubyte
*d
= ((GLubyte
*) dst
);
777 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[ACOMP
]);
781 /* MESA_FORMAT_A16 */
784 pack_ubyte_A16(const GLubyte src
[4], void *dst
)
786 GLushort
*d
= ((GLushort
*) dst
);
787 *d
= UBYTE_TO_USHORT(src
[ACOMP
]);
791 pack_float_A16(const GLfloat src
[4], void *dst
)
793 GLushort
*d
= ((GLushort
*) dst
);
794 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[ACOMP
]);
801 pack_ubyte_L8(const GLubyte src
[4], void *dst
)
803 GLubyte
*d
= ((GLubyte
*) dst
);
808 pack_float_L8(const GLfloat src
[4], void *dst
)
810 GLubyte
*d
= ((GLubyte
*) dst
);
811 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
815 /* MESA_FORMAT_L16 */
818 pack_ubyte_L16(const GLubyte src
[4], void *dst
)
820 GLushort
*d
= ((GLushort
*) dst
);
821 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
825 pack_float_L16(const GLfloat src
[4], void *dst
)
827 GLushort
*d
= ((GLushort
*) dst
);
828 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
832 /* MESA_FORMAT_YCBCR */
835 pack_ubyte_YCBCR(const GLubyte src
[4], void *dst
)
841 pack_float_YCBCR(const GLfloat src
[4], void *dst
)
847 /* MESA_FORMAT_YCBCR_REV */
850 pack_ubyte_YCBCR_REV(const GLubyte src
[4], void *dst
)
856 pack_float_YCBCR_REV(const GLfloat src
[4], void *dst
)
865 pack_ubyte_R8(const GLubyte src
[4], void *dst
)
867 GLubyte
*d
= ((GLubyte
*) dst
);
872 pack_float_R8(const GLfloat src
[4], void *dst
)
874 GLubyte
*d
= ((GLubyte
*) dst
);
876 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
881 /* MESA_FORMAT_GR88 */
884 pack_ubyte_GR88(const GLubyte src
[4], void *dst
)
886 GLubyte
*d
= ((GLubyte
*) dst
);
887 *d
= PACK_COLOR_88(src
[GCOMP
], src
[RCOMP
]);
891 pack_float_GR88(const GLfloat src
[4], void *dst
)
893 GLushort
*d
= ((GLushort
*) dst
);
895 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
896 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
897 *d
= PACK_COLOR_88(g
, r
);
901 /* MESA_FORMAT_RG88 */
904 pack_ubyte_RG88(const GLubyte src
[4], void *dst
)
906 GLubyte
*d
= ((GLubyte
*) dst
);
907 *d
= PACK_COLOR_88(src
[RCOMP
], src
[GCOMP
]);
911 pack_float_RG88(const GLfloat src
[4], void *dst
)
913 GLushort
*d
= ((GLushort
*) dst
);
915 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
916 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
917 *d
= PACK_COLOR_88(r
, g
);
921 /* MESA_FORMAT_R16 */
924 pack_ubyte_R16(const GLubyte src
[4], void *dst
)
926 GLushort
*d
= ((GLushort
*) dst
);
927 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
931 pack_float_R16(const GLfloat src
[4], void *dst
)
933 GLushort
*d
= ((GLushort
*) dst
);
934 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
938 /* MESA_FORMAT_GR1616 */
941 pack_ubyte_GR1616(const GLubyte src
[4], void *dst
)
943 GLuint
*d
= ((GLuint
*) dst
);
944 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
945 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
946 *d
= PACK_COLOR_1616(g
, r
);
950 pack_float_GR1616(const GLfloat src
[4], void *dst
)
952 GLuint
*d
= ((GLuint
*) dst
);
954 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
955 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
956 *d
= PACK_COLOR_1616(g
, r
);
960 /* MESA_FORMAT_RG1616 */
963 pack_ubyte_RG1616(const GLubyte src
[4], void *dst
)
965 GLuint
*d
= ((GLuint
*) dst
);
966 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
967 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
968 *d
= PACK_COLOR_1616(r
, g
);
973 pack_float_RG1616(const GLfloat src
[4], void *dst
)
975 GLuint
*d
= ((GLuint
*) dst
);
977 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
978 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
979 *d
= PACK_COLOR_1616(r
, g
);
983 /* MESA_FORMAT_ARGB2101010 */
986 pack_ubyte_ARGB2101010(const GLubyte src
[4], void *dst
)
988 GLuint
*d
= ((GLuint
*) dst
);
989 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
990 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
991 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
992 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
993 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
997 pack_float_ARGB2101010(const GLfloat src
[4], void *dst
)
999 GLuint
*d
= ((GLuint
*) dst
);
1000 GLushort r
, g
, b
, a
;
1001 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1002 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1003 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1004 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1005 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
1009 /* MESA_FORMAT_ABGR2101010_UINT */
1012 pack_ubyte_ABGR2101010_UINT(const GLubyte src
[4], void *dst
)
1014 GLuint
*d
= ((GLuint
*) dst
);
1015 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
1016 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
1017 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
1018 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
1019 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1023 pack_float_ABGR2101010_UINT(const GLfloat src
[4], void *dst
)
1025 GLuint
*d
= ((GLuint
*) dst
);
1026 GLushort r
, g
, b
, a
;
1027 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1028 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1029 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1030 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1031 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1035 /* MESA_FORMAT_SRGB8 */
1038 pack_ubyte_SRGB8(const GLubyte src
[4], void *dst
)
1040 GLubyte
*d
= ((GLubyte
*) dst
);
1041 d
[2] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1042 d
[1] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1043 d
[0] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1047 pack_float_SRGB8(const GLfloat src
[4], void *dst
)
1049 GLubyte
*d
= ((GLubyte
*) dst
);
1050 d
[2] = linear_float_to_srgb_ubyte(src
[RCOMP
]);
1051 d
[1] = linear_float_to_srgb_ubyte(src
[GCOMP
]);
1052 d
[0] = linear_float_to_srgb_ubyte(src
[BCOMP
]);
1056 /* MESA_FORMAT_SRGBA8 */
1059 pack_ubyte_SRGBA8(const GLubyte src
[4], void *dst
)
1061 GLuint
*d
= ((GLuint
*) dst
);
1062 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1063 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[GCOMP
]);
1064 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[BCOMP
]);
1065 *d
= PACK_COLOR_8888(r
, g
, b
, src
[ACOMP
]);
1069 pack_float_SRGBA8(const GLfloat src
[4], void *dst
)
1071 GLuint
*d
= ((GLuint
*) dst
);
1073 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1074 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1075 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1076 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1077 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1081 /* MESA_FORMAT_SARGB8 */
1084 pack_ubyte_SARGB8(const GLubyte src
[4], void *dst
)
1086 GLuint
*d
= ((GLuint
*) dst
);
1087 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1088 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1089 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1090 *d
= PACK_COLOR_8888(src
[ACOMP
], r
, g
, b
);
1094 pack_float_SARGB8(const GLfloat src
[4], void *dst
)
1096 GLuint
*d
= ((GLuint
*) dst
);
1098 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1099 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1100 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1101 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1102 *d
= PACK_COLOR_8888(a
, r
, g
, b
);
1106 /* MESA_FORMAT_SL8 */
1109 pack_ubyte_SL8(const GLubyte src
[4], void *dst
)
1111 GLubyte
*d
= ((GLubyte
*) dst
);
1112 *d
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1116 pack_float_SL8(const GLfloat src
[4], void *dst
)
1118 GLubyte
*d
= ((GLubyte
*) dst
);
1119 GLubyte l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1124 /* MESA_FORMAT_SLA8 */
1127 pack_ubyte_SLA8(const GLubyte src
[4], void *dst
)
1129 GLushort
*d
= ((GLushort
*) dst
);
1130 GLubyte l
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1131 *d
= PACK_COLOR_88(src
[ACOMP
], l
);
1135 pack_float_SLA8(const GLfloat src
[4], void *dst
)
1137 GLushort
*d
= ((GLushort
*) dst
);
1138 GLubyte a
, l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1139 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1140 *d
= PACK_COLOR_88(a
, l
);
1144 /* MESA_FORMAT_RGBA_FLOAT32 */
1147 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
1149 GLfloat
*d
= ((GLfloat
*) dst
);
1150 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1151 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1152 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1153 d
[3] = UBYTE_TO_FLOAT(src
[3]);
1157 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
1159 GLfloat
*d
= ((GLfloat
*) dst
);
1167 /* MESA_FORMAT_RGBA_FLOAT16 */
1170 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
1172 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1173 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1174 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1175 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1176 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
1180 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
1182 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1183 d
[0] = _mesa_float_to_half(src
[0]);
1184 d
[1] = _mesa_float_to_half(src
[1]);
1185 d
[2] = _mesa_float_to_half(src
[2]);
1186 d
[3] = _mesa_float_to_half(src
[3]);
1190 /* MESA_FORMAT_RGB_FLOAT32 */
1193 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
1195 GLfloat
*d
= ((GLfloat
*) dst
);
1196 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1197 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1198 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1202 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
1204 GLfloat
*d
= ((GLfloat
*) dst
);
1211 /* MESA_FORMAT_RGB_FLOAT16 */
1214 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
1216 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1217 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1218 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1219 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1223 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
1225 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1226 d
[0] = _mesa_float_to_half(src
[0]);
1227 d
[1] = _mesa_float_to_half(src
[1]);
1228 d
[2] = _mesa_float_to_half(src
[2]);
1232 /* MESA_FORMAT_ALPHA_FLOAT32 */
1235 pack_ubyte_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1237 GLfloat
*d
= ((GLfloat
*) dst
);
1238 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1242 pack_float_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1244 GLfloat
*d
= ((GLfloat
*) dst
);
1249 /* MESA_FORMAT_ALPHA_FLOAT16 */
1252 pack_ubyte_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1254 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1255 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1259 pack_float_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1261 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1262 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
1266 /* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
1269 pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src
[4], void *dst
)
1271 GLfloat
*d
= ((GLfloat
*) dst
);
1272 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1276 pack_float_LUMINANCE_FLOAT32(const GLfloat src
[4], void *dst
)
1278 GLfloat
*d
= ((GLfloat
*) dst
);
1283 /* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
1286 pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src
[4], void *dst
)
1288 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1289 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1293 pack_float_LUMINANCE_FLOAT16(const GLfloat src
[4], void *dst
)
1295 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1296 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1300 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
1303 pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1305 GLfloat
*d
= ((GLfloat
*) dst
);
1306 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1307 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1311 pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1313 GLfloat
*d
= ((GLfloat
*) dst
);
1319 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
1322 pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1324 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1325 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1326 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1330 pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1332 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1333 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1334 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1338 /* MESA_FORMAT_RG_FLOAT32 */
1341 pack_ubyte_RG_FLOAT32(const GLubyte src
[4], void *dst
)
1343 GLfloat
*d
= ((GLfloat
*) dst
);
1344 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1345 d
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1349 pack_float_RG_FLOAT32(const GLfloat src
[4], void *dst
)
1351 GLfloat
*d
= ((GLfloat
*) dst
);
1357 /* MESA_FORMAT_RG_FLOAT16 */
1360 pack_ubyte_RG_FLOAT16(const GLubyte src
[4], void *dst
)
1362 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1363 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1364 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[GCOMP
]));
1368 pack_float_RG_FLOAT16(const GLfloat src
[4], void *dst
)
1370 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1371 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1372 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1376 /* MESA_FORMAT_DUDV8 */
1379 pack_ubyte_DUDV8(const GLubyte src
[4], void *dst
)
1381 /* XXX is this ever used? */
1382 GLushort
*d
= ((GLushort
*) dst
);
1383 *d
= PACK_COLOR_88(src
[0], src
[1]);
1387 pack_float_DUDV8(const GLfloat src
[4], void *dst
)
1389 GLushort
*d
= ((GLushort
*) dst
);
1391 du
= FLOAT_TO_BYTE(CLAMP(src
[0], 0.0F
, 1.0F
));
1392 dv
= FLOAT_TO_BYTE(CLAMP(src
[1], 0.0F
, 1.0F
));
1393 *d
= PACK_COLOR_88(du
, dv
);
1397 /* MESA_FORMAT_RGBA_16 */
1400 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1402 GLushort
*d
= ((GLushort
*) dst
);
1403 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1404 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1405 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1406 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1410 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1412 GLushort
*d
= ((GLushort
*) dst
);
1413 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1414 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1415 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1416 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1422 * MESA_FORMAT_SIGNED_R8
1426 pack_float_SIGNED_R8(const GLfloat src
[4], void *dst
)
1428 GLbyte
*d
= (GLbyte
*) dst
;
1429 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1434 * MESA_FORMAT_SIGNED_RG88_REV
1438 pack_float_SIGNED_RG88_REV(const GLfloat src
[4], void *dst
)
1440 GLushort
*d
= (GLushort
*) 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
));
1448 * MESA_FORMAT_SIGNED_RGBX8888
1452 pack_float_SIGNED_RGBX8888(const GLfloat src
[4], void *dst
)
1454 GLuint
*d
= (GLuint
*) dst
;
1455 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1456 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1457 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1459 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1464 * MESA_FORMAT_SIGNED_RGBA8888
1468 pack_float_SIGNED_RGBA8888(const GLfloat src
[4], void *dst
)
1470 GLuint
*d
= (GLuint
*) dst
;
1471 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1472 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1473 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1474 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1475 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1480 * MESA_FORMAT_SIGNED_RGBA8888_REV
1484 pack_float_SIGNED_RGBA8888_REV(const GLfloat src
[4], void *dst
)
1486 GLuint
*d
= (GLuint
*) dst
;
1487 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1488 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1489 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1490 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1491 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1496 * MESA_FORMAT_SIGNED_R16
1500 pack_float_SIGNED_R16(const GLfloat src
[4], void *dst
)
1502 GLshort
*d
= (GLshort
*) dst
;
1503 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1508 * MESA_FORMAT_SIGNED_GR1616
1512 pack_float_SIGNED_GR1616(const GLfloat src
[4], void *dst
)
1514 GLuint
*d
= (GLuint
*) dst
;
1515 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1516 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1517 *d
= (g
<< 16) | (r
& 0xffff);
1522 * MESA_FORMAT_SIGNED_RGB_16
1526 pack_float_SIGNED_RGB_16(const GLfloat src
[4], void *dst
)
1528 GLshort
*d
= (GLshort
*) dst
;
1529 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1530 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1531 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1536 * MESA_FORMAT_SIGNED_RGBA_16
1540 pack_float_SIGNED_RGBA_16(const GLfloat src
[4], void *dst
)
1542 GLshort
*d
= (GLshort
*) dst
;
1543 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1544 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1545 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1546 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1551 * MESA_FORMAT_SIGNED_A8
1555 pack_float_SIGNED_A8(const GLfloat src
[4], void *dst
)
1557 GLbyte
*d
= (GLbyte
*) dst
;
1558 *d
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1563 * MESA_FORMAT_SIGNED_L8
1567 pack_float_SIGNED_L8(const GLfloat src
[4], void *dst
)
1569 GLbyte
*d
= (GLbyte
*) dst
;
1570 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1575 * MESA_FORMAT_SIGNED_AL88
1579 pack_float_SIGNED_AL88(const GLfloat src
[4], void *dst
)
1581 GLushort
*d
= (GLushort
*) dst
;
1582 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1583 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1589 * MESA_FORMAT_SIGNED_A16
1593 pack_float_SIGNED_A16(const GLfloat src
[4], void *dst
)
1595 GLshort
*d
= (GLshort
*) dst
;
1596 *d
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1601 * MESA_FORMAT_SIGNED_L16
1605 pack_float_SIGNED_L16(const GLfloat src
[4], void *dst
)
1607 GLshort
*d
= (GLshort
*) dst
;
1608 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1613 * MESA_FORMAT_SIGNED_AL1616
1617 pack_float_SIGNED_AL1616(const GLfloat src
[4], void *dst
)
1619 GLuint
*d
= (GLuint
*) dst
;
1620 GLshort l
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1621 GLshort a
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1622 *d
= PACK_COLOR_1616(a
, l
);
1627 * MESA_FORMAT_RGB9_E5_FLOAT;
1631 pack_float_RGB9_E5_FLOAT(const GLfloat src
[4], void *dst
)
1633 GLuint
*d
= (GLuint
*) dst
;
1634 *d
= float3_to_rgb9e5(src
);
1638 pack_ubyte_RGB9_E5_FLOAT(const GLubyte src
[4], void *dst
)
1640 GLuint
*d
= (GLuint
*) dst
;
1642 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1643 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1644 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1645 *d
= float3_to_rgb9e5(rgb
);
1651 * MESA_FORMAT_R11_G11_B10_FLOAT;
1655 pack_ubyte_R11_G11_B10_FLOAT(const GLubyte src
[4], void *dst
)
1657 GLuint
*d
= (GLuint
*) dst
;
1659 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1660 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1661 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1662 *d
= float3_to_r11g11b10f(rgb
);
1666 pack_float_R11_G11_B10_FLOAT(const GLfloat src
[4], void *dst
)
1668 GLuint
*d
= (GLuint
*) dst
;
1669 *d
= float3_to_r11g11b10f(src
);
1674 * MESA_FORMAT_XRGB4444_UNORM
1678 pack_ubyte_XRGB4444_UNORM(const GLubyte src
[4], void *dst
)
1680 GLushort
*d
= ((GLushort
*) dst
);
1681 *d
= PACK_COLOR_4444(255, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
1685 pack_float_XRGB4444_UNORM(const GLfloat src
[4], void *dst
)
1688 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
1689 pack_ubyte_XRGB4444_UNORM(v
, dst
);
1694 * MESA_FORMAT_XRGB1555_UNORM
1698 pack_ubyte_XRGB1555_UNORM(const GLubyte src
[4], void *dst
)
1700 GLushort
*d
= ((GLushort
*) dst
);
1701 *d
= PACK_COLOR_1555(255, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
1705 pack_float_XRGB1555_UNORM(const GLfloat src
[4], void *dst
)
1708 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
1709 pack_ubyte_XRGB1555_UNORM(v
, dst
);
1714 * MESA_FORMAT_XBGR8888_SNORM
1718 pack_float_XBGR8888_SNORM(const GLfloat src
[4], void *dst
)
1720 GLuint
*d
= (GLuint
*) dst
;
1721 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1722 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1723 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1724 *d
= PACK_COLOR_8888(127, b
, g
, r
);
1729 * MESA_FORMAT_XBGR8888_SRGB
1733 pack_float_XBGR8888_SRGB(const GLfloat src
[4], void *dst
)
1735 GLuint
*d
= (GLuint
*) dst
;
1736 GLubyte r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1737 GLubyte g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1738 GLubyte b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1739 *d
= PACK_COLOR_8888(127, b
, g
, r
);
1743 /* MESA_FORMAT_XRGB2101010_UNORM */
1746 pack_ubyte_XRGB2101010_UNORM(const GLubyte src
[4], void *dst
)
1748 GLuint
*d
= ((GLuint
*) dst
);
1749 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
1750 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
1751 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
1752 *d
= PACK_COLOR_2101010_US(3, r
, g
, b
);
1756 pack_float_XRGB2101010_UNORM(const GLfloat src
[4], void *dst
)
1758 GLuint
*d
= ((GLuint
*) dst
);
1760 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1761 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1762 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1763 *d
= PACK_COLOR_2101010_US(3, r
, g
, b
);
1767 /* MESA_FORMAT_XBGR16161616_UNORM */
1770 pack_ubyte_XBGR16161616_UNORM(const GLubyte src
[4], void *dst
)
1772 GLushort
*d
= ((GLushort
*) dst
);
1773 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1774 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1775 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1780 pack_float_XBGR16161616_UNORM(const GLfloat src
[4], void *dst
)
1782 GLushort
*d
= ((GLushort
*) dst
);
1783 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1784 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1785 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1790 /* MESA_FORMAT_XBGR16161616_SNORM */
1793 pack_float_XBGR16161616_SNORM(const GLfloat src
[4], void *dst
)
1795 GLushort
*d
= ((GLushort
*) dst
);
1796 UNCLAMPED_FLOAT_TO_SHORT(d
[0], src
[RCOMP
]);
1797 UNCLAMPED_FLOAT_TO_SHORT(d
[1], src
[GCOMP
]);
1798 UNCLAMPED_FLOAT_TO_SHORT(d
[2], src
[BCOMP
]);
1803 /* MESA_FORMAT_XBGR16161616_FLOAT */
1806 pack_float_XBGR16161616_FLOAT(const GLfloat src
[4], void *dst
)
1808 GLushort
*d
= ((GLushort
*) dst
);
1809 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1810 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1811 d
[2] = _mesa_float_to_half(src
[BCOMP
]);
1812 d
[3] = _mesa_float_to_half(1.0);
1815 /* MESA_FORMAT_XBGR32323232_FLOAT */
1818 pack_float_XBGR32323232_FLOAT(const GLfloat src
[4], void *dst
)
1820 GLfloat
*d
= ((GLfloat
*) dst
);
1827 /* MESA_FORMAT_ABGR2101010 */
1830 pack_ubyte_ABGR2101010(const GLubyte src
[4], void *dst
)
1832 GLuint
*d
= ((GLuint
*) dst
);
1833 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
1834 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
1835 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
1836 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
1837 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1841 pack_float_ABGR2101010(const GLfloat src
[4], void *dst
)
1843 GLuint
*d
= ((GLuint
*) dst
);
1844 GLushort r
, g
, b
, a
;
1845 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1846 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1847 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1848 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1849 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1853 * MESA_FORMAT_SIGNED_RG88
1857 pack_float_SIGNED_RG88(const GLfloat src
[4], void *dst
)
1859 GLushort
*d
= (GLushort
*) dst
;
1860 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1861 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1862 *d
= (r
<< 8) | (g
& 0xff);
1866 * MESA_FORMAT_SIGNED_RG1616
1870 pack_float_SIGNED_RG1616(const GLfloat src
[4], void *dst
)
1872 GLuint
*d
= (GLuint
*) dst
;
1873 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1874 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1875 *d
= (r
<< 16) | (g
& 0xffff);
1879 * Return a function that can pack a GLubyte rgba[4] color.
1881 gl_pack_ubyte_rgba_func
1882 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1884 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1885 static GLboolean initialized
= GL_FALSE
;
1888 memset(table
, 0, sizeof(table
));
1890 table
[MESA_FORMAT_NONE
] = NULL
;
1892 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1893 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1894 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1895 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1896 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1897 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1898 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1899 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1900 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1901 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1902 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1903 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1904 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1905 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1906 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1907 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1908 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1909 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1910 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1911 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1912 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1913 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1914 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1915 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1916 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1917 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1918 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1919 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1920 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1921 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1922 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1923 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1924 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1925 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1926 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1927 table
[MESA_FORMAT_GR1616
] = pack_ubyte_GR1616
;
1928 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1929 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1930 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_ubyte_ABGR2101010_UINT
;
1932 /* should never convert RGBA to these formats */
1933 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1934 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1935 table
[MESA_FORMAT_Z16
] = NULL
;
1936 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1937 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1938 table
[MESA_FORMAT_Z32
] = NULL
;
1939 table
[MESA_FORMAT_S8
] = NULL
;
1942 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1943 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1944 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1945 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1946 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1949 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1950 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1951 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1952 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1954 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1955 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1956 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1957 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1958 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1959 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1961 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1962 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1963 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1964 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1965 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1966 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1967 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1968 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1969 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1970 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1971 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1972 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1973 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1974 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1975 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1976 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1979 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1980 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1981 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1982 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1983 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1984 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1986 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1988 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1991 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1992 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1993 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1994 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1995 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1996 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1997 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1998 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1999 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
2000 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
2001 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
2002 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
2003 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
2004 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
2005 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
2006 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
2007 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
2010 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
2012 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
2013 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
2015 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_ubyte_XRGB4444_UNORM
;
2016 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_ubyte_XRGB1555_UNORM
;
2017 table
[MESA_FORMAT_XBGR8888_SNORM
] = NULL
;
2018 table
[MESA_FORMAT_XBGR8888_SRGB
] = NULL
;
2019 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
2020 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
2021 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_ubyte_XRGB2101010_UNORM
;
2022 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_ubyte_XBGR16161616_UNORM
;
2023 table
[MESA_FORMAT_XBGR16161616_SNORM
] = NULL
;
2024 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = NULL
;
2025 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
2026 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
2027 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = NULL
;
2028 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
2029 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
2031 table
[MESA_FORMAT_ABGR2101010
] = pack_ubyte_ABGR2101010
;
2033 initialized
= GL_TRUE
;
2036 return table
[format
];
2042 * Return a function that can pack a GLfloat rgba[4] color.
2044 gl_pack_float_rgba_func
2045 _mesa_get_pack_float_rgba_function(gl_format format
)
2047 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
2048 static GLboolean initialized
= GL_FALSE
;
2051 memset(table
, 0, sizeof(table
));
2053 table
[MESA_FORMAT_NONE
] = NULL
;
2055 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
2056 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
2057 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
2058 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
2059 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
2060 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
2061 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
2062 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
2063 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
2064 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
2065 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
2066 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
2067 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
2068 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
2069 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
2070 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
2071 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
2073 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
2074 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
2075 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
2076 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
2077 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
2078 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
2079 table
[MESA_FORMAT_A8
] = pack_float_A8
;
2080 table
[MESA_FORMAT_A16
] = pack_float_A16
;
2081 table
[MESA_FORMAT_L8
] = pack_float_L8
;
2082 table
[MESA_FORMAT_L16
] = pack_float_L16
;
2083 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
2084 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
2085 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
2086 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
2087 table
[MESA_FORMAT_R8
] = pack_float_R8
;
2088 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
2089 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
2090 table
[MESA_FORMAT_R16
] = pack_float_R16
;
2091 table
[MESA_FORMAT_GR1616
] = pack_float_GR1616
;
2092 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
2093 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
2094 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_float_ABGR2101010_UINT
;
2096 /* should never convert RGBA to these formats */
2097 table
[MESA_FORMAT_Z24_S8
] = NULL
;
2098 table
[MESA_FORMAT_S8_Z24
] = NULL
;
2099 table
[MESA_FORMAT_Z16
] = NULL
;
2100 table
[MESA_FORMAT_X8_Z24
] = NULL
;
2101 table
[MESA_FORMAT_Z24_X8
] = NULL
;
2102 table
[MESA_FORMAT_Z32
] = NULL
;
2103 table
[MESA_FORMAT_S8
] = NULL
;
2105 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
2106 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
2107 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
2108 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
2109 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
2112 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
2113 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
2114 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
2115 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
2117 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
2118 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
2119 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
2120 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
2121 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
2122 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
2124 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
2125 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
2126 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
2127 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
2128 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
2129 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
2130 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2131 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2132 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
2133 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
2135 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2136 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2137 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2138 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2139 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
2140 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
2143 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
2144 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
2145 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
2146 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
2147 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
2148 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
2150 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
2152 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
2154 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
2155 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
2156 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
2157 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
2158 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
2159 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
2160 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
2161 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
2162 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
2163 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
2164 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
2165 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
2166 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
2167 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
2168 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
2169 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
2170 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
2172 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
2173 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
2175 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_float_XRGB4444_UNORM
;
2176 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_float_XRGB1555_UNORM
;
2177 table
[MESA_FORMAT_XBGR8888_SNORM
] = pack_float_XBGR8888_SNORM
;
2178 table
[MESA_FORMAT_XBGR8888_SRGB
] = pack_float_XBGR8888_SRGB
;
2179 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
2180 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
2181 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_float_XRGB2101010_UNORM
;
2182 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_float_XBGR16161616_UNORM
;
2183 table
[MESA_FORMAT_XBGR16161616_SNORM
] = pack_float_XBGR16161616_SNORM
;
2184 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = pack_float_XBGR16161616_FLOAT
;
2185 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
2186 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
2187 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = pack_float_XBGR32323232_FLOAT
;
2188 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
2189 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
2191 table
[MESA_FORMAT_ABGR2101010
] = pack_float_ABGR2101010
;
2193 table
[MESA_FORMAT_SIGNED_RG88
] = pack_float_SIGNED_RG88
;
2194 table
[MESA_FORMAT_SIGNED_RG1616
] = pack_float_SIGNED_RG1616
;
2196 initialized
= GL_TRUE
;
2199 return table
[format
];
2204 static pack_float_rgba_row_func
2205 get_pack_float_rgba_row_function(gl_format format
)
2207 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
2208 static GLboolean initialized
= GL_FALSE
;
2211 /* We don't need a special row packing function for each format.
2212 * There's a generic fallback which uses a per-pixel packing function.
2214 memset(table
, 0, sizeof(table
));
2216 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
2217 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
2218 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
2219 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
2220 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
2221 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
2222 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
2223 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
2224 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
2225 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
2226 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
2227 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
2229 initialized
= GL_TRUE
;
2232 return table
[format
];
2237 static pack_ubyte_rgba_row_func
2238 get_pack_ubyte_rgba_row_function(gl_format format
)
2240 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
2241 static GLboolean initialized
= GL_FALSE
;
2244 /* We don't need a special row packing function for each format.
2245 * There's a generic fallback which uses a per-pixel packing function.
2247 memset(table
, 0, sizeof(table
));
2249 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
2250 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
2251 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
2252 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
2253 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
2254 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
2255 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
2256 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
2257 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
2258 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
2259 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
2260 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
2262 initialized
= GL_TRUE
;
2265 return table
[format
];
2271 * Pack a row of GLfloat rgba[4] values to the destination.
2274 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
2275 const GLfloat src
[][4], void *dst
)
2277 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2279 /* use "fast" function */
2280 packrow(n
, src
, dst
);
2283 /* slower fallback */
2284 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2285 GLuint dstStride
= _mesa_get_format_bytes(format
);
2286 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2293 for (i
= 0; i
< n
; i
++) {
2294 pack(src
[i
], dstPtr
);
2295 dstPtr
+= dstStride
;
2302 * Pack a row of GLubyte rgba[4] values to the destination.
2305 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2306 const GLubyte src
[][4], void *dst
)
2308 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2310 /* use "fast" function */
2311 packrow(n
, src
, dst
);
2314 /* slower fallback */
2315 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2316 const GLuint stride
= _mesa_get_format_bytes(format
);
2317 GLubyte
*d
= ((GLubyte
*) dst
);
2324 for (i
= 0; i
< n
; i
++) {
2333 * Pack a 2D image of ubyte RGBA pixels in the given format.
2334 * \param srcRowStride source image row stride in bytes
2335 * \param dstRowStride destination image row stride in bytes
2338 _mesa_pack_ubyte_rgba_rect(gl_format format
, GLuint width
, GLuint height
,
2339 const GLubyte
*src
, GLint srcRowStride
,
2340 void *dst
, GLint dstRowStride
)
2342 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2343 GLubyte
*dstUB
= (GLubyte
*) dst
;
2347 if (srcRowStride
== width
* 4 * sizeof(GLubyte
) &&
2348 dstRowStride
== _mesa_format_row_stride(format
, width
)) {
2349 /* do whole image at once */
2350 packrow(width
* height
, (const GLubyte (*)[4]) src
, dst
);
2354 for (i
= 0; i
< height
; i
++) {
2355 packrow(width
, (const GLubyte (*)[4]) src
, dstUB
);
2356 src
+= srcRowStride
;
2357 dstUB
+= dstRowStride
;
2362 /* slower fallback */
2363 for (i
= 0; i
< height
; i
++) {
2364 _mesa_pack_ubyte_rgba_row(format
, width
,
2365 (const GLubyte (*)[4]) src
, dstUB
);
2366 src
+= srcRowStride
;
2367 dstUB
+= dstRowStride
;
2375 ** Pack float Z pixels
2379 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2381 /* don't disturb the stencil values */
2382 GLuint
*d
= ((GLuint
*) dst
);
2383 const GLdouble scale
= (GLdouble
) 0xffffff;
2384 GLuint s
= *d
& 0xff;
2385 GLuint z
= (GLuint
) (*src
* scale
);
2386 assert(z
<= 0xffffff);
2391 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2393 /* don't disturb the stencil values */
2394 GLuint
*d
= ((GLuint
*) dst
);
2395 const GLdouble scale
= (GLdouble
) 0xffffff;
2396 GLuint s
= *d
& 0xff000000;
2397 GLuint z
= (GLuint
) (*src
* scale
);
2398 assert(z
<= 0xffffff);
2403 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2405 GLushort
*d
= ((GLushort
*) dst
);
2406 const GLfloat scale
= (GLfloat
) 0xffff;
2407 *d
= (GLushort
) (*src
* scale
);
2411 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2413 GLuint
*d
= ((GLuint
*) dst
);
2414 const GLdouble scale
= (GLdouble
) 0xffffffff;
2415 *d
= (GLuint
) (*src
* scale
);
2419 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2421 GLfloat
*d
= (GLfloat
*) dst
;
2425 gl_pack_float_z_func
2426 _mesa_get_pack_float_z_func(gl_format format
)
2429 case MESA_FORMAT_Z24_S8
:
2430 case MESA_FORMAT_Z24_X8
:
2431 return pack_float_z_Z24_S8
;
2432 case MESA_FORMAT_S8_Z24
:
2433 case MESA_FORMAT_X8_Z24
:
2434 return pack_float_z_S8_Z24
;
2435 case MESA_FORMAT_Z16
:
2436 return pack_float_z_Z16
;
2437 case MESA_FORMAT_Z32
:
2438 return pack_float_z_Z32
;
2439 case MESA_FORMAT_Z32_FLOAT
:
2440 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2441 return pack_float_z_Z32_FLOAT
;
2444 "unexpected format in _mesa_get_pack_float_z_func()");
2452 ** Pack uint Z pixels. The incoming src value is always in
2453 ** the range [0, 2^32-1].
2457 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2459 /* don't disturb the stencil values */
2460 GLuint
*d
= ((GLuint
*) dst
);
2461 GLuint s
= *d
& 0xff;
2462 GLuint z
= *src
& 0xffffff00;
2467 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2469 /* don't disturb the stencil values */
2470 GLuint
*d
= ((GLuint
*) dst
);
2471 GLuint s
= *d
& 0xff000000;
2472 GLuint z
= *src
>> 8;
2477 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2479 GLushort
*d
= ((GLushort
*) dst
);
2484 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2486 GLuint
*d
= ((GLuint
*) dst
);
2491 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2493 GLuint
*d
= ((GLuint
*) dst
);
2494 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2495 *d
= (GLuint
) (*src
* scale
);
2501 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2503 GLfloat
*d
= ((GLfloat
*) dst
);
2504 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2505 *d
= (GLfloat
) (*src
* scale
);
2511 _mesa_get_pack_uint_z_func(gl_format format
)
2514 case MESA_FORMAT_Z24_S8
:
2515 case MESA_FORMAT_Z24_X8
:
2516 return pack_uint_z_Z24_S8
;
2517 case MESA_FORMAT_S8_Z24
:
2518 case MESA_FORMAT_X8_Z24
:
2519 return pack_uint_z_S8_Z24
;
2520 case MESA_FORMAT_Z16
:
2521 return pack_uint_z_Z16
;
2522 case MESA_FORMAT_Z32
:
2523 return pack_uint_z_Z32
;
2524 case MESA_FORMAT_Z32_FLOAT
:
2525 return pack_uint_z_Z32_FLOAT
;
2526 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2527 return pack_uint_z_Z32_FLOAT_X24S8
;
2529 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2536 ** Pack ubyte stencil pixels
2540 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2542 /* don't disturb the Z values */
2543 GLuint
*d
= ((GLuint
*) dst
);
2545 GLuint z
= *d
& 0xffffff00;
2550 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2552 /* don't disturb the Z values */
2553 GLuint
*d
= ((GLuint
*) dst
);
2554 GLuint s
= *src
<< 24;
2555 GLuint z
= *d
& 0xffffff;
2560 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2562 GLubyte
*d
= (GLubyte
*) dst
;
2567 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2569 GLfloat
*d
= ((GLfloat
*) dst
);
2574 gl_pack_ubyte_stencil_func
2575 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2578 case MESA_FORMAT_Z24_S8
:
2579 return pack_ubyte_stencil_Z24_S8
;
2580 case MESA_FORMAT_S8_Z24
:
2581 return pack_ubyte_stencil_S8_Z24
;
2582 case MESA_FORMAT_S8
:
2583 return pack_ubyte_stencil_S8
;
2584 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2585 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2588 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2596 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2597 const GLfloat
*src
, void *dst
)
2600 case MESA_FORMAT_Z24_S8
:
2601 case MESA_FORMAT_Z24_X8
:
2603 /* don't disturb the stencil values */
2604 GLuint
*d
= ((GLuint
*) dst
);
2605 const GLdouble scale
= (GLdouble
) 0xffffff;
2607 for (i
= 0; i
< n
; i
++) {
2608 GLuint s
= d
[i
] & 0xff;
2609 GLuint z
= (GLuint
) (src
[i
] * scale
);
2610 assert(z
<= 0xffffff);
2611 d
[i
] = (z
<< 8) | s
;
2615 case MESA_FORMAT_S8_Z24
:
2616 case MESA_FORMAT_X8_Z24
:
2618 /* don't disturb the stencil values */
2619 GLuint
*d
= ((GLuint
*) dst
);
2620 const GLdouble scale
= (GLdouble
) 0xffffff;
2622 for (i
= 0; i
< n
; i
++) {
2623 GLuint s
= d
[i
] & 0xff000000;
2624 GLuint z
= (GLuint
) (src
[i
] * scale
);
2625 assert(z
<= 0xffffff);
2630 case MESA_FORMAT_Z16
:
2632 GLushort
*d
= ((GLushort
*) dst
);
2633 const GLfloat scale
= (GLfloat
) 0xffff;
2635 for (i
= 0; i
< n
; i
++) {
2636 d
[i
] = (GLushort
) (src
[i
] * scale
);
2640 case MESA_FORMAT_Z32
:
2642 GLuint
*d
= ((GLuint
*) dst
);
2643 const GLdouble scale
= (GLdouble
) 0xffffffff;
2645 for (i
= 0; i
< n
; i
++) {
2646 d
[i
] = (GLuint
) (src
[i
] * scale
);
2650 case MESA_FORMAT_Z32_FLOAT
:
2651 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2653 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2655 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2657 for (i
= 0; i
< n
; i
++) {
2663 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2669 * The incoming Z values are always in the range [0, 0xffffffff].
2672 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2673 const GLuint
*src
, void *dst
)
2676 case MESA_FORMAT_Z24_S8
:
2677 case MESA_FORMAT_Z24_X8
:
2679 /* don't disturb the stencil values */
2680 GLuint
*d
= ((GLuint
*) dst
);
2682 for (i
= 0; i
< n
; i
++) {
2683 GLuint s
= d
[i
] & 0xff;
2684 GLuint z
= src
[i
] & 0xffffff00;
2689 case MESA_FORMAT_S8_Z24
:
2690 case MESA_FORMAT_X8_Z24
:
2692 /* don't disturb the stencil values */
2693 GLuint
*d
= ((GLuint
*) dst
);
2695 for (i
= 0; i
< n
; i
++) {
2696 GLuint s
= d
[i
] & 0xff000000;
2697 GLuint z
= src
[i
] >> 8;
2702 case MESA_FORMAT_Z16
:
2704 GLushort
*d
= ((GLushort
*) dst
);
2706 for (i
= 0; i
< n
; i
++) {
2707 d
[i
] = src
[i
] >> 16;
2711 case MESA_FORMAT_Z32
:
2712 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2714 case MESA_FORMAT_Z32_FLOAT
:
2716 GLuint
*d
= ((GLuint
*) dst
);
2717 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2719 for (i
= 0; i
< n
; i
++) {
2720 d
[i
] = (GLuint
) (src
[i
] * scale
);
2721 assert(d
[i
] >= 0.0f
);
2722 assert(d
[i
] <= 1.0f
);
2726 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2728 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2729 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2731 for (i
= 0; i
< n
; i
++) {
2732 d
[i
].z
= (GLfloat
) (src
[i
] * scale
);
2733 assert(d
[i
].z
>= 0.0f
);
2734 assert(d
[i
].z
<= 1.0f
);
2739 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2745 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2746 const GLubyte
*src
, void *dst
)
2749 case MESA_FORMAT_Z24_S8
:
2751 /* don't disturb the Z values */
2752 GLuint
*d
= ((GLuint
*) dst
);
2754 for (i
= 0; i
< n
; i
++) {
2756 GLuint z
= d
[i
] & 0xffffff00;
2761 case MESA_FORMAT_S8_Z24
:
2763 /* don't disturb the Z values */
2764 GLuint
*d
= ((GLuint
*) dst
);
2766 for (i
= 0; i
< n
; i
++) {
2767 GLuint s
= src
[i
] << 24;
2768 GLuint z
= d
[i
] & 0xffffff;
2773 case MESA_FORMAT_S8
:
2774 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2776 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2778 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2780 for (i
= 0; i
< n
; i
++) {
2781 d
[i
].x24s8
= src
[i
];
2786 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2792 * Incoming Z/stencil values are always in uint_24_8 format.
2795 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2796 const GLuint
*src
, void *dst
)
2799 case MESA_FORMAT_Z24_S8
:
2800 memcpy(dst
, src
, n
* sizeof(GLuint
));
2802 case MESA_FORMAT_S8_Z24
:
2804 GLuint
*d
= ((GLuint
*) dst
);
2806 for (i
= 0; i
< n
; i
++) {
2807 GLuint s
= src
[i
] << 24;
2808 GLuint z
= src
[i
] >> 8;
2813 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2815 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2816 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2818 for (i
= 0; i
< n
; i
++) {
2819 GLfloat z
= (GLfloat
) ((src
[i
] >> 8) * scale
);
2821 d
[i
].x24s8
= src
[i
];
2826 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2827 _mesa_get_format_name(format
));
2835 * Convert a boolean color mask to a packed color where each channel of
2836 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2839 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2841 GLfloat maskColor
[4];
2843 switch (_mesa_get_format_datatype(format
)) {
2844 case GL_UNSIGNED_NORMALIZED
:
2845 /* simple: 1.0 will convert to ~0 in the right bit positions */
2846 maskColor
[0] = colorMask
[0] ? 1.0f
: 0.0f
;
2847 maskColor
[1] = colorMask
[1] ? 1.0f
: 0.0f
;
2848 maskColor
[2] = colorMask
[2] ? 1.0f
: 0.0f
;
2849 maskColor
[3] = colorMask
[3] ? 1.0f
: 0.0f
;
2850 _mesa_pack_float_rgba_row(format
, 1,
2851 (const GLfloat (*)[4]) maskColor
, dst
);
2853 case GL_SIGNED_NORMALIZED
:
2855 /* These formats are harder because it's hard to know the floating
2856 * point values that will convert to ~0 for each color channel's bits.
2857 * This solution just generates a non-zero value for each color channel
2858 * then fixes up the non-zero values to be ~0.
2859 * Note: we'll need to add special case code if we ever have to deal
2860 * with formats with unequal color channel sizes, like R11_G11_B10.
2861 * We issue a warning below for channel sizes other than 8,16,32.
2864 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2865 GLuint bytes
= _mesa_get_format_bytes(format
);
2868 /* this should put non-zero values into the channels of dst */
2869 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2870 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2871 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2872 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2873 _mesa_pack_float_rgba_row(format
, 1,
2874 (const GLfloat (*)[4]) maskColor
, dst
);
2876 /* fix-up the dst channels by converting non-zero values to ~0 */
2878 GLubyte
*d
= (GLubyte
*) dst
;
2879 for (i
= 0; i
< bytes
; i
++) {
2880 d
[i
] = d
[i
] ? 0xff : 0x0;
2883 else if (bits
== 16) {
2884 GLushort
*d
= (GLushort
*) dst
;
2885 for (i
= 0; i
< bytes
/ 2; i
++) {
2886 d
[i
] = d
[i
] ? 0xffff : 0x0;
2889 else if (bits
== 32) {
2890 GLuint
*d
= (GLuint
*) dst
;
2891 for (i
= 0; i
< bytes
/ 4; i
++) {
2892 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2896 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2902 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");