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
);
1854 * Return a function that can pack a GLubyte rgba[4] color.
1856 gl_pack_ubyte_rgba_func
1857 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1859 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1860 static GLboolean initialized
= GL_FALSE
;
1863 memset(table
, 0, sizeof(table
));
1865 table
[MESA_FORMAT_NONE
] = NULL
;
1867 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1868 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1869 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1870 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1871 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1872 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1873 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1874 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1875 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1876 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1877 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1878 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1879 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1880 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1881 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1882 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1883 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1884 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1885 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1886 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1887 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1888 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1889 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1890 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1891 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1892 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1893 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1894 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1895 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1896 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1897 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1898 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1899 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1900 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1901 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1902 table
[MESA_FORMAT_GR1616
] = pack_ubyte_GR1616
;
1903 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1904 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1905 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_ubyte_ABGR2101010_UINT
;
1907 /* should never convert RGBA to these formats */
1908 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1909 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1910 table
[MESA_FORMAT_Z16
] = NULL
;
1911 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1912 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1913 table
[MESA_FORMAT_Z32
] = NULL
;
1914 table
[MESA_FORMAT_S8
] = NULL
;
1917 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1918 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1919 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1920 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1921 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1924 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1925 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1926 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1927 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1929 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1930 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1931 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1932 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1933 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1934 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1936 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1937 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1938 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1939 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1940 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1941 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1942 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1943 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1944 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1945 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1946 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1947 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1948 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1949 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1950 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1951 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1954 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1955 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1956 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1957 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1958 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1959 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1961 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1963 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1966 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1967 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1968 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1969 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1970 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1971 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1972 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1973 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1974 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1975 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1976 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1977 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1978 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1979 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1980 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1981 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1982 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1985 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1987 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
1988 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
1990 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_ubyte_XRGB4444_UNORM
;
1991 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_ubyte_XRGB1555_UNORM
;
1992 table
[MESA_FORMAT_XBGR8888_SNORM
] = NULL
;
1993 table
[MESA_FORMAT_XBGR8888_SRGB
] = NULL
;
1994 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
1995 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
1996 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_ubyte_XRGB2101010_UNORM
;
1997 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_ubyte_XBGR16161616_UNORM
;
1998 table
[MESA_FORMAT_XBGR16161616_SNORM
] = NULL
;
1999 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = NULL
;
2000 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
2001 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
2002 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = NULL
;
2003 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
2004 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
2006 table
[MESA_FORMAT_ABGR2101010
] = pack_ubyte_ABGR2101010
;
2008 initialized
= GL_TRUE
;
2011 return table
[format
];
2017 * Return a function that can pack a GLfloat rgba[4] color.
2019 gl_pack_float_rgba_func
2020 _mesa_get_pack_float_rgba_function(gl_format format
)
2022 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
2023 static GLboolean initialized
= GL_FALSE
;
2026 memset(table
, 0, sizeof(table
));
2028 table
[MESA_FORMAT_NONE
] = NULL
;
2030 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
2031 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
2032 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
2033 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
2034 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
2035 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
2036 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
2037 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
2038 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
2039 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
2040 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
2041 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
2042 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
2043 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
2044 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
2045 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
2046 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
2048 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
2049 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
2050 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
2051 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
2052 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
2053 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
2054 table
[MESA_FORMAT_A8
] = pack_float_A8
;
2055 table
[MESA_FORMAT_A16
] = pack_float_A16
;
2056 table
[MESA_FORMAT_L8
] = pack_float_L8
;
2057 table
[MESA_FORMAT_L16
] = pack_float_L16
;
2058 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
2059 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
2060 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
2061 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
2062 table
[MESA_FORMAT_R8
] = pack_float_R8
;
2063 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
2064 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
2065 table
[MESA_FORMAT_R16
] = pack_float_R16
;
2066 table
[MESA_FORMAT_GR1616
] = pack_float_GR1616
;
2067 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
2068 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
2069 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_float_ABGR2101010_UINT
;
2071 /* should never convert RGBA to these formats */
2072 table
[MESA_FORMAT_Z24_S8
] = NULL
;
2073 table
[MESA_FORMAT_S8_Z24
] = NULL
;
2074 table
[MESA_FORMAT_Z16
] = NULL
;
2075 table
[MESA_FORMAT_X8_Z24
] = NULL
;
2076 table
[MESA_FORMAT_Z24_X8
] = NULL
;
2077 table
[MESA_FORMAT_Z32
] = NULL
;
2078 table
[MESA_FORMAT_S8
] = NULL
;
2080 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
2081 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
2082 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
2083 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
2084 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
2087 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
2088 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
2089 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
2090 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
2092 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
2093 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
2094 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
2095 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
2096 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
2097 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
2099 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
2100 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
2101 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
2102 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
2103 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
2104 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
2105 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2106 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2107 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
2108 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
2110 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2111 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2112 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2113 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2114 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
2115 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
2118 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
2119 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
2120 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
2121 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
2122 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
2123 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
2125 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
2127 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
2129 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
2130 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
2131 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
2132 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
2133 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
2134 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
2135 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
2136 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
2137 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
2138 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
2139 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
2140 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
2141 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
2142 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
2143 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
2144 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
2145 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
2147 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
2148 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
2150 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_float_XRGB4444_UNORM
;
2151 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_float_XRGB1555_UNORM
;
2152 table
[MESA_FORMAT_XBGR8888_SNORM
] = pack_float_XBGR8888_SNORM
;
2153 table
[MESA_FORMAT_XBGR8888_SRGB
] = pack_float_XBGR8888_SRGB
;
2154 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
2155 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
2156 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_float_XRGB2101010_UNORM
;
2157 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_float_XBGR16161616_UNORM
;
2158 table
[MESA_FORMAT_XBGR16161616_SNORM
] = pack_float_XBGR16161616_SNORM
;
2159 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = pack_float_XBGR16161616_FLOAT
;
2160 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
2161 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
2162 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = pack_float_XBGR32323232_FLOAT
;
2163 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
2164 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
2166 table
[MESA_FORMAT_ABGR2101010
] = pack_float_ABGR2101010
;
2168 initialized
= GL_TRUE
;
2171 return table
[format
];
2176 static pack_float_rgba_row_func
2177 get_pack_float_rgba_row_function(gl_format format
)
2179 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
2180 static GLboolean initialized
= GL_FALSE
;
2183 /* We don't need a special row packing function for each format.
2184 * There's a generic fallback which uses a per-pixel packing function.
2186 memset(table
, 0, sizeof(table
));
2188 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
2189 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
2190 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
2191 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
2192 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
2193 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
2194 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
2195 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
2196 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
2197 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
2198 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
2199 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
2201 initialized
= GL_TRUE
;
2204 return table
[format
];
2209 static pack_ubyte_rgba_row_func
2210 get_pack_ubyte_rgba_row_function(gl_format format
)
2212 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
2213 static GLboolean initialized
= GL_FALSE
;
2216 /* We don't need a special row packing function for each format.
2217 * There's a generic fallback which uses a per-pixel packing function.
2219 memset(table
, 0, sizeof(table
));
2221 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
2222 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
2223 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
2224 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
2225 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
2226 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
2227 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
2228 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
2229 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
2230 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
2231 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
2232 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
2234 initialized
= GL_TRUE
;
2237 return table
[format
];
2243 * Pack a row of GLfloat rgba[4] values to the destination.
2246 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
2247 const GLfloat src
[][4], void *dst
)
2249 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2251 /* use "fast" function */
2252 packrow(n
, src
, dst
);
2255 /* slower fallback */
2256 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2257 GLuint dstStride
= _mesa_get_format_bytes(format
);
2258 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2265 for (i
= 0; i
< n
; i
++) {
2266 pack(src
[i
], dstPtr
);
2267 dstPtr
+= dstStride
;
2274 * Pack a row of GLubyte rgba[4] values to the destination.
2277 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2278 const GLubyte src
[][4], void *dst
)
2280 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2282 /* use "fast" function */
2283 packrow(n
, src
, dst
);
2286 /* slower fallback */
2287 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2288 const GLuint stride
= _mesa_get_format_bytes(format
);
2289 GLubyte
*d
= ((GLubyte
*) dst
);
2296 for (i
= 0; i
< n
; i
++) {
2305 * Pack a 2D image of ubyte RGBA pixels in the given format.
2306 * \param srcRowStride source image row stride in bytes
2307 * \param dstRowStride destination image row stride in bytes
2310 _mesa_pack_ubyte_rgba_rect(gl_format format
, GLuint width
, GLuint height
,
2311 const GLubyte
*src
, GLint srcRowStride
,
2312 void *dst
, GLint dstRowStride
)
2314 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2315 GLubyte
*dstUB
= (GLubyte
*) dst
;
2319 if (srcRowStride
== width
* 4 * sizeof(GLubyte
) &&
2320 dstRowStride
== _mesa_format_row_stride(format
, width
)) {
2321 /* do whole image at once */
2322 packrow(width
* height
, (const GLubyte (*)[4]) src
, dst
);
2326 for (i
= 0; i
< height
; i
++) {
2327 packrow(width
, (const GLubyte (*)[4]) src
, dstUB
);
2328 src
+= srcRowStride
;
2329 dstUB
+= dstRowStride
;
2334 /* slower fallback */
2335 for (i
= 0; i
< height
; i
++) {
2336 _mesa_pack_ubyte_rgba_row(format
, width
,
2337 (const GLubyte (*)[4]) src
, dstUB
);
2338 src
+= srcRowStride
;
2339 dstUB
+= dstRowStride
;
2347 ** Pack float Z pixels
2351 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2353 /* don't disturb the stencil values */
2354 GLuint
*d
= ((GLuint
*) dst
);
2355 const GLdouble scale
= (GLdouble
) 0xffffff;
2356 GLuint s
= *d
& 0xff;
2357 GLuint z
= (GLuint
) (*src
* scale
);
2358 assert(z
<= 0xffffff);
2363 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2365 /* don't disturb the stencil values */
2366 GLuint
*d
= ((GLuint
*) dst
);
2367 const GLdouble scale
= (GLdouble
) 0xffffff;
2368 GLuint s
= *d
& 0xff000000;
2369 GLuint z
= (GLuint
) (*src
* scale
);
2370 assert(z
<= 0xffffff);
2375 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2377 GLushort
*d
= ((GLushort
*) dst
);
2378 const GLfloat scale
= (GLfloat
) 0xffff;
2379 *d
= (GLushort
) (*src
* scale
);
2383 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2385 GLuint
*d
= ((GLuint
*) dst
);
2386 const GLdouble scale
= (GLdouble
) 0xffffffff;
2387 *d
= (GLuint
) (*src
* scale
);
2391 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2393 GLfloat
*d
= (GLfloat
*) dst
;
2397 gl_pack_float_z_func
2398 _mesa_get_pack_float_z_func(gl_format format
)
2401 case MESA_FORMAT_Z24_S8
:
2402 case MESA_FORMAT_Z24_X8
:
2403 return pack_float_z_Z24_S8
;
2404 case MESA_FORMAT_S8_Z24
:
2405 case MESA_FORMAT_X8_Z24
:
2406 return pack_float_z_S8_Z24
;
2407 case MESA_FORMAT_Z16
:
2408 return pack_float_z_Z16
;
2409 case MESA_FORMAT_Z32
:
2410 return pack_float_z_Z32
;
2411 case MESA_FORMAT_Z32_FLOAT
:
2412 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2413 return pack_float_z_Z32_FLOAT
;
2416 "unexpected format in _mesa_get_pack_float_z_func()");
2424 ** Pack uint Z pixels. The incoming src value is always in
2425 ** the range [0, 2^32-1].
2429 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2431 /* don't disturb the stencil values */
2432 GLuint
*d
= ((GLuint
*) dst
);
2433 GLuint s
= *d
& 0xff;
2434 GLuint z
= *src
& 0xffffff00;
2439 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2441 /* don't disturb the stencil values */
2442 GLuint
*d
= ((GLuint
*) dst
);
2443 GLuint s
= *d
& 0xff000000;
2444 GLuint z
= *src
>> 8;
2449 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2451 GLushort
*d
= ((GLushort
*) dst
);
2456 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2458 GLuint
*d
= ((GLuint
*) dst
);
2463 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2465 GLuint
*d
= ((GLuint
*) dst
);
2466 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2467 *d
= (GLuint
) (*src
* scale
);
2473 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2475 GLfloat
*d
= ((GLfloat
*) dst
);
2476 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2477 *d
= (GLfloat
) (*src
* scale
);
2483 _mesa_get_pack_uint_z_func(gl_format format
)
2486 case MESA_FORMAT_Z24_S8
:
2487 case MESA_FORMAT_Z24_X8
:
2488 return pack_uint_z_Z24_S8
;
2489 case MESA_FORMAT_S8_Z24
:
2490 case MESA_FORMAT_X8_Z24
:
2491 return pack_uint_z_S8_Z24
;
2492 case MESA_FORMAT_Z16
:
2493 return pack_uint_z_Z16
;
2494 case MESA_FORMAT_Z32
:
2495 return pack_uint_z_Z32
;
2496 case MESA_FORMAT_Z32_FLOAT
:
2497 return pack_uint_z_Z32_FLOAT
;
2498 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2499 return pack_uint_z_Z32_FLOAT_X24S8
;
2501 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2508 ** Pack ubyte stencil pixels
2512 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2514 /* don't disturb the Z values */
2515 GLuint
*d
= ((GLuint
*) dst
);
2517 GLuint z
= *d
& 0xffffff00;
2522 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2524 /* don't disturb the Z values */
2525 GLuint
*d
= ((GLuint
*) dst
);
2526 GLuint s
= *src
<< 24;
2527 GLuint z
= *d
& 0xffffff;
2532 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2534 GLubyte
*d
= (GLubyte
*) dst
;
2539 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2541 GLfloat
*d
= ((GLfloat
*) dst
);
2546 gl_pack_ubyte_stencil_func
2547 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2550 case MESA_FORMAT_Z24_S8
:
2551 return pack_ubyte_stencil_Z24_S8
;
2552 case MESA_FORMAT_S8_Z24
:
2553 return pack_ubyte_stencil_S8_Z24
;
2554 case MESA_FORMAT_S8
:
2555 return pack_ubyte_stencil_S8
;
2556 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2557 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2560 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2568 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2569 const GLfloat
*src
, void *dst
)
2572 case MESA_FORMAT_Z24_S8
:
2573 case MESA_FORMAT_Z24_X8
:
2575 /* don't disturb the stencil values */
2576 GLuint
*d
= ((GLuint
*) dst
);
2577 const GLdouble scale
= (GLdouble
) 0xffffff;
2579 for (i
= 0; i
< n
; i
++) {
2580 GLuint s
= d
[i
] & 0xff;
2581 GLuint z
= (GLuint
) (src
[i
] * scale
);
2582 assert(z
<= 0xffffff);
2583 d
[i
] = (z
<< 8) | s
;
2587 case MESA_FORMAT_S8_Z24
:
2588 case MESA_FORMAT_X8_Z24
:
2590 /* don't disturb the stencil values */
2591 GLuint
*d
= ((GLuint
*) dst
);
2592 const GLdouble scale
= (GLdouble
) 0xffffff;
2594 for (i
= 0; i
< n
; i
++) {
2595 GLuint s
= d
[i
] & 0xff000000;
2596 GLuint z
= (GLuint
) (src
[i
] * scale
);
2597 assert(z
<= 0xffffff);
2602 case MESA_FORMAT_Z16
:
2604 GLushort
*d
= ((GLushort
*) dst
);
2605 const GLfloat scale
= (GLfloat
) 0xffff;
2607 for (i
= 0; i
< n
; i
++) {
2608 d
[i
] = (GLushort
) (src
[i
] * scale
);
2612 case MESA_FORMAT_Z32
:
2614 GLuint
*d
= ((GLuint
*) dst
);
2615 const GLdouble scale
= (GLdouble
) 0xffffffff;
2617 for (i
= 0; i
< n
; i
++) {
2618 d
[i
] = (GLuint
) (src
[i
] * scale
);
2622 case MESA_FORMAT_Z32_FLOAT
:
2623 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2625 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2627 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2629 for (i
= 0; i
< n
; i
++) {
2635 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2641 * The incoming Z values are always in the range [0, 0xffffffff].
2644 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2645 const GLuint
*src
, void *dst
)
2648 case MESA_FORMAT_Z24_S8
:
2649 case MESA_FORMAT_Z24_X8
:
2651 /* don't disturb the stencil values */
2652 GLuint
*d
= ((GLuint
*) dst
);
2654 for (i
= 0; i
< n
; i
++) {
2655 GLuint s
= d
[i
] & 0xff;
2656 GLuint z
= src
[i
] & 0xffffff00;
2661 case MESA_FORMAT_S8_Z24
:
2662 case MESA_FORMAT_X8_Z24
:
2664 /* don't disturb the stencil values */
2665 GLuint
*d
= ((GLuint
*) dst
);
2667 for (i
= 0; i
< n
; i
++) {
2668 GLuint s
= d
[i
] & 0xff000000;
2669 GLuint z
= src
[i
] >> 8;
2674 case MESA_FORMAT_Z16
:
2676 GLushort
*d
= ((GLushort
*) dst
);
2678 for (i
= 0; i
< n
; i
++) {
2679 d
[i
] = src
[i
] >> 16;
2683 case MESA_FORMAT_Z32
:
2684 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2686 case MESA_FORMAT_Z32_FLOAT
:
2688 GLuint
*d
= ((GLuint
*) dst
);
2689 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2691 for (i
= 0; i
< n
; i
++) {
2692 d
[i
] = (GLuint
) (src
[i
] * scale
);
2693 assert(d
[i
] >= 0.0f
);
2694 assert(d
[i
] <= 1.0f
);
2698 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2700 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2701 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2703 for (i
= 0; i
< n
; i
++) {
2704 d
[i
].z
= (GLfloat
) (src
[i
] * scale
);
2705 assert(d
[i
].z
>= 0.0f
);
2706 assert(d
[i
].z
<= 1.0f
);
2711 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2717 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2718 const GLubyte
*src
, void *dst
)
2721 case MESA_FORMAT_Z24_S8
:
2723 /* don't disturb the Z values */
2724 GLuint
*d
= ((GLuint
*) dst
);
2726 for (i
= 0; i
< n
; i
++) {
2728 GLuint z
= d
[i
] & 0xffffff00;
2733 case MESA_FORMAT_S8_Z24
:
2735 /* don't disturb the Z values */
2736 GLuint
*d
= ((GLuint
*) dst
);
2738 for (i
= 0; i
< n
; i
++) {
2739 GLuint s
= src
[i
] << 24;
2740 GLuint z
= d
[i
] & 0xffffff;
2745 case MESA_FORMAT_S8
:
2746 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2748 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2750 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2752 for (i
= 0; i
< n
; i
++) {
2753 d
[i
].x24s8
= src
[i
];
2758 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2764 * Incoming Z/stencil values are always in uint_24_8 format.
2767 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2768 const GLuint
*src
, void *dst
)
2771 case MESA_FORMAT_Z24_S8
:
2772 memcpy(dst
, src
, n
* sizeof(GLuint
));
2774 case MESA_FORMAT_S8_Z24
:
2776 GLuint
*d
= ((GLuint
*) dst
);
2778 for (i
= 0; i
< n
; i
++) {
2779 GLuint s
= src
[i
] << 24;
2780 GLuint z
= src
[i
] >> 8;
2785 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2787 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2788 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2790 for (i
= 0; i
< n
; i
++) {
2791 GLfloat z
= (GLfloat
) ((src
[i
] >> 8) * scale
);
2793 d
[i
].x24s8
= src
[i
];
2798 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2799 _mesa_get_format_name(format
));
2807 * Convert a boolean color mask to a packed color where each channel of
2808 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2811 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2813 GLfloat maskColor
[4];
2815 switch (_mesa_get_format_datatype(format
)) {
2816 case GL_UNSIGNED_NORMALIZED
:
2817 /* simple: 1.0 will convert to ~0 in the right bit positions */
2818 maskColor
[0] = colorMask
[0] ? 1.0f
: 0.0f
;
2819 maskColor
[1] = colorMask
[1] ? 1.0f
: 0.0f
;
2820 maskColor
[2] = colorMask
[2] ? 1.0f
: 0.0f
;
2821 maskColor
[3] = colorMask
[3] ? 1.0f
: 0.0f
;
2822 _mesa_pack_float_rgba_row(format
, 1,
2823 (const GLfloat (*)[4]) maskColor
, dst
);
2825 case GL_SIGNED_NORMALIZED
:
2827 /* These formats are harder because it's hard to know the floating
2828 * point values that will convert to ~0 for each color channel's bits.
2829 * This solution just generates a non-zero value for each color channel
2830 * then fixes up the non-zero values to be ~0.
2831 * Note: we'll need to add special case code if we ever have to deal
2832 * with formats with unequal color channel sizes, like R11_G11_B10.
2833 * We issue a warning below for channel sizes other than 8,16,32.
2836 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2837 GLuint bytes
= _mesa_get_format_bytes(format
);
2840 /* this should put non-zero values into the channels of dst */
2841 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2842 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2843 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2844 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2845 _mesa_pack_float_rgba_row(format
, 1,
2846 (const GLfloat (*)[4]) maskColor
, dst
);
2848 /* fix-up the dst channels by converting non-zero values to ~0 */
2850 GLubyte
*d
= (GLubyte
*) dst
;
2851 for (i
= 0; i
< bytes
; i
++) {
2852 d
[i
] = d
[i
] ? 0xff : 0x0;
2855 else if (bits
== 16) {
2856 GLushort
*d
= (GLushort
*) dst
;
2857 for (i
= 0; i
< bytes
/ 2; i
++) {
2858 d
[i
] = d
[i
] ? 0xffff : 0x0;
2861 else if (bits
== 32) {
2862 GLuint
*d
= (GLuint
*) dst
;
2863 for (i
= 0; i
< bytes
/ 4; i
++) {
2864 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2868 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2874 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");