2 * Mesa 3-D graphics library
4 * Copyright (c) 2011 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Color, depth, stencil packing functions.
27 * Used to pack basic color, depth and stencil formats to specific
30 * There are both per-pixel and per-row packing functions:
31 * - The former will be used by swrast to write values to the color, depth,
32 * stencil buffers when drawing points, lines and masked spans.
33 * - The later will be used for image-oriented functions like glDrawPixels,
34 * glAccum, and glTexImage.
39 #include "format_pack.h"
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
);
1674 * Return a function that can pack a GLubyte rgba[4] color.
1676 gl_pack_ubyte_rgba_func
1677 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1679 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1680 static GLboolean initialized
= GL_FALSE
;
1683 memset(table
, 0, sizeof(table
));
1685 table
[MESA_FORMAT_NONE
] = NULL
;
1687 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1688 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1689 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1690 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1691 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1692 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1693 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1694 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1695 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1696 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1697 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1698 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1699 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1700 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1701 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1702 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1703 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1704 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1705 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1706 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1707 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1708 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1709 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1710 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1711 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1712 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1713 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1714 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1715 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1716 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1717 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1718 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1719 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1720 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1721 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1722 table
[MESA_FORMAT_GR1616
] = pack_ubyte_GR1616
;
1723 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1724 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1725 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_ubyte_ABGR2101010_UINT
;
1727 /* should never convert RGBA to these formats */
1728 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1729 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1730 table
[MESA_FORMAT_Z16
] = NULL
;
1731 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1732 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1733 table
[MESA_FORMAT_Z32
] = NULL
;
1734 table
[MESA_FORMAT_S8
] = NULL
;
1737 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1738 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1739 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1740 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1741 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1744 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1745 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1746 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1747 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1749 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1750 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1751 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1752 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1753 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1754 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1756 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1757 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1758 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1759 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1760 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1761 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1762 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1763 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1764 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1765 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1766 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1767 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1768 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1769 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1770 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1771 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1774 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1775 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1776 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1777 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1778 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1779 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1781 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1783 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1786 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1787 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1788 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1789 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1790 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1791 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1792 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1793 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1794 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1795 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1796 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1797 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1798 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1799 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1800 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1801 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1802 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1805 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1807 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
1808 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
1810 initialized
= GL_TRUE
;
1813 return table
[format
];
1819 * Return a function that can pack a GLfloat rgba[4] color.
1821 gl_pack_float_rgba_func
1822 _mesa_get_pack_float_rgba_function(gl_format format
)
1824 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1825 static GLboolean initialized
= GL_FALSE
;
1828 memset(table
, 0, sizeof(table
));
1830 table
[MESA_FORMAT_NONE
] = NULL
;
1832 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
1833 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
1834 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
1835 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
1836 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
1837 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
1838 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
1839 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
1840 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
1841 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
1842 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
1843 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
1844 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
1845 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
1846 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
1847 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
1848 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
1850 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
1851 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
1852 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
1853 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
1854 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
1855 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
1856 table
[MESA_FORMAT_A8
] = pack_float_A8
;
1857 table
[MESA_FORMAT_A16
] = pack_float_A16
;
1858 table
[MESA_FORMAT_L8
] = pack_float_L8
;
1859 table
[MESA_FORMAT_L16
] = pack_float_L16
;
1860 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
1861 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
1862 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
1863 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
1864 table
[MESA_FORMAT_R8
] = pack_float_R8
;
1865 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
1866 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
1867 table
[MESA_FORMAT_R16
] = pack_float_R16
;
1868 table
[MESA_FORMAT_GR1616
] = pack_float_GR1616
;
1869 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
1870 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
1871 table
[MESA_FORMAT_ABGR2101010_UINT
] = pack_float_ABGR2101010_UINT
;
1873 /* should never convert RGBA to these formats */
1874 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1875 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1876 table
[MESA_FORMAT_Z16
] = NULL
;
1877 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1878 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1879 table
[MESA_FORMAT_Z32
] = NULL
;
1880 table
[MESA_FORMAT_S8
] = NULL
;
1882 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
1883 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
1884 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
1885 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
1886 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
1889 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
1890 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
1891 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
1892 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
1894 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
1895 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
1896 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
1897 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
1898 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
1899 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
1901 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
1902 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
1903 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
1904 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
1905 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
1906 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
1907 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1908 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1909 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
1910 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
1912 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1913 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1914 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1915 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1916 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
1917 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
1920 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
1921 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
1922 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
1923 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
1924 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
1925 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
1927 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
1929 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
1931 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
1932 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
1933 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
1934 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
1935 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
1936 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
1937 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
1938 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
1939 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
1940 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
1941 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
1942 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
1943 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
1944 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
1945 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
1946 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
1947 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
1949 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
1950 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
1952 initialized
= GL_TRUE
;
1955 return table
[format
];
1960 static pack_float_rgba_row_func
1961 get_pack_float_rgba_row_function(gl_format format
)
1963 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
1964 static GLboolean initialized
= GL_FALSE
;
1967 /* We don't need a special row packing function for each format.
1968 * There's a generic fallback which uses a per-pixel packing function.
1970 memset(table
, 0, sizeof(table
));
1972 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
1973 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
1974 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
1975 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
1976 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
1977 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
1978 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
1979 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
1980 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
1981 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
1982 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
1983 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
1985 initialized
= GL_TRUE
;
1988 return table
[format
];
1993 static pack_ubyte_rgba_row_func
1994 get_pack_ubyte_rgba_row_function(gl_format format
)
1996 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
1997 static GLboolean initialized
= GL_FALSE
;
2000 /* We don't need a special row packing function for each format.
2001 * There's a generic fallback which uses a per-pixel packing function.
2003 memset(table
, 0, sizeof(table
));
2005 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
2006 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
2007 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
2008 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
2009 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
2010 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
2011 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
2012 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
2013 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
2014 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
2015 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
2016 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
2018 initialized
= GL_TRUE
;
2021 return table
[format
];
2027 * Pack a row of GLfloat rgba[4] values to the destination.
2030 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
2031 const GLfloat src
[][4], void *dst
)
2033 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2035 /* use "fast" function */
2036 packrow(n
, src
, dst
);
2039 /* slower fallback */
2040 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2041 GLuint dstStride
= _mesa_get_format_bytes(format
);
2042 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2049 for (i
= 0; i
< n
; i
++) {
2050 pack(src
[i
], dstPtr
);
2051 dstPtr
+= dstStride
;
2058 * Pack a row of GLubyte rgba[4] values to the destination.
2061 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2062 const GLubyte src
[][4], void *dst
)
2064 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2066 /* use "fast" function */
2067 packrow(n
, src
, dst
);
2070 /* slower fallback */
2071 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2072 const GLuint stride
= _mesa_get_format_bytes(format
);
2073 GLubyte
*d
= ((GLubyte
*) dst
);
2080 for (i
= 0; i
< n
; i
++) {
2089 * Pack a 2D image of ubyte RGBA pixels in the given format.
2090 * \param srcRowStride source image row stride in bytes
2091 * \param dstRowStride destination image row stride in bytes
2094 _mesa_pack_ubyte_rgba_rect(gl_format format
, GLuint width
, GLuint height
,
2095 const GLubyte
*src
, GLint srcRowStride
,
2096 void *dst
, GLint dstRowStride
)
2098 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2099 GLubyte
*dstUB
= (GLubyte
*) dst
;
2103 if (srcRowStride
== width
* 4 * sizeof(GLubyte
) &&
2104 dstRowStride
== _mesa_format_row_stride(format
, width
)) {
2105 /* do whole image at once */
2106 packrow(width
* height
, (const GLubyte (*)[4]) src
, dst
);
2110 for (i
= 0; i
< height
; i
++) {
2111 packrow(width
, (const GLubyte (*)[4]) src
, dstUB
);
2112 src
+= srcRowStride
;
2113 dstUB
+= dstRowStride
;
2118 /* slower fallback */
2119 for (i
= 0; i
< height
; i
++) {
2120 _mesa_pack_ubyte_rgba_row(format
, width
,
2121 (const GLubyte (*)[4]) src
, dstUB
);
2122 src
+= srcRowStride
;
2123 dstUB
+= dstRowStride
;
2131 ** Pack float Z pixels
2135 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2137 /* don't disturb the stencil values */
2138 GLuint
*d
= ((GLuint
*) dst
);
2139 const GLdouble scale
= (GLdouble
) 0xffffff;
2140 GLuint s
= *d
& 0xff;
2141 GLuint z
= (GLuint
) (*src
* scale
);
2142 assert(z
<= 0xffffff);
2147 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2149 /* don't disturb the stencil values */
2150 GLuint
*d
= ((GLuint
*) dst
);
2151 const GLdouble scale
= (GLdouble
) 0xffffff;
2152 GLuint s
= *d
& 0xff000000;
2153 GLuint z
= (GLuint
) (*src
* scale
);
2154 assert(z
<= 0xffffff);
2159 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2161 GLushort
*d
= ((GLushort
*) dst
);
2162 const GLfloat scale
= (GLfloat
) 0xffff;
2163 *d
= (GLushort
) (*src
* scale
);
2167 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2169 GLuint
*d
= ((GLuint
*) dst
);
2170 const GLdouble scale
= (GLdouble
) 0xffffffff;
2171 *d
= (GLuint
) (*src
* scale
);
2175 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2177 GLfloat
*d
= (GLfloat
*) dst
;
2181 gl_pack_float_z_func
2182 _mesa_get_pack_float_z_func(gl_format format
)
2185 case MESA_FORMAT_Z24_S8
:
2186 case MESA_FORMAT_Z24_X8
:
2187 return pack_float_z_Z24_S8
;
2188 case MESA_FORMAT_S8_Z24
:
2189 case MESA_FORMAT_X8_Z24
:
2190 return pack_float_z_S8_Z24
;
2191 case MESA_FORMAT_Z16
:
2192 return pack_float_z_Z16
;
2193 case MESA_FORMAT_Z32
:
2194 return pack_float_z_Z32
;
2195 case MESA_FORMAT_Z32_FLOAT
:
2196 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2197 return pack_float_z_Z32_FLOAT
;
2200 "unexpected format in _mesa_get_pack_float_z_func()");
2208 ** Pack uint Z pixels. The incoming src value is always in
2209 ** the range [0, 2^32-1].
2213 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2215 /* don't disturb the stencil values */
2216 GLuint
*d
= ((GLuint
*) dst
);
2217 GLuint s
= *d
& 0xff;
2218 GLuint z
= *src
& 0xffffff00;
2223 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2225 /* don't disturb the stencil values */
2226 GLuint
*d
= ((GLuint
*) dst
);
2227 GLuint s
= *d
& 0xff000000;
2228 GLuint z
= *src
>> 8;
2233 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2235 GLushort
*d
= ((GLushort
*) dst
);
2240 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2242 GLuint
*d
= ((GLuint
*) dst
);
2247 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2249 GLuint
*d
= ((GLuint
*) dst
);
2250 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2251 *d
= (GLuint
) (*src
* scale
);
2257 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2259 GLfloat
*d
= ((GLfloat
*) dst
);
2260 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2261 *d
= (GLfloat
) (*src
* scale
);
2267 _mesa_get_pack_uint_z_func(gl_format format
)
2270 case MESA_FORMAT_Z24_S8
:
2271 case MESA_FORMAT_Z24_X8
:
2272 return pack_uint_z_Z24_S8
;
2273 case MESA_FORMAT_S8_Z24
:
2274 case MESA_FORMAT_X8_Z24
:
2275 return pack_uint_z_S8_Z24
;
2276 case MESA_FORMAT_Z16
:
2277 return pack_uint_z_Z16
;
2278 case MESA_FORMAT_Z32
:
2279 return pack_uint_z_Z32
;
2280 case MESA_FORMAT_Z32_FLOAT
:
2281 return pack_uint_z_Z32_FLOAT
;
2282 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2283 return pack_uint_z_Z32_FLOAT_X24S8
;
2285 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2292 ** Pack ubyte stencil pixels
2296 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2298 /* don't disturb the Z values */
2299 GLuint
*d
= ((GLuint
*) dst
);
2301 GLuint z
= *d
& 0xffffff00;
2306 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2308 /* don't disturb the Z values */
2309 GLuint
*d
= ((GLuint
*) dst
);
2310 GLuint s
= *src
<< 24;
2311 GLuint z
= *d
& 0xffffff;
2316 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2318 GLubyte
*d
= (GLubyte
*) dst
;
2323 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2325 GLfloat
*d
= ((GLfloat
*) dst
);
2330 gl_pack_ubyte_stencil_func
2331 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2334 case MESA_FORMAT_Z24_S8
:
2335 return pack_ubyte_stencil_Z24_S8
;
2336 case MESA_FORMAT_S8_Z24
:
2337 return pack_ubyte_stencil_S8_Z24
;
2338 case MESA_FORMAT_S8
:
2339 return pack_ubyte_stencil_S8
;
2340 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2341 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2344 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2352 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2353 const GLfloat
*src
, void *dst
)
2356 case MESA_FORMAT_Z24_S8
:
2357 case MESA_FORMAT_Z24_X8
:
2359 /* don't disturb the stencil values */
2360 GLuint
*d
= ((GLuint
*) dst
);
2361 const GLdouble scale
= (GLdouble
) 0xffffff;
2363 for (i
= 0; i
< n
; i
++) {
2364 GLuint s
= d
[i
] & 0xff;
2365 GLuint z
= (GLuint
) (src
[i
] * scale
);
2366 assert(z
<= 0xffffff);
2367 d
[i
] = (z
<< 8) | s
;
2371 case MESA_FORMAT_S8_Z24
:
2372 case MESA_FORMAT_X8_Z24
:
2374 /* don't disturb the stencil values */
2375 GLuint
*d
= ((GLuint
*) dst
);
2376 const GLdouble scale
= (GLdouble
) 0xffffff;
2378 for (i
= 0; i
< n
; i
++) {
2379 GLuint s
= d
[i
] & 0xff000000;
2380 GLuint z
= (GLuint
) (src
[i
] * scale
);
2381 assert(z
<= 0xffffff);
2386 case MESA_FORMAT_Z16
:
2388 GLushort
*d
= ((GLushort
*) dst
);
2389 const GLfloat scale
= (GLfloat
) 0xffff;
2391 for (i
= 0; i
< n
; i
++) {
2392 d
[i
] = (GLushort
) (src
[i
] * scale
);
2396 case MESA_FORMAT_Z32
:
2398 GLuint
*d
= ((GLuint
*) dst
);
2399 const GLdouble scale
= (GLdouble
) 0xffffffff;
2401 for (i
= 0; i
< n
; i
++) {
2402 d
[i
] = (GLuint
) (src
[i
] * scale
);
2406 case MESA_FORMAT_Z32_FLOAT
:
2407 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2409 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2411 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2413 for (i
= 0; i
< n
; i
++) {
2419 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2425 * The incoming Z values are always in the range [0, 0xffffffff].
2428 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2429 const GLuint
*src
, void *dst
)
2432 case MESA_FORMAT_Z24_S8
:
2433 case MESA_FORMAT_Z24_X8
:
2435 /* don't disturb the stencil values */
2436 GLuint
*d
= ((GLuint
*) dst
);
2438 for (i
= 0; i
< n
; i
++) {
2439 GLuint s
= d
[i
] & 0xff;
2440 GLuint z
= src
[i
] & 0xffffff00;
2445 case MESA_FORMAT_S8_Z24
:
2446 case MESA_FORMAT_X8_Z24
:
2448 /* don't disturb the stencil values */
2449 GLuint
*d
= ((GLuint
*) dst
);
2451 for (i
= 0; i
< n
; i
++) {
2452 GLuint s
= d
[i
] & 0xff000000;
2453 GLuint z
= src
[i
] >> 8;
2458 case MESA_FORMAT_Z16
:
2460 GLushort
*d
= ((GLushort
*) dst
);
2462 for (i
= 0; i
< n
; i
++) {
2463 d
[i
] = src
[i
] >> 16;
2467 case MESA_FORMAT_Z32
:
2468 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2470 case MESA_FORMAT_Z32_FLOAT
:
2472 GLuint
*d
= ((GLuint
*) dst
);
2473 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2475 for (i
= 0; i
< n
; i
++) {
2476 d
[i
] = (GLuint
) (src
[i
] * scale
);
2477 assert(d
[i
] >= 0.0f
);
2478 assert(d
[i
] <= 1.0f
);
2482 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2484 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2485 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2487 for (i
= 0; i
< n
; i
++) {
2488 d
[i
].z
= (GLfloat
) (src
[i
] * scale
);
2489 assert(d
[i
].z
>= 0.0f
);
2490 assert(d
[i
].z
<= 1.0f
);
2495 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2501 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2502 const GLubyte
*src
, void *dst
)
2505 case MESA_FORMAT_Z24_S8
:
2507 /* don't disturb the Z values */
2508 GLuint
*d
= ((GLuint
*) dst
);
2510 for (i
= 0; i
< n
; i
++) {
2512 GLuint z
= d
[i
] & 0xffffff00;
2517 case MESA_FORMAT_S8_Z24
:
2519 /* don't disturb the Z values */
2520 GLuint
*d
= ((GLuint
*) dst
);
2522 for (i
= 0; i
< n
; i
++) {
2523 GLuint s
= src
[i
] << 24;
2524 GLuint z
= d
[i
] & 0xffffff;
2529 case MESA_FORMAT_S8
:
2530 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2532 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2534 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2536 for (i
= 0; i
< n
; i
++) {
2537 d
[i
].x24s8
= src
[i
];
2542 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2548 * Incoming Z/stencil values are always in uint_24_8 format.
2551 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2552 const GLuint
*src
, void *dst
)
2555 case MESA_FORMAT_Z24_S8
:
2556 memcpy(dst
, src
, n
* sizeof(GLuint
));
2558 case MESA_FORMAT_S8_Z24
:
2560 GLuint
*d
= ((GLuint
*) dst
);
2562 for (i
= 0; i
< n
; i
++) {
2563 GLuint s
= src
[i
] << 24;
2564 GLuint z
= src
[i
] >> 8;
2569 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2571 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2572 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2574 for (i
= 0; i
< n
; i
++) {
2575 GLfloat z
= (GLfloat
) ((src
[i
] >> 8) * scale
);
2577 d
[i
].x24s8
= src
[i
];
2582 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2583 _mesa_get_format_name(format
));
2591 * Convert a boolean color mask to a packed color where each channel of
2592 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2595 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2597 GLfloat maskColor
[4];
2599 switch (_mesa_get_format_datatype(format
)) {
2600 case GL_UNSIGNED_NORMALIZED
:
2601 /* simple: 1.0 will convert to ~0 in the right bit positions */
2602 maskColor
[0] = colorMask
[0] ? 1.0f
: 0.0f
;
2603 maskColor
[1] = colorMask
[1] ? 1.0f
: 0.0f
;
2604 maskColor
[2] = colorMask
[2] ? 1.0f
: 0.0f
;
2605 maskColor
[3] = colorMask
[3] ? 1.0f
: 0.0f
;
2606 _mesa_pack_float_rgba_row(format
, 1,
2607 (const GLfloat (*)[4]) maskColor
, dst
);
2609 case GL_SIGNED_NORMALIZED
:
2611 /* These formats are harder because it's hard to know the floating
2612 * point values that will convert to ~0 for each color channel's bits.
2613 * This solution just generates a non-zero value for each color channel
2614 * then fixes up the non-zero values to be ~0.
2615 * Note: we'll need to add special case code if we ever have to deal
2616 * with formats with unequal color channel sizes, like R11_G11_B10.
2617 * We issue a warning below for channel sizes other than 8,16,32.
2620 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2621 GLuint bytes
= _mesa_get_format_bytes(format
);
2624 /* this should put non-zero values into the channels of dst */
2625 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2626 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2627 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2628 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2629 _mesa_pack_float_rgba_row(format
, 1,
2630 (const GLfloat (*)[4]) maskColor
, dst
);
2632 /* fix-up the dst channels by converting non-zero values to ~0 */
2634 GLubyte
*d
= (GLubyte
*) dst
;
2635 for (i
= 0; i
< bytes
; i
++) {
2636 d
[i
] = d
[i
] ? 0xff : 0x0;
2639 else if (bits
== 16) {
2640 GLushort
*d
= (GLushort
*) dst
;
2641 for (i
= 0; i
< bytes
/ 2; i
++) {
2642 d
[i
] = d
[i
] ? 0xffff : 0x0;
2645 else if (bits
== 32) {
2646 GLuint
*d
= (GLuint
*) dst
;
2647 for (i
= 0; i
< bytes
/ 4; i
++) {
2648 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2652 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2658 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");