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 OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Color, depth, stencil packing functions.
27 * Used to pack basic color, depth and stencil formats to specific
30 * There are both per-pixel and per-row packing functions:
31 * - The former will be used by swrast to write values to the color, depth,
32 * stencil buffers when drawing points, lines and masked spans.
33 * - The later will be used for image-oriented functions like glDrawPixels,
34 * glAccum, and glTexImage.
39 #include "format_pack.h"
41 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
42 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
45 /** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */
53 typedef void (*pack_ubyte_rgba_row_func
)(GLuint n
,
54 const GLubyte src
[][4], void *dst
);
56 typedef void (*pack_float_rgba_row_func
)(GLuint n
,
57 const GLfloat src
[][4], void *dst
);
62 linear_to_srgb(GLfloat cl
)
66 else if (cl
< 0.0031308f
)
69 return 1.055f
* powf(cl
, 0.41666f
) - 0.055f
;
76 linear_float_to_srgb_ubyte(GLfloat cl
)
78 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
));
84 linear_ubyte_to_srgb_ubyte(GLubyte cl
)
86 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
/ 255.0f
));
94 * MESA_FORMAT_RGBA8888
98 pack_ubyte_RGBA8888(const GLubyte src
[4], void *dst
)
100 GLuint
*d
= ((GLuint
*) dst
);
101 *d
= PACK_COLOR_8888(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
105 pack_float_RGBA8888(const GLfloat src
[4], void *dst
)
108 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
109 pack_ubyte_RGBA8888(v
, dst
);
113 pack_row_ubyte_RGBA8888(GLuint n
, const GLubyte src
[][4], void *dst
)
115 GLuint
*d
= ((GLuint
*) dst
);
117 for (i
= 0; i
< n
; i
++) {
118 d
[i
] = PACK_COLOR_8888(src
[i
][RCOMP
], src
[i
][GCOMP
],
119 src
[i
][BCOMP
], src
[i
][ACOMP
]);
124 pack_row_float_RGBA8888(GLuint n
, const GLfloat src
[][4], void *dst
)
126 GLuint
*d
= ((GLuint
*) dst
);
128 for (i
= 0; i
< n
; i
++) {
130 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
131 pack_ubyte_RGBA8888(v
, d
+ i
);
138 * MESA_FORMAT_RGBA8888_REV
142 pack_ubyte_RGBA8888_REV(const GLubyte src
[4], void *dst
)
144 GLuint
*d
= ((GLuint
*) dst
);
145 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[BCOMP
], src
[GCOMP
], src
[RCOMP
]);
149 pack_float_RGBA8888_REV(const GLfloat src
[4], void *dst
)
152 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
153 pack_ubyte_RGBA8888_REV(v
, dst
);
157 pack_row_ubyte_RGBA8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
159 GLuint
*d
= ((GLuint
*) dst
);
161 for (i
= 0; i
< n
; i
++) {
162 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][BCOMP
],
163 src
[i
][GCOMP
], src
[i
][RCOMP
]);
168 pack_row_float_RGBA8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
170 GLuint
*d
= ((GLuint
*) dst
);
172 for (i
= 0; i
< n
; i
++) {
174 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
175 pack_ubyte_RGBA8888_REV(v
, d
+ i
);
181 * MESA_FORMAT_ARGB8888
185 pack_ubyte_ARGB8888(const GLubyte src
[4], void *dst
)
187 GLuint
*d
= ((GLuint
*) dst
);
188 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
192 pack_float_ARGB8888(const GLfloat src
[4], void *dst
)
195 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
196 pack_ubyte_ARGB8888(v
, dst
);
200 pack_row_ubyte_ARGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
202 GLuint
*d
= ((GLuint
*) dst
);
204 for (i
= 0; i
< n
; i
++) {
205 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][RCOMP
],
206 src
[i
][GCOMP
], src
[i
][BCOMP
]);
211 pack_row_float_ARGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
213 GLuint
*d
= ((GLuint
*) dst
);
215 for (i
= 0; i
< n
; i
++) {
217 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
218 pack_ubyte_ARGB8888(v
, d
+ i
);
224 * MESA_FORMAT_ARGB8888_REV
228 pack_ubyte_ARGB8888_REV(const GLubyte src
[4], void *dst
)
230 GLuint
*d
= ((GLuint
*) dst
);
231 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
235 pack_float_ARGB8888_REV(const GLfloat src
[4], void *dst
)
238 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
239 pack_ubyte_ARGB8888_REV(v
, dst
);
243 pack_row_ubyte_ARGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
245 GLuint
*d
= ((GLuint
*) dst
);
247 for (i
= 0; i
< n
; i
++) {
248 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
],
249 src
[i
][RCOMP
], src
[i
][ACOMP
]);
254 pack_row_float_ARGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
256 GLuint
*d
= ((GLuint
*) dst
);
258 for (i
= 0; i
< n
; i
++) {
260 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
261 pack_ubyte_ARGB8888_REV(v
, d
+ i
);
267 * MESA_FORMAT_XRGB8888
271 pack_ubyte_XRGB8888(const GLubyte src
[4], void *dst
)
273 GLuint
*d
= ((GLuint
*) dst
);
274 *d
= PACK_COLOR_8888(0x0, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
278 pack_float_XRGB8888(const GLfloat src
[4], void *dst
)
281 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
282 pack_ubyte_XRGB8888(v
, dst
);
286 pack_row_ubyte_XRGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
288 GLuint
*d
= ((GLuint
*) dst
);
290 for (i
= 0; i
< n
; i
++) {
291 d
[i
] = PACK_COLOR_8888(0, src
[i
][RCOMP
], src
[i
][GCOMP
], src
[i
][BCOMP
]);
296 pack_row_float_XRGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
298 GLuint
*d
= ((GLuint
*) dst
);
300 for (i
= 0; i
< n
; i
++) {
302 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
303 pack_ubyte_XRGB8888(v
, d
+ i
);
309 * MESA_FORMAT_XRGB8888_REV
313 pack_ubyte_XRGB8888_REV(const GLubyte src
[4], void *dst
)
315 GLuint
*d
= ((GLuint
*) dst
);
316 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], 0);
320 pack_float_XRGB8888_REV(const GLfloat src
[4], void *dst
)
323 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
324 pack_ubyte_XRGB8888_REV(v
, dst
);
328 pack_row_ubyte_XRGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
330 GLuint
*d
= ((GLuint
*) dst
);
332 for (i
= 0; i
< n
; i
++) {
333 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
], src
[i
][RCOMP
], 0);
338 pack_row_float_XRGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
340 GLuint
*d
= ((GLuint
*) dst
);
342 for (i
= 0; i
< n
; i
++) {
344 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
345 pack_ubyte_XRGB8888_REV(v
, d
+ i
);
355 pack_ubyte_RGB888(const GLubyte src
[4], void *dst
)
357 GLubyte
*d
= ((GLubyte
*) dst
);
364 pack_float_RGB888(const GLfloat src
[4], void *dst
)
366 GLubyte
*d
= ((GLubyte
*) dst
);
367 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[RCOMP
]);
368 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
369 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[BCOMP
]);
373 pack_row_ubyte_RGB888(GLuint n
, const GLubyte src
[][4], void *dst
)
375 GLubyte
*d
= ((GLubyte
*) dst
);
377 for (i
= 0; i
< n
; i
++) {
378 d
[i
*3+2] = src
[i
][RCOMP
];
379 d
[i
*3+1] = src
[i
][GCOMP
];
380 d
[i
*3+0] = src
[i
][BCOMP
];
385 pack_row_float_RGB888(GLuint n
, const GLfloat src
[][4], void *dst
)
387 GLubyte
*d
= ((GLubyte
*) dst
);
389 for (i
= 0; i
< n
; i
++) {
391 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
404 pack_ubyte_BGR888(const GLubyte src
[4], void *dst
)
406 GLubyte
*d
= ((GLubyte
*) dst
);
413 pack_float_BGR888(const GLfloat src
[4], void *dst
)
415 GLubyte
*d
= ((GLubyte
*) dst
);
416 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[BCOMP
]);
417 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
418 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
422 pack_row_ubyte_BGR888(GLuint n
, const GLubyte src
[][4], void *dst
)
424 GLubyte
*d
= ((GLubyte
*) dst
);
426 for (i
= 0; i
< n
; i
++) {
427 d
[i
*3+2] = src
[i
][BCOMP
];
428 d
[i
*3+1] = src
[i
][GCOMP
];
429 d
[i
*3+0] = src
[i
][RCOMP
];
434 pack_row_float_BGR888(GLuint n
, const GLfloat src
[][4], void *dst
)
436 GLubyte
*d
= ((GLubyte
*) dst
);
438 for (i
= 0; i
< n
; i
++) {
440 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
453 pack_ubyte_RGB565(const GLubyte src
[4], void *dst
)
455 GLushort
*d
= ((GLushort
*) dst
);
456 *d
= PACK_COLOR_565(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
460 pack_float_RGB565(const GLfloat src
[4], void *dst
)
463 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
464 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
465 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
466 pack_ubyte_RGB565(v
, dst
);
470 pack_row_ubyte_RGB565(GLuint n
, const GLubyte src
[][4], void *dst
)
472 GLushort
*d
= ((GLushort
*) dst
);
474 for (i
= 0; i
< n
; i
++) {
475 pack_ubyte_RGB565(src
[i
], d
+ i
);
480 pack_row_float_RGB565(GLuint n
, const GLfloat src
[][4], void *dst
)
482 GLushort
*d
= ((GLushort
*) dst
);
484 for (i
= 0; i
< n
; i
++) {
486 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
487 pack_ubyte_RGB565(v
, d
+ i
);
493 * MESA_FORMAT_RGB565_REV
497 pack_ubyte_RGB565_REV(const GLubyte src
[4], void *dst
)
499 GLushort
*d
= ((GLushort
*) dst
);
500 *d
= PACK_COLOR_565_REV(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
504 pack_float_RGB565_REV(const GLfloat src
[4], void *dst
)
506 GLushort
*d
= ((GLushort
*) dst
);
508 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
509 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
510 UNCLAMPED_FLOAT_TO_UBYTE(b
, src
[BCOMP
]);
511 *d
= PACK_COLOR_565_REV(r
, g
, b
);
515 pack_row_ubyte_RGB565_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
517 GLushort
*d
= ((GLushort
*) dst
);
519 for (i
= 0; i
< n
; i
++) {
520 pack_ubyte_RGB565_REV(src
[i
], d
+ i
);
525 pack_row_float_RGB565_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
527 GLushort
*d
= ((GLushort
*) dst
);
529 for (i
= 0; i
< n
; i
++) {
531 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
532 pack_ubyte_RGB565_REV(v
, d
+ i
);
538 * MESA_FORMAT_ARGB4444
542 pack_ubyte_ARGB4444(const GLubyte src
[4], void *dst
)
544 GLushort
*d
= ((GLushort
*) dst
);
545 *d
= PACK_COLOR_4444(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
549 pack_float_ARGB4444(const GLfloat src
[4], void *dst
)
552 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
553 pack_ubyte_ARGB4444(v
, dst
);
556 /* use fallback row packing functions */
560 * MESA_FORMAT_ARGB4444_REV
564 pack_ubyte_ARGB4444_REV(const GLubyte src
[4], void *dst
)
566 GLushort
*d
= ((GLushort
*) dst
);
567 *d
= PACK_COLOR_4444(src
[GCOMP
], src
[BCOMP
], src
[ACOMP
], src
[RCOMP
]);
571 pack_float_ARGB4444_REV(const GLfloat src
[4], void *dst
)
574 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
575 pack_ubyte_ARGB4444_REV(v
, dst
);
578 /* use fallback row packing functions */
582 * MESA_FORMAT_RGBA5551
586 pack_ubyte_RGBA5551(const GLubyte src
[4], void *dst
)
588 GLushort
*d
= ((GLushort
*) dst
);
589 *d
= PACK_COLOR_5551(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
593 pack_float_RGBA5551(const GLfloat src
[4], void *dst
)
596 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
597 pack_ubyte_RGBA5551(v
, dst
);
600 /* use fallback row packing functions */
604 * MESA_FORMAT_ARGB1555
608 pack_ubyte_ARGB1555(const GLubyte src
[4], void *dst
)
610 GLushort
*d
= ((GLushort
*) dst
);
611 *d
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
615 pack_float_ARGB1555(const GLfloat src
[4], void *dst
)
618 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
619 pack_ubyte_ARGB1555(v
, dst
);
623 /* MESA_FORMAT_ARGB1555_REV */
626 pack_ubyte_ARGB1555_REV(const GLubyte src
[4], void *dst
)
628 GLushort
*d
= ((GLushort
*) dst
), tmp
;
629 tmp
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
630 *d
= (tmp
>> 8) | (tmp
<< 8);
634 pack_float_ARGB1555_REV(const GLfloat src
[4], void *dst
)
637 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
638 pack_ubyte_ARGB1555_REV(v
, dst
);
642 /* MESA_FORMAT_AL44 */
645 pack_ubyte_AL44(const GLubyte src
[4], void *dst
)
647 GLubyte
*d
= ((GLubyte
*) dst
);
648 *d
= PACK_COLOR_44(src
[ACOMP
], src
[RCOMP
]);
652 pack_float_AL44(const GLfloat src
[4], void *dst
)
655 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
656 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
657 pack_ubyte_AL44(v
, dst
);
661 /* MESA_FORMAT_AL88 */
664 pack_ubyte_AL88(const GLubyte src
[4], void *dst
)
666 GLushort
*d
= ((GLushort
*) dst
);
667 *d
= PACK_COLOR_88(src
[ACOMP
], src
[RCOMP
]);
671 pack_float_AL88(const GLfloat src
[4], void *dst
)
674 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
675 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
676 pack_ubyte_AL88(v
, dst
);
680 /* MESA_FORMAT_AL88_REV */
683 pack_ubyte_AL88_REV(const GLubyte src
[4], void *dst
)
685 GLushort
*d
= ((GLushort
*) dst
);
686 *d
= PACK_COLOR_88(src
[RCOMP
], src
[ACOMP
]);
690 pack_float_AL88_REV(const GLfloat src
[4], void *dst
)
693 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
694 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
695 pack_ubyte_AL88_REV(v
, dst
);
699 /* MESA_FORMAT_AL1616 */
702 pack_ubyte_AL1616(const GLubyte src
[4], void *dst
)
704 GLuint
*d
= ((GLuint
*) dst
);
705 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
706 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
707 *d
= PACK_COLOR_1616(a
, l
);
711 pack_float_AL1616(const GLfloat src
[4], void *dst
)
713 GLuint
*d
= ((GLuint
*) dst
);
715 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
716 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
717 *d
= PACK_COLOR_1616(a
, l
);
721 /* MESA_FORMAT_AL1616_REV */
724 pack_ubyte_AL1616_REV(const GLubyte src
[4], void *dst
)
726 GLuint
*d
= ((GLuint
*) dst
);
727 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
728 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
729 *d
= PACK_COLOR_1616(l
, a
);
733 pack_float_AL1616_REV(const GLfloat src
[4], void *dst
)
735 GLuint
*d
= ((GLuint
*) dst
);
737 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
738 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
739 *d
= PACK_COLOR_1616(l
, a
);
743 /* MESA_FORMAT_RGB332 */
746 pack_ubyte_RGB332(const GLubyte src
[4], void *dst
)
748 GLubyte
*d
= ((GLubyte
*) dst
);
749 *d
= PACK_COLOR_332(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
753 pack_float_RGB332(const GLfloat src
[4], void *dst
)
756 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
757 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
758 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
759 pack_ubyte_RGB332(v
, dst
);
766 pack_ubyte_A8(const GLubyte src
[4], void *dst
)
768 GLubyte
*d
= ((GLubyte
*) dst
);
773 pack_float_A8(const GLfloat src
[4], void *dst
)
775 GLubyte
*d
= ((GLubyte
*) dst
);
776 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[ACOMP
]);
780 /* MESA_FORMAT_A16 */
783 pack_ubyte_A16(const GLubyte src
[4], void *dst
)
785 GLushort
*d
= ((GLushort
*) dst
);
786 *d
= UBYTE_TO_USHORT(src
[ACOMP
]);
790 pack_float_A16(const GLfloat src
[4], void *dst
)
792 GLushort
*d
= ((GLushort
*) dst
);
793 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[ACOMP
]);
800 pack_ubyte_L8(const GLubyte src
[4], void *dst
)
802 GLubyte
*d
= ((GLubyte
*) dst
);
807 pack_float_L8(const GLfloat src
[4], void *dst
)
809 GLubyte
*d
= ((GLubyte
*) dst
);
810 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
814 /* MESA_FORMAT_L16 */
817 pack_ubyte_L16(const GLubyte src
[4], void *dst
)
819 GLushort
*d
= ((GLushort
*) dst
);
820 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
824 pack_float_L16(const GLfloat src
[4], void *dst
)
826 GLushort
*d
= ((GLushort
*) dst
);
827 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
831 /* MESA_FORMAT_YCBCR */
834 pack_ubyte_YCBCR(const GLubyte src
[4], void *dst
)
840 pack_float_YCBCR(const GLfloat src
[4], void *dst
)
846 /* MESA_FORMAT_YCBCR_REV */
849 pack_ubyte_YCBCR_REV(const GLubyte src
[4], void *dst
)
855 pack_float_YCBCR_REV(const GLfloat src
[4], void *dst
)
864 pack_ubyte_R8(const GLubyte src
[4], void *dst
)
866 GLubyte
*d
= ((GLubyte
*) dst
);
871 pack_float_R8(const GLfloat src
[4], void *dst
)
873 GLubyte
*d
= ((GLubyte
*) dst
);
875 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
880 /* MESA_FORMAT_GR88 */
883 pack_ubyte_GR88(const GLubyte src
[4], void *dst
)
885 GLubyte
*d
= ((GLubyte
*) dst
);
886 *d
= PACK_COLOR_88(src
[GCOMP
], src
[RCOMP
]);
890 pack_float_GR88(const GLfloat src
[4], void *dst
)
892 GLushort
*d
= ((GLushort
*) dst
);
894 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
895 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
896 *d
= PACK_COLOR_88(g
, r
);
900 /* MESA_FORMAT_RG88 */
903 pack_ubyte_RG88(const GLubyte src
[4], void *dst
)
905 GLubyte
*d
= ((GLubyte
*) dst
);
906 *d
= PACK_COLOR_88(src
[RCOMP
], src
[GCOMP
]);
910 pack_float_RG88(const GLfloat src
[4], void *dst
)
912 GLushort
*d
= ((GLushort
*) dst
);
914 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
915 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
916 *d
= PACK_COLOR_88(r
, g
);
920 /* MESA_FORMAT_R16 */
923 pack_ubyte_R16(const GLubyte src
[4], void *dst
)
925 GLushort
*d
= ((GLushort
*) dst
);
926 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
930 pack_float_R16(const GLfloat src
[4], void *dst
)
932 GLushort
*d
= ((GLushort
*) dst
);
933 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
937 /* MESA_FORMAT_GR1616 */
940 pack_ubyte_GR1616(const GLubyte src
[4], void *dst
)
942 GLuint
*d
= ((GLuint
*) dst
);
943 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
944 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
945 *d
= PACK_COLOR_1616(g
, r
);
949 pack_float_GR1616(const GLfloat src
[4], void *dst
)
951 GLuint
*d
= ((GLuint
*) dst
);
953 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
954 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
955 *d
= PACK_COLOR_1616(g
, r
);
959 /* MESA_FORMAT_RG1616 */
962 pack_ubyte_RG1616(const GLubyte src
[4], void *dst
)
964 GLuint
*d
= ((GLuint
*) dst
);
965 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
966 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
967 *d
= PACK_COLOR_1616(r
, g
);
972 pack_float_RG1616(const GLfloat src
[4], void *dst
)
974 GLuint
*d
= ((GLuint
*) dst
);
976 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
977 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
978 *d
= PACK_COLOR_1616(r
, g
);
982 /* MESA_FORMAT_ARGB2101010 */
985 pack_ubyte_ARGB2101010(const GLubyte src
[4], void *dst
)
987 GLuint
*d
= ((GLuint
*) dst
);
988 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
989 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
990 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
991 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
992 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
996 pack_float_ARGB2101010(const GLfloat src
[4], void *dst
)
998 GLuint
*d
= ((GLuint
*) dst
);
1000 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1001 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1002 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1003 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1004 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
1008 /* MESA_FORMAT_ABGR2101010_UINT */
1011 pack_ubyte_ABGR2101010_UINT(const GLubyte src
[4], void *dst
)
1013 GLuint
*d
= ((GLuint
*) dst
);
1014 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
1015 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
1016 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
1017 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
1018 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1022 pack_float_ABGR2101010_UINT(const GLfloat src
[4], void *dst
)
1024 GLuint
*d
= ((GLuint
*) dst
);
1025 GLushort r
, g
, b
, a
;
1026 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1027 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1028 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1029 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1030 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1034 /* MESA_FORMAT_SRGB8 */
1037 pack_ubyte_SRGB8(const GLubyte src
[4], void *dst
)
1039 GLubyte
*d
= ((GLubyte
*) dst
);
1040 d
[2] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1041 d
[1] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1042 d
[0] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1046 pack_float_SRGB8(const GLfloat src
[4], void *dst
)
1048 GLubyte
*d
= ((GLubyte
*) dst
);
1049 d
[2] = linear_float_to_srgb_ubyte(src
[RCOMP
]);
1050 d
[1] = linear_float_to_srgb_ubyte(src
[GCOMP
]);
1051 d
[0] = linear_float_to_srgb_ubyte(src
[BCOMP
]);
1055 /* MESA_FORMAT_SRGBA8 */
1058 pack_ubyte_SRGBA8(const GLubyte src
[4], void *dst
)
1060 GLuint
*d
= ((GLuint
*) dst
);
1061 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1062 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[GCOMP
]);
1063 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[BCOMP
]);
1064 *d
= PACK_COLOR_8888(r
, g
, b
, src
[ACOMP
]);
1068 pack_float_SRGBA8(const GLfloat src
[4], void *dst
)
1070 GLuint
*d
= ((GLuint
*) dst
);
1072 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1073 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1074 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1075 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1076 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1080 /* MESA_FORMAT_SARGB8 */
1083 pack_ubyte_SARGB8(const GLubyte src
[4], void *dst
)
1085 GLuint
*d
= ((GLuint
*) dst
);
1086 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1087 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1088 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1089 *d
= PACK_COLOR_8888(src
[ACOMP
], r
, g
, b
);
1093 pack_float_SARGB8(const GLfloat src
[4], void *dst
)
1095 GLuint
*d
= ((GLuint
*) dst
);
1097 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1098 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1099 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1100 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1101 *d
= PACK_COLOR_8888(a
, r
, g
, b
);
1105 /* MESA_FORMAT_SL8 */
1108 pack_ubyte_SL8(const GLubyte src
[4], void *dst
)
1110 GLubyte
*d
= ((GLubyte
*) dst
);
1111 *d
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1115 pack_float_SL8(const GLfloat src
[4], void *dst
)
1117 GLubyte
*d
= ((GLubyte
*) dst
);
1118 GLubyte l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1123 /* MESA_FORMAT_SLA8 */
1126 pack_ubyte_SLA8(const GLubyte src
[4], void *dst
)
1128 GLushort
*d
= ((GLushort
*) dst
);
1129 GLubyte l
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1130 *d
= PACK_COLOR_88(src
[ACOMP
], l
);
1134 pack_float_SLA8(const GLfloat src
[4], void *dst
)
1136 GLushort
*d
= ((GLushort
*) dst
);
1137 GLubyte a
, l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1138 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1139 *d
= PACK_COLOR_88(a
, l
);
1143 /* MESA_FORMAT_RGBA_FLOAT32 */
1146 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
1148 GLfloat
*d
= ((GLfloat
*) dst
);
1149 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1150 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1151 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1152 d
[3] = UBYTE_TO_FLOAT(src
[3]);
1156 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
1158 GLfloat
*d
= ((GLfloat
*) dst
);
1166 /* MESA_FORMAT_RGBA_FLOAT16 */
1169 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
1171 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1172 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1173 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1174 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1175 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
1179 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
1181 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1182 d
[0] = _mesa_float_to_half(src
[0]);
1183 d
[1] = _mesa_float_to_half(src
[1]);
1184 d
[2] = _mesa_float_to_half(src
[2]);
1185 d
[3] = _mesa_float_to_half(src
[3]);
1189 /* MESA_FORMAT_RGB_FLOAT32 */
1192 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
1194 GLfloat
*d
= ((GLfloat
*) dst
);
1195 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1196 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1197 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1201 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
1203 GLfloat
*d
= ((GLfloat
*) dst
);
1210 /* MESA_FORMAT_RGB_FLOAT16 */
1213 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
1215 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1216 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1217 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1218 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1222 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
1224 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1225 d
[0] = _mesa_float_to_half(src
[0]);
1226 d
[1] = _mesa_float_to_half(src
[1]);
1227 d
[2] = _mesa_float_to_half(src
[2]);
1231 /* MESA_FORMAT_ALPHA_FLOAT32 */
1234 pack_ubyte_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1236 GLfloat
*d
= ((GLfloat
*) dst
);
1237 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1241 pack_float_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1243 GLfloat
*d
= ((GLfloat
*) dst
);
1248 /* MESA_FORMAT_ALPHA_FLOAT16 */
1251 pack_ubyte_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1253 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1254 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1258 pack_float_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1260 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1261 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
1265 /* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
1268 pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src
[4], void *dst
)
1270 GLfloat
*d
= ((GLfloat
*) dst
);
1271 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1275 pack_float_LUMINANCE_FLOAT32(const GLfloat src
[4], void *dst
)
1277 GLfloat
*d
= ((GLfloat
*) dst
);
1282 /* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
1285 pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src
[4], void *dst
)
1287 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1288 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1292 pack_float_LUMINANCE_FLOAT16(const GLfloat src
[4], void *dst
)
1294 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1295 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1299 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
1302 pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1304 GLfloat
*d
= ((GLfloat
*) dst
);
1305 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1306 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1310 pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1312 GLfloat
*d
= ((GLfloat
*) dst
);
1318 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
1321 pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1323 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1324 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1325 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1329 pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1331 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1332 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1333 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1337 /* MESA_FORMAT_RG_FLOAT32 */
1340 pack_ubyte_RG_FLOAT32(const GLubyte src
[4], void *dst
)
1342 GLfloat
*d
= ((GLfloat
*) dst
);
1343 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1344 d
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1348 pack_float_RG_FLOAT32(const GLfloat src
[4], void *dst
)
1350 GLfloat
*d
= ((GLfloat
*) dst
);
1356 /* MESA_FORMAT_RG_FLOAT16 */
1359 pack_ubyte_RG_FLOAT16(const GLubyte src
[4], void *dst
)
1361 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1362 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1363 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[GCOMP
]));
1367 pack_float_RG_FLOAT16(const GLfloat src
[4], void *dst
)
1369 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1370 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1371 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1375 /* MESA_FORMAT_DUDV8 */
1378 pack_ubyte_DUDV8(const GLubyte src
[4], void *dst
)
1380 /* XXX is this ever used? */
1381 GLushort
*d
= ((GLushort
*) dst
);
1382 *d
= PACK_COLOR_88(src
[0], src
[1]);
1386 pack_float_DUDV8(const GLfloat src
[4], void *dst
)
1388 GLushort
*d
= ((GLushort
*) dst
);
1390 du
= FLOAT_TO_BYTE(CLAMP(src
[0], 0.0F
, 1.0F
));
1391 dv
= FLOAT_TO_BYTE(CLAMP(src
[1], 0.0F
, 1.0F
));
1392 *d
= PACK_COLOR_88(du
, dv
);
1396 /* MESA_FORMAT_RGBA_16 */
1399 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1401 GLushort
*d
= ((GLushort
*) dst
);
1402 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1403 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1404 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1405 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1409 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1411 GLushort
*d
= ((GLushort
*) dst
);
1412 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1413 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1414 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1415 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1421 * MESA_FORMAT_SIGNED_R8
1425 pack_float_SIGNED_R8(const GLfloat src
[4], void *dst
)
1427 GLbyte
*d
= (GLbyte
*) dst
;
1428 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1433 * MESA_FORMAT_SIGNED_RG88_REV
1437 pack_float_SIGNED_RG88_REV(const GLfloat src
[4], void *dst
)
1439 GLushort
*d
= (GLushort
*) dst
;
1440 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1441 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1447 * MESA_FORMAT_SIGNED_RGBX8888
1451 pack_float_SIGNED_RGBX8888(const GLfloat src
[4], void *dst
)
1453 GLuint
*d
= (GLuint
*) dst
;
1454 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1455 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1456 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1458 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1463 * MESA_FORMAT_SIGNED_RGBA8888
1467 pack_float_SIGNED_RGBA8888(const GLfloat src
[4], void *dst
)
1469 GLuint
*d
= (GLuint
*) dst
;
1470 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1471 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1472 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1473 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1474 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1479 * MESA_FORMAT_SIGNED_RGBA8888_REV
1483 pack_float_SIGNED_RGBA8888_REV(const GLfloat src
[4], void *dst
)
1485 GLuint
*d
= (GLuint
*) dst
;
1486 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1487 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1488 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1489 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1490 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1495 * MESA_FORMAT_SIGNED_R16
1499 pack_float_SIGNED_R16(const GLfloat src
[4], void *dst
)
1501 GLshort
*d
= (GLshort
*) dst
;
1502 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1507 * MESA_FORMAT_SIGNED_GR1616
1511 pack_float_SIGNED_GR1616(const GLfloat src
[4], void *dst
)
1513 GLuint
*d
= (GLuint
*) dst
;
1514 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1515 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1516 *d
= (g
<< 16) | (r
& 0xffff);
1521 * MESA_FORMAT_SIGNED_RGB_16
1525 pack_float_SIGNED_RGB_16(const GLfloat src
[4], void *dst
)
1527 GLshort
*d
= (GLshort
*) dst
;
1528 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1529 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1530 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1535 * MESA_FORMAT_SIGNED_RGBA_16
1539 pack_float_SIGNED_RGBA_16(const GLfloat src
[4], void *dst
)
1541 GLshort
*d
= (GLshort
*) dst
;
1542 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1543 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1544 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1545 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1550 * MESA_FORMAT_SIGNED_A8
1554 pack_float_SIGNED_A8(const GLfloat src
[4], void *dst
)
1556 GLbyte
*d
= (GLbyte
*) dst
;
1557 *d
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1562 * MESA_FORMAT_SIGNED_L8
1566 pack_float_SIGNED_L8(const GLfloat src
[4], void *dst
)
1568 GLbyte
*d
= (GLbyte
*) dst
;
1569 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1574 * MESA_FORMAT_SIGNED_AL88
1578 pack_float_SIGNED_AL88(const GLfloat src
[4], void *dst
)
1580 GLushort
*d
= (GLushort
*) dst
;
1581 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1582 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1588 * MESA_FORMAT_SIGNED_A16
1592 pack_float_SIGNED_A16(const GLfloat src
[4], void *dst
)
1594 GLshort
*d
= (GLshort
*) dst
;
1595 *d
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1600 * MESA_FORMAT_SIGNED_L16
1604 pack_float_SIGNED_L16(const GLfloat src
[4], void *dst
)
1606 GLshort
*d
= (GLshort
*) dst
;
1607 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1612 * MESA_FORMAT_SIGNED_AL1616
1616 pack_float_SIGNED_AL1616(const GLfloat src
[4], void *dst
)
1618 GLuint
*d
= (GLuint
*) dst
;
1619 GLshort l
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1620 GLshort a
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1621 *d
= PACK_COLOR_1616(a
, l
);
1626 * MESA_FORMAT_RGB9_E5_FLOAT;
1630 pack_float_RGB9_E5_FLOAT(const GLfloat src
[4], void *dst
)
1632 GLuint
*d
= (GLuint
*) dst
;
1633 *d
= float3_to_rgb9e5(src
);
1637 pack_ubyte_RGB9_E5_FLOAT(const GLubyte src
[4], void *dst
)
1639 GLuint
*d
= (GLuint
*) dst
;
1641 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1642 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1643 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1644 *d
= float3_to_rgb9e5(rgb
);
1650 * MESA_FORMAT_R11_G11_B10_FLOAT;
1654 pack_ubyte_R11_G11_B10_FLOAT(const GLubyte src
[4], void *dst
)
1656 GLuint
*d
= (GLuint
*) dst
;
1658 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1659 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1660 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1661 *d
= float3_to_r11g11b10f(rgb
);
1665 pack_float_R11_G11_B10_FLOAT(const GLfloat src
[4], void *dst
)
1667 GLuint
*d
= (GLuint
*) dst
;
1668 *d
= float3_to_r11g11b10f(src
);
1673 * MESA_FORMAT_XRGB4444_UNORM
1677 pack_ubyte_XRGB4444_UNORM(const GLubyte src
[4], void *dst
)
1679 GLushort
*d
= ((GLushort
*) dst
);
1680 *d
= PACK_COLOR_4444(255, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
1684 pack_float_XRGB4444_UNORM(const GLfloat src
[4], void *dst
)
1687 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
1688 pack_ubyte_XRGB4444_UNORM(v
, dst
);
1693 * MESA_FORMAT_XRGB1555_UNORM
1697 pack_ubyte_XRGB1555_UNORM(const GLubyte src
[4], void *dst
)
1699 GLushort
*d
= ((GLushort
*) dst
);
1700 *d
= PACK_COLOR_1555(255, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
1704 pack_float_XRGB1555_UNORM(const GLfloat src
[4], void *dst
)
1707 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
1708 pack_ubyte_XRGB1555_UNORM(v
, dst
);
1713 * MESA_FORMAT_XBGR8888_SNORM
1717 pack_float_XBGR8888_SNORM(const GLfloat src
[4], void *dst
)
1719 GLuint
*d
= (GLuint
*) dst
;
1720 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1721 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1722 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1723 *d
= PACK_COLOR_8888(127, b
, g
, r
);
1728 * MESA_FORMAT_XBGR8888_SRGB
1732 pack_float_XBGR8888_SRGB(const GLfloat src
[4], void *dst
)
1734 GLuint
*d
= (GLuint
*) dst
;
1735 GLubyte r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1736 GLubyte g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1737 GLubyte b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1738 *d
= PACK_COLOR_8888(127, b
, g
, r
);
1742 /* MESA_FORMAT_XRGB2101010_UNORM */
1745 pack_ubyte_XRGB2101010_UNORM(const GLubyte src
[4], void *dst
)
1747 GLuint
*d
= ((GLuint
*) dst
);
1748 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
1749 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
1750 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
1751 *d
= PACK_COLOR_2101010_US(3, r
, g
, b
);
1755 pack_float_XRGB2101010_UNORM(const GLfloat src
[4], void *dst
)
1757 GLuint
*d
= ((GLuint
*) dst
);
1759 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1760 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1761 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1762 *d
= PACK_COLOR_2101010_US(3, r
, g
, b
);
1766 /* MESA_FORMAT_XBGR16161616_UNORM */
1769 pack_ubyte_XBGR16161616_UNORM(const GLubyte src
[4], void *dst
)
1771 GLushort
*d
= ((GLushort
*) dst
);
1772 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1773 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1774 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1779 pack_float_XBGR16161616_UNORM(const GLfloat src
[4], void *dst
)
1781 GLushort
*d
= ((GLushort
*) dst
);
1782 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1783 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1784 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1789 /* MESA_FORMAT_XBGR16161616_SNORM */
1792 pack_float_XBGR16161616_SNORM(const GLfloat src
[4], void *dst
)
1794 GLushort
*d
= ((GLushort
*) dst
);
1795 UNCLAMPED_FLOAT_TO_SHORT(d
[0], src
[RCOMP
]);
1796 UNCLAMPED_FLOAT_TO_SHORT(d
[1], src
[GCOMP
]);
1797 UNCLAMPED_FLOAT_TO_SHORT(d
[2], src
[BCOMP
]);
1802 /* MESA_FORMAT_XBGR16161616_FLOAT */
1805 pack_float_XBGR16161616_FLOAT(const GLfloat src
[4], void *dst
)
1807 GLushort
*d
= ((GLushort
*) dst
);
1808 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1809 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1810 d
[2] = _mesa_float_to_half(src
[BCOMP
]);
1811 d
[3] = _mesa_float_to_half(1.0);
1814 /* MESA_FORMAT_XBGR32323232_FLOAT */
1817 pack_float_XBGR32323232_FLOAT(const GLfloat src
[4], void *dst
)
1819 GLfloat
*d
= ((GLfloat
*) dst
);
1828 * Return a function that can pack a GLubyte rgba[4] color.
1830 gl_pack_ubyte_rgba_func
1831 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1833 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1834 static GLboolean initialized
= GL_FALSE
;
1837 memset(table
, 0, sizeof(table
));
1839 table
[MESA_FORMAT_NONE
] = NULL
;
1841 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1842 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1843 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1844 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1845 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1846 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1847 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1848 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1849 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1850 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1851 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1852 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1853 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1854 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1855 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1856 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1857 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1858 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1859 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1860 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1861 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1862 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1863 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1864 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1865 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1866 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1867 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1868 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1869 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1870 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1871 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1872 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1873 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1874 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1875 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1876 table
[MESA_FORMAT_GR1616
] = pack_ubyte_GR1616
;
1877 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1878 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1879 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_ubyte_ABGR2101010_UINT
;
1881 /* should never convert RGBA to these formats */
1882 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1883 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1884 table
[MESA_FORMAT_Z16
] = NULL
;
1885 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1886 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1887 table
[MESA_FORMAT_Z32
] = NULL
;
1888 table
[MESA_FORMAT_S8
] = NULL
;
1891 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1892 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1893 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1894 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1895 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1898 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1899 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1900 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1901 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1903 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1904 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1905 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1906 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1907 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1908 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1910 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1911 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1912 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1913 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1914 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1915 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1916 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1917 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1918 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1919 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1920 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1921 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1922 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1923 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1924 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1925 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1928 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1929 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1930 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1931 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1932 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1933 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1935 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1937 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1940 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1941 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1942 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1943 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1944 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1945 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1946 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1947 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1948 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1949 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1950 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1951 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1952 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1953 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1954 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1955 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1956 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1959 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1961 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
1962 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
1964 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_ubyte_XRGB4444_UNORM
;
1965 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_ubyte_XRGB1555_UNORM
;
1966 table
[MESA_FORMAT_XBGR8888_SNORM
] = NULL
;
1967 table
[MESA_FORMAT_XBGR8888_SRGB
] = NULL
;
1968 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
1969 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
1970 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_ubyte_XRGB2101010_UNORM
;
1971 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_ubyte_XBGR16161616_UNORM
;
1972 table
[MESA_FORMAT_XBGR16161616_SNORM
] = NULL
;
1973 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = NULL
;
1974 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
1975 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
1976 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = NULL
;
1977 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
1978 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
1980 initialized
= GL_TRUE
;
1983 return table
[format
];
1989 * Return a function that can pack a GLfloat rgba[4] color.
1991 gl_pack_float_rgba_func
1992 _mesa_get_pack_float_rgba_function(gl_format format
)
1994 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1995 static GLboolean initialized
= GL_FALSE
;
1998 memset(table
, 0, sizeof(table
));
2000 table
[MESA_FORMAT_NONE
] = NULL
;
2002 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
2003 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
2004 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
2005 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
2006 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
2007 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
2008 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
2009 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
2010 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
2011 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
2012 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
2013 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
2014 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
2015 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
2016 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
2017 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
2018 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
2020 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
2021 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
2022 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
2023 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
2024 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
2025 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
2026 table
[MESA_FORMAT_A8
] = pack_float_A8
;
2027 table
[MESA_FORMAT_A16
] = pack_float_A16
;
2028 table
[MESA_FORMAT_L8
] = pack_float_L8
;
2029 table
[MESA_FORMAT_L16
] = pack_float_L16
;
2030 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
2031 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
2032 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
2033 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
2034 table
[MESA_FORMAT_R8
] = pack_float_R8
;
2035 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
2036 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
2037 table
[MESA_FORMAT_R16
] = pack_float_R16
;
2038 table
[MESA_FORMAT_GR1616
] = pack_float_GR1616
;
2039 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
2040 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
2041 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_float_ABGR2101010_UINT
;
2043 /* should never convert RGBA to these formats */
2044 table
[MESA_FORMAT_Z24_S8
] = NULL
;
2045 table
[MESA_FORMAT_S8_Z24
] = NULL
;
2046 table
[MESA_FORMAT_Z16
] = NULL
;
2047 table
[MESA_FORMAT_X8_Z24
] = NULL
;
2048 table
[MESA_FORMAT_Z24_X8
] = NULL
;
2049 table
[MESA_FORMAT_Z32
] = NULL
;
2050 table
[MESA_FORMAT_S8
] = NULL
;
2052 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
2053 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
2054 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
2055 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
2056 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
2059 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
2060 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
2061 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
2062 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
2064 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
2065 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
2066 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
2067 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
2068 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
2069 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
2071 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
2072 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
2073 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
2074 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
2075 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
2076 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
2077 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2078 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2079 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
2080 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
2082 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2083 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2084 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
2085 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
2086 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
2087 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
2090 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
2091 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
2092 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
2093 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
2094 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
2095 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
2097 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
2099 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
2101 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
2102 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
2103 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
2104 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
2105 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
2106 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
2107 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
2108 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
2109 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
2110 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
2111 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
2112 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
2113 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
2114 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
2115 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
2116 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
2117 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
2119 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
2120 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
2122 table
[MESA_FORMAT_XRGB4444_UNORM
] = pack_float_XRGB4444_UNORM
;
2123 table
[MESA_FORMAT_XRGB1555_UNORM
] = pack_float_XRGB1555_UNORM
;
2124 table
[MESA_FORMAT_XBGR8888_SNORM
] = pack_float_XBGR8888_SNORM
;
2125 table
[MESA_FORMAT_XBGR8888_SRGB
] = pack_float_XBGR8888_SRGB
;
2126 table
[MESA_FORMAT_XBGR8888_UINT
] = NULL
;
2127 table
[MESA_FORMAT_XBGR8888_SINT
] = NULL
;
2128 table
[MESA_FORMAT_XRGB2101010_UNORM
] = pack_float_XRGB2101010_UNORM
;
2129 table
[MESA_FORMAT_XBGR16161616_UNORM
] = pack_float_XBGR16161616_UNORM
;
2130 table
[MESA_FORMAT_XBGR16161616_SNORM
] = pack_float_XBGR16161616_SNORM
;
2131 table
[MESA_FORMAT_XBGR16161616_FLOAT
] = pack_float_XBGR16161616_FLOAT
;
2132 table
[MESA_FORMAT_XBGR16161616_UINT
] = NULL
;
2133 table
[MESA_FORMAT_XBGR16161616_SINT
] = NULL
;
2134 table
[MESA_FORMAT_XBGR32323232_FLOAT
] = pack_float_XBGR32323232_FLOAT
;
2135 table
[MESA_FORMAT_XBGR32323232_UINT
] = NULL
;
2136 table
[MESA_FORMAT_XBGR32323232_SINT
] = NULL
;
2138 initialized
= GL_TRUE
;
2141 return table
[format
];
2146 static pack_float_rgba_row_func
2147 get_pack_float_rgba_row_function(gl_format format
)
2149 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
2150 static GLboolean initialized
= GL_FALSE
;
2153 /* We don't need a special row packing function for each format.
2154 * There's a generic fallback which uses a per-pixel packing function.
2156 memset(table
, 0, sizeof(table
));
2158 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
2159 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
2160 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
2161 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
2162 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
2163 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
2164 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
2165 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
2166 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
2167 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
2168 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
2169 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
2171 initialized
= GL_TRUE
;
2174 return table
[format
];
2179 static pack_ubyte_rgba_row_func
2180 get_pack_ubyte_rgba_row_function(gl_format format
)
2182 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
2183 static GLboolean initialized
= GL_FALSE
;
2186 /* We don't need a special row packing function for each format.
2187 * There's a generic fallback which uses a per-pixel packing function.
2189 memset(table
, 0, sizeof(table
));
2191 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
2192 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
2193 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
2194 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
2195 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
2196 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
2197 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
2198 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
2199 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
2200 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
2201 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
2202 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
2204 initialized
= GL_TRUE
;
2207 return table
[format
];
2213 * Pack a row of GLfloat rgba[4] values to the destination.
2216 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
2217 const GLfloat src
[][4], void *dst
)
2219 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2221 /* use "fast" function */
2222 packrow(n
, src
, dst
);
2225 /* slower fallback */
2226 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2227 GLuint dstStride
= _mesa_get_format_bytes(format
);
2228 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2235 for (i
= 0; i
< n
; i
++) {
2236 pack(src
[i
], dstPtr
);
2237 dstPtr
+= dstStride
;
2244 * Pack a row of GLubyte rgba[4] values to the destination.
2247 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2248 const GLubyte src
[][4], void *dst
)
2250 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2252 /* use "fast" function */
2253 packrow(n
, src
, dst
);
2256 /* slower fallback */
2257 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2258 const GLuint stride
= _mesa_get_format_bytes(format
);
2259 GLubyte
*d
= ((GLubyte
*) dst
);
2266 for (i
= 0; i
< n
; i
++) {
2275 * Pack a 2D image of ubyte RGBA pixels in the given format.
2276 * \param srcRowStride source image row stride in bytes
2277 * \param dstRowStride destination image row stride in bytes
2280 _mesa_pack_ubyte_rgba_rect(gl_format format
, GLuint width
, GLuint height
,
2281 const GLubyte
*src
, GLint srcRowStride
,
2282 void *dst
, GLint dstRowStride
)
2284 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2285 GLubyte
*dstUB
= (GLubyte
*) dst
;
2289 if (srcRowStride
== width
* 4 * sizeof(GLubyte
) &&
2290 dstRowStride
== _mesa_format_row_stride(format
, width
)) {
2291 /* do whole image at once */
2292 packrow(width
* height
, (const GLubyte (*)[4]) src
, dst
);
2296 for (i
= 0; i
< height
; i
++) {
2297 packrow(width
, (const GLubyte (*)[4]) src
, dstUB
);
2298 src
+= srcRowStride
;
2299 dstUB
+= dstRowStride
;
2304 /* slower fallback */
2305 for (i
= 0; i
< height
; i
++) {
2306 _mesa_pack_ubyte_rgba_row(format
, width
,
2307 (const GLubyte (*)[4]) src
, dstUB
);
2308 src
+= srcRowStride
;
2309 dstUB
+= dstRowStride
;
2317 ** Pack float Z pixels
2321 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2323 /* don't disturb the stencil values */
2324 GLuint
*d
= ((GLuint
*) dst
);
2325 const GLdouble scale
= (GLdouble
) 0xffffff;
2326 GLuint s
= *d
& 0xff;
2327 GLuint z
= (GLuint
) (*src
* scale
);
2328 assert(z
<= 0xffffff);
2333 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2335 /* don't disturb the stencil values */
2336 GLuint
*d
= ((GLuint
*) dst
);
2337 const GLdouble scale
= (GLdouble
) 0xffffff;
2338 GLuint s
= *d
& 0xff000000;
2339 GLuint z
= (GLuint
) (*src
* scale
);
2340 assert(z
<= 0xffffff);
2345 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2347 GLushort
*d
= ((GLushort
*) dst
);
2348 const GLfloat scale
= (GLfloat
) 0xffff;
2349 *d
= (GLushort
) (*src
* scale
);
2353 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2355 GLuint
*d
= ((GLuint
*) dst
);
2356 const GLdouble scale
= (GLdouble
) 0xffffffff;
2357 *d
= (GLuint
) (*src
* scale
);
2361 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2363 GLfloat
*d
= (GLfloat
*) dst
;
2367 gl_pack_float_z_func
2368 _mesa_get_pack_float_z_func(gl_format format
)
2371 case MESA_FORMAT_Z24_S8
:
2372 case MESA_FORMAT_Z24_X8
:
2373 return pack_float_z_Z24_S8
;
2374 case MESA_FORMAT_S8_Z24
:
2375 case MESA_FORMAT_X8_Z24
:
2376 return pack_float_z_S8_Z24
;
2377 case MESA_FORMAT_Z16
:
2378 return pack_float_z_Z16
;
2379 case MESA_FORMAT_Z32
:
2380 return pack_float_z_Z32
;
2381 case MESA_FORMAT_Z32_FLOAT
:
2382 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2383 return pack_float_z_Z32_FLOAT
;
2386 "unexpected format in _mesa_get_pack_float_z_func()");
2394 ** Pack uint Z pixels. The incoming src value is always in
2395 ** the range [0, 2^32-1].
2399 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2401 /* don't disturb the stencil values */
2402 GLuint
*d
= ((GLuint
*) dst
);
2403 GLuint s
= *d
& 0xff;
2404 GLuint z
= *src
& 0xffffff00;
2409 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2411 /* don't disturb the stencil values */
2412 GLuint
*d
= ((GLuint
*) dst
);
2413 GLuint s
= *d
& 0xff000000;
2414 GLuint z
= *src
>> 8;
2419 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2421 GLushort
*d
= ((GLushort
*) dst
);
2426 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2428 GLuint
*d
= ((GLuint
*) dst
);
2433 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2435 GLuint
*d
= ((GLuint
*) dst
);
2436 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2437 *d
= (GLuint
) (*src
* scale
);
2443 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2445 GLfloat
*d
= ((GLfloat
*) dst
);
2446 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2447 *d
= (GLfloat
) (*src
* scale
);
2453 _mesa_get_pack_uint_z_func(gl_format format
)
2456 case MESA_FORMAT_Z24_S8
:
2457 case MESA_FORMAT_Z24_X8
:
2458 return pack_uint_z_Z24_S8
;
2459 case MESA_FORMAT_S8_Z24
:
2460 case MESA_FORMAT_X8_Z24
:
2461 return pack_uint_z_S8_Z24
;
2462 case MESA_FORMAT_Z16
:
2463 return pack_uint_z_Z16
;
2464 case MESA_FORMAT_Z32
:
2465 return pack_uint_z_Z32
;
2466 case MESA_FORMAT_Z32_FLOAT
:
2467 return pack_uint_z_Z32_FLOAT
;
2468 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2469 return pack_uint_z_Z32_FLOAT_X24S8
;
2471 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2478 ** Pack ubyte stencil pixels
2482 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2484 /* don't disturb the Z values */
2485 GLuint
*d
= ((GLuint
*) dst
);
2487 GLuint z
= *d
& 0xffffff00;
2492 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2494 /* don't disturb the Z values */
2495 GLuint
*d
= ((GLuint
*) dst
);
2496 GLuint s
= *src
<< 24;
2497 GLuint z
= *d
& 0xffffff;
2502 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2504 GLubyte
*d
= (GLubyte
*) dst
;
2509 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2511 GLfloat
*d
= ((GLfloat
*) dst
);
2516 gl_pack_ubyte_stencil_func
2517 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2520 case MESA_FORMAT_Z24_S8
:
2521 return pack_ubyte_stencil_Z24_S8
;
2522 case MESA_FORMAT_S8_Z24
:
2523 return pack_ubyte_stencil_S8_Z24
;
2524 case MESA_FORMAT_S8
:
2525 return pack_ubyte_stencil_S8
;
2526 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2527 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2530 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2538 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2539 const GLfloat
*src
, void *dst
)
2542 case MESA_FORMAT_Z24_S8
:
2543 case MESA_FORMAT_Z24_X8
:
2545 /* don't disturb the stencil values */
2546 GLuint
*d
= ((GLuint
*) dst
);
2547 const GLdouble scale
= (GLdouble
) 0xffffff;
2549 for (i
= 0; i
< n
; i
++) {
2550 GLuint s
= d
[i
] & 0xff;
2551 GLuint z
= (GLuint
) (src
[i
] * scale
);
2552 assert(z
<= 0xffffff);
2553 d
[i
] = (z
<< 8) | s
;
2557 case MESA_FORMAT_S8_Z24
:
2558 case MESA_FORMAT_X8_Z24
:
2560 /* don't disturb the stencil values */
2561 GLuint
*d
= ((GLuint
*) dst
);
2562 const GLdouble scale
= (GLdouble
) 0xffffff;
2564 for (i
= 0; i
< n
; i
++) {
2565 GLuint s
= d
[i
] & 0xff000000;
2566 GLuint z
= (GLuint
) (src
[i
] * scale
);
2567 assert(z
<= 0xffffff);
2572 case MESA_FORMAT_Z16
:
2574 GLushort
*d
= ((GLushort
*) dst
);
2575 const GLfloat scale
= (GLfloat
) 0xffff;
2577 for (i
= 0; i
< n
; i
++) {
2578 d
[i
] = (GLushort
) (src
[i
] * scale
);
2582 case MESA_FORMAT_Z32
:
2584 GLuint
*d
= ((GLuint
*) dst
);
2585 const GLdouble scale
= (GLdouble
) 0xffffffff;
2587 for (i
= 0; i
< n
; i
++) {
2588 d
[i
] = (GLuint
) (src
[i
] * scale
);
2592 case MESA_FORMAT_Z32_FLOAT
:
2593 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2595 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2597 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2599 for (i
= 0; i
< n
; i
++) {
2605 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2611 * The incoming Z values are always in the range [0, 0xffffffff].
2614 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2615 const GLuint
*src
, void *dst
)
2618 case MESA_FORMAT_Z24_S8
:
2619 case MESA_FORMAT_Z24_X8
:
2621 /* don't disturb the stencil values */
2622 GLuint
*d
= ((GLuint
*) dst
);
2624 for (i
= 0; i
< n
; i
++) {
2625 GLuint s
= d
[i
] & 0xff;
2626 GLuint z
= src
[i
] & 0xffffff00;
2631 case MESA_FORMAT_S8_Z24
:
2632 case MESA_FORMAT_X8_Z24
:
2634 /* don't disturb the stencil values */
2635 GLuint
*d
= ((GLuint
*) dst
);
2637 for (i
= 0; i
< n
; i
++) {
2638 GLuint s
= d
[i
] & 0xff000000;
2639 GLuint z
= src
[i
] >> 8;
2644 case MESA_FORMAT_Z16
:
2646 GLushort
*d
= ((GLushort
*) dst
);
2648 for (i
= 0; i
< n
; i
++) {
2649 d
[i
] = src
[i
] >> 16;
2653 case MESA_FORMAT_Z32
:
2654 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2656 case MESA_FORMAT_Z32_FLOAT
:
2658 GLuint
*d
= ((GLuint
*) dst
);
2659 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2661 for (i
= 0; i
< n
; i
++) {
2662 d
[i
] = (GLuint
) (src
[i
] * scale
);
2663 assert(d
[i
] >= 0.0f
);
2664 assert(d
[i
] <= 1.0f
);
2668 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2670 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2671 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2673 for (i
= 0; i
< n
; i
++) {
2674 d
[i
].z
= (GLfloat
) (src
[i
] * scale
);
2675 assert(d
[i
].z
>= 0.0f
);
2676 assert(d
[i
].z
<= 1.0f
);
2681 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2687 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2688 const GLubyte
*src
, void *dst
)
2691 case MESA_FORMAT_Z24_S8
:
2693 /* don't disturb the Z values */
2694 GLuint
*d
= ((GLuint
*) dst
);
2696 for (i
= 0; i
< n
; i
++) {
2698 GLuint z
= d
[i
] & 0xffffff00;
2703 case MESA_FORMAT_S8_Z24
:
2705 /* don't disturb the Z values */
2706 GLuint
*d
= ((GLuint
*) dst
);
2708 for (i
= 0; i
< n
; i
++) {
2709 GLuint s
= src
[i
] << 24;
2710 GLuint z
= d
[i
] & 0xffffff;
2715 case MESA_FORMAT_S8
:
2716 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2718 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2720 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2722 for (i
= 0; i
< n
; i
++) {
2723 d
[i
].x24s8
= src
[i
];
2728 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2734 * Incoming Z/stencil values are always in uint_24_8 format.
2737 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2738 const GLuint
*src
, void *dst
)
2741 case MESA_FORMAT_Z24_S8
:
2742 memcpy(dst
, src
, n
* sizeof(GLuint
));
2744 case MESA_FORMAT_S8_Z24
:
2746 GLuint
*d
= ((GLuint
*) dst
);
2748 for (i
= 0; i
< n
; i
++) {
2749 GLuint s
= src
[i
] << 24;
2750 GLuint z
= src
[i
] >> 8;
2755 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2757 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2758 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2760 for (i
= 0; i
< n
; i
++) {
2761 GLfloat z
= (GLfloat
) ((src
[i
] >> 8) * scale
);
2763 d
[i
].x24s8
= src
[i
];
2768 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2769 _mesa_get_format_name(format
));
2777 * Convert a boolean color mask to a packed color where each channel of
2778 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2781 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2783 GLfloat maskColor
[4];
2785 switch (_mesa_get_format_datatype(format
)) {
2786 case GL_UNSIGNED_NORMALIZED
:
2787 /* simple: 1.0 will convert to ~0 in the right bit positions */
2788 maskColor
[0] = colorMask
[0] ? 1.0f
: 0.0f
;
2789 maskColor
[1] = colorMask
[1] ? 1.0f
: 0.0f
;
2790 maskColor
[2] = colorMask
[2] ? 1.0f
: 0.0f
;
2791 maskColor
[3] = colorMask
[3] ? 1.0f
: 0.0f
;
2792 _mesa_pack_float_rgba_row(format
, 1,
2793 (const GLfloat (*)[4]) maskColor
, dst
);
2795 case GL_SIGNED_NORMALIZED
:
2797 /* These formats are harder because it's hard to know the floating
2798 * point values that will convert to ~0 for each color channel's bits.
2799 * This solution just generates a non-zero value for each color channel
2800 * then fixes up the non-zero values to be ~0.
2801 * Note: we'll need to add special case code if we ever have to deal
2802 * with formats with unequal color channel sizes, like R11_G11_B10.
2803 * We issue a warning below for channel sizes other than 8,16,32.
2806 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2807 GLuint bytes
= _mesa_get_format_bytes(format
);
2810 /* this should put non-zero values into the channels of dst */
2811 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2812 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2813 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2814 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2815 _mesa_pack_float_rgba_row(format
, 1,
2816 (const GLfloat (*)[4]) maskColor
, dst
);
2818 /* fix-up the dst channels by converting non-zero values to ~0 */
2820 GLubyte
*d
= (GLubyte
*) dst
;
2821 for (i
= 0; i
< bytes
; i
++) {
2822 d
[i
] = d
[i
] ? 0xff : 0x0;
2825 else if (bits
== 16) {
2826 GLushort
*d
= (GLushort
*) dst
;
2827 for (i
= 0; i
< bytes
/ 2; i
++) {
2828 d
[i
] = d
[i
] ? 0xffff : 0x0;
2831 else if (bits
== 32) {
2832 GLuint
*d
= (GLuint
*) dst
;
2833 for (i
= 0; i
< bytes
/ 4; i
++) {
2834 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2838 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2844 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");