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 typedef void (*pack_ubyte_rgba_row_func
)(GLuint n
,
46 const GLubyte src
[][4], void *dst
);
48 typedef void (*pack_float_rgba_row_func
)(GLuint n
,
49 const GLfloat src
[][4], void *dst
);
54 linear_to_srgb(GLfloat cl
)
58 else if (cl
< 0.0031308f
)
61 return 1.055f
* powf(cl
, 0.41666f
) - 0.055f
;
68 linear_float_to_srgb_ubyte(GLfloat cl
)
70 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
));
76 linear_ubyte_to_srgb_ubyte(GLubyte cl
)
78 GLubyte res
= FLOAT_TO_UBYTE(linear_to_srgb(cl
/ 255.0f
));
86 * MESA_FORMAT_RGBA8888
90 pack_ubyte_RGBA8888(const GLubyte src
[4], void *dst
)
92 GLuint
*d
= ((GLuint
*) dst
);
93 *d
= PACK_COLOR_8888(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
97 pack_float_RGBA8888(const GLfloat src
[4], void *dst
)
100 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
101 pack_ubyte_RGBA8888(v
, dst
);
105 pack_row_ubyte_RGBA8888(GLuint n
, const GLubyte src
[][4], void *dst
)
107 GLuint
*d
= ((GLuint
*) dst
);
109 for (i
= 0; i
< n
; i
++) {
110 d
[i
] = PACK_COLOR_8888(src
[i
][RCOMP
], src
[i
][GCOMP
],
111 src
[i
][BCOMP
], src
[i
][ACOMP
]);
116 pack_row_float_RGBA8888(GLuint n
, const GLfloat src
[][4], void *dst
)
118 GLuint
*d
= ((GLuint
*) dst
);
120 for (i
= 0; i
< n
; i
++) {
122 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
123 pack_ubyte_RGBA8888(v
, d
+ i
);
130 * MESA_FORMAT_RGBA8888_REV
134 pack_ubyte_RGBA8888_REV(const GLubyte src
[4], void *dst
)
136 GLuint
*d
= ((GLuint
*) dst
);
137 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[BCOMP
], src
[GCOMP
], src
[RCOMP
]);
141 pack_float_RGBA8888_REV(const GLfloat src
[4], void *dst
)
144 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
145 pack_ubyte_RGBA8888_REV(v
, dst
);
149 pack_row_ubyte_RGBA8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
151 GLuint
*d
= ((GLuint
*) dst
);
153 for (i
= 0; i
< n
; i
++) {
154 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][BCOMP
],
155 src
[i
][GCOMP
], src
[i
][RCOMP
]);
160 pack_row_float_RGBA8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
162 GLuint
*d
= ((GLuint
*) dst
);
164 for (i
= 0; i
< n
; i
++) {
166 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
167 pack_ubyte_RGBA8888_REV(v
, d
+ i
);
173 * MESA_FORMAT_ARGB8888
177 pack_ubyte_ARGB8888(const GLubyte src
[4], void *dst
)
179 GLuint
*d
= ((GLuint
*) dst
);
180 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
184 pack_float_ARGB8888(const GLfloat src
[4], void *dst
)
187 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
188 pack_ubyte_ARGB8888(v
, dst
);
192 pack_row_ubyte_ARGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
194 GLuint
*d
= ((GLuint
*) dst
);
196 for (i
= 0; i
< n
; i
++) {
197 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][RCOMP
],
198 src
[i
][GCOMP
], src
[i
][BCOMP
]);
203 pack_row_float_ARGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
205 GLuint
*d
= ((GLuint
*) dst
);
207 for (i
= 0; i
< n
; i
++) {
209 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
210 pack_ubyte_ARGB8888(v
, d
+ i
);
216 * MESA_FORMAT_ARGB8888_REV
220 pack_ubyte_ARGB8888_REV(const GLubyte src
[4], void *dst
)
222 GLuint
*d
= ((GLuint
*) dst
);
223 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
227 pack_float_ARGB8888_REV(const GLfloat src
[4], void *dst
)
230 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
231 pack_ubyte_ARGB8888_REV(v
, dst
);
235 pack_row_ubyte_ARGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
237 GLuint
*d
= ((GLuint
*) dst
);
239 for (i
= 0; i
< n
; i
++) {
240 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
],
241 src
[i
][RCOMP
], src
[i
][ACOMP
]);
246 pack_row_float_ARGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
248 GLuint
*d
= ((GLuint
*) dst
);
250 for (i
= 0; i
< n
; i
++) {
252 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
253 pack_ubyte_ARGB8888_REV(v
, d
+ i
);
259 * MESA_FORMAT_XRGB8888
263 pack_ubyte_XRGB8888(const GLubyte src
[4], void *dst
)
265 GLuint
*d
= ((GLuint
*) dst
);
266 *d
= PACK_COLOR_8888(0x0, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
270 pack_float_XRGB8888(const GLfloat src
[4], void *dst
)
273 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
274 pack_ubyte_XRGB8888(v
, dst
);
278 pack_row_ubyte_XRGB8888(GLuint n
, const GLubyte src
[][4], void *dst
)
280 GLuint
*d
= ((GLuint
*) dst
);
282 for (i
= 0; i
< n
; i
++) {
283 d
[i
] = PACK_COLOR_8888(0, src
[i
][RCOMP
], src
[i
][GCOMP
], src
[i
][BCOMP
]);
288 pack_row_float_XRGB8888(GLuint n
, const GLfloat src
[][4], void *dst
)
290 GLuint
*d
= ((GLuint
*) dst
);
292 for (i
= 0; i
< n
; i
++) {
294 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
295 pack_ubyte_XRGB8888(v
, d
+ i
);
301 * MESA_FORMAT_XRGB8888_REV
305 pack_ubyte_XRGB8888_REV(const GLubyte src
[4], void *dst
)
307 GLuint
*d
= ((GLuint
*) dst
);
308 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], 0);
312 pack_float_XRGB8888_REV(const GLfloat src
[4], void *dst
)
315 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
316 pack_ubyte_XRGB8888_REV(v
, dst
);
320 pack_row_ubyte_XRGB8888_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
322 GLuint
*d
= ((GLuint
*) dst
);
324 for (i
= 0; i
< n
; i
++) {
325 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
], src
[i
][RCOMP
], 0);
330 pack_row_float_XRGB8888_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
332 GLuint
*d
= ((GLuint
*) dst
);
334 for (i
= 0; i
< n
; i
++) {
336 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
337 pack_ubyte_XRGB8888_REV(v
, d
+ i
);
347 pack_ubyte_RGB888(const GLubyte src
[4], void *dst
)
349 GLubyte
*d
= ((GLubyte
*) dst
);
356 pack_float_RGB888(const GLfloat src
[4], void *dst
)
358 GLubyte
*d
= ((GLubyte
*) dst
);
359 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[RCOMP
]);
360 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
361 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[BCOMP
]);
365 pack_row_ubyte_RGB888(GLuint n
, const GLubyte src
[][4], void *dst
)
367 GLubyte
*d
= ((GLubyte
*) dst
);
369 for (i
= 0; i
< n
; i
++) {
370 d
[i
*3+2] = src
[i
][RCOMP
];
371 d
[i
*3+1] = src
[i
][GCOMP
];
372 d
[i
*3+0] = src
[i
][BCOMP
];
377 pack_row_float_RGB888(GLuint n
, const GLfloat src
[][4], void *dst
)
379 GLubyte
*d
= ((GLubyte
*) dst
);
381 for (i
= 0; i
< n
; i
++) {
383 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
396 pack_ubyte_BGR888(const GLubyte src
[4], void *dst
)
398 GLubyte
*d
= ((GLubyte
*) dst
);
405 pack_float_BGR888(const GLfloat src
[4], void *dst
)
407 GLubyte
*d
= ((GLubyte
*) dst
);
408 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[BCOMP
]);
409 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
410 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
414 pack_row_ubyte_BGR888(GLuint n
, const GLubyte src
[][4], void *dst
)
416 GLubyte
*d
= ((GLubyte
*) dst
);
418 for (i
= 0; i
< n
; i
++) {
419 d
[i
*3+2] = src
[i
][BCOMP
];
420 d
[i
*3+1] = src
[i
][GCOMP
];
421 d
[i
*3+0] = src
[i
][RCOMP
];
426 pack_row_float_BGR888(GLuint n
, const GLfloat src
[][4], void *dst
)
428 GLubyte
*d
= ((GLubyte
*) dst
);
430 for (i
= 0; i
< n
; i
++) {
432 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
445 pack_ubyte_RGB565(const GLubyte src
[4], void *dst
)
447 GLushort
*d
= ((GLushort
*) dst
);
448 *d
= PACK_COLOR_565(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
452 pack_float_RGB565(const GLfloat src
[4], void *dst
)
455 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
456 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
457 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
458 pack_ubyte_RGB565(v
, dst
);
462 pack_row_ubyte_RGB565(GLuint n
, const GLubyte src
[][4], void *dst
)
464 GLushort
*d
= ((GLushort
*) dst
);
466 for (i
= 0; i
< n
; i
++) {
467 pack_ubyte_RGB565(src
[i
], d
+ i
);
472 pack_row_float_RGB565(GLuint n
, const GLfloat src
[][4], void *dst
)
474 GLushort
*d
= ((GLushort
*) dst
);
476 for (i
= 0; i
< n
; i
++) {
478 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
479 pack_ubyte_RGB565(v
, d
+ i
);
485 * MESA_FORMAT_RGB565_REV
489 pack_ubyte_RGB565_REV(const GLubyte src
[4], void *dst
)
491 GLushort
*d
= ((GLushort
*) dst
);
492 *d
= PACK_COLOR_565_REV(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
496 pack_float_RGB565_REV(const GLfloat src
[4], void *dst
)
498 GLushort
*d
= ((GLushort
*) dst
);
500 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
501 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
502 UNCLAMPED_FLOAT_TO_UBYTE(b
, src
[BCOMP
]);
503 *d
= PACK_COLOR_565_REV(r
, g
, b
);
507 pack_row_ubyte_RGB565_REV(GLuint n
, const GLubyte src
[][4], void *dst
)
509 GLushort
*d
= ((GLushort
*) dst
);
511 for (i
= 0; i
< n
; i
++) {
512 pack_ubyte_RGB565_REV(src
[i
], d
+ i
);
517 pack_row_float_RGB565_REV(GLuint n
, const GLfloat src
[][4], void *dst
)
519 GLushort
*d
= ((GLushort
*) dst
);
521 for (i
= 0; i
< n
; i
++) {
523 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
524 pack_ubyte_RGB565_REV(v
, d
+ i
);
530 * MESA_FORMAT_ARGB4444
534 pack_ubyte_ARGB4444(const GLubyte src
[4], void *dst
)
536 GLushort
*d
= ((GLushort
*) dst
);
537 *d
= PACK_COLOR_4444(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
541 pack_float_ARGB4444(const GLfloat src
[4], void *dst
)
544 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
545 pack_ubyte_ARGB4444(v
, dst
);
548 /* use fallback row packing functions */
552 * MESA_FORMAT_ARGB4444_REV
556 pack_ubyte_ARGB4444_REV(const GLubyte src
[4], void *dst
)
558 GLushort
*d
= ((GLushort
*) dst
);
559 *d
= PACK_COLOR_4444(src
[GCOMP
], src
[BCOMP
], src
[ACOMP
], src
[RCOMP
]);
563 pack_float_ARGB4444_REV(const GLfloat src
[4], void *dst
)
566 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
567 pack_ubyte_ARGB4444_REV(v
, dst
);
570 /* use fallback row packing functions */
574 * MESA_FORMAT_RGBA5551
578 pack_ubyte_RGBA5551(const GLubyte src
[4], void *dst
)
580 GLushort
*d
= ((GLushort
*) dst
);
581 *d
= PACK_COLOR_5551(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
585 pack_float_RGBA5551(const GLfloat src
[4], void *dst
)
588 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
589 pack_ubyte_RGBA5551(v
, dst
);
592 /* use fallback row packing functions */
596 * MESA_FORMAT_ARGB1555
600 pack_ubyte_ARGB1555(const GLubyte src
[4], void *dst
)
602 GLushort
*d
= ((GLushort
*) dst
);
603 *d
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
607 pack_float_ARGB1555(const GLfloat src
[4], void *dst
)
610 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
611 pack_ubyte_ARGB1555(v
, dst
);
615 /* MESA_FORMAT_ARGB1555_REV */
618 pack_ubyte_ARGB1555_REV(const GLubyte src
[4], void *dst
)
620 GLushort
*d
= ((GLushort
*) dst
), tmp
;
621 tmp
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
622 *d
= (tmp
>> 8) | (tmp
<< 8);
626 pack_float_ARGB1555_REV(const GLfloat src
[4], void *dst
)
629 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
630 pack_ubyte_ARGB1555_REV(v
, dst
);
634 /* MESA_FORMAT_AL44 */
637 pack_ubyte_AL44(const GLubyte src
[4], void *dst
)
639 GLubyte
*d
= ((GLubyte
*) dst
);
640 *d
= PACK_COLOR_44(src
[ACOMP
], src
[RCOMP
]);
644 pack_float_AL44(const GLfloat src
[4], void *dst
)
647 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
648 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
649 pack_ubyte_AL44(v
, dst
);
653 /* MESA_FORMAT_AL88 */
656 pack_ubyte_AL88(const GLubyte src
[4], void *dst
)
658 GLushort
*d
= ((GLushort
*) dst
);
659 *d
= PACK_COLOR_88(src
[ACOMP
], src
[RCOMP
]);
663 pack_float_AL88(const GLfloat src
[4], void *dst
)
666 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
667 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
668 pack_ubyte_AL88(v
, dst
);
672 /* MESA_FORMAT_AL88_REV */
675 pack_ubyte_AL88_REV(const GLubyte src
[4], void *dst
)
677 GLushort
*d
= ((GLushort
*) dst
);
678 *d
= PACK_COLOR_88(src
[RCOMP
], src
[ACOMP
]);
682 pack_float_AL88_REV(const GLfloat src
[4], void *dst
)
685 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
686 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
687 pack_ubyte_AL88_REV(v
, dst
);
691 /* MESA_FORMAT_AL1616 */
694 pack_ubyte_AL1616(const GLubyte src
[4], void *dst
)
696 GLuint
*d
= ((GLuint
*) dst
);
697 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
698 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
699 *d
= PACK_COLOR_1616(a
, l
);
703 pack_float_AL1616(const GLfloat src
[4], void *dst
)
705 GLuint
*d
= ((GLuint
*) dst
);
707 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
708 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
709 *d
= PACK_COLOR_1616(a
, l
);
713 /* MESA_FORMAT_AL1616_REV */
716 pack_ubyte_AL1616_REV(const GLubyte src
[4], void *dst
)
718 GLuint
*d
= ((GLuint
*) dst
);
719 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
720 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
721 *d
= PACK_COLOR_1616(l
, a
);
725 pack_float_AL1616_REV(const GLfloat src
[4], void *dst
)
727 GLuint
*d
= ((GLuint
*) dst
);
729 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
730 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
731 *d
= PACK_COLOR_1616(l
, a
);
735 /* MESA_FORMAT_RGB332 */
738 pack_ubyte_RGB332(const GLubyte src
[4], void *dst
)
740 GLubyte
*d
= ((GLubyte
*) dst
);
741 *d
= PACK_COLOR_332(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
745 pack_float_RGB332(const GLfloat src
[4], void *dst
)
748 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
749 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
750 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
751 pack_ubyte_RGB332(v
, dst
);
758 pack_ubyte_A8(const GLubyte src
[4], void *dst
)
760 GLubyte
*d
= ((GLubyte
*) dst
);
765 pack_float_A8(const GLfloat src
[4], void *dst
)
767 GLubyte
*d
= ((GLubyte
*) dst
);
768 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[ACOMP
]);
772 /* MESA_FORMAT_A16 */
775 pack_ubyte_A16(const GLubyte src
[4], void *dst
)
777 GLushort
*d
= ((GLushort
*) dst
);
778 *d
= UBYTE_TO_USHORT(src
[ACOMP
]);
782 pack_float_A16(const GLfloat src
[4], void *dst
)
784 GLushort
*d
= ((GLushort
*) dst
);
785 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[ACOMP
]);
792 pack_ubyte_L8(const GLubyte src
[4], void *dst
)
794 GLubyte
*d
= ((GLubyte
*) dst
);
799 pack_float_L8(const GLfloat src
[4], void *dst
)
801 GLubyte
*d
= ((GLubyte
*) dst
);
802 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
806 /* MESA_FORMAT_L16 */
809 pack_ubyte_L16(const GLubyte src
[4], void *dst
)
811 GLushort
*d
= ((GLushort
*) dst
);
812 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
816 pack_float_L16(const GLfloat src
[4], void *dst
)
818 GLushort
*d
= ((GLushort
*) dst
);
819 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
823 /* MESA_FORMAT_YCBCR */
826 pack_ubyte_YCBCR(const GLubyte src
[4], void *dst
)
832 pack_float_YCBCR(const GLfloat src
[4], void *dst
)
838 /* MESA_FORMAT_YCBCR_REV */
841 pack_ubyte_YCBCR_REV(const GLubyte src
[4], void *dst
)
847 pack_float_YCBCR_REV(const GLfloat src
[4], void *dst
)
856 pack_ubyte_R8(const GLubyte src
[4], void *dst
)
858 GLubyte
*d
= ((GLubyte
*) dst
);
863 pack_float_R8(const GLfloat src
[4], void *dst
)
865 GLubyte
*d
= ((GLubyte
*) dst
);
867 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
872 /* MESA_FORMAT_GR88 */
875 pack_ubyte_GR88(const GLubyte src
[4], void *dst
)
877 GLubyte
*d
= ((GLubyte
*) dst
);
878 *d
= PACK_COLOR_88(src
[GCOMP
], src
[RCOMP
]);
882 pack_float_GR88(const GLfloat src
[4], void *dst
)
884 GLushort
*d
= ((GLushort
*) dst
);
886 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
887 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
888 *d
= PACK_COLOR_88(g
, r
);
892 /* MESA_FORMAT_RG88 */
895 pack_ubyte_RG88(const GLubyte src
[4], void *dst
)
897 GLubyte
*d
= ((GLubyte
*) dst
);
898 *d
= PACK_COLOR_88(src
[RCOMP
], src
[GCOMP
]);
902 pack_float_RG88(const GLfloat src
[4], void *dst
)
904 GLushort
*d
= ((GLushort
*) dst
);
906 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
907 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
908 *d
= PACK_COLOR_88(r
, g
);
912 /* MESA_FORMAT_R16 */
915 pack_ubyte_R16(const GLubyte src
[4], void *dst
)
917 GLushort
*d
= ((GLushort
*) dst
);
918 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
922 pack_float_R16(const GLfloat src
[4], void *dst
)
924 GLushort
*d
= ((GLushort
*) dst
);
925 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
929 /* MESA_FORMAT_RG1616 */
932 pack_ubyte_RG1616(const GLubyte src
[4], void *dst
)
934 GLuint
*d
= ((GLuint
*) dst
);
935 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
936 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
937 *d
= PACK_COLOR_1616(g
, r
);
941 pack_float_RG1616(const GLfloat src
[4], void *dst
)
943 GLuint
*d
= ((GLuint
*) dst
);
945 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
946 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
947 *d
= PACK_COLOR_1616(g
, r
);
951 /* MESA_FORMAT_RG1616_REV */
954 pack_ubyte_RG1616_REV(const GLubyte src
[4], void *dst
)
956 GLuint
*d
= ((GLuint
*) dst
);
957 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
958 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
959 *d
= PACK_COLOR_1616(r
, g
);
964 pack_float_RG1616_REV(const GLfloat src
[4], void *dst
)
966 GLuint
*d
= ((GLuint
*) dst
);
968 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
969 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
970 *d
= PACK_COLOR_1616(r
, g
);
974 /* MESA_FORMAT_ARGB2101010 */
977 pack_ubyte_ARGB2101010(const GLubyte src
[4], void *dst
)
979 GLuint
*d
= ((GLuint
*) dst
);
980 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
981 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
982 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
983 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
984 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
988 pack_float_ARGB2101010(const GLfloat src
[4], void *dst
)
990 GLuint
*d
= ((GLuint
*) dst
);
992 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
993 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
994 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
995 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
996 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
1000 /* MESA_FORMAT_SRGB8 */
1003 pack_ubyte_SRGB8(const GLubyte src
[4], void *dst
)
1005 GLubyte
*d
= ((GLubyte
*) dst
);
1006 d
[2] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1007 d
[1] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1008 d
[0] = linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1012 pack_float_SRGB8(const GLfloat src
[4], void *dst
)
1014 GLubyte
*d
= ((GLubyte
*) dst
);
1015 d
[2] = linear_float_to_srgb_ubyte(src
[RCOMP
]);
1016 d
[1] = linear_float_to_srgb_ubyte(src
[GCOMP
]);
1017 d
[0] = linear_float_to_srgb_ubyte(src
[BCOMP
]);
1021 /* MESA_FORMAT_SRGBA8 */
1024 pack_ubyte_SRGBA8(const GLubyte src
[4], void *dst
)
1026 GLuint
*d
= ((GLuint
*) dst
);
1027 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1028 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[GCOMP
]);
1029 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[BCOMP
]);
1030 *d
= PACK_COLOR_8888(r
, g
, b
, src
[ACOMP
]);
1034 pack_float_SRGBA8(const GLfloat src
[4], void *dst
)
1036 GLuint
*d
= ((GLuint
*) dst
);
1038 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1039 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1040 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1041 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1042 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1046 /* MESA_FORMAT_SARGB8 */
1049 pack_ubyte_SARGB8(const GLubyte src
[4], void *dst
)
1051 GLuint
*d
= ((GLuint
*) dst
);
1052 GLubyte r
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1053 GLubyte g
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1054 GLubyte b
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1055 *d
= PACK_COLOR_8888(src
[ACOMP
], r
, g
, b
);
1059 pack_float_SARGB8(const GLfloat src
[4], void *dst
)
1061 GLuint
*d
= ((GLuint
*) dst
);
1063 r
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1064 g
= linear_float_to_srgb_ubyte(src
[GCOMP
]);
1065 b
= linear_float_to_srgb_ubyte(src
[BCOMP
]);
1066 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1067 *d
= PACK_COLOR_8888(a
, r
, g
, b
);
1071 /* MESA_FORMAT_SL8 */
1074 pack_ubyte_SL8(const GLubyte src
[4], void *dst
)
1076 GLubyte
*d
= ((GLubyte
*) dst
);
1077 *d
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1081 pack_float_SL8(const GLfloat src
[4], void *dst
)
1083 GLubyte
*d
= ((GLubyte
*) dst
);
1084 GLubyte l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1089 /* MESA_FORMAT_SLA8 */
1092 pack_ubyte_SLA8(const GLubyte src
[4], void *dst
)
1094 GLushort
*d
= ((GLushort
*) dst
);
1095 GLubyte l
= linear_ubyte_to_srgb_ubyte(src
[RCOMP
]);
1096 *d
= PACK_COLOR_88(src
[ACOMP
], l
);
1100 pack_float_SLA8(const GLfloat src
[4], void *dst
)
1102 GLushort
*d
= ((GLushort
*) dst
);
1103 GLubyte a
, l
= linear_float_to_srgb_ubyte(src
[RCOMP
]);
1104 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1105 *d
= PACK_COLOR_88(a
, l
);
1109 /* MESA_FORMAT_RGBA_FLOAT32 */
1112 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
1114 GLfloat
*d
= ((GLfloat
*) dst
);
1115 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1116 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1117 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1118 d
[3] = UBYTE_TO_FLOAT(src
[3]);
1122 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
1124 GLfloat
*d
= ((GLfloat
*) dst
);
1132 /* MESA_FORMAT_RGBA_FLOAT16 */
1135 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
1137 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1138 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1139 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1140 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1141 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
1145 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
1147 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1148 d
[0] = _mesa_float_to_half(src
[0]);
1149 d
[1] = _mesa_float_to_half(src
[1]);
1150 d
[2] = _mesa_float_to_half(src
[2]);
1151 d
[3] = _mesa_float_to_half(src
[3]);
1155 /* MESA_FORMAT_RGB_FLOAT32 */
1158 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
1160 GLfloat
*d
= ((GLfloat
*) dst
);
1161 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1162 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1163 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1167 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
1169 GLfloat
*d
= ((GLfloat
*) dst
);
1176 /* MESA_FORMAT_RGB_FLOAT16 */
1179 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
1181 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1182 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1183 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1184 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1188 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
1190 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1191 d
[0] = _mesa_float_to_half(src
[0]);
1192 d
[1] = _mesa_float_to_half(src
[1]);
1193 d
[2] = _mesa_float_to_half(src
[2]);
1197 /* MESA_FORMAT_ALPHA_FLOAT32 */
1200 pack_ubyte_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1202 GLfloat
*d
= ((GLfloat
*) dst
);
1203 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1207 pack_float_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1209 GLfloat
*d
= ((GLfloat
*) dst
);
1214 /* MESA_FORMAT_ALPHA_FLOAT16 */
1217 pack_ubyte_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1219 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1220 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1224 pack_float_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1226 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1227 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
1231 /* MESA_FORMAT_LUMINANCE_FLOAT32 (and INTENSITY_FLOAT32, R_FLOAT32) */
1234 pack_ubyte_LUMINANCE_FLOAT32(const GLubyte src
[4], void *dst
)
1236 GLfloat
*d
= ((GLfloat
*) dst
);
1237 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1241 pack_float_LUMINANCE_FLOAT32(const GLfloat src
[4], void *dst
)
1243 GLfloat
*d
= ((GLfloat
*) dst
);
1248 /* MESA_FORMAT_LUMINANCE_FLOAT16 (and INTENSITY_FLOAT16, R_FLOAT32) */
1251 pack_ubyte_LUMINANCE_FLOAT16(const GLubyte src
[4], void *dst
)
1253 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1254 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1258 pack_float_LUMINANCE_FLOAT16(const GLfloat src
[4], void *dst
)
1260 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1261 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1265 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 */
1268 pack_ubyte_LUMINANCE_ALPHA_FLOAT32(const GLubyte src
[4], void *dst
)
1270 GLfloat
*d
= ((GLfloat
*) dst
);
1271 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1272 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1276 pack_float_LUMINANCE_ALPHA_FLOAT32(const GLfloat src
[4], void *dst
)
1278 GLfloat
*d
= ((GLfloat
*) dst
);
1284 /* MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 */
1287 pack_ubyte_LUMINANCE_ALPHA_FLOAT16(const GLubyte src
[4], void *dst
)
1289 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1290 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1291 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1295 pack_float_LUMINANCE_ALPHA_FLOAT16(const GLfloat src
[4], void *dst
)
1297 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1298 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1299 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1303 /* MESA_FORMAT_RG_FLOAT32 */
1306 pack_ubyte_RG_FLOAT32(const GLubyte src
[4], void *dst
)
1308 GLfloat
*d
= ((GLfloat
*) dst
);
1309 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1310 d
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1314 pack_float_RG_FLOAT32(const GLfloat src
[4], void *dst
)
1316 GLfloat
*d
= ((GLfloat
*) dst
);
1322 /* MESA_FORMAT_RG_FLOAT16 */
1325 pack_ubyte_RG_FLOAT16(const GLubyte src
[4], void *dst
)
1327 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1328 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1329 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[GCOMP
]));
1333 pack_float_RG_FLOAT16(const GLfloat src
[4], void *dst
)
1335 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1336 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1337 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1341 /* MESA_FORMAT_DUDV8 */
1344 pack_ubyte_DUDV8(const GLubyte src
[4], void *dst
)
1346 /* XXX is this ever used? */
1347 GLushort
*d
= ((GLushort
*) dst
);
1348 *d
= PACK_COLOR_88(src
[0], src
[1]);
1352 pack_float_DUDV8(const GLfloat src
[4], void *dst
)
1354 GLushort
*d
= ((GLushort
*) dst
);
1356 du
= FLOAT_TO_BYTE(CLAMP(src
[0], 0.0F
, 1.0F
));
1357 dv
= FLOAT_TO_BYTE(CLAMP(src
[1], 0.0F
, 1.0F
));
1358 *d
= PACK_COLOR_88(du
, dv
);
1362 /* MESA_FORMAT_RGBA_16 */
1365 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1367 GLushort
*d
= ((GLushort
*) dst
);
1368 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1369 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1370 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1371 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1375 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1377 GLushort
*d
= ((GLushort
*) dst
);
1378 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1379 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1380 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1381 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1387 * MESA_FORMAT_SIGNED_R8
1391 pack_float_SIGNED_R8(const GLfloat src
[4], void *dst
)
1393 GLbyte
*d
= (GLbyte
*) dst
;
1394 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1399 * MESA_FORMAT_SIGNED_RG88_REV
1403 pack_float_SIGNED_RG88_REV(const GLfloat src
[4], void *dst
)
1405 GLushort
*d
= (GLushort
*) dst
;
1406 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1407 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1413 * MESA_FORMAT_SIGNED_RGBX8888
1417 pack_float_SIGNED_RGBX8888(const GLfloat src
[4], void *dst
)
1419 GLuint
*d
= (GLuint
*) dst
;
1420 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1421 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1422 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1424 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1429 * MESA_FORMAT_SIGNED_RGBA8888
1433 pack_float_SIGNED_RGBA8888(const GLfloat src
[4], void *dst
)
1435 GLuint
*d
= (GLuint
*) dst
;
1436 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1437 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1438 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1439 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1440 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1445 * MESA_FORMAT_SIGNED_RGBA8888_REV
1449 pack_float_SIGNED_RGBA8888_REV(const GLfloat src
[4], void *dst
)
1451 GLuint
*d
= (GLuint
*) dst
;
1452 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1453 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1454 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1455 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1456 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1461 * MESA_FORMAT_SIGNED_R16
1465 pack_float_SIGNED_R16(const GLfloat src
[4], void *dst
)
1467 GLshort
*d
= (GLshort
*) dst
;
1468 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1473 * MESA_FORMAT_SIGNED_GR1616
1477 pack_float_SIGNED_GR1616(const GLfloat src
[4], void *dst
)
1479 GLuint
*d
= (GLuint
*) dst
;
1480 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1481 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1482 *d
= (g
<< 16) | (r
& 0xffff);
1487 * MESA_FORMAT_SIGNED_RGB_16
1491 pack_float_SIGNED_RGB_16(const GLfloat src
[4], void *dst
)
1493 GLshort
*d
= (GLshort
*) dst
;
1494 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1495 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1496 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1501 * MESA_FORMAT_SIGNED_RGBA_16
1505 pack_float_SIGNED_RGBA_16(const GLfloat src
[4], void *dst
)
1507 GLshort
*d
= (GLshort
*) dst
;
1508 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1509 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1510 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1511 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1516 * MESA_FORMAT_SIGNED_A8
1520 pack_float_SIGNED_A8(const GLfloat src
[4], void *dst
)
1522 GLbyte
*d
= (GLbyte
*) dst
;
1523 *d
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1528 * MESA_FORMAT_SIGNED_L8
1532 pack_float_SIGNED_L8(const GLfloat src
[4], void *dst
)
1534 GLbyte
*d
= (GLbyte
*) dst
;
1535 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1540 * MESA_FORMAT_SIGNED_AL88
1544 pack_float_SIGNED_AL88(const GLfloat src
[4], void *dst
)
1546 GLushort
*d
= (GLushort
*) dst
;
1547 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1548 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1554 * MESA_FORMAT_SIGNED_A16
1558 pack_float_SIGNED_A16(const GLfloat src
[4], void *dst
)
1560 GLshort
*d
= (GLshort
*) dst
;
1561 *d
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1566 * MESA_FORMAT_SIGNED_L16
1570 pack_float_SIGNED_L16(const GLfloat src
[4], void *dst
)
1572 GLshort
*d
= (GLshort
*) dst
;
1573 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1578 * MESA_FORMAT_SIGNED_AL1616
1582 pack_float_SIGNED_AL1616(const GLfloat src
[4], void *dst
)
1584 GLuint
*d
= (GLuint
*) dst
;
1585 GLshort l
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1586 GLshort a
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1587 *d
= PACK_COLOR_1616(a
, l
);
1592 * MESA_FORMAT_RGB9_E5_FLOAT;
1596 pack_float_RGB9_E5_FLOAT(const GLfloat src
[4], void *dst
)
1598 GLuint
*d
= (GLuint
*) dst
;
1599 *d
= float3_to_rgb9e5(src
);
1603 pack_ubyte_RGB9_E5_FLOAT(const GLubyte src
[4], void *dst
)
1605 GLuint
*d
= (GLuint
*) dst
;
1607 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1608 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1609 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1610 *d
= float3_to_rgb9e5(rgb
);
1616 * MESA_FORMAT_R11_G11_B10_FLOAT;
1620 pack_ubyte_R11_G11_B10_FLOAT(const GLubyte src
[4], void *dst
)
1622 GLuint
*d
= (GLuint
*) dst
;
1624 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1625 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1626 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1627 *d
= float3_to_r11g11b10f(rgb
);
1631 pack_float_R11_G11_B10_FLOAT(const GLfloat src
[4], void *dst
)
1633 GLuint
*d
= (GLuint
*) dst
;
1634 *d
= float3_to_r11g11b10f(src
);
1640 * Return a function that can pack a GLubyte rgba[4] color.
1642 gl_pack_ubyte_rgba_func
1643 _mesa_get_pack_ubyte_rgba_function(gl_format format
)
1645 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1646 static GLboolean initialized
= GL_FALSE
;
1649 memset(table
, 0, sizeof(table
));
1651 table
[MESA_FORMAT_NONE
] = NULL
;
1653 table
[MESA_FORMAT_RGBA8888
] = pack_ubyte_RGBA8888
;
1654 table
[MESA_FORMAT_RGBA8888_REV
] = pack_ubyte_RGBA8888_REV
;
1655 table
[MESA_FORMAT_ARGB8888
] = pack_ubyte_ARGB8888
;
1656 table
[MESA_FORMAT_ARGB8888_REV
] = pack_ubyte_ARGB8888_REV
;
1657 table
[MESA_FORMAT_RGBX8888
] = pack_ubyte_RGBA8888
; /* reused */
1658 table
[MESA_FORMAT_RGBX8888_REV
] = pack_ubyte_RGBA8888_REV
; /* reused */
1659 table
[MESA_FORMAT_XRGB8888
] = pack_ubyte_XRGB8888
;
1660 table
[MESA_FORMAT_XRGB8888_REV
] = pack_ubyte_XRGB8888_REV
;
1661 table
[MESA_FORMAT_RGB888
] = pack_ubyte_RGB888
;
1662 table
[MESA_FORMAT_BGR888
] = pack_ubyte_BGR888
;
1663 table
[MESA_FORMAT_RGB565
] = pack_ubyte_RGB565
;
1664 table
[MESA_FORMAT_RGB565_REV
] = pack_ubyte_RGB565_REV
;
1665 table
[MESA_FORMAT_ARGB4444
] = pack_ubyte_ARGB4444
;
1666 table
[MESA_FORMAT_ARGB4444_REV
] = pack_ubyte_ARGB4444_REV
;
1667 table
[MESA_FORMAT_RGBA5551
] = pack_ubyte_RGBA5551
;
1668 table
[MESA_FORMAT_ARGB1555
] = pack_ubyte_ARGB1555
;
1669 table
[MESA_FORMAT_ARGB1555_REV
] = pack_ubyte_ARGB1555_REV
;
1670 table
[MESA_FORMAT_AL44
] = pack_ubyte_AL44
;
1671 table
[MESA_FORMAT_AL88
] = pack_ubyte_AL88
;
1672 table
[MESA_FORMAT_AL88_REV
] = pack_ubyte_AL88_REV
;
1673 table
[MESA_FORMAT_AL1616
] = pack_ubyte_AL1616
;
1674 table
[MESA_FORMAT_AL1616_REV
] = pack_ubyte_AL1616_REV
;
1675 table
[MESA_FORMAT_RGB332
] = pack_ubyte_RGB332
;
1676 table
[MESA_FORMAT_A8
] = pack_ubyte_A8
;
1677 table
[MESA_FORMAT_A16
] = pack_ubyte_A16
;
1678 table
[MESA_FORMAT_L8
] = pack_ubyte_L8
;
1679 table
[MESA_FORMAT_L16
] = pack_ubyte_L16
;
1680 table
[MESA_FORMAT_I8
] = pack_ubyte_L8
; /* reuse pack_ubyte_L8 */
1681 table
[MESA_FORMAT_I16
] = pack_ubyte_L16
; /* reuse pack_ubyte_L16 */
1682 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
1683 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
1684 table
[MESA_FORMAT_R8
] = pack_ubyte_R8
;
1685 table
[MESA_FORMAT_GR88
] = pack_ubyte_GR88
;
1686 table
[MESA_FORMAT_RG88
] = pack_ubyte_RG88
;
1687 table
[MESA_FORMAT_R16
] = pack_ubyte_R16
;
1688 table
[MESA_FORMAT_RG1616
] = pack_ubyte_RG1616
;
1689 table
[MESA_FORMAT_RG1616_REV
] = pack_ubyte_RG1616_REV
;
1690 table
[MESA_FORMAT_ARGB2101010
] = pack_ubyte_ARGB2101010
;
1692 /* should never convert RGBA to these formats */
1693 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1694 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1695 table
[MESA_FORMAT_Z16
] = NULL
;
1696 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1697 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1698 table
[MESA_FORMAT_Z32
] = NULL
;
1699 table
[MESA_FORMAT_S8
] = NULL
;
1702 table
[MESA_FORMAT_SRGB8
] = pack_ubyte_SRGB8
;
1703 table
[MESA_FORMAT_SRGBA8
] = pack_ubyte_SRGBA8
;
1704 table
[MESA_FORMAT_SARGB8
] = pack_ubyte_SARGB8
;
1705 table
[MESA_FORMAT_SL8
] = pack_ubyte_SL8
;
1706 table
[MESA_FORMAT_SLA8
] = pack_ubyte_SLA8
;
1709 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
1710 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
1711 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
1712 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
1714 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
1715 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
1716 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
1717 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
1718 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
1719 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
1721 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
1722 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
1723 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
1724 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
1725 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_ubyte_ALPHA_FLOAT32
;
1726 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_ubyte_ALPHA_FLOAT16
;
1727 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1728 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1729 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT32
;
1730 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_ubyte_LUMINANCE_ALPHA_FLOAT16
;
1731 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1732 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1733 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_LUMINANCE_FLOAT32
;
1734 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_LUMINANCE_FLOAT16
;
1735 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
1736 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
1739 table
[MESA_FORMAT_RGBA_INT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
1740 table
[MESA_FORMAT_RGBA_INT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
1741 table
[MESA_FORMAT_RGBA_INT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
1742 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
1743 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
1744 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
1746 table
[MESA_FORMAT_DUDV8
] = pack_ubyte_DUDV8
;
1748 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1751 table
[MESA_FORMAT_SIGNED_R8
] = NULL
;
1752 table
[MESA_FORMAT_SIGNED_RG88_REV
] = NULL
;
1753 table
[MESA_FORMAT_SIGNED_RGBX8888
] = NULL
;
1754 table
[MESA_FORMAT_SIGNED_RGBA8888
] = NULL
;
1755 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = NULL
;
1756 table
[MESA_FORMAT_SIGNED_R16
] = NULL
;
1757 table
[MESA_FORMAT_SIGNED_GR1616
] = NULL
;
1758 table
[MESA_FORMAT_SIGNED_RGB_16
] = NULL
;
1759 table
[MESA_FORMAT_SIGNED_RGBA_16
] = NULL
;
1760 table
[MESA_FORMAT_SIGNED_A8
] = NULL
;
1761 table
[MESA_FORMAT_SIGNED_L8
] = NULL
;
1762 table
[MESA_FORMAT_SIGNED_AL88
] = NULL
;
1763 table
[MESA_FORMAT_SIGNED_I8
] = NULL
;
1764 table
[MESA_FORMAT_SIGNED_A16
] = NULL
;
1765 table
[MESA_FORMAT_SIGNED_L16
] = NULL
;
1766 table
[MESA_FORMAT_SIGNED_AL1616
] = NULL
;
1767 table
[MESA_FORMAT_SIGNED_I16
] = NULL
;
1770 table
[MESA_FORMAT_RGBA_16
] = pack_ubyte_RGBA_16
;
1772 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_ubyte_RGB9_E5_FLOAT
;
1773 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_ubyte_R11_G11_B10_FLOAT
;
1775 initialized
= GL_TRUE
;
1778 return table
[format
];
1784 * Return a function that can pack a GLfloat rgba[4] color.
1786 gl_pack_float_rgba_func
1787 _mesa_get_pack_float_rgba_function(gl_format format
)
1789 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
1790 static GLboolean initialized
= GL_FALSE
;
1793 memset(table
, 0, sizeof(table
));
1795 table
[MESA_FORMAT_NONE
] = NULL
;
1797 table
[MESA_FORMAT_RGBA8888
] = pack_float_RGBA8888
;
1798 table
[MESA_FORMAT_RGBA8888_REV
] = pack_float_RGBA8888_REV
;
1799 table
[MESA_FORMAT_ARGB8888
] = pack_float_ARGB8888
;
1800 table
[MESA_FORMAT_ARGB8888_REV
] = pack_float_ARGB8888_REV
;
1801 table
[MESA_FORMAT_RGBX8888
] = pack_float_RGBA8888
; /* reused */
1802 table
[MESA_FORMAT_RGBX8888_REV
] = pack_float_RGBA8888_REV
; /* reused */
1803 table
[MESA_FORMAT_XRGB8888
] = pack_float_XRGB8888
;
1804 table
[MESA_FORMAT_XRGB8888_REV
] = pack_float_XRGB8888_REV
;
1805 table
[MESA_FORMAT_RGB888
] = pack_float_RGB888
;
1806 table
[MESA_FORMAT_BGR888
] = pack_float_BGR888
;
1807 table
[MESA_FORMAT_RGB565
] = pack_float_RGB565
;
1808 table
[MESA_FORMAT_RGB565_REV
] = pack_float_RGB565_REV
;
1809 table
[MESA_FORMAT_ARGB4444
] = pack_float_ARGB4444
;
1810 table
[MESA_FORMAT_ARGB4444_REV
] = pack_float_ARGB4444_REV
;
1811 table
[MESA_FORMAT_RGBA5551
] = pack_float_RGBA5551
;
1812 table
[MESA_FORMAT_ARGB1555
] = pack_float_ARGB1555
;
1813 table
[MESA_FORMAT_ARGB1555_REV
] = pack_float_ARGB1555_REV
;
1815 table
[MESA_FORMAT_AL44
] = pack_float_AL44
;
1816 table
[MESA_FORMAT_AL88
] = pack_float_AL88
;
1817 table
[MESA_FORMAT_AL88_REV
] = pack_float_AL88_REV
;
1818 table
[MESA_FORMAT_AL1616
] = pack_float_AL1616
;
1819 table
[MESA_FORMAT_AL1616_REV
] = pack_float_AL1616_REV
;
1820 table
[MESA_FORMAT_RGB332
] = pack_float_RGB332
;
1821 table
[MESA_FORMAT_A8
] = pack_float_A8
;
1822 table
[MESA_FORMAT_A16
] = pack_float_A16
;
1823 table
[MESA_FORMAT_L8
] = pack_float_L8
;
1824 table
[MESA_FORMAT_L16
] = pack_float_L16
;
1825 table
[MESA_FORMAT_I8
] = pack_float_L8
; /* reuse pack_float_L8 */
1826 table
[MESA_FORMAT_I16
] = pack_float_L16
; /* reuse pack_float_L16 */
1827 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
1828 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
1829 table
[MESA_FORMAT_R8
] = pack_float_R8
;
1830 table
[MESA_FORMAT_GR88
] = pack_float_GR88
;
1831 table
[MESA_FORMAT_RG88
] = pack_float_RG88
;
1832 table
[MESA_FORMAT_R16
] = pack_float_R16
;
1833 table
[MESA_FORMAT_RG1616
] = pack_float_RG1616
;
1834 table
[MESA_FORMAT_RG1616_REV
] = pack_float_RG1616_REV
;
1835 table
[MESA_FORMAT_ARGB2101010
] = pack_float_ARGB2101010
;
1837 /* should never convert RGBA to these formats */
1838 table
[MESA_FORMAT_Z24_S8
] = NULL
;
1839 table
[MESA_FORMAT_S8_Z24
] = NULL
;
1840 table
[MESA_FORMAT_Z16
] = NULL
;
1841 table
[MESA_FORMAT_X8_Z24
] = NULL
;
1842 table
[MESA_FORMAT_Z24_X8
] = NULL
;
1843 table
[MESA_FORMAT_Z32
] = NULL
;
1844 table
[MESA_FORMAT_S8
] = NULL
;
1846 table
[MESA_FORMAT_SRGB8
] = pack_float_SRGB8
;
1847 table
[MESA_FORMAT_SRGBA8
] = pack_float_SRGBA8
;
1848 table
[MESA_FORMAT_SARGB8
] = pack_float_SARGB8
;
1849 table
[MESA_FORMAT_SL8
] = pack_float_SL8
;
1850 table
[MESA_FORMAT_SLA8
] = pack_float_SLA8
;
1853 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
1854 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
1855 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
1856 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
1858 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
1859 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
1860 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
1861 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
1862 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
1863 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
1865 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
1866 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
1867 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
1868 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
1869 table
[MESA_FORMAT_ALPHA_FLOAT32
] = pack_float_ALPHA_FLOAT32
;
1870 table
[MESA_FORMAT_ALPHA_FLOAT16
] = pack_float_ALPHA_FLOAT16
;
1871 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1872 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1873 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = pack_float_LUMINANCE_ALPHA_FLOAT32
;
1874 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = pack_float_LUMINANCE_ALPHA_FLOAT16
;
1876 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1877 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1878 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_LUMINANCE_FLOAT32
;
1879 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_LUMINANCE_FLOAT16
;
1880 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
1881 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
1884 table
[MESA_FORMAT_RGBA_INT8
] = NULL
;
1885 table
[MESA_FORMAT_RGBA_INT16
] = NULL
;
1886 table
[MESA_FORMAT_RGBA_INT32
] = NULL
;
1887 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
1888 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
1889 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
1891 table
[MESA_FORMAT_DUDV8
] = pack_float_DUDV8
;
1893 table
[MESA_FORMAT_RGBA_16
] = pack_float_RGBA_16
;
1895 table
[MESA_FORMAT_SIGNED_R8
] = pack_float_SIGNED_R8
;
1896 table
[MESA_FORMAT_SIGNED_RG88_REV
] = pack_float_SIGNED_RG88_REV
;
1897 table
[MESA_FORMAT_SIGNED_RGBX8888
] = pack_float_SIGNED_RGBX8888
;
1898 table
[MESA_FORMAT_SIGNED_RGBA8888
] = pack_float_SIGNED_RGBA8888
;
1899 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = pack_float_SIGNED_RGBA8888_REV
;
1900 table
[MESA_FORMAT_SIGNED_R16
] = pack_float_SIGNED_R16
;
1901 table
[MESA_FORMAT_SIGNED_GR1616
] = pack_float_SIGNED_GR1616
;
1902 table
[MESA_FORMAT_SIGNED_RGB_16
] = pack_float_SIGNED_RGB_16
;
1903 table
[MESA_FORMAT_SIGNED_RGBA_16
] = pack_float_SIGNED_RGBA_16
;
1904 table
[MESA_FORMAT_SIGNED_A8
] = pack_float_SIGNED_A8
;
1905 table
[MESA_FORMAT_SIGNED_L8
] = pack_float_SIGNED_L8
;
1906 table
[MESA_FORMAT_SIGNED_AL88
] = pack_float_SIGNED_AL88
;
1907 table
[MESA_FORMAT_SIGNED_I8
] = pack_float_SIGNED_L8
; /* reused */
1908 table
[MESA_FORMAT_SIGNED_A16
] = pack_float_SIGNED_A16
;
1909 table
[MESA_FORMAT_SIGNED_L16
] = pack_float_SIGNED_L16
;
1910 table
[MESA_FORMAT_SIGNED_AL1616
] = pack_float_SIGNED_AL1616
;
1911 table
[MESA_FORMAT_SIGNED_I16
] = pack_float_SIGNED_L16
; /* reused */
1913 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = pack_float_RGB9_E5_FLOAT
;
1914 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = pack_float_R11_G11_B10_FLOAT
;
1916 initialized
= GL_TRUE
;
1919 return table
[format
];
1924 static pack_float_rgba_row_func
1925 get_pack_float_rgba_row_function(gl_format format
)
1927 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
1928 static GLboolean initialized
= GL_FALSE
;
1931 /* We don't need a special row packing function for each format.
1932 * There's a generic fallback which uses a per-pixel packing function.
1934 memset(table
, 0, sizeof(table
));
1936 table
[MESA_FORMAT_RGBA8888
] = pack_row_float_RGBA8888
;
1937 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_float_RGBA8888_REV
;
1938 table
[MESA_FORMAT_ARGB8888
] = pack_row_float_ARGB8888
;
1939 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_float_ARGB8888_REV
;
1940 table
[MESA_FORMAT_RGBX8888
] = pack_row_float_RGBA8888
; /* reused */
1941 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_float_RGBA8888_REV
; /* reused */
1942 table
[MESA_FORMAT_XRGB8888
] = pack_row_float_XRGB8888
;
1943 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_float_XRGB8888_REV
;
1944 table
[MESA_FORMAT_RGB888
] = pack_row_float_RGB888
;
1945 table
[MESA_FORMAT_BGR888
] = pack_row_float_BGR888
;
1946 table
[MESA_FORMAT_RGB565
] = pack_row_float_RGB565
;
1947 table
[MESA_FORMAT_RGB565_REV
] = pack_row_float_RGB565_REV
;
1949 initialized
= GL_TRUE
;
1952 return table
[format
];
1957 static pack_ubyte_rgba_row_func
1958 get_pack_ubyte_rgba_row_function(gl_format format
)
1960 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
1961 static GLboolean initialized
= GL_FALSE
;
1964 /* We don't need a special row packing function for each format.
1965 * There's a generic fallback which uses a per-pixel packing function.
1967 memset(table
, 0, sizeof(table
));
1969 table
[MESA_FORMAT_RGBA8888
] = pack_row_ubyte_RGBA8888
;
1970 table
[MESA_FORMAT_RGBA8888_REV
] = pack_row_ubyte_RGBA8888_REV
;
1971 table
[MESA_FORMAT_ARGB8888
] = pack_row_ubyte_ARGB8888
;
1972 table
[MESA_FORMAT_ARGB8888_REV
] = pack_row_ubyte_ARGB8888_REV
;
1973 table
[MESA_FORMAT_RGBX8888
] = pack_row_ubyte_RGBA8888
; /* reused */
1974 table
[MESA_FORMAT_RGBX8888_REV
] = pack_row_ubyte_RGBA8888_REV
; /* reused */
1975 table
[MESA_FORMAT_XRGB8888
] = pack_row_ubyte_XRGB8888
;
1976 table
[MESA_FORMAT_XRGB8888_REV
] = pack_row_ubyte_XRGB8888_REV
;
1977 table
[MESA_FORMAT_RGB888
] = pack_row_ubyte_RGB888
;
1978 table
[MESA_FORMAT_BGR888
] = pack_row_ubyte_BGR888
;
1979 table
[MESA_FORMAT_RGB565
] = pack_row_ubyte_RGB565
;
1980 table
[MESA_FORMAT_RGB565_REV
] = pack_row_ubyte_RGB565_REV
;
1982 initialized
= GL_TRUE
;
1985 return table
[format
];
1991 * Pack a row of GLfloat rgba[4] values to the destination.
1994 _mesa_pack_float_rgba_row(gl_format format
, GLuint n
,
1995 const GLfloat src
[][4], void *dst
)
1997 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
1999 /* use "fast" function */
2000 packrow(n
, src
, dst
);
2003 /* slower fallback */
2004 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2005 GLuint dstStride
= _mesa_get_format_bytes(format
);
2006 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2013 for (i
= 0; i
< n
; i
++) {
2014 pack(src
[i
], dstPtr
);
2015 dstPtr
+= dstStride
;
2022 * Pack a row of GLubyte rgba[4] values to the destination.
2025 _mesa_pack_ubyte_rgba_row(gl_format format
, GLuint n
,
2026 const GLubyte src
[][4], void *dst
)
2028 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2030 /* use "fast" function */
2031 packrow(n
, src
, dst
);
2034 /* slower fallback */
2035 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2036 const GLuint stride
= _mesa_get_format_bytes(format
);
2037 GLubyte
*d
= ((GLubyte
*) dst
);
2044 for (i
= 0; i
< n
; i
++) {
2053 ** Pack float Z pixels
2057 pack_float_z_Z24_S8(const GLfloat
*src
, void *dst
)
2059 /* don't disturb the stencil values */
2060 GLuint
*d
= ((GLuint
*) dst
);
2061 const GLdouble scale
= (GLdouble
) 0xffffff;
2062 GLuint s
= *d
& 0xff;
2063 GLuint z
= (GLuint
) (*src
* scale
);
2064 assert(z
<= 0xffffff);
2069 pack_float_z_S8_Z24(const GLfloat
*src
, void *dst
)
2071 /* don't disturb the stencil values */
2072 GLuint
*d
= ((GLuint
*) dst
);
2073 const GLdouble scale
= (GLdouble
) 0xffffff;
2074 GLuint s
= *d
& 0xff000000;
2075 GLuint z
= (GLuint
) (*src
* scale
);
2076 assert(z
<= 0xffffff);
2081 pack_float_z_Z16(const GLfloat
*src
, void *dst
)
2083 GLushort
*d
= ((GLushort
*) dst
);
2084 const GLfloat scale
= (GLfloat
) 0xffff;
2085 *d
= (GLushort
) (*src
* scale
);
2089 pack_float_z_Z32(const GLfloat
*src
, void *dst
)
2091 GLuint
*d
= ((GLuint
*) dst
);
2092 const GLdouble scale
= (GLdouble
) 0xffffffff;
2093 *d
= (GLuint
) (*src
* scale
);
2097 pack_float_z_Z32_FLOAT(const GLfloat
*src
, void *dst
)
2099 GLfloat
*d
= (GLfloat
*) dst
;
2103 gl_pack_float_z_func
2104 _mesa_get_pack_float_z_func(gl_format format
)
2107 case MESA_FORMAT_Z24_S8
:
2108 case MESA_FORMAT_Z24_X8
:
2109 return pack_float_z_Z24_S8
;
2110 case MESA_FORMAT_S8_Z24
:
2111 case MESA_FORMAT_X8_Z24
:
2112 return pack_float_z_S8_Z24
;
2113 case MESA_FORMAT_Z16
:
2114 return pack_float_z_Z16
;
2115 case MESA_FORMAT_Z32
:
2116 return pack_float_z_Z32
;
2117 case MESA_FORMAT_Z32_FLOAT
:
2118 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2119 return pack_float_z_Z32_FLOAT
;
2122 "unexpected format in _mesa_get_pack_float_z_func()");
2130 ** Pack uint Z pixels. The incoming src value is always in
2131 ** the range [0, 2^32-1].
2135 pack_uint_z_Z24_S8(const GLuint
*src
, void *dst
)
2137 /* don't disturb the stencil values */
2138 GLuint
*d
= ((GLuint
*) dst
);
2139 GLuint s
= *d
& 0xff;
2140 GLuint z
= *src
& 0xffffff00;
2145 pack_uint_z_S8_Z24(const GLuint
*src
, void *dst
)
2147 /* don't disturb the stencil values */
2148 GLuint
*d
= ((GLuint
*) dst
);
2149 GLuint s
= *d
& 0xff000000;
2150 GLuint z
= *src
>> 8;
2155 pack_uint_z_Z16(const GLuint
*src
, void *dst
)
2157 GLushort
*d
= ((GLushort
*) dst
);
2162 pack_uint_z_Z32(const GLuint
*src
, void *dst
)
2164 GLuint
*d
= ((GLuint
*) dst
);
2169 pack_uint_z_Z32_FLOAT(const GLuint
*src
, void *dst
)
2171 GLuint
*d
= ((GLuint
*) dst
);
2172 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2179 pack_uint_z_Z32_FLOAT_X24S8(const GLuint
*src
, void *dst
)
2181 GLfloat
*d
= ((GLfloat
*) dst
);
2182 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2189 _mesa_get_pack_uint_z_func(gl_format format
)
2192 case MESA_FORMAT_Z24_S8
:
2193 case MESA_FORMAT_Z24_X8
:
2194 return pack_uint_z_Z24_S8
;
2195 case MESA_FORMAT_S8_Z24
:
2196 case MESA_FORMAT_X8_Z24
:
2197 return pack_uint_z_S8_Z24
;
2198 case MESA_FORMAT_Z16
:
2199 return pack_uint_z_Z16
;
2200 case MESA_FORMAT_Z32
:
2201 return pack_uint_z_Z32
;
2202 case MESA_FORMAT_Z32_FLOAT
:
2203 return pack_uint_z_Z32_FLOAT
;
2204 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2205 return pack_uint_z_Z32_FLOAT_X24S8
;
2207 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2214 ** Pack ubyte stencil pixels
2218 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2220 /* don't disturb the Z values */
2221 GLuint
*d
= ((GLuint
*) dst
);
2223 GLuint z
= *d
& 0xffffff00;
2228 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2230 /* don't disturb the Z values */
2231 GLuint
*d
= ((GLuint
*) dst
);
2232 GLuint s
= *src
<< 24;
2233 GLuint z
= *d
& 0xffffff;
2238 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2240 GLubyte
*d
= (GLubyte
*) dst
;
2245 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2247 GLfloat
*d
= ((GLfloat
*) dst
);
2252 gl_pack_ubyte_stencil_func
2253 _mesa_get_pack_ubyte_stencil_func(gl_format format
)
2256 case MESA_FORMAT_Z24_S8
:
2257 return pack_ubyte_stencil_Z24_S8
;
2258 case MESA_FORMAT_S8_Z24
:
2259 return pack_ubyte_stencil_S8_Z24
;
2260 case MESA_FORMAT_S8
:
2261 return pack_ubyte_stencil_S8
;
2262 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2263 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2266 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2274 _mesa_pack_float_z_row(gl_format format
, GLuint n
,
2275 const GLfloat
*src
, void *dst
)
2278 case MESA_FORMAT_Z24_S8
:
2279 case MESA_FORMAT_Z24_X8
:
2281 /* don't disturb the stencil values */
2282 GLuint
*d
= ((GLuint
*) dst
);
2283 const GLdouble scale
= (GLdouble
) 0xffffff;
2285 for (i
= 0; i
< n
; i
++) {
2286 GLuint s
= d
[i
] & 0xff;
2287 GLuint z
= (GLuint
) (src
[i
] * scale
);
2288 assert(z
<= 0xffffff);
2289 d
[i
] = (z
<< 8) | s
;
2293 case MESA_FORMAT_S8_Z24
:
2294 case MESA_FORMAT_X8_Z24
:
2296 /* don't disturb the stencil values */
2297 GLuint
*d
= ((GLuint
*) dst
);
2298 const GLdouble scale
= (GLdouble
) 0xffffff;
2300 for (i
= 0; i
< n
; i
++) {
2301 GLuint s
= d
[i
] & 0xff000000;
2302 GLuint z
= (GLuint
) (src
[i
] * scale
);
2303 assert(z
<= 0xffffff);
2308 case MESA_FORMAT_Z16
:
2310 GLushort
*d
= ((GLushort
*) dst
);
2311 const GLfloat scale
= (GLfloat
) 0xffff;
2313 for (i
= 0; i
< n
; i
++) {
2314 d
[i
] = (GLushort
) (src
[i
] * scale
);
2318 case MESA_FORMAT_Z32
:
2320 GLuint
*d
= ((GLuint
*) dst
);
2321 const GLdouble scale
= (GLdouble
) 0xffffffff;
2323 for (i
= 0; i
< n
; i
++) {
2324 d
[i
] = (GLuint
) (src
[i
] * scale
);
2328 case MESA_FORMAT_Z32_FLOAT
:
2329 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2331 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2333 GLfloat
*d
= ((GLfloat
*) dst
);
2335 for (i
= 0; i
< n
; i
++) {
2341 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2347 * The incoming Z values are always in the range [0, 0xffffffff].
2350 _mesa_pack_uint_z_row(gl_format format
, GLuint n
,
2351 const GLuint
*src
, void *dst
)
2354 case MESA_FORMAT_Z24_S8
:
2355 case MESA_FORMAT_Z24_X8
:
2357 /* don't disturb the stencil values */
2358 GLuint
*d
= ((GLuint
*) dst
);
2360 for (i
= 0; i
< n
; i
++) {
2361 GLuint s
= d
[i
] & 0xff;
2362 GLuint z
= src
[i
] & 0xffffff00;
2367 case MESA_FORMAT_S8_Z24
:
2368 case MESA_FORMAT_X8_Z24
:
2370 /* don't disturb the stencil values */
2371 GLuint
*d
= ((GLuint
*) dst
);
2373 for (i
= 0; i
< n
; i
++) {
2374 GLuint s
= d
[i
] & 0xff000000;
2375 GLuint z
= src
[i
] >> 8;
2380 case MESA_FORMAT_Z16
:
2382 GLushort
*d
= ((GLushort
*) dst
);
2384 for (i
= 0; i
< n
; i
++) {
2385 d
[i
] = src
[i
] >> 16;
2389 case MESA_FORMAT_Z32
:
2390 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2392 case MESA_FORMAT_Z32_FLOAT
:
2394 GLuint
*d
= ((GLuint
*) dst
);
2395 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2397 for (i
= 0; i
< n
; i
++) {
2398 d
[i
] = src
[i
] * scale
;
2399 assert(d
[i
] >= 0.0f
);
2400 assert(d
[i
] <= 1.0f
);
2404 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2406 GLfloat
*d
= ((GLfloat
*) dst
);
2407 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2409 for (i
= 0; i
< n
; i
++) {
2410 d
[i
* 2] = src
[i
] * scale
;
2411 assert(d
[i
* 2] >= 0.0f
);
2412 assert(d
[i
* 2] <= 1.0f
);
2417 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2423 _mesa_pack_ubyte_stencil_row(gl_format format
, GLuint n
,
2424 const GLubyte
*src
, void *dst
)
2427 case MESA_FORMAT_Z24_S8
:
2429 /* don't disturb the Z values */
2430 GLuint
*d
= ((GLuint
*) dst
);
2432 for (i
= 0; i
< n
; i
++) {
2434 GLuint z
= d
[i
] & 0xffffff00;
2439 case MESA_FORMAT_S8_Z24
:
2441 /* don't disturb the Z values */
2442 GLuint
*d
= ((GLuint
*) dst
);
2444 for (i
= 0; i
< n
; i
++) {
2445 GLuint s
= src
[i
] << 24;
2446 GLuint z
= d
[i
] & 0xffffff;
2451 case MESA_FORMAT_S8
:
2452 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2454 case MESA_FORMAT_Z32_FLOAT_X24S8
:
2458 for (i
= 0; i
< n
; i
++) {
2459 d
[i
* 2 + 1] = src
[i
];
2464 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2470 * Incoming Z/stencil values are always in uint_24_8 format.
2473 _mesa_pack_uint_24_8_depth_stencil_row(gl_format format
, GLuint n
,
2474 const GLuint
*src
, void *dst
)
2477 case MESA_FORMAT_Z24_S8
:
2478 memcpy(dst
, src
, n
* sizeof(GLuint
));
2480 case MESA_FORMAT_S8_Z24
:
2482 GLuint
*d
= ((GLuint
*) dst
);
2484 for (i
= 0; i
< n
; i
++) {
2485 GLuint s
= src
[i
] << 24;
2486 GLuint z
= src
[i
] >> 8;
2492 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2493 _mesa_get_format_name(format
));
2501 * Convert a boolean color mask to a packed color where each channel of
2502 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2505 _mesa_pack_colormask(gl_format format
, const GLubyte colorMask
[4], void *dst
)
2507 GLfloat maskColor
[4];
2509 switch (_mesa_get_format_datatype(format
)) {
2510 case GL_UNSIGNED_NORMALIZED
:
2511 /* simple: 1.0 will convert to ~0 in the right bit positions */
2512 maskColor
[0] = colorMask
[0] ? 1.0 : 0.0;
2513 maskColor
[1] = colorMask
[1] ? 1.0 : 0.0;
2514 maskColor
[2] = colorMask
[2] ? 1.0 : 0.0;
2515 maskColor
[3] = colorMask
[3] ? 1.0 : 0.0;
2516 _mesa_pack_float_rgba_row(format
, 1,
2517 (const GLfloat (*)[4]) maskColor
, dst
);
2519 case GL_SIGNED_NORMALIZED
:
2521 /* These formats are harder because it's hard to know the floating
2522 * point values that will convert to ~0 for each color channel's bits.
2523 * This solution just generates a non-zero value for each color channel
2524 * then fixes up the non-zero values to be ~0.
2525 * Note: we'll need to add special case code if we ever have to deal
2526 * with formats with unequal color channel sizes, like R11_G11_B10.
2527 * We issue a warning below for channel sizes other than 8,16,32.
2530 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2531 GLuint bytes
= _mesa_get_format_bytes(format
);
2534 /* this should put non-zero values into the channels of dst */
2535 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2536 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2537 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2538 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2539 _mesa_pack_float_rgba_row(format
, 1,
2540 (const GLfloat (*)[4]) maskColor
, dst
);
2542 /* fix-up the dst channels by converting non-zero values to ~0 */
2544 GLubyte
*d
= (GLubyte
*) dst
;
2545 for (i
= 0; i
< bytes
; i
++) {
2546 d
[i
] = d
[i
] ? 0xffff : 0x0;
2549 else if (bits
== 16) {
2550 GLushort
*d
= (GLushort
*) dst
;
2551 for (i
= 0; i
< bytes
/ 2; i
++) {
2552 d
[i
] = d
[i
] ? 0xffff : 0x0;
2555 else if (bits
== 32) {
2556 GLuint
*d
= (GLuint
*) dst
;
2557 for (i
= 0; i
< bytes
/ 4; i
++) {
2558 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2562 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2568 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");