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
);
1829 * Return a function that can pack a GLubyte rgba[4] color.
1831 gl_pack_ubyte_rgba_func
1832 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1834 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1835 static GLboolean initialized
= GL_FALSE
;
1838 memset(table
, 0, sizeof(table
));
1840 table
[MESA_FORMAT_NONE
] = NULL
;
1842 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1843 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1844 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1845 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1846 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1847 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1848 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1849 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1850 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1851 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1852 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1853 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1854 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1855 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1856 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1857 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1858 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1859 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1860 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1861 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1862 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1863 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1864 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1865 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1866 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1867 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1868 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1869 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1870 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1871 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1872 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1873 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1874 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1875 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1876 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1877 table
[MESA_FORMAT_GR1616
] = pack_ubyte_GR1616
;
1878 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1879 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1880 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_ubyte_ABGR2101010_UINT
;
1882 /* should never convert RGBA to these formats */
1883 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1884 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1885 table
[MESA_FORMAT_Z16
] = NULL
;
1886 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1887 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1888 table
[MESA_FORMAT_Z32
] = NULL
;
1889 table
[MESA_FORMAT_S8
] = NULL
;
1892 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1893 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1894 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1895 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1896 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1899 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1900 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1901 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1902 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1904 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1905 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1906 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1907 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1908 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1909 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1911 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1912 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1913 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1914 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1915 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1916 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1917 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1918 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1919 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1920 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1921 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1922 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1923 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1924 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1925 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1926 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1929 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1930 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1931 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1932 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1933 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1934 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1936 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1938 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1941 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1942 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1943 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1944 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1945 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1946 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1947 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1948 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1949 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1950 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1951 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1952 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1953 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1954 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1955 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1956 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1957 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1960 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1962 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
1963 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
1965 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_ubyte_XRGB4444_UNORM
;
1966 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_ubyte_XRGB1555_UNORM
;
1967 table
[MESA_FORMAT_XBGR8888_SNORM
] = NULL
;
1968 table
[MESA_FORMAT_XBGR8888_SRGB
] = NULL
;
1969 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
1970 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
1971 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_ubyte_XRGB2101010_UNORM
;
1972 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_ubyte_XBGR16161616_UNORM
;
1973 table
[MESA_FORMAT_XBGR16161616_SNORM
] = NULL
;
1974 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = NULL
;
1975 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
1976 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
1977 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = NULL
;
1978 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
1979 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
1981 initialized
= GL_TRUE
;
1984 return table
[format
];
1990 * Return a function that can pack a GLfloat rgba[4] color.
1992 gl_pack_float_rgba_func
1993 _mesa_get_pack_float_rgba_function(gl_format format
)
1995 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1996 static GLboolean initialized
= GL_FALSE
;
1999 memset(table
, 0, sizeof(table
));
2001 table
[MESA_FORMAT_NONE
] = NULL
;
2003 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
2004 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
2005 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
2006 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
2007 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
2008 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
2009 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
2010 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
2011 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
2012 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
2013 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
2014 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
2015 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
2016 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
2017 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
2018 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
2019 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
2021 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
2022 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
2023 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
2024 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
2025 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
2026 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
2027 table
[MESA_FORMAT_A8
] = pack_float_A8
;
2028 table
[MESA_FORMAT_A16
] = pack_float_A16
;
2029 table
[MESA_FORMAT_L8
] = pack_float_L8
;
2030 table
[MESA_FORMAT_L16
] = pack_float_L16
;
2031 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
2032 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
2033 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
2034 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
2035 table
[MESA_FORMAT_R8
] = pack_float_R8
;
2036 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
2037 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
2038 table
[MESA_FORMAT_R16
] = pack_float_R16
;
2039 table
[MESA_FORMAT_GR1616
] = pack_float_GR1616
;
2040 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
2041 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
2042 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_float_ABGR2101010_UINT
;
2044 /* should never convert RGBA to these formats */
2045 table
[MESA_FORMAT_Z24_S8
] = NULL
;
2046 table
[MESA_FORMAT_S8_Z24
] = NULL
;
2047 table
[MESA_FORMAT_Z16
] = NULL
;
2048 table
[MESA_FORMAT_X8_Z24
] = NULL
;
2049 table
[MESA_FORMAT_Z24_X8
] = NULL
;
2050 table
[MESA_FORMAT_Z32
] = NULL
;
2051 table
[MESA_FORMAT_S8
] = NULL
;
2053 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
2054 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
2055 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
2056 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
2057 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
2060 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
2061 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
2062 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
2063 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
2065 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
2066 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
2067 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
2068 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
2069 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
2070 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
2072 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
2073 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
2074 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
2075 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
2076 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
2077 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
2078 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2079 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2080 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
2081 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
2083 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2084 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2085 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2086 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2087 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
2088 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
2091 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
2092 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
2093 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
2094 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
2095 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
2096 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
2098 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
2100 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
2102 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
2103 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
2104 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
2105 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
2106 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
2107 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
2108 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
2109 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
2110 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
2111 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
2112 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
2113 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
2114 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
2115 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
2116 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
2117 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
2118 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
2120 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
2121 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
2123 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_float_XRGB4444_UNORM
;
2124 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_float_XRGB1555_UNORM
;
2125 table
[MESA_FORMAT_XBGR8888_SNORM
] = pack_float_XBGR8888_SNORM
;
2126 table
[MESA_FORMAT_XBGR8888_SRGB
] = pack_float_XBGR8888_SRGB
;
2127 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
2128 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
2129 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_float_XRGB2101010_UNORM
;
2130 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_float_XBGR16161616_UNORM
;
2131 table
[MESA_FORMAT_XBGR16161616_SNORM
] = pack_float_XBGR16161616_SNORM
;
2132 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = pack_float_XBGR16161616_FLOAT
;
2133 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
2134 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
2135 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = pack_float_XBGR32323232_FLOAT
;
2136 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
2137 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
2139 initialized
= GL_TRUE
;
2142 return table
[format
];
2147 static pack_float_rgba_row_func
2148 get_pack_float_rgba_row_function(gl_format format
)
2150 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
2151 static GLboolean initialized
= GL_FALSE
;
2154 /* We don't need a special row packing function for each format.
2155 * There's a generic fallback which uses a per-pixel packing function.
2157 memset(table
, 0, sizeof(table
));
2159 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
2160 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
2161 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
2162 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
2163 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
2164 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
2165 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
2166 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
2167 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
2168 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
2169 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
2170 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
2172 initialized
= GL_TRUE
;
2175 return table
[format
];
2180 static pack_ubyte_rgba_row_func
2181 get_pack_ubyte_rgba_row_function(gl_format format
)
2183 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
2184 static GLboolean initialized
= GL_FALSE
;
2187 /* We don't need a special row packing function for each format.
2188 * There's a generic fallback which uses a per-pixel packing function.
2190 memset(table
, 0, sizeof(table
));
2192 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
2193 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
2194 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
2195 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
2196 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
2197 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
2198 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
2199 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
2200 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
2201 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
2202 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
2203 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
2205 initialized
= GL_TRUE
;
2208 return table
[format
];
2214 * Pack a row of GLfloat rgba[4] values to the destination.
2217 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
2218 const GLfloat src
[][4], void *dst
)
2220 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2222 /* use "fast" function */
2223 packrow(n
, src
, dst
);
2226 /* slower fallback */
2227 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2228 GLuint dstStride
= _mesa_get_format_bytes(format
);
2229 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2236 for (i
= 0; i
< n
; i
++) {
2237 pack(src
[i
], dstPtr
);
2238 dstPtr
+= dstStride
;
2245 * Pack a row of GLubyte rgba[4] values to the destination.
2248 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2249 const GLubyte src
[][4], void *dst
)
2251 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2253 /* use "fast" function */
2254 packrow(n
, src
, dst
);
2257 /* slower fallback */
2258 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2259 const GLuint stride
= _mesa_get_format_bytes(format
);
2260 GLubyte
*d
= ((GLubyte
*) dst
);
2267 for (i
= 0; i
< n
; i
++) {
2276 * Pack a 2D image of ubyte RGBA pixels in the given format.
2277 * \param srcRowStride source image row stride in bytes
2278 * \param dstRowStride destination image row stride in bytes
2281 _mesa_pack_ubyte_rgba_rect(gl_format format
, GLuint width
, GLuint height
,
2282 const GLubyte
*src
, GLint srcRowStride
,
2283 void *dst
, GLint dstRowStride
)
2285 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2286 GLubyte
*dstUB
= (GLubyte
*) dst
;
2290 if (srcRowStride
== width
* 4 * sizeof(GLubyte
) &&
2291 dstRowStride
== _mesa_format_row_stride(format
, width
)) {
2292 /* do whole image at once */
2293 packrow(width
* height
, (const GLubyte (*)[4]) src
, dst
);
2297 for (i
= 0; i
< height
; i
++) {
2298 packrow(width
, (const GLubyte (*)[4]) src
, dstUB
);
2299 src
+= srcRowStride
;
2300 dstUB
+= dstRowStride
;
2305 /* slower fallback */
2306 for (i
= 0; i
< height
; i
++) {
2307 _mesa_pack_ubyte_rgba_row(format
, width
,
2308 (const GLubyte (*)[4]) src
, dstUB
);
2309 src
+= srcRowStride
;
2310 dstUB
+= dstRowStride
;
2318 ** Pack float Z pixels
2322 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2324 /* don't disturb the stencil values */
2325 GLuint
*d
= ((GLuint
*) dst
);
2326 const GLdouble scale
= (GLdouble
) 0xffffff;
2327 GLuint s
= *d
& 0xff;
2328 GLuint z
= (GLuint
) (*src
* scale
);
2329 assert(z
<= 0xffffff);
2334 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2336 /* don't disturb the stencil values */
2337 GLuint
*d
= ((GLuint
*) dst
);
2338 const GLdouble scale
= (GLdouble
) 0xffffff;
2339 GLuint s
= *d
& 0xff000000;
2340 GLuint z
= (GLuint
) (*src
* scale
);
2341 assert(z
<= 0xffffff);
2346 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2348 GLushort
*d
= ((GLushort
*) dst
);
2349 const GLfloat scale
= (GLfloat
) 0xffff;
2350 *d
= (GLushort
) (*src
* scale
);
2354 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2356 GLuint
*d
= ((GLuint
*) dst
);
2357 const GLdouble scale
= (GLdouble
) 0xffffffff;
2358 *d
= (GLuint
) (*src
* scale
);
2362 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2364 GLfloat
*d
= (GLfloat
*) dst
;
2368 gl_pack_float_z_func
2369 _mesa_get_pack_float_z_func(gl_format format
)
2372 case MESA_FORMAT_Z24_S8
:
2373 case MESA_FORMAT_Z24_X8
:
2374 return pack_float_z_Z24_S8
;
2375 case MESA_FORMAT_S8_Z24
:
2376 case MESA_FORMAT_X8_Z24
:
2377 return pack_float_z_S8_Z24
;
2378 case MESA_FORMAT_Z16
:
2379 return pack_float_z_Z16
;
2380 case MESA_FORMAT_Z32
:
2381 return pack_float_z_Z32
;
2382 case MESA_FORMAT_Z32_FLOAT
:
2383 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2384 return pack_float_z_Z32_FLOAT
;
2387 "unexpected format in _mesa_get_pack_float_z_func()");
2395 ** Pack uint Z pixels. The incoming src value is always in
2396 ** the range [0, 2^32-1].
2400 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2402 /* don't disturb the stencil values */
2403 GLuint
*d
= ((GLuint
*) dst
);
2404 GLuint s
= *d
& 0xff;
2405 GLuint z
= *src
& 0xffffff00;
2410 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2412 /* don't disturb the stencil values */
2413 GLuint
*d
= ((GLuint
*) dst
);
2414 GLuint s
= *d
& 0xff000000;
2415 GLuint z
= *src
>> 8;
2420 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2422 GLushort
*d
= ((GLushort
*) dst
);
2427 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2429 GLuint
*d
= ((GLuint
*) dst
);
2434 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2436 GLuint
*d
= ((GLuint
*) dst
);
2437 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2438 *d
= (GLuint
) (*src
* scale
);
2444 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2446 GLfloat
*d
= ((GLfloat
*) dst
);
2447 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2448 *d
= (GLfloat
) (*src
* scale
);
2454 _mesa_get_pack_uint_z_func(gl_format format
)
2457 case MESA_FORMAT_Z24_S8
:
2458 case MESA_FORMAT_Z24_X8
:
2459 return pack_uint_z_Z24_S8
;
2460 case MESA_FORMAT_S8_Z24
:
2461 case MESA_FORMAT_X8_Z24
:
2462 return pack_uint_z_S8_Z24
;
2463 case MESA_FORMAT_Z16
:
2464 return pack_uint_z_Z16
;
2465 case MESA_FORMAT_Z32
:
2466 return pack_uint_z_Z32
;
2467 case MESA_FORMAT_Z32_FLOAT
:
2468 return pack_uint_z_Z32_FLOAT
;
2469 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2470 return pack_uint_z_Z32_FLOAT_X24S8
;
2472 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2479 ** Pack ubyte stencil pixels
2483 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2485 /* don't disturb the Z values */
2486 GLuint
*d
= ((GLuint
*) dst
);
2488 GLuint z
= *d
& 0xffffff00;
2493 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2495 /* don't disturb the Z values */
2496 GLuint
*d
= ((GLuint
*) dst
);
2497 GLuint s
= *src
<< 24;
2498 GLuint z
= *d
& 0xffffff;
2503 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2505 GLubyte
*d
= (GLubyte
*) dst
;
2510 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2512 GLfloat
*d
= ((GLfloat
*) dst
);
2517 gl_pack_ubyte_stencil_func
2518 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2521 case MESA_FORMAT_Z24_S8
:
2522 return pack_ubyte_stencil_Z24_S8
;
2523 case MESA_FORMAT_S8_Z24
:
2524 return pack_ubyte_stencil_S8_Z24
;
2525 case MESA_FORMAT_S8
:
2526 return pack_ubyte_stencil_S8
;
2527 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2528 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2531 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2539 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2540 const GLfloat
*src
, void *dst
)
2543 case MESA_FORMAT_Z24_S8
:
2544 case MESA_FORMAT_Z24_X8
:
2546 /* don't disturb the stencil values */
2547 GLuint
*d
= ((GLuint
*) dst
);
2548 const GLdouble scale
= (GLdouble
) 0xffffff;
2550 for (i
= 0; i
< n
; i
++) {
2551 GLuint s
= d
[i
] & 0xff;
2552 GLuint z
= (GLuint
) (src
[i
] * scale
);
2553 assert(z
<= 0xffffff);
2554 d
[i
] = (z
<< 8) | s
;
2558 case MESA_FORMAT_S8_Z24
:
2559 case MESA_FORMAT_X8_Z24
:
2561 /* don't disturb the stencil values */
2562 GLuint
*d
= ((GLuint
*) dst
);
2563 const GLdouble scale
= (GLdouble
) 0xffffff;
2565 for (i
= 0; i
< n
; i
++) {
2566 GLuint s
= d
[i
] & 0xff000000;
2567 GLuint z
= (GLuint
) (src
[i
] * scale
);
2568 assert(z
<= 0xffffff);
2573 case MESA_FORMAT_Z16
:
2575 GLushort
*d
= ((GLushort
*) dst
);
2576 const GLfloat scale
= (GLfloat
) 0xffff;
2578 for (i
= 0; i
< n
; i
++) {
2579 d
[i
] = (GLushort
) (src
[i
] * scale
);
2583 case MESA_FORMAT_Z32
:
2585 GLuint
*d
= ((GLuint
*) dst
);
2586 const GLdouble scale
= (GLdouble
) 0xffffffff;
2588 for (i
= 0; i
< n
; i
++) {
2589 d
[i
] = (GLuint
) (src
[i
] * scale
);
2593 case MESA_FORMAT_Z32_FLOAT
:
2594 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2596 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2598 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2600 for (i
= 0; i
< n
; i
++) {
2606 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2612 * The incoming Z values are always in the range [0, 0xffffffff].
2615 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2616 const GLuint
*src
, void *dst
)
2619 case MESA_FORMAT_Z24_S8
:
2620 case MESA_FORMAT_Z24_X8
:
2622 /* don't disturb the stencil values */
2623 GLuint
*d
= ((GLuint
*) dst
);
2625 for (i
= 0; i
< n
; i
++) {
2626 GLuint s
= d
[i
] & 0xff;
2627 GLuint z
= src
[i
] & 0xffffff00;
2632 case MESA_FORMAT_S8_Z24
:
2633 case MESA_FORMAT_X8_Z24
:
2635 /* don't disturb the stencil values */
2636 GLuint
*d
= ((GLuint
*) dst
);
2638 for (i
= 0; i
< n
; i
++) {
2639 GLuint s
= d
[i
] & 0xff000000;
2640 GLuint z
= src
[i
] >> 8;
2645 case MESA_FORMAT_Z16
:
2647 GLushort
*d
= ((GLushort
*) dst
);
2649 for (i
= 0; i
< n
; i
++) {
2650 d
[i
] = src
[i
] >> 16;
2654 case MESA_FORMAT_Z32
:
2655 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2657 case MESA_FORMAT_Z32_FLOAT
:
2659 GLuint
*d
= ((GLuint
*) dst
);
2660 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2662 for (i
= 0; i
< n
; i
++) {
2663 d
[i
] = (GLuint
) (src
[i
] * scale
);
2664 assert(d
[i
] >= 0.0f
);
2665 assert(d
[i
] <= 1.0f
);
2669 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2671 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2672 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2674 for (i
= 0; i
< n
; i
++) {
2675 d
[i
].z
= (GLfloat
) (src
[i
] * scale
);
2676 assert(d
[i
].z
>= 0.0f
);
2677 assert(d
[i
].z
<= 1.0f
);
2682 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2688 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2689 const GLubyte
*src
, void *dst
)
2692 case MESA_FORMAT_Z24_S8
:
2694 /* don't disturb the Z values */
2695 GLuint
*d
= ((GLuint
*) dst
);
2697 for (i
= 0; i
< n
; i
++) {
2699 GLuint z
= d
[i
] & 0xffffff00;
2704 case MESA_FORMAT_S8_Z24
:
2706 /* don't disturb the Z values */
2707 GLuint
*d
= ((GLuint
*) dst
);
2709 for (i
= 0; i
< n
; i
++) {
2710 GLuint s
= src
[i
] << 24;
2711 GLuint z
= d
[i
] & 0xffffff;
2716 case MESA_FORMAT_S8
:
2717 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2719 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2721 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2723 for (i
= 0; i
< n
; i
++) {
2724 d
[i
].x24s8
= src
[i
];
2729 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2735 * Incoming Z/stencil values are always in uint_24_8 format.
2738 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2739 const GLuint
*src
, void *dst
)
2742 case MESA_FORMAT_Z24_S8
:
2743 memcpy(dst
, src
, n
* sizeof(GLuint
));
2745 case MESA_FORMAT_S8_Z24
:
2747 GLuint
*d
= ((GLuint
*) dst
);
2749 for (i
= 0; i
< n
; i
++) {
2750 GLuint s
= src
[i
] << 24;
2751 GLuint z
= src
[i
] >> 8;
2756 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2758 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2759 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2761 for (i
= 0; i
< n
; i
++) {
2762 GLfloat z
= (GLfloat
) ((src
[i
] >> 8) * scale
);
2764 d
[i
].x24s8
= src
[i
];
2769 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2770 _mesa_get_format_name(format
));
2778 * Convert a boolean color mask to a packed color where each channel of
2779 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2782 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2784 GLfloat maskColor
[4];
2786 switch (_mesa_get_format_datatype(format
)) {
2787 case GL_UNSIGNED_NORMALIZED
:
2788 /* simple: 1.0 will convert to ~0 in the right bit positions */
2789 maskColor
[0] = colorMask
[0] ? 1.0f
: 0.0f
;
2790 maskColor
[1] = colorMask
[1] ? 1.0f
: 0.0f
;
2791 maskColor
[2] = colorMask
[2] ? 1.0f
: 0.0f
;
2792 maskColor
[3] = colorMask
[3] ? 1.0f
: 0.0f
;
2793 _mesa_pack_float_rgba_row(format
, 1,
2794 (const GLfloat (*)[4]) maskColor
, dst
);
2796 case GL_SIGNED_NORMALIZED
:
2798 /* These formats are harder because it's hard to know the floating
2799 * point values that will convert to ~0 for each color channel's bits.
2800 * This solution just generates a non-zero value for each color channel
2801 * then fixes up the non-zero values to be ~0.
2802 * Note: we'll need to add special case code if we ever have to deal
2803 * with formats with unequal color channel sizes, like R11_G11_B10.
2804 * We issue a warning below for channel sizes other than 8,16,32.
2807 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2808 GLuint bytes
= _mesa_get_format_bytes(format
);
2811 /* this should put non-zero values into the channels of dst */
2812 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2813 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2814 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2815 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2816 _mesa_pack_float_rgba_row(format
, 1,
2817 (const GLfloat (*)[4]) maskColor
, dst
);
2819 /* fix-up the dst channels by converting non-zero values to ~0 */
2821 GLubyte
*d
= (GLubyte
*) dst
;
2822 for (i
= 0; i
< bytes
; i
++) {
2823 d
[i
] = d
[i
] ? 0xff : 0x0;
2826 else if (bits
== 16) {
2827 GLushort
*d
= (GLushort
*) dst
;
2828 for (i
= 0; i
< bytes
/ 2; i
++) {
2829 d
[i
] = d
[i
] ? 0xffff : 0x0;
2832 else if (bits
== 32) {
2833 GLuint
*d
= (GLuint
*) dst
;
2834 for (i
= 0; i
< bytes
/ 4; i
++) {
2835 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2839 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2845 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");