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_RG1616 */
940 pack_ubyte_RG1616(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_RG1616(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_REV */
962 pack_ubyte_RG1616_REV(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_REV(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_SRGB8 */
1011 pack_ubyte_SRGB8(const GLubyte src
[4], void *dst
)
1013 GLubyte
*d
= ((GLubyte
*) dst
);
1014 d
[2] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1015 d
[1] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1016 d
[0] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1020 pack_float_SRGB8(const GLfloat src
[4], void *dst
)
1022 GLubyte
*d
= ((GLubyte
*) dst
);
1023 d
[2] = linear_float_to_srgb_ubyte(src
[RCOMP
]);
1024 d
[1] = linear_float_to_srgb_ubyte(src
[GCOMP
]);
1025 d
[0] = linear_float_to_srgb_ubyte(src
[BCOMP
]);
1029 /* MESA_FORMAT_SRGBA8 */
1032 pack_ubyte_SRGBA8(const GLubyte src
[4], void *dst
)
1034 GLuint
*d
= ((GLuint
*) dst
);
1035 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1036 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[GCOMP
]);
1037 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[BCOMP
]);
1038 *d
= PACK_COLOR_8888(r
, g
, b
, src
[ACOMP
]);
1042 pack_float_SRGBA8(const GLfloat src
[4], void *dst
)
1044 GLuint
*d
= ((GLuint
*) dst
);
1046 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1047 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1048 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1049 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1050 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1054 /* MESA_FORMAT_SARGB8 */
1057 pack_ubyte_SARGB8(const GLubyte src
[4], void *dst
)
1059 GLuint
*d
= ((GLuint
*) dst
);
1060 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1061 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1062 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1063 *d
= PACK_COLOR_8888(src
[ACOMP
], r
, g
, b
);
1067 pack_float_SARGB8(const GLfloat src
[4], void *dst
)
1069 GLuint
*d
= ((GLuint
*) dst
);
1071 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1072 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1073 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1074 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1075 *d
= PACK_COLOR_8888(a
, r
, g
, b
);
1079 /* MESA_FORMAT_SL8 */
1082 pack_ubyte_SL8(const GLubyte src
[4], void *dst
)
1084 GLubyte
*d
= ((GLubyte
*) dst
);
1085 *d
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1089 pack_float_SL8(const GLfloat src
[4], void *dst
)
1091 GLubyte
*d
= ((GLubyte
*) dst
);
1092 GLubyte l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1097 /* MESA_FORMAT_SLA8 */
1100 pack_ubyte_SLA8(const GLubyte src
[4], void *dst
)
1102 GLushort
*d
= ((GLushort
*) dst
);
1103 GLubyte l
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1104 *d
= PACK_COLOR_88(src
[ACOMP
], l
);
1108 pack_float_SLA8(const GLfloat src
[4], void *dst
)
1110 GLushort
*d
= ((GLushort
*) dst
);
1111 GLubyte a
, l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1112 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1113 *d
= PACK_COLOR_88(a
, l
);
1117 /* MESA_FORMAT_RGBA_FLOAT32 */
1120 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
1122 GLfloat
*d
= ((GLfloat
*) dst
);
1123 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1124 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1125 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1126 d
[3] = UBYTE_TO_FLOAT(src
[3]);
1130 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
1132 GLfloat
*d
= ((GLfloat
*) dst
);
1140 /* MESA_FORMAT_RGBA_FLOAT16 */
1143 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
1145 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1146 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1147 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1148 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1149 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
1153 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
1155 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1156 d
[0] = _mesa_float_to_half(src
[0]);
1157 d
[1] = _mesa_float_to_half(src
[1]);
1158 d
[2] = _mesa_float_to_half(src
[2]);
1159 d
[3] = _mesa_float_to_half(src
[3]);
1163 /* MESA_FORMAT_RGB_FLOAT32 */
1166 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
1168 GLfloat
*d
= ((GLfloat
*) dst
);
1169 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1170 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1171 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1175 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
1177 GLfloat
*d
= ((GLfloat
*) dst
);
1184 /* MESA_FORMAT_RGB_FLOAT16 */
1187 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
1189 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1190 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1191 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1192 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1196 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
1198 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1199 d
[0] = _mesa_float_to_half(src
[0]);
1200 d
[1] = _mesa_float_to_half(src
[1]);
1201 d
[2] = _mesa_float_to_half(src
[2]);
1205 /* MESA_FORMAT_ALPHA_FLOAT32 */
1208 pack_ubyte_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1210 GLfloat
*d
= ((GLfloat
*) dst
);
1211 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1215 pack_float_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1217 GLfloat
*d
= ((GLfloat
*) dst
);
1222 /* MESA_FORMAT_ALPHA_FLOAT16 */
1225 pack_ubyte_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1227 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1228 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1232 pack_float_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1234 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1235 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
1239 /* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
1242 pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src
[4], void *dst
)
1244 GLfloat
*d
= ((GLfloat
*) dst
);
1245 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1249 pack_float_LUMINANCE_FLOAT32(const GLfloat src
[4], void *dst
)
1251 GLfloat
*d
= ((GLfloat
*) dst
);
1256 /* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
1259 pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src
[4], void *dst
)
1261 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1262 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1266 pack_float_LUMINANCE_FLOAT16(const GLfloat src
[4], void *dst
)
1268 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1269 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1273 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
1276 pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1278 GLfloat
*d
= ((GLfloat
*) dst
);
1279 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1280 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1284 pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1286 GLfloat
*d
= ((GLfloat
*) dst
);
1292 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
1295 pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1297 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1298 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1299 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1303 pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1305 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1306 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1307 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1311 /* MESA_FORMAT_RG_FLOAT32 */
1314 pack_ubyte_RG_FLOAT32(const GLubyte src
[4], void *dst
)
1316 GLfloat
*d
= ((GLfloat
*) dst
);
1317 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1318 d
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1322 pack_float_RG_FLOAT32(const GLfloat src
[4], void *dst
)
1324 GLfloat
*d
= ((GLfloat
*) dst
);
1330 /* MESA_FORMAT_RG_FLOAT16 */
1333 pack_ubyte_RG_FLOAT16(const GLubyte src
[4], void *dst
)
1335 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1336 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1337 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[GCOMP
]));
1341 pack_float_RG_FLOAT16(const GLfloat src
[4], void *dst
)
1343 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1344 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1345 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1349 /* MESA_FORMAT_DUDV8 */
1352 pack_ubyte_DUDV8(const GLubyte src
[4], void *dst
)
1354 /* XXX is this ever used? */
1355 GLushort
*d
= ((GLushort
*) dst
);
1356 *d
= PACK_COLOR_88(src
[0], src
[1]);
1360 pack_float_DUDV8(const GLfloat src
[4], void *dst
)
1362 GLushort
*d
= ((GLushort
*) dst
);
1364 du
= FLOAT_TO_BYTE(CLAMP(src
[0], 0.0F
, 1.0F
));
1365 dv
= FLOAT_TO_BYTE(CLAMP(src
[1], 0.0F
, 1.0F
));
1366 *d
= PACK_COLOR_88(du
, dv
);
1370 /* MESA_FORMAT_RGBA_16 */
1373 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1375 GLushort
*d
= ((GLushort
*) dst
);
1376 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1377 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1378 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1379 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1383 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1385 GLushort
*d
= ((GLushort
*) dst
);
1386 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1387 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1388 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1389 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1395 * MESA_FORMAT_SIGNED_R8
1399 pack_float_SIGNED_R8(const GLfloat src
[4], void *dst
)
1401 GLbyte
*d
= (GLbyte
*) dst
;
1402 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1407 * MESA_FORMAT_SIGNED_RG88_REV
1411 pack_float_SIGNED_RG88_REV(const GLfloat src
[4], void *dst
)
1413 GLushort
*d
= (GLushort
*) dst
;
1414 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1415 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1421 * MESA_FORMAT_SIGNED_RGBX8888
1425 pack_float_SIGNED_RGBX8888(const GLfloat src
[4], void *dst
)
1427 GLuint
*d
= (GLuint
*) dst
;
1428 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1429 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1430 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1432 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1437 * MESA_FORMAT_SIGNED_RGBA8888
1441 pack_float_SIGNED_RGBA8888(const GLfloat src
[4], void *dst
)
1443 GLuint
*d
= (GLuint
*) dst
;
1444 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1445 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1446 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1447 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1448 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1453 * MESA_FORMAT_SIGNED_RGBA8888_REV
1457 pack_float_SIGNED_RGBA8888_REV(const GLfloat src
[4], void *dst
)
1459 GLuint
*d
= (GLuint
*) dst
;
1460 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1461 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1462 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1463 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1464 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1469 * MESA_FORMAT_SIGNED_R16
1473 pack_float_SIGNED_R16(const GLfloat src
[4], void *dst
)
1475 GLshort
*d
= (GLshort
*) dst
;
1476 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1481 * MESA_FORMAT_SIGNED_GR1616
1485 pack_float_SIGNED_GR1616(const GLfloat src
[4], void *dst
)
1487 GLuint
*d
= (GLuint
*) dst
;
1488 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1489 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1490 *d
= (g
<< 16) | (r
& 0xffff);
1495 * MESA_FORMAT_SIGNED_RGB_16
1499 pack_float_SIGNED_RGB_16(const GLfloat src
[4], void *dst
)
1501 GLshort
*d
= (GLshort
*) dst
;
1502 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1503 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1504 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1509 * MESA_FORMAT_SIGNED_RGBA_16
1513 pack_float_SIGNED_RGBA_16(const GLfloat src
[4], void *dst
)
1515 GLshort
*d
= (GLshort
*) dst
;
1516 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1517 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1518 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1519 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1524 * MESA_FORMAT_SIGNED_A8
1528 pack_float_SIGNED_A8(const GLfloat src
[4], void *dst
)
1530 GLbyte
*d
= (GLbyte
*) dst
;
1531 *d
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1536 * MESA_FORMAT_SIGNED_L8
1540 pack_float_SIGNED_L8(const GLfloat src
[4], void *dst
)
1542 GLbyte
*d
= (GLbyte
*) dst
;
1543 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1548 * MESA_FORMAT_SIGNED_AL88
1552 pack_float_SIGNED_AL88(const GLfloat src
[4], void *dst
)
1554 GLushort
*d
= (GLushort
*) dst
;
1555 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1556 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1562 * MESA_FORMAT_SIGNED_A16
1566 pack_float_SIGNED_A16(const GLfloat src
[4], void *dst
)
1568 GLshort
*d
= (GLshort
*) dst
;
1569 *d
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1574 * MESA_FORMAT_SIGNED_L16
1578 pack_float_SIGNED_L16(const GLfloat src
[4], void *dst
)
1580 GLshort
*d
= (GLshort
*) dst
;
1581 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1586 * MESA_FORMAT_SIGNED_AL1616
1590 pack_float_SIGNED_AL1616(const GLfloat src
[4], void *dst
)
1592 GLuint
*d
= (GLuint
*) dst
;
1593 GLshort l
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1594 GLshort a
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1595 *d
= PACK_COLOR_1616(a
, l
);
1600 * MESA_FORMAT_RGB9_E5_FLOAT;
1604 pack_float_RGB9_E5_FLOAT(const GLfloat src
[4], void *dst
)
1606 GLuint
*d
= (GLuint
*) dst
;
1607 *d
= float3_to_rgb9e5(src
);
1611 pack_ubyte_RGB9_E5_FLOAT(const GLubyte src
[4], void *dst
)
1613 GLuint
*d
= (GLuint
*) dst
;
1615 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1616 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1617 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1618 *d
= float3_to_rgb9e5(rgb
);
1624 * MESA_FORMAT_R11_G11_B10_FLOAT;
1628 pack_ubyte_R11_G11_B10_FLOAT(const GLubyte src
[4], void *dst
)
1630 GLuint
*d
= (GLuint
*) dst
;
1632 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1633 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1634 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1635 *d
= float3_to_r11g11b10f(rgb
);
1639 pack_float_R11_G11_B10_FLOAT(const GLfloat src
[4], void *dst
)
1641 GLuint
*d
= (GLuint
*) dst
;
1642 *d
= float3_to_r11g11b10f(src
);
1648 * Return a function that can pack a GLubyte rgba[4] color.
1650 gl_pack_ubyte_rgba_func
1651 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1653 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1654 static GLboolean initialized
= GL_FALSE
;
1657 memset(table
, 0, sizeof(table
));
1659 table
[MESA_FORMAT_NONE
] = NULL
;
1661 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1662 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1663 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1664 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1665 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1666 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1667 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1668 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1669 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1670 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1671 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1672 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1673 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1674 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1675 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1676 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1677 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1678 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1679 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1680 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1681 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1682 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1683 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1684 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1685 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1686 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1687 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1688 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1689 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1690 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1691 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1692 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1693 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1694 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1695 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1696 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1697 table
[MESA_FORMAT_RG1616_REV
] = pack_ubyte_RG1616_REV
;
1698 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1700 /* should never convert RGBA to these formats */
1701 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1702 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1703 table
[MESA_FORMAT_Z16
] = NULL
;
1704 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1705 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1706 table
[MESA_FORMAT_Z32
] = NULL
;
1707 table
[MESA_FORMAT_S8
] = NULL
;
1710 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1711 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1712 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1713 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1714 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1717 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1718 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1719 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1720 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1722 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1723 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1724 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1725 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1726 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1727 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1729 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1730 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1731 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1732 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1733 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1734 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1735 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1736 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1737 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1738 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1739 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1740 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1741 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1742 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1743 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1744 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1747 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1748 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1749 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1750 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1751 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1752 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1754 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1756 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1759 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1760 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1761 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1762 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1763 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1764 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1765 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1766 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1767 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1768 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1769 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1770 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1771 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1772 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1773 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1774 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1775 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1778 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1780 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
1781 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
1783 initialized
= GL_TRUE
;
1786 return table
[format
];
1792 * Return a function that can pack a GLfloat rgba[4] color.
1794 gl_pack_float_rgba_func
1795 _mesa_get_pack_float_rgba_function(gl_format format
)
1797 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1798 static GLboolean initialized
= GL_FALSE
;
1801 memset(table
, 0, sizeof(table
));
1803 table
[MESA_FORMAT_NONE
] = NULL
;
1805 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
1806 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
1807 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
1808 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
1809 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
1810 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
1811 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
1812 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
1813 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
1814 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
1815 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
1816 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
1817 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
1818 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
1819 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
1820 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
1821 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
1823 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
1824 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
1825 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
1826 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
1827 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
1828 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
1829 table
[MESA_FORMAT_A8
] = pack_float_A8
;
1830 table
[MESA_FORMAT_A16
] = pack_float_A16
;
1831 table
[MESA_FORMAT_L8
] = pack_float_L8
;
1832 table
[MESA_FORMAT_L16
] = pack_float_L16
;
1833 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
1834 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
1835 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
1836 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
1837 table
[MESA_FORMAT_R8
] = pack_float_R8
;
1838 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
1839 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
1840 table
[MESA_FORMAT_R16
] = pack_float_R16
;
1841 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
1842 table
[MESA_FORMAT_RG1616_REV
] = pack_float_RG1616_REV
;
1843 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
1845 /* should never convert RGBA to these formats */
1846 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1847 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1848 table
[MESA_FORMAT_Z16
] = NULL
;
1849 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1850 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1851 table
[MESA_FORMAT_Z32
] = NULL
;
1852 table
[MESA_FORMAT_S8
] = NULL
;
1854 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
1855 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
1856 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
1857 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
1858 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
1861 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
1862 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
1863 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
1864 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
1866 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
1867 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
1868 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
1869 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
1870 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
1871 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
1873 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
1874 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
1875 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
1876 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
1877 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
1878 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
1879 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1880 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1881 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
1882 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
1884 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1885 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1886 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1887 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1888 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
1889 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
1892 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
1893 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
1894 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
1895 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
1896 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
1897 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
1899 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
1901 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
1903 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
1904 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
1905 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
1906 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
1907 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
1908 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
1909 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
1910 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
1911 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
1912 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
1913 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
1914 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
1915 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
1916 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
1917 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
1918 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
1919 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
1921 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
1922 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
1924 initialized
= GL_TRUE
;
1927 return table
[format
];
1932 static pack_float_rgba_row_func
1933 get_pack_float_rgba_row_function(gl_format format
)
1935 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
1936 static GLboolean initialized
= GL_FALSE
;
1939 /* We don't need a special row packing function for each format.
1940 * There's a generic fallback which uses a per-pixel packing function.
1942 memset(table
, 0, sizeof(table
));
1944 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
1945 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
1946 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
1947 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
1948 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
1949 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
1950 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
1951 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
1952 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
1953 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
1954 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
1955 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
1957 initialized
= GL_TRUE
;
1960 return table
[format
];
1965 static pack_ubyte_rgba_row_func
1966 get_pack_ubyte_rgba_row_function(gl_format format
)
1968 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
1969 static GLboolean initialized
= GL_FALSE
;
1972 /* We don't need a special row packing function for each format.
1973 * There's a generic fallback which uses a per-pixel packing function.
1975 memset(table
, 0, sizeof(table
));
1977 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
1978 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
1979 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
1980 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
1981 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
1982 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
1983 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
1984 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
1985 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
1986 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
1987 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
1988 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
1990 initialized
= GL_TRUE
;
1993 return table
[format
];
1999 * Pack a row of GLfloat rgba[4] values to the destination.
2002 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
2003 const GLfloat src
[][4], void *dst
)
2005 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2007 /* use "fast" function */
2008 packrow(n
, src
, dst
);
2011 /* slower fallback */
2012 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2013 GLuint dstStride
= _mesa_get_format_bytes(format
);
2014 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2021 for (i
= 0; i
< n
; i
++) {
2022 pack(src
[i
], dstPtr
);
2023 dstPtr
+= dstStride
;
2030 * Pack a row of GLubyte rgba[4] values to the destination.
2033 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2034 const GLubyte src
[][4], void *dst
)
2036 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2038 /* use "fast" function */
2039 packrow(n
, src
, dst
);
2042 /* slower fallback */
2043 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2044 const GLuint stride
= _mesa_get_format_bytes(format
);
2045 GLubyte
*d
= ((GLubyte
*) dst
);
2052 for (i
= 0; i
< n
; i
++) {
2061 * Pack a 2D image of ubyte RGBA pixels in the given format.
2062 * \param srcRowStride source image row stride in bytes
2063 * \param dstRowStride destination image row stride in bytes
2066 _mesa_pack_ubyte_rgba_rect(gl_format format
, GLuint width
, GLuint height
,
2067 const GLubyte
*src
, GLint srcRowStride
,
2068 void *dst
, GLint dstRowStride
)
2070 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2071 GLubyte
*dstUB
= (GLubyte
*) dst
;
2075 if (srcRowStride
== width
* 4 * sizeof(GLubyte
) &&
2076 dstRowStride
== _mesa_format_row_stride(format
, width
)) {
2077 /* do whole image at once */
2078 packrow(width
* height
, (const GLubyte (*)[4]) src
, dst
);
2082 for (i
= 0; i
< height
; i
++) {
2083 packrow(width
, (const GLubyte (*)[4]) src
, dstUB
);
2084 src
+= srcRowStride
;
2085 dstUB
+= dstRowStride
;
2090 /* slower fallback */
2091 for (i
= 0; i
< height
; i
++) {
2092 _mesa_pack_ubyte_rgba_row(format
, width
,
2093 (const GLubyte (*)[4]) src
, dstUB
);
2094 src
+= srcRowStride
;
2095 dstUB
+= dstRowStride
;
2103 ** Pack float Z pixels
2107 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2109 /* don't disturb the stencil values */
2110 GLuint
*d
= ((GLuint
*) dst
);
2111 const GLdouble scale
= (GLdouble
) 0xffffff;
2112 GLuint s
= *d
& 0xff;
2113 GLuint z
= (GLuint
) (*src
* scale
);
2114 assert(z
<= 0xffffff);
2119 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2121 /* don't disturb the stencil values */
2122 GLuint
*d
= ((GLuint
*) dst
);
2123 const GLdouble scale
= (GLdouble
) 0xffffff;
2124 GLuint s
= *d
& 0xff000000;
2125 GLuint z
= (GLuint
) (*src
* scale
);
2126 assert(z
<= 0xffffff);
2131 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2133 GLushort
*d
= ((GLushort
*) dst
);
2134 const GLfloat scale
= (GLfloat
) 0xffff;
2135 *d
= (GLushort
) (*src
* scale
);
2139 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2141 GLuint
*d
= ((GLuint
*) dst
);
2142 const GLdouble scale
= (GLdouble
) 0xffffffff;
2143 *d
= (GLuint
) (*src
* scale
);
2147 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2149 GLfloat
*d
= (GLfloat
*) dst
;
2153 gl_pack_float_z_func
2154 _mesa_get_pack_float_z_func(gl_format format
)
2157 case MESA_FORMAT_Z24_S8
:
2158 case MESA_FORMAT_Z24_X8
:
2159 return pack_float_z_Z24_S8
;
2160 case MESA_FORMAT_S8_Z24
:
2161 case MESA_FORMAT_X8_Z24
:
2162 return pack_float_z_S8_Z24
;
2163 case MESA_FORMAT_Z16
:
2164 return pack_float_z_Z16
;
2165 case MESA_FORMAT_Z32
:
2166 return pack_float_z_Z32
;
2167 case MESA_FORMAT_Z32_FLOAT
:
2168 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2169 return pack_float_z_Z32_FLOAT
;
2172 "unexpected format in _mesa_get_pack_float_z_func()");
2180 ** Pack uint Z pixels. The incoming src value is always in
2181 ** the range [0, 2^32-1].
2185 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2187 /* don't disturb the stencil values */
2188 GLuint
*d
= ((GLuint
*) dst
);
2189 GLuint s
= *d
& 0xff;
2190 GLuint z
= *src
& 0xffffff00;
2195 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2197 /* don't disturb the stencil values */
2198 GLuint
*d
= ((GLuint
*) dst
);
2199 GLuint s
= *d
& 0xff000000;
2200 GLuint z
= *src
>> 8;
2205 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2207 GLushort
*d
= ((GLushort
*) dst
);
2212 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2214 GLuint
*d
= ((GLuint
*) dst
);
2219 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2221 GLuint
*d
= ((GLuint
*) dst
);
2222 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2229 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2231 GLfloat
*d
= ((GLfloat
*) dst
);
2232 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2239 _mesa_get_pack_uint_z_func(gl_format format
)
2242 case MESA_FORMAT_Z24_S8
:
2243 case MESA_FORMAT_Z24_X8
:
2244 return pack_uint_z_Z24_S8
;
2245 case MESA_FORMAT_S8_Z24
:
2246 case MESA_FORMAT_X8_Z24
:
2247 return pack_uint_z_S8_Z24
;
2248 case MESA_FORMAT_Z16
:
2249 return pack_uint_z_Z16
;
2250 case MESA_FORMAT_Z32
:
2251 return pack_uint_z_Z32
;
2252 case MESA_FORMAT_Z32_FLOAT
:
2253 return pack_uint_z_Z32_FLOAT
;
2254 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2255 return pack_uint_z_Z32_FLOAT_X24S8
;
2257 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2264 ** Pack ubyte stencil pixels
2268 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2270 /* don't disturb the Z values */
2271 GLuint
*d
= ((GLuint
*) dst
);
2273 GLuint z
= *d
& 0xffffff00;
2278 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2280 /* don't disturb the Z values */
2281 GLuint
*d
= ((GLuint
*) dst
);
2282 GLuint s
= *src
<< 24;
2283 GLuint z
= *d
& 0xffffff;
2288 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2290 GLubyte
*d
= (GLubyte
*) dst
;
2295 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2297 GLfloat
*d
= ((GLfloat
*) dst
);
2302 gl_pack_ubyte_stencil_func
2303 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2306 case MESA_FORMAT_Z24_S8
:
2307 return pack_ubyte_stencil_Z24_S8
;
2308 case MESA_FORMAT_S8_Z24
:
2309 return pack_ubyte_stencil_S8_Z24
;
2310 case MESA_FORMAT_S8
:
2311 return pack_ubyte_stencil_S8
;
2312 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2313 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2316 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2324 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2325 const GLfloat
*src
, void *dst
)
2328 case MESA_FORMAT_Z24_S8
:
2329 case MESA_FORMAT_Z24_X8
:
2331 /* don't disturb the stencil values */
2332 GLuint
*d
= ((GLuint
*) dst
);
2333 const GLdouble scale
= (GLdouble
) 0xffffff;
2335 for (i
= 0; i
< n
; i
++) {
2336 GLuint s
= d
[i
] & 0xff;
2337 GLuint z
= (GLuint
) (src
[i
] * scale
);
2338 assert(z
<= 0xffffff);
2339 d
[i
] = (z
<< 8) | s
;
2343 case MESA_FORMAT_S8_Z24
:
2344 case MESA_FORMAT_X8_Z24
:
2346 /* don't disturb the stencil values */
2347 GLuint
*d
= ((GLuint
*) dst
);
2348 const GLdouble scale
= (GLdouble
) 0xffffff;
2350 for (i
= 0; i
< n
; i
++) {
2351 GLuint s
= d
[i
] & 0xff000000;
2352 GLuint z
= (GLuint
) (src
[i
] * scale
);
2353 assert(z
<= 0xffffff);
2358 case MESA_FORMAT_Z16
:
2360 GLushort
*d
= ((GLushort
*) dst
);
2361 const GLfloat scale
= (GLfloat
) 0xffff;
2363 for (i
= 0; i
< n
; i
++) {
2364 d
[i
] = (GLushort
) (src
[i
] * scale
);
2368 case MESA_FORMAT_Z32
:
2370 GLuint
*d
= ((GLuint
*) dst
);
2371 const GLdouble scale
= (GLdouble
) 0xffffffff;
2373 for (i
= 0; i
< n
; i
++) {
2374 d
[i
] = (GLuint
) (src
[i
] * scale
);
2378 case MESA_FORMAT_Z32_FLOAT
:
2379 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2381 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2383 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2385 for (i
= 0; i
< n
; i
++) {
2391 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2397 * The incoming Z values are always in the range [0, 0xffffffff].
2400 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2401 const GLuint
*src
, void *dst
)
2404 case MESA_FORMAT_Z24_S8
:
2405 case MESA_FORMAT_Z24_X8
:
2407 /* don't disturb the stencil values */
2408 GLuint
*d
= ((GLuint
*) dst
);
2410 for (i
= 0; i
< n
; i
++) {
2411 GLuint s
= d
[i
] & 0xff;
2412 GLuint z
= src
[i
] & 0xffffff00;
2417 case MESA_FORMAT_S8_Z24
:
2418 case MESA_FORMAT_X8_Z24
:
2420 /* don't disturb the stencil values */
2421 GLuint
*d
= ((GLuint
*) dst
);
2423 for (i
= 0; i
< n
; i
++) {
2424 GLuint s
= d
[i
] & 0xff000000;
2425 GLuint z
= src
[i
] >> 8;
2430 case MESA_FORMAT_Z16
:
2432 GLushort
*d
= ((GLushort
*) dst
);
2434 for (i
= 0; i
< n
; i
++) {
2435 d
[i
] = src
[i
] >> 16;
2439 case MESA_FORMAT_Z32
:
2440 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2442 case MESA_FORMAT_Z32_FLOAT
:
2444 GLuint
*d
= ((GLuint
*) dst
);
2445 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2447 for (i
= 0; i
< n
; i
++) {
2448 d
[i
] = src
[i
] * scale
;
2449 assert(d
[i
] >= 0.0f
);
2450 assert(d
[i
] <= 1.0f
);
2454 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2456 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2457 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2459 for (i
= 0; i
< n
; i
++) {
2460 d
[i
].z
= src
[i
] * scale
;
2461 assert(d
[i
].z
>= 0.0f
);
2462 assert(d
[i
].z
<= 1.0f
);
2467 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2473 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2474 const GLubyte
*src
, void *dst
)
2477 case MESA_FORMAT_Z24_S8
:
2479 /* don't disturb the Z values */
2480 GLuint
*d
= ((GLuint
*) dst
);
2482 for (i
= 0; i
< n
; i
++) {
2484 GLuint z
= d
[i
] & 0xffffff00;
2489 case MESA_FORMAT_S8_Z24
:
2491 /* don't disturb the Z values */
2492 GLuint
*d
= ((GLuint
*) dst
);
2494 for (i
= 0; i
< n
; i
++) {
2495 GLuint s
= src
[i
] << 24;
2496 GLuint z
= d
[i
] & 0xffffff;
2501 case MESA_FORMAT_S8
:
2502 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2504 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2506 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2508 for (i
= 0; i
< n
; i
++) {
2509 d
[i
].x24s8
= src
[i
];
2514 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2520 * Incoming Z/stencil values are always in uint_24_8 format.
2523 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2524 const GLuint
*src
, void *dst
)
2527 case MESA_FORMAT_Z24_S8
:
2528 memcpy(dst
, src
, n
* sizeof(GLuint
));
2530 case MESA_FORMAT_S8_Z24
:
2532 GLuint
*d
= ((GLuint
*) dst
);
2534 for (i
= 0; i
< n
; i
++) {
2535 GLuint s
= src
[i
] << 24;
2536 GLuint z
= src
[i
] >> 8;
2541 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2543 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2544 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2546 for (i
= 0; i
< n
; i
++) {
2547 GLfloat z
= (src
[i
] >> 8) * scale
;
2549 d
[i
].x24s8
= src
[i
];
2554 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2555 _mesa_get_format_name(format
));
2563 * Convert a boolean color mask to a packed color where each channel of
2564 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2567 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2569 GLfloat maskColor
[4];
2571 switch (_mesa_get_format_datatype(format
)) {
2572 case GL_UNSIGNED_NORMALIZED
:
2573 /* simple: 1.0 will convert to ~0 in the right bit positions */
2574 maskColor
[0] = colorMask
[0] ? 1.0 : 0.0;
2575 maskColor
[1] = colorMask
[1] ? 1.0 : 0.0;
2576 maskColor
[2] = colorMask
[2] ? 1.0 : 0.0;
2577 maskColor
[3] = colorMask
[3] ? 1.0 : 0.0;
2578 _mesa_pack_float_rgba_row(format
, 1,
2579 (const GLfloat (*)[4]) maskColor
, dst
);
2581 case GL_SIGNED_NORMALIZED
:
2583 /* These formats are harder because it's hard to know the floating
2584 * point values that will convert to ~0 for each color channel's bits.
2585 * This solution just generates a non-zero value for each color channel
2586 * then fixes up the non-zero values to be ~0.
2587 * Note: we'll need to add special case code if we ever have to deal
2588 * with formats with unequal color channel sizes, like R11_G11_B10.
2589 * We issue a warning below for channel sizes other than 8,16,32.
2592 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2593 GLuint bytes
= _mesa_get_format_bytes(format
);
2596 /* this should put non-zero values into the channels of dst */
2597 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2598 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2599 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2600 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2601 _mesa_pack_float_rgba_row(format
, 1,
2602 (const GLfloat (*)[4]) maskColor
, dst
);
2604 /* fix-up the dst channels by converting non-zero values to ~0 */
2606 GLubyte
*d
= (GLubyte
*) dst
;
2607 for (i
= 0; i
< bytes
; i
++) {
2608 d
[i
] = d
[i
] ? 0xff : 0x0;
2611 else if (bits
== 16) {
2612 GLushort
*d
= (GLushort
*) dst
;
2613 for (i
= 0; i
< bytes
/ 2; i
++) {
2614 d
[i
] = d
[i
] ? 0xffff : 0x0;
2617 else if (bits
== 32) {
2618 GLuint
*d
= (GLuint
*) dst
;
2619 for (i
= 0; i
< bytes
/ 4; i
++) {
2620 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2624 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2630 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");