2 * Mesa 3-D graphics library
4 * Copyright (c) 2011 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
27 * Color, depth, stencil packing functions.
28 * Used to pack basic color, depth and stencil formats to specific
31 * There are both per-pixel and per-row packing functions:
32 * - The former will be used by swrast to write values to the color, depth,
33 * stencil buffers when drawing points, lines and masked spans.
34 * - The later will be used for image-oriented functions like glDrawPixels,
35 * glAccum, and glTexImage.
40 #include "format_pack.h"
42 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
43 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
44 #include "util/format_srgb.h"
47 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
55 typedef void (*pack_ubyte_rgba_row_func
)(GLuint n
,
56 const GLubyte src
[][4], void *dst
);
58 typedef void (*pack_float_rgba_row_func
)(GLuint n
,
59 const GLfloat src
[][4], void *dst
);
63 * MESA_FORMAT_A8B8G8R8_UNORM
67 pack_ubyte_A8B8G8R8_UNORM(const GLubyte src
[4], void *dst
)
69 GLuint
*d
= ((GLuint
*) dst
);
70 *d
= PACK_COLOR_8888(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
74 pack_float_A8B8G8R8_UNORM(const GLfloat src
[4], void *dst
)
77 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
78 pack_ubyte_A8B8G8R8_UNORM(v
, dst
);
82 pack_row_ubyte_A8B8G8R8_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
84 GLuint
*d
= ((GLuint
*) dst
);
86 for (i
= 0; i
< n
; i
++) {
87 d
[i
] = PACK_COLOR_8888(src
[i
][RCOMP
], src
[i
][GCOMP
],
88 src
[i
][BCOMP
], src
[i
][ACOMP
]);
93 pack_row_float_A8B8G8R8_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
95 GLuint
*d
= ((GLuint
*) dst
);
97 for (i
= 0; i
< n
; i
++) {
99 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
100 pack_ubyte_A8B8G8R8_UNORM(v
, d
+ i
);
107 * MESA_FORMAT_R8G8B8A8_UNORM
111 pack_ubyte_R8G8B8A8_UNORM(const GLubyte src
[4], void *dst
)
113 GLuint
*d
= ((GLuint
*) dst
);
114 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[BCOMP
], src
[GCOMP
], src
[RCOMP
]);
118 pack_float_R8G8B8A8_UNORM(const GLfloat src
[4], void *dst
)
121 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
122 pack_ubyte_R8G8B8A8_UNORM(v
, dst
);
126 pack_row_ubyte_R8G8B8A8_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
128 GLuint
*d
= ((GLuint
*) dst
);
130 for (i
= 0; i
< n
; i
++) {
131 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][BCOMP
],
132 src
[i
][GCOMP
], src
[i
][RCOMP
]);
137 pack_row_float_R8G8B8A8_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
139 GLuint
*d
= ((GLuint
*) dst
);
141 for (i
= 0; i
< n
; i
++) {
143 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
144 pack_ubyte_R8G8B8A8_UNORM(v
, d
+ i
);
150 * MESA_FORMAT_B8G8R8A8_UNORM
154 pack_ubyte_B8G8R8A8_UNORM(const GLubyte src
[4], void *dst
)
156 GLuint
*d
= ((GLuint
*) dst
);
157 *d
= PACK_COLOR_8888(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
161 pack_float_B8G8R8A8_UNORM(const GLfloat src
[4], void *dst
)
164 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
165 pack_ubyte_B8G8R8A8_UNORM(v
, dst
);
169 pack_row_ubyte_B8G8R8A8_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
171 GLuint
*d
= ((GLuint
*) dst
);
173 for (i
= 0; i
< n
; i
++) {
174 d
[i
] = PACK_COLOR_8888(src
[i
][ACOMP
], src
[i
][RCOMP
],
175 src
[i
][GCOMP
], src
[i
][BCOMP
]);
180 pack_row_float_B8G8R8A8_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
182 GLuint
*d
= ((GLuint
*) dst
);
184 for (i
= 0; i
< n
; i
++) {
186 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
187 pack_ubyte_B8G8R8A8_UNORM(v
, d
+ i
);
193 * MESA_FORMAT_A8R8G8B8_UNORM
197 pack_ubyte_A8R8G8B8_UNORM(const GLubyte src
[4], void *dst
)
199 GLuint
*d
= ((GLuint
*) dst
);
200 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
204 pack_float_A8R8G8B8_UNORM(const GLfloat src
[4], void *dst
)
207 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
208 pack_ubyte_A8R8G8B8_UNORM(v
, dst
);
212 pack_row_ubyte_A8R8G8B8_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
214 GLuint
*d
= ((GLuint
*) dst
);
216 for (i
= 0; i
< n
; i
++) {
217 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
],
218 src
[i
][RCOMP
], src
[i
][ACOMP
]);
223 pack_row_float_A8R8G8B8_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
225 GLuint
*d
= ((GLuint
*) dst
);
227 for (i
= 0; i
< n
; i
++) {
229 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
230 pack_ubyte_A8R8G8B8_UNORM(v
, d
+ i
);
236 * MESA_FORMAT_B8G8R8X8_UNORM
240 pack_ubyte_B8G8R8X8_UNORM(const GLubyte src
[4], void *dst
)
242 GLuint
*d
= ((GLuint
*) dst
);
243 *d
= PACK_COLOR_8888(0x0, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
247 pack_float_B8G8R8X8_UNORM(const GLfloat src
[4], void *dst
)
250 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
251 pack_ubyte_B8G8R8X8_UNORM(v
, dst
);
255 pack_row_ubyte_B8G8R8X8_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
257 GLuint
*d
= ((GLuint
*) dst
);
259 for (i
= 0; i
< n
; i
++) {
260 d
[i
] = PACK_COLOR_8888(0, src
[i
][RCOMP
], src
[i
][GCOMP
], src
[i
][BCOMP
]);
265 pack_row_float_B8G8R8X8_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
267 GLuint
*d
= ((GLuint
*) dst
);
269 for (i
= 0; i
< n
; i
++) {
271 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
272 pack_ubyte_B8G8R8X8_UNORM(v
, d
+ i
);
278 * MESA_FORMAT_X8R8G8B8_UNORM
282 pack_ubyte_X8R8G8B8_UNORM(const GLubyte src
[4], void *dst
)
284 GLuint
*d
= ((GLuint
*) dst
);
285 *d
= PACK_COLOR_8888(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], 0);
289 pack_float_X8R8G8B8_UNORM(const GLfloat src
[4], void *dst
)
292 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
293 pack_ubyte_X8R8G8B8_UNORM(v
, dst
);
297 pack_row_ubyte_X8R8G8B8_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
299 GLuint
*d
= ((GLuint
*) dst
);
301 for (i
= 0; i
< n
; i
++) {
302 d
[i
] = PACK_COLOR_8888(src
[i
][BCOMP
], src
[i
][GCOMP
], src
[i
][RCOMP
], 0);
307 pack_row_float_X8R8G8B8_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
309 GLuint
*d
= ((GLuint
*) dst
);
311 for (i
= 0; i
< n
; i
++) {
313 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
314 pack_ubyte_X8R8G8B8_UNORM(v
, d
+ i
);
320 * MESA_FORMAT_BGR_UNORM8
324 pack_ubyte_BGR_UNORM8(const GLubyte src
[4], void *dst
)
326 GLubyte
*d
= ((GLubyte
*) dst
);
333 pack_float_BGR_UNORM8(const GLfloat src
[4], void *dst
)
335 GLubyte
*d
= ((GLubyte
*) dst
);
336 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[RCOMP
]);
337 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
338 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[BCOMP
]);
342 pack_row_ubyte_BGR_UNORM8(GLuint n
, const GLubyte src
[][4], void *dst
)
344 GLubyte
*d
= ((GLubyte
*) dst
);
346 for (i
= 0; i
< n
; i
++) {
347 d
[i
*3+2] = src
[i
][RCOMP
];
348 d
[i
*3+1] = src
[i
][GCOMP
];
349 d
[i
*3+0] = src
[i
][BCOMP
];
354 pack_row_float_BGR_UNORM8(GLuint n
, const GLfloat src
[][4], void *dst
)
356 GLubyte
*d
= ((GLubyte
*) dst
);
358 for (i
= 0; i
< n
; i
++) {
360 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
369 * MESA_FORMAT_RGB_UNORM8
373 pack_ubyte_RGB_UNORM8(const GLubyte src
[4], void *dst
)
375 GLubyte
*d
= ((GLubyte
*) dst
);
382 pack_float_RGB_UNORM8(const GLfloat src
[4], void *dst
)
384 GLubyte
*d
= ((GLubyte
*) dst
);
385 UNCLAMPED_FLOAT_TO_UBYTE(d
[2], src
[BCOMP
]);
386 UNCLAMPED_FLOAT_TO_UBYTE(d
[1], src
[GCOMP
]);
387 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
391 pack_row_ubyte_RGB_UNORM8(GLuint n
, const GLubyte src
[][4], void *dst
)
393 GLubyte
*d
= ((GLubyte
*) dst
);
395 for (i
= 0; i
< n
; i
++) {
396 d
[i
*3+2] = src
[i
][BCOMP
];
397 d
[i
*3+1] = src
[i
][GCOMP
];
398 d
[i
*3+0] = src
[i
][RCOMP
];
403 pack_row_float_RGB_UNORM8(GLuint n
, const GLfloat src
[][4], void *dst
)
405 GLubyte
*d
= ((GLubyte
*) dst
);
407 for (i
= 0; i
< n
; i
++) {
409 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
418 * MESA_FORMAT_B5G6R5_UNORM
422 pack_ubyte_B5G6R5_UNORM(const GLubyte src
[4], void *dst
)
424 GLushort
*d
= ((GLushort
*) dst
);
425 *d
= PACK_COLOR_565(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
429 pack_float_B5G6R5_UNORM(const GLfloat src
[4], void *dst
)
432 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
433 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
434 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
435 pack_ubyte_B5G6R5_UNORM(v
, dst
);
439 pack_row_ubyte_B5G6R5_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
441 GLushort
*d
= ((GLushort
*) dst
);
443 for (i
= 0; i
< n
; i
++) {
444 pack_ubyte_B5G6R5_UNORM(src
[i
], d
+ i
);
449 pack_row_float_B5G6R5_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
451 GLushort
*d
= ((GLushort
*) dst
);
453 for (i
= 0; i
< n
; i
++) {
455 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
456 pack_ubyte_B5G6R5_UNORM(v
, d
+ i
);
462 * MESA_FORMAT_R5G6B5_UNORM
463 * Warning: these functions do not match the current Mesa definition
464 * of MESA_FORMAT_R5G6B5_UNORM.
468 pack_ubyte_R5G6B5_UNORM(const GLubyte src
[4], void *dst
)
470 GLushort
*d
= ((GLushort
*) dst
);
471 *d
= PACK_COLOR_565_REV(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
475 pack_float_R5G6B5_UNORM(const GLfloat src
[4], void *dst
)
477 GLushort
*d
= ((GLushort
*) dst
);
479 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
480 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
481 UNCLAMPED_FLOAT_TO_UBYTE(b
, src
[BCOMP
]);
482 *d
= PACK_COLOR_565_REV(r
, g
, b
);
486 pack_row_ubyte_R5G6B5_UNORM(GLuint n
, const GLubyte src
[][4], void *dst
)
488 GLushort
*d
= ((GLushort
*) dst
);
490 for (i
= 0; i
< n
; i
++) {
491 pack_ubyte_R5G6B5_UNORM(src
[i
], d
+ i
);
496 pack_row_float_R5G6B5_UNORM(GLuint n
, const GLfloat src
[][4], void *dst
)
498 GLushort
*d
= ((GLushort
*) dst
);
500 for (i
= 0; i
< n
; i
++) {
502 _mesa_unclamped_float_rgba_to_ubyte(v
, src
[i
]);
503 pack_ubyte_R5G6B5_UNORM(v
, d
+ i
);
509 * MESA_FORMAT_B4G4R4A4_UNORM
513 pack_ubyte_B4G4R4A4_UNORM(const GLubyte src
[4], void *dst
)
515 GLushort
*d
= ((GLushort
*) dst
);
516 *d
= PACK_COLOR_4444(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
520 pack_float_B4G4R4A4_UNORM(const GLfloat src
[4], void *dst
)
523 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
524 pack_ubyte_B4G4R4A4_UNORM(v
, dst
);
527 /* use fallback row packing functions */
531 * MESA_FORMAT_A4R4G4B4_UNORM
535 pack_ubyte_A4R4G4B4_UNORM(const GLubyte src
[4], void *dst
)
537 GLushort
*d
= ((GLushort
*) dst
);
538 *d
= PACK_COLOR_4444(src
[BCOMP
], src
[GCOMP
], src
[RCOMP
], src
[ACOMP
]);
542 pack_float_A4R4G4B4_UNORM(const GLfloat src
[4], void *dst
)
545 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
546 pack_ubyte_A4R4G4B4_UNORM(v
, dst
);
549 /* use fallback row packing functions */
553 * MESA_FORMAT_A1B5G5R5_UNORM
557 pack_ubyte_A1B5G5R5_UNORM(const GLubyte src
[4], void *dst
)
559 GLushort
*d
= ((GLushort
*) dst
);
560 *d
= PACK_COLOR_5551(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
], src
[ACOMP
]);
564 pack_float_A1B5G5R5_UNORM(const GLfloat src
[4], void *dst
)
567 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
568 pack_ubyte_A1B5G5R5_UNORM(v
, dst
);
571 /* use fallback row packing functions */
575 * MESA_FORMAT_B5G5R5A1_UNORM
579 pack_ubyte_B5G5R5A1_UNORM(const GLubyte src
[4], void *dst
)
581 GLushort
*d
= ((GLushort
*) dst
);
582 *d
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
586 pack_float_B5G5R5A1_UNORM(const GLfloat src
[4], void *dst
)
589 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
590 pack_ubyte_B5G5R5A1_UNORM(v
, dst
);
594 /* MESA_FORMAT_A1R5G5B5_UNORM
595 * Warning: these functions do not match the current Mesa definition
596 * of MESA_FORMAT_A1R5G5B5_UNORM.
600 pack_ubyte_A1R5G5B5_UNORM(const GLubyte src
[4], void *dst
)
602 GLushort
*d
= ((GLushort
*) dst
), tmp
;
603 tmp
= PACK_COLOR_1555(src
[ACOMP
], src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
604 *d
= (tmp
>> 8) | (tmp
<< 8);
608 pack_float_A1R5G5B5_UNORM(const GLfloat src
[4], void *dst
)
611 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
612 pack_ubyte_A1R5G5B5_UNORM(v
, dst
);
616 /* MESA_FORMAT_L4A4_UNORM */
619 pack_ubyte_L4A4_UNORM(const GLubyte src
[4], void *dst
)
621 GLubyte
*d
= ((GLubyte
*) dst
);
622 *d
= PACK_COLOR_44(src
[ACOMP
], src
[RCOMP
]);
626 pack_float_L4A4_UNORM(const GLfloat src
[4], void *dst
)
629 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
630 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
631 pack_ubyte_L4A4_UNORM(v
, dst
);
635 /* MESA_FORMAT_L8A8_UNORM */
638 pack_ubyte_L8A8_UNORM(const GLubyte src
[4], void *dst
)
640 GLushort
*d
= ((GLushort
*) dst
);
641 *d
= PACK_COLOR_88(src
[ACOMP
], src
[RCOMP
]);
645 pack_float_L8A8_UNORM(const GLfloat src
[4], void *dst
)
648 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
649 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
650 pack_ubyte_L8A8_UNORM(v
, dst
);
654 /* MESA_FORMAT_A8L8_UNORM */
657 pack_ubyte_A8L8_UNORM(const GLubyte src
[4], void *dst
)
659 GLushort
*d
= ((GLushort
*) dst
);
660 *d
= PACK_COLOR_88(src
[RCOMP
], src
[ACOMP
]);
664 pack_float_A8L8_UNORM(const GLfloat src
[4], void *dst
)
667 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
668 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], src
[ACOMP
]);
669 pack_ubyte_A8L8_UNORM(v
, dst
);
673 /* MESA_FORMAT_L16A16_UNORM */
676 pack_ubyte_L16A16_UNORM(const GLubyte src
[4], void *dst
)
678 GLuint
*d
= ((GLuint
*) dst
);
679 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
680 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
681 *d
= PACK_COLOR_1616(a
, l
);
685 pack_float_L16A16_UNORM(const GLfloat src
[4], void *dst
)
687 GLuint
*d
= ((GLuint
*) dst
);
689 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
690 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
691 *d
= PACK_COLOR_1616(a
, l
);
695 /* MESA_FORMAT_A16L16_UNORM */
698 pack_ubyte_A16L16_UNORM(const GLubyte src
[4], void *dst
)
700 GLuint
*d
= ((GLuint
*) dst
);
701 GLushort l
= UBYTE_TO_USHORT(src
[RCOMP
]);
702 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
703 *d
= PACK_COLOR_1616(l
, a
);
707 pack_float_A16L16_UNORM(const GLfloat src
[4], void *dst
)
709 GLuint
*d
= ((GLuint
*) dst
);
711 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[RCOMP
]);
712 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
713 *d
= PACK_COLOR_1616(l
, a
);
717 /* MESA_FORMAT_B2G3R3_UNORM */
720 pack_ubyte_B2G3R3_UNORM(const GLubyte src
[4], void *dst
)
722 GLubyte
*d
= ((GLubyte
*) dst
);
723 *d
= PACK_COLOR_332(src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
727 pack_float_B2G3R3_UNORM(const GLfloat src
[4], void *dst
)
730 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], src
[RCOMP
]);
731 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], src
[GCOMP
]);
732 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], src
[BCOMP
]);
733 pack_ubyte_B2G3R3_UNORM(v
, dst
);
737 /* MESA_FORMAT_A_UNORM8 */
740 pack_ubyte_A_UNORM8(const GLubyte src
[4], void *dst
)
742 GLubyte
*d
= ((GLubyte
*) dst
);
747 pack_float_A_UNORM8(const GLfloat src
[4], void *dst
)
749 GLubyte
*d
= ((GLubyte
*) dst
);
750 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[ACOMP
]);
754 /* MESA_FORMAT_A_UNORM16 */
757 pack_ubyte_A_UNORM16(const GLubyte src
[4], void *dst
)
759 GLushort
*d
= ((GLushort
*) dst
);
760 *d
= UBYTE_TO_USHORT(src
[ACOMP
]);
764 pack_float_A_UNORM16(const GLfloat src
[4], void *dst
)
766 GLushort
*d
= ((GLushort
*) dst
);
767 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[ACOMP
]);
771 /* MESA_FORMAT_L_UNORM8 */
774 pack_ubyte_L_UNORM8(const GLubyte src
[4], void *dst
)
776 GLubyte
*d
= ((GLubyte
*) dst
);
781 pack_float_L_UNORM8(const GLfloat src
[4], void *dst
)
783 GLubyte
*d
= ((GLubyte
*) dst
);
784 UNCLAMPED_FLOAT_TO_UBYTE(d
[0], src
[RCOMP
]);
788 /* MESA_FORMAT_L_UNORM16 */
791 pack_ubyte_L_UNORM16(const GLubyte src
[4], void *dst
)
793 GLushort
*d
= ((GLushort
*) dst
);
794 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
798 pack_float_L_UNORM16(const GLfloat src
[4], void *dst
)
800 GLushort
*d
= ((GLushort
*) dst
);
801 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
805 /* MESA_FORMAT_YCBCR */
808 pack_ubyte_YCBCR(const GLubyte src
[4], void *dst
)
814 pack_float_YCBCR(const GLfloat src
[4], void *dst
)
820 /* MESA_FORMAT_YCBCR_REV */
823 pack_ubyte_YCBCR_REV(const GLubyte src
[4], void *dst
)
829 pack_float_YCBCR_REV(const GLfloat src
[4], void *dst
)
835 /* MESA_FORMAT_R_UNORM8 */
838 pack_ubyte_R_UNORM8(const GLubyte src
[4], void *dst
)
840 GLubyte
*d
= ((GLubyte
*) dst
);
845 pack_float_R_UNORM8(const GLfloat src
[4], void *dst
)
847 GLubyte
*d
= ((GLubyte
*) dst
);
849 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
854 /* MESA_FORMAT_R8G8_UNORM */
857 pack_ubyte_R8G8_UNORM(const GLubyte src
[4], void *dst
)
859 GLushort
*d
= ((GLushort
*) dst
);
860 *d
= PACK_COLOR_88(src
[GCOMP
], src
[RCOMP
]);
864 pack_float_R8G8_UNORM(const GLfloat src
[4], void *dst
)
866 GLushort
*d
= ((GLushort
*) dst
);
868 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
869 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
870 *d
= PACK_COLOR_88(g
, r
);
874 /* MESA_FORMAT_G8R8_UNORM */
877 pack_ubyte_G8R8_UNORM(const GLubyte src
[4], void *dst
)
879 GLubyte
*d
= ((GLubyte
*) dst
);
880 *d
= PACK_COLOR_88(src
[RCOMP
], src
[GCOMP
]);
884 pack_float_G8R8_UNORM(const GLfloat src
[4], void *dst
)
886 GLushort
*d
= ((GLushort
*) dst
);
888 UNCLAMPED_FLOAT_TO_UBYTE(r
, src
[RCOMP
]);
889 UNCLAMPED_FLOAT_TO_UBYTE(g
, src
[GCOMP
]);
890 *d
= PACK_COLOR_88(r
, g
);
894 /* MESA_FORMAT_R_UNORM16 */
897 pack_ubyte_R_UNORM16(const GLubyte src
[4], void *dst
)
899 GLushort
*d
= ((GLushort
*) dst
);
900 *d
= UBYTE_TO_USHORT(src
[RCOMP
]);
904 pack_float_R_UNORM16(const GLfloat src
[4], void *dst
)
906 GLushort
*d
= ((GLushort
*) dst
);
907 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
911 /* MESA_FORMAT_R16G16_UNORM */
914 pack_ubyte_R16G16_UNORM(const GLubyte src
[4], void *dst
)
916 GLuint
*d
= ((GLuint
*) dst
);
917 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
918 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
919 *d
= PACK_COLOR_1616(g
, r
);
923 pack_float_R16G16_UNORM(const GLfloat src
[4], void *dst
)
925 GLuint
*d
= ((GLuint
*) dst
);
927 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
928 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
929 *d
= PACK_COLOR_1616(g
, r
);
933 /* MESA_FORMAT_G16R16_UNORM */
936 pack_ubyte_G16R16_UNORM(const GLubyte src
[4], void *dst
)
938 GLuint
*d
= ((GLuint
*) dst
);
939 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
940 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
941 *d
= PACK_COLOR_1616(r
, g
);
946 pack_float_G16R16_UNORM(const GLfloat src
[4], void *dst
)
948 GLuint
*d
= ((GLuint
*) dst
);
950 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
951 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
952 *d
= PACK_COLOR_1616(r
, g
);
956 /* MESA_FORMAT_B10G10R10A2_UNORM */
959 pack_ubyte_B10G10R10A2_UNORM(const GLubyte src
[4], void *dst
)
961 GLuint
*d
= ((GLuint
*) dst
);
962 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
963 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
964 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
965 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
966 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
970 pack_float_B10G10R10A2_UNORM(const GLfloat src
[4], void *dst
)
972 GLuint
*d
= ((GLuint
*) dst
);
974 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
975 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
976 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
977 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
978 *d
= PACK_COLOR_2101010_US(a
, r
, g
, b
);
982 /* MESA_FORMAT_R10G10B10A2_UINT */
985 pack_ubyte_R10G10B10A2_UINT(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
, b
, g
, r
);
996 pack_float_R10G10B10A2_UINT(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
, b
, g
, r
);
1008 /* MESA_FORMAT_BGR_SRGB8 */
1011 pack_ubyte_BGR_SRGB8(const GLubyte src
[4], void *dst
)
1013 GLubyte
*d
= ((GLubyte
*) dst
);
1014 d
[2] = util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1015 d
[1] = util_format_linear_to_srgb_8unorm(src
[GCOMP
]);
1016 d
[0] = util_format_linear_to_srgb_8unorm(src
[BCOMP
]);
1020 pack_float_BGR_SRGB8(const GLfloat src
[4], void *dst
)
1022 GLubyte
*d
= ((GLubyte
*) dst
);
1023 d
[2] = util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1024 d
[1] = util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1025 d
[0] = util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1029 /* MESA_FORMAT_A8B8G8R8_SRGB */
1032 pack_ubyte_A8B8G8R8_SRGB(const GLubyte src
[4], void *dst
)
1034 GLuint
*d
= ((GLuint
*) dst
);
1035 GLubyte r
= util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1036 GLubyte g
= util_format_linear_to_srgb_8unorm(src
[GCOMP
]);
1037 GLubyte b
= util_format_linear_to_srgb_8unorm(src
[BCOMP
]);
1038 *d
= PACK_COLOR_8888(r
, g
, b
, src
[ACOMP
]);
1042 pack_float_A8B8G8R8_SRGB(const GLfloat src
[4], void *dst
)
1044 GLuint
*d
= ((GLuint
*) dst
);
1046 r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1047 g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1048 b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1049 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1050 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1054 /* MESA_FORMAT_B8G8R8A8_SRGB */
1057 pack_ubyte_B8G8R8A8_SRGB(const GLubyte src
[4], void *dst
)
1059 GLuint
*d
= ((GLuint
*) dst
);
1060 GLubyte r
= util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1061 GLubyte g
= util_format_linear_to_srgb_8unorm(src
[GCOMP
]);
1062 GLubyte b
= util_format_linear_to_srgb_8unorm(src
[BCOMP
]);
1063 *d
= PACK_COLOR_8888(src
[ACOMP
], r
, g
, b
);
1067 pack_float_B8G8R8A8_SRGB(const GLfloat src
[4], void *dst
)
1069 GLuint
*d
= ((GLuint
*) dst
);
1071 r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1072 g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1073 b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1074 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1075 *d
= PACK_COLOR_8888(a
, r
, g
, b
);
1079 /* MESA_FORMAT_A8R8G8B8_SRGB */
1082 pack_ubyte_A8R8G8B8_SRGB(const GLubyte src
[4], void *dst
)
1084 GLuint
*d
= ((GLuint
*) dst
);
1085 GLubyte r
= util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1086 GLubyte g
= util_format_linear_to_srgb_8unorm(src
[GCOMP
]);
1087 GLubyte b
= util_format_linear_to_srgb_8unorm(src
[BCOMP
]);
1088 *d
= PACK_COLOR_8888(b
, g
, r
, src
[ACOMP
]);
1092 pack_float_A8R8G8B8_SRGB(const GLfloat src
[4], void *dst
)
1094 GLuint
*d
= ((GLuint
*) dst
);
1096 r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1097 g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1098 b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1099 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1100 *d
= PACK_COLOR_8888(b
, g
, r
, a
);
1104 /* MESA_FORMAT_R8G8B8A8_SRGB */
1107 pack_ubyte_R8G8B8A8_SRGB(const GLubyte src
[4], void *dst
)
1109 GLuint
*d
= ((GLuint
*) dst
);
1110 GLubyte r
= util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1111 GLubyte g
= util_format_linear_to_srgb_8unorm(src
[GCOMP
]);
1112 GLubyte b
= util_format_linear_to_srgb_8unorm(src
[BCOMP
]);
1113 *d
= PACK_COLOR_8888(src
[ACOMP
], b
, g
, r
);
1117 pack_float_R8G8B8A8_SRGB(const GLfloat src
[4], void *dst
)
1119 GLuint
*d
= ((GLuint
*) dst
);
1121 r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1122 g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1123 b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1124 UNCLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1125 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1129 /* MESA_FORMAT_L_SRGB8 */
1132 pack_ubyte_L_SRGB8(const GLubyte src
[4], void *dst
)
1134 GLubyte
*d
= ((GLubyte
*) dst
);
1135 *d
= util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1139 pack_float_L_SRGB8(const GLfloat src
[4], void *dst
)
1141 GLubyte
*d
= ((GLubyte
*) dst
);
1142 GLubyte l
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1147 /* MESA_FORMAT_L8A8_SRGB */
1150 pack_ubyte_L8A8_SRGB(const GLubyte src
[4], void *dst
)
1152 GLushort
*d
= ((GLushort
*) dst
);
1153 GLubyte l
= util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1154 *d
= PACK_COLOR_88(src
[ACOMP
], l
);
1157 /* MESA_FORMAT_A8L8_SRGB */
1160 pack_ubyte_A8L8_SRGB(const GLubyte src
[4], void *dst
)
1162 GLushort
*d
= ((GLushort
*) dst
);
1163 GLubyte l
= util_format_linear_to_srgb_8unorm(src
[RCOMP
]);
1164 *d
= PACK_COLOR_88(l
, src
[ACOMP
]);
1168 pack_float_L8A8_SRGB(const GLfloat src
[4], void *dst
)
1170 GLushort
*d
= ((GLushort
*) dst
);
1171 GLubyte a
, l
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1172 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1173 *d
= PACK_COLOR_88(a
, l
);
1177 pack_float_A8L8_SRGB(const GLfloat src
[4], void *dst
)
1179 GLushort
*d
= ((GLushort
*) dst
);
1180 GLubyte a
, l
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1181 CLAMPED_FLOAT_TO_UBYTE(a
, src
[ACOMP
]);
1182 *d
= PACK_COLOR_88(l
, a
);
1186 /* MESA_FORMAT_RGBA_FLOAT32 */
1189 pack_ubyte_RGBA_FLOAT32(const GLubyte src
[4], void *dst
)
1191 GLfloat
*d
= ((GLfloat
*) dst
);
1192 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1193 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1194 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1195 d
[3] = UBYTE_TO_FLOAT(src
[3]);
1199 pack_float_RGBA_FLOAT32(const GLfloat src
[4], void *dst
)
1201 GLfloat
*d
= ((GLfloat
*) dst
);
1209 /* MESA_FORMAT_RGBA_FLOAT16 */
1212 pack_ubyte_RGBA_FLOAT16(const GLubyte src
[4], void *dst
)
1214 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1215 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1216 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1217 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1218 d
[3] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[3]));
1222 pack_float_RGBA_FLOAT16(const GLfloat src
[4], void *dst
)
1224 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1225 d
[0] = _mesa_float_to_half(src
[0]);
1226 d
[1] = _mesa_float_to_half(src
[1]);
1227 d
[2] = _mesa_float_to_half(src
[2]);
1228 d
[3] = _mesa_float_to_half(src
[3]);
1232 /* MESA_FORMAT_RGB_FLOAT32 */
1235 pack_ubyte_RGB_FLOAT32(const GLubyte src
[4], void *dst
)
1237 GLfloat
*d
= ((GLfloat
*) dst
);
1238 d
[0] = UBYTE_TO_FLOAT(src
[0]);
1239 d
[1] = UBYTE_TO_FLOAT(src
[1]);
1240 d
[2] = UBYTE_TO_FLOAT(src
[2]);
1244 pack_float_RGB_FLOAT32(const GLfloat src
[4], void *dst
)
1246 GLfloat
*d
= ((GLfloat
*) dst
);
1253 /* MESA_FORMAT_RGB_FLOAT16 */
1256 pack_ubyte_RGB_FLOAT16(const GLubyte src
[4], void *dst
)
1258 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1259 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[0]));
1260 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[1]));
1261 d
[2] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[2]));
1265 pack_float_RGB_FLOAT16(const GLfloat src
[4], void *dst
)
1267 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1268 d
[0] = _mesa_float_to_half(src
[0]);
1269 d
[1] = _mesa_float_to_half(src
[1]);
1270 d
[2] = _mesa_float_to_half(src
[2]);
1274 /* MESA_FORMAT_A_FLOAT32 */
1277 pack_ubyte_A_FLOAT32(const GLubyte src
[4], void *dst
)
1279 GLfloat
*d
= ((GLfloat
*) dst
);
1280 d
[0] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1284 pack_float_A_FLOAT32(const GLfloat src
[4], void *dst
)
1286 GLfloat
*d
= ((GLfloat
*) dst
);
1291 /* MESA_FORMAT_A_FLOAT16 */
1294 pack_ubyte_A_FLOAT16(const GLubyte src
[4], void *dst
)
1296 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1297 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1301 pack_float_A_FLOAT16(const GLfloat src
[4], void *dst
)
1303 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1304 d
[0] = _mesa_float_to_half(src
[ACOMP
]);
1308 /* MESA_FORMAT_L_FLOAT32 (and I_FLOAT32, R_FLOAT32) */
1311 pack_ubyte_L_FLOAT32(const GLubyte src
[4], void *dst
)
1313 GLfloat
*d
= ((GLfloat
*) dst
);
1314 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1318 pack_float_L_FLOAT32(const GLfloat src
[4], void *dst
)
1320 GLfloat
*d
= ((GLfloat
*) dst
);
1325 /* MESA_FORMAT_L_FLOAT16 (and I_FLOAT16, R_FLOAT32) */
1328 pack_ubyte_L_FLOAT16(const GLubyte src
[4], void *dst
)
1330 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1331 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1335 pack_float_L_FLOAT16(const GLfloat src
[4], void *dst
)
1337 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1338 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1342 /* MESA_FORMAT_LA_FLOAT32 */
1345 pack_ubyte_LA_FLOAT32(const GLubyte src
[4], void *dst
)
1347 GLfloat
*d
= ((GLfloat
*) dst
);
1348 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1349 d
[1] = UBYTE_TO_FLOAT(src
[ACOMP
]);
1353 pack_float_LA_FLOAT32(const GLfloat src
[4], void *dst
)
1355 GLfloat
*d
= ((GLfloat
*) dst
);
1361 /* MESA_FORMAT_LA_FLOAT16 */
1364 pack_ubyte_LA_FLOAT16(const GLubyte src
[4], void *dst
)
1366 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1367 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1368 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[ACOMP
]));
1372 pack_float_LA_FLOAT16(const GLfloat src
[4], void *dst
)
1374 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1375 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1376 d
[1] = _mesa_float_to_half(src
[ACOMP
]);
1380 /* MESA_FORMAT_RG_FLOAT32 */
1383 pack_ubyte_RG_FLOAT32(const GLubyte src
[4], void *dst
)
1385 GLfloat
*d
= ((GLfloat
*) dst
);
1386 d
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1387 d
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1391 pack_float_RG_FLOAT32(const GLfloat src
[4], void *dst
)
1393 GLfloat
*d
= ((GLfloat
*) dst
);
1399 /* MESA_FORMAT_RG_FLOAT16 */
1402 pack_ubyte_RG_FLOAT16(const GLubyte src
[4], void *dst
)
1404 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1405 d
[0] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[RCOMP
]));
1406 d
[1] = _mesa_float_to_half(UBYTE_TO_FLOAT(src
[GCOMP
]));
1410 pack_float_RG_FLOAT16(const GLfloat src
[4], void *dst
)
1412 GLhalfARB
*d
= ((GLhalfARB
*) dst
);
1413 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1414 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1418 /* MESA_FORMAT_RGBA_UNORM16 */
1421 pack_ubyte_RGBA_16(const GLubyte src
[4], void *dst
)
1423 GLushort
*d
= ((GLushort
*) dst
);
1424 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1425 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1426 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1427 d
[3] = UBYTE_TO_USHORT(src
[ACOMP
]);
1431 pack_float_RGBA_16(const GLfloat src
[4], void *dst
)
1433 GLushort
*d
= ((GLushort
*) dst
);
1434 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1435 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1436 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1437 UNCLAMPED_FLOAT_TO_USHORT(d
[3], src
[ACOMP
]);
1443 * MESA_FORMAT_R_SNORM8
1447 pack_float_R_SNORM8(const GLfloat src
[4], void *dst
)
1449 GLbyte
*d
= (GLbyte
*) dst
;
1450 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1455 * MESA_FORMAT_R8G8_SNORM
1459 pack_float_R8G8_SNORM(const GLfloat src
[4], void *dst
)
1461 GLushort
*d
= (GLushort
*) dst
;
1462 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1463 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1469 * MESA_FORMAT_X8B8G8R8_SNORM
1473 pack_float_X8B8G8R8_SNORM(const GLfloat src
[4], void *dst
)
1475 GLuint
*d
= (GLuint
*) dst
;
1476 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1477 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1478 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1480 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1485 * MESA_FORMAT_A8B8G8R8_SNORM
1489 pack_float_A8B8G8R8_SNORM(const GLfloat src
[4], void *dst
)
1491 GLuint
*d
= (GLuint
*) dst
;
1492 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1493 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1494 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1495 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1496 *d
= PACK_COLOR_8888(r
, g
, b
, a
);
1501 * MESA_FORMAT_R8G8B8A8_SNORM
1505 pack_float_R8G8B8A8_SNORM(const GLfloat src
[4], void *dst
)
1507 GLuint
*d
= (GLuint
*) dst
;
1508 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1509 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1510 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1511 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1512 *d
= PACK_COLOR_8888(a
, b
, g
, r
);
1517 * MESA_FORMAT_R_SNORM16
1521 pack_float_R_SNORM16(const GLfloat src
[4], void *dst
)
1523 GLshort
*d
= (GLshort
*) dst
;
1524 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1529 * MESA_FORMAT_R16G16_SNORM
1533 pack_float_R16G16_SNORM(const GLfloat src
[4], void *dst
)
1535 GLuint
*d
= (GLuint
*) dst
;
1536 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1537 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1538 *d
= (g
<< 16) | (r
& 0xffff);
1543 * MESA_FORMAT_RGB_SNORM16
1547 pack_float_RGB_SNORM16(const GLfloat src
[4], void *dst
)
1549 GLshort
*d
= (GLshort
*) dst
;
1550 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1551 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1552 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1557 * MESA_FORMAT_RGBA_SNORM16
1561 pack_float_RGBA_SNORM16(const GLfloat src
[4], void *dst
)
1563 GLshort
*d
= (GLshort
*) dst
;
1564 d
[0] = FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1565 d
[1] = FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1566 d
[2] = FLOAT_TO_SHORT(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1567 d
[3] = FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1572 * MESA_FORMAT_A_SNORM8
1576 pack_float_A_SNORM8(const GLfloat src
[4], void *dst
)
1578 GLbyte
*d
= (GLbyte
*) dst
;
1579 *d
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1584 * MESA_FORMAT_L_SNORM8
1588 pack_float_L_SNORM8(const GLfloat src
[4], void *dst
)
1590 GLbyte
*d
= (GLbyte
*) dst
;
1591 *d
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1596 * MESA_FORMAT_L8A8_SNORM
1600 pack_float_L8A8_SNORM(const GLfloat src
[4], void *dst
)
1602 GLushort
*d
= (GLushort
*) dst
;
1603 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1604 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1610 * MESA_FORMAT_A8L8_SNORM
1614 pack_float_A8L8_SNORM(const GLfloat src
[4], void *dst
)
1616 GLushort
*d
= (GLushort
*) dst
;
1617 GLbyte l
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1618 GLbyte a
= FLOAT_TO_BYTE(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1624 * MESA_FORMAT_A_SNORM16
1628 pack_float_A_SNORM16(const GLfloat src
[4], void *dst
)
1630 GLshort
*d
= (GLshort
*) dst
;
1631 *d
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1636 * MESA_FORMAT_L_SNORM16
1640 pack_float_L_SNORM16(const GLfloat src
[4], void *dst
)
1642 GLshort
*d
= (GLshort
*) dst
;
1643 *d
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1648 * MESA_FORMAT_LA_SNORM16
1652 pack_float_LA_SNORM16(const GLfloat src
[4], void *dst
)
1654 GLuint
*d
= (GLuint
*) dst
;
1655 GLshort l
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1656 GLshort a
= FLOAT_TO_SHORT(CLAMP(src
[ACOMP
], -1.0f
, 1.0f
));
1657 *d
= PACK_COLOR_1616(a
, l
);
1662 * MESA_FORMAT_R9G9B9E5_FLOAT;
1666 pack_float_R9G9B9E5_FLOAT(const GLfloat src
[4], void *dst
)
1668 GLuint
*d
= (GLuint
*) dst
;
1669 *d
= float3_to_rgb9e5(src
);
1673 pack_ubyte_R9G9B9E5_FLOAT(const GLubyte src
[4], void *dst
)
1675 GLuint
*d
= (GLuint
*) dst
;
1677 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1678 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1679 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1680 *d
= float3_to_rgb9e5(rgb
);
1686 * MESA_FORMAT_R11G11B10_FLOAT;
1690 pack_ubyte_R11G11B10_FLOAT(const GLubyte src
[4], void *dst
)
1692 GLuint
*d
= (GLuint
*) dst
;
1694 rgb
[0] = UBYTE_TO_FLOAT(src
[RCOMP
]);
1695 rgb
[1] = UBYTE_TO_FLOAT(src
[GCOMP
]);
1696 rgb
[2] = UBYTE_TO_FLOAT(src
[BCOMP
]);
1697 *d
= float3_to_r11g11b10f(rgb
);
1701 pack_float_R11G11B10_FLOAT(const GLfloat src
[4], void *dst
)
1703 GLuint
*d
= (GLuint
*) dst
;
1704 *d
= float3_to_r11g11b10f(src
);
1709 * MESA_FORMAT_B4G4R4X4_UNORM
1713 pack_ubyte_XRGB4444_UNORM(const GLubyte src
[4], void *dst
)
1715 GLushort
*d
= ((GLushort
*) dst
);
1716 *d
= PACK_COLOR_4444(255, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
1720 pack_float_XRGB4444_UNORM(const GLfloat src
[4], void *dst
)
1723 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
1724 pack_ubyte_XRGB4444_UNORM(v
, dst
);
1729 * MESA_FORMAT_B5G5R5X1_UNORM
1733 pack_ubyte_XRGB1555_UNORM(const GLubyte src
[4], void *dst
)
1735 GLushort
*d
= ((GLushort
*) dst
);
1736 *d
= PACK_COLOR_1555(255, src
[RCOMP
], src
[GCOMP
], src
[BCOMP
]);
1740 pack_float_XRGB1555_UNORM(const GLfloat src
[4], void *dst
)
1743 _mesa_unclamped_float_rgba_to_ubyte(v
, src
);
1744 pack_ubyte_XRGB1555_UNORM(v
, dst
);
1749 * MESA_FORMAT_R8G8B8X8_SNORM
1753 pack_float_XBGR8888_SNORM(const GLfloat src
[4], void *dst
)
1755 GLuint
*d
= (GLuint
*) dst
;
1756 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1757 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1758 GLbyte b
= FLOAT_TO_BYTE(CLAMP(src
[BCOMP
], -1.0f
, 1.0f
));
1759 *d
= PACK_COLOR_8888(127, b
, g
, r
);
1764 * MESA_FORMAT_R8G8B8X8_SRGB
1768 pack_float_R8G8B8X8_SRGB(const GLfloat src
[4], void *dst
)
1770 GLuint
*d
= (GLuint
*) dst
;
1771 GLubyte r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1772 GLubyte g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1773 GLubyte b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1774 *d
= PACK_COLOR_8888(255, b
, g
, r
);
1779 * MESA_FORMAT_X8B8G8R8_SRGB
1783 pack_float_X8B8G8R8_SRGB(const GLfloat src
[4], void *dst
)
1785 GLuint
*d
= (GLuint
*) dst
;
1786 GLubyte r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1787 GLubyte g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1788 GLubyte b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1789 *d
= PACK_COLOR_8888(r
, g
, b
, 255);
1793 /* MESA_FORMAT_B10G10R10X2_UNORM */
1796 pack_ubyte_B10G10R10X2_UNORM(const GLubyte src
[4], void *dst
)
1798 GLuint
*d
= ((GLuint
*) dst
);
1799 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
1800 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
1801 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
1802 *d
= PACK_COLOR_2101010_US(3, r
, g
, b
);
1806 pack_float_B10G10R10X2_UNORM(const GLfloat src
[4], void *dst
)
1808 GLuint
*d
= ((GLuint
*) dst
);
1810 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1811 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1812 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1813 *d
= PACK_COLOR_2101010_US(3, r
, g
, b
);
1817 /* MESA_FORMAT_RGBX_UNORM16 */
1820 pack_ubyte_RGBX_UNORM16(const GLubyte src
[4], void *dst
)
1822 GLushort
*d
= ((GLushort
*) dst
);
1823 d
[0] = UBYTE_TO_USHORT(src
[RCOMP
]);
1824 d
[1] = UBYTE_TO_USHORT(src
[GCOMP
]);
1825 d
[2] = UBYTE_TO_USHORT(src
[BCOMP
]);
1830 pack_float_RGBX_UNORM16(const GLfloat src
[4], void *dst
)
1832 GLushort
*d
= ((GLushort
*) dst
);
1833 UNCLAMPED_FLOAT_TO_USHORT(d
[0], src
[RCOMP
]);
1834 UNCLAMPED_FLOAT_TO_USHORT(d
[1], src
[GCOMP
]);
1835 UNCLAMPED_FLOAT_TO_USHORT(d
[2], src
[BCOMP
]);
1840 /* MESA_FORMAT_RGBX_SNORM16 */
1843 pack_float_RGBX_SNORM16(const GLfloat src
[4], void *dst
)
1845 GLushort
*d
= ((GLushort
*) dst
);
1846 UNCLAMPED_FLOAT_TO_SHORT(d
[0], src
[RCOMP
]);
1847 UNCLAMPED_FLOAT_TO_SHORT(d
[1], src
[GCOMP
]);
1848 UNCLAMPED_FLOAT_TO_SHORT(d
[2], src
[BCOMP
]);
1853 /* MESA_FORMAT_RGBX_FLOAT16 */
1856 pack_float_XBGR16161616_FLOAT(const GLfloat src
[4], void *dst
)
1858 GLushort
*d
= ((GLushort
*) dst
);
1859 d
[0] = _mesa_float_to_half(src
[RCOMP
]);
1860 d
[1] = _mesa_float_to_half(src
[GCOMP
]);
1861 d
[2] = _mesa_float_to_half(src
[BCOMP
]);
1862 d
[3] = _mesa_float_to_half(1.0);
1865 /* MESA_FORMAT_RGBX_FLOAT32 */
1868 pack_float_RGBX_FLOAT32(const GLfloat src
[4], void *dst
)
1870 GLfloat
*d
= ((GLfloat
*) dst
);
1877 /* MESA_FORMAT_R10G10B10A2_UNORM */
1880 pack_ubyte_R10G10B10A2_UNORM(const GLubyte src
[4], void *dst
)
1882 GLuint
*d
= ((GLuint
*) dst
);
1883 GLushort r
= UBYTE_TO_USHORT(src
[RCOMP
]);
1884 GLushort g
= UBYTE_TO_USHORT(src
[GCOMP
]);
1885 GLushort b
= UBYTE_TO_USHORT(src
[BCOMP
]);
1886 GLushort a
= UBYTE_TO_USHORT(src
[ACOMP
]);
1887 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1891 pack_float_R10G10B10A2_UNORM(const GLfloat src
[4], void *dst
)
1893 GLuint
*d
= ((GLuint
*) dst
);
1894 GLushort r
, g
, b
, a
;
1895 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1896 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1897 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1898 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1899 *d
= PACK_COLOR_2101010_US(a
, b
, g
, r
);
1903 * MESA_FORMAT_G8R8_SNORM
1907 pack_float_G8R8_SNORM(const GLfloat src
[4], void *dst
)
1909 GLushort
*d
= (GLushort
*) dst
;
1910 GLbyte r
= FLOAT_TO_BYTE(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1911 GLbyte g
= FLOAT_TO_BYTE(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1912 *d
= (r
<< 8) | (g
& 0xff);
1916 * MESA_FORMAT_G16R16_SNORM
1920 pack_float_G16R16_SNORM(const GLfloat src
[4], void *dst
)
1922 GLuint
*d
= (GLuint
*) dst
;
1923 GLshort r
= FLOAT_TO_SHORT(CLAMP(src
[RCOMP
], -1.0f
, 1.0f
));
1924 GLshort g
= FLOAT_TO_SHORT(CLAMP(src
[GCOMP
], -1.0f
, 1.0f
));
1925 *d
= (r
<< 16) | (g
& 0xffff);
1929 * MESA_FORMAT_B8G8R8X8_SRGB
1933 pack_float_B8G8R8X8_SRGB(const GLfloat src
[4], void *dst
)
1935 GLuint
*d
= (GLuint
*) dst
;
1936 GLubyte r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1937 GLubyte g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1938 GLubyte b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1939 *d
= PACK_COLOR_8888(127, r
, g
, b
);
1943 * MESA_FORMAT_X8R8G8B8_SRGB
1947 pack_float_X8R8G8B8_SRGB(const GLfloat src
[4], void *dst
)
1949 GLuint
*d
= (GLuint
*) dst
;
1950 GLubyte r
= util_format_linear_float_to_srgb_8unorm(src
[RCOMP
]);
1951 GLubyte g
= util_format_linear_float_to_srgb_8unorm(src
[GCOMP
]);
1952 GLubyte b
= util_format_linear_float_to_srgb_8unorm(src
[BCOMP
]);
1953 *d
= PACK_COLOR_8888(b
, g
, r
, 255);
1957 * Return a function that can pack a GLubyte rgba[4] color.
1959 gl_pack_ubyte_rgba_func
1960 _mesa_get_pack_ubyte_rgba_function(mesa_format format
)
1962 static gl_pack_ubyte_rgba_func table
[MESA_FORMAT_COUNT
];
1963 static GLboolean initialized
= GL_FALSE
;
1966 memset(table
, 0, sizeof(table
));
1968 table
[MESA_FORMAT_NONE
] = NULL
;
1970 table
[MESA_FORMAT_A8B8G8R8_UNORM
] = pack_ubyte_A8B8G8R8_UNORM
;
1971 table
[MESA_FORMAT_R8G8B8A8_UNORM
] = pack_ubyte_R8G8B8A8_UNORM
;
1972 table
[MESA_FORMAT_B8G8R8A8_UNORM
] = pack_ubyte_B8G8R8A8_UNORM
;
1973 table
[MESA_FORMAT_A8R8G8B8_UNORM
] = pack_ubyte_A8R8G8B8_UNORM
;
1974 table
[MESA_FORMAT_X8B8G8R8_UNORM
] = pack_ubyte_A8B8G8R8_UNORM
; /* reused */
1975 table
[MESA_FORMAT_R8G8B8X8_UNORM
] = pack_ubyte_R8G8B8A8_UNORM
; /* reused */
1976 table
[MESA_FORMAT_B8G8R8X8_UNORM
] = pack_ubyte_B8G8R8X8_UNORM
;
1977 table
[MESA_FORMAT_X8R8G8B8_UNORM
] = pack_ubyte_X8R8G8B8_UNORM
;
1978 table
[MESA_FORMAT_BGR_UNORM8
] = pack_ubyte_BGR_UNORM8
;
1979 table
[MESA_FORMAT_RGB_UNORM8
] = pack_ubyte_RGB_UNORM8
;
1980 table
[MESA_FORMAT_B5G6R5_UNORM
] = pack_ubyte_B5G6R5_UNORM
;
1981 table
[MESA_FORMAT_R5G6B5_UNORM
] = pack_ubyte_R5G6B5_UNORM
;
1982 table
[MESA_FORMAT_B4G4R4A4_UNORM
] = pack_ubyte_B4G4R4A4_UNORM
;
1983 table
[MESA_FORMAT_A4R4G4B4_UNORM
] = pack_ubyte_A4R4G4B4_UNORM
;
1984 table
[MESA_FORMAT_A1B5G5R5_UNORM
] = pack_ubyte_A1B5G5R5_UNORM
;
1985 table
[MESA_FORMAT_B5G5R5A1_UNORM
] = pack_ubyte_B5G5R5A1_UNORM
;
1986 table
[MESA_FORMAT_A1R5G5B5_UNORM
] = pack_ubyte_A1R5G5B5_UNORM
;
1987 table
[MESA_FORMAT_L4A4_UNORM
] = pack_ubyte_L4A4_UNORM
;
1988 table
[MESA_FORMAT_L8A8_UNORM
] = pack_ubyte_L8A8_UNORM
;
1989 table
[MESA_FORMAT_A8L8_UNORM
] = pack_ubyte_A8L8_UNORM
;
1990 table
[MESA_FORMAT_L16A16_UNORM
] = pack_ubyte_L16A16_UNORM
;
1991 table
[MESA_FORMAT_A16L16_UNORM
] = pack_ubyte_A16L16_UNORM
;
1992 table
[MESA_FORMAT_B2G3R3_UNORM
] = pack_ubyte_B2G3R3_UNORM
;
1993 table
[MESA_FORMAT_A_UNORM8
] = pack_ubyte_A_UNORM8
;
1994 table
[MESA_FORMAT_A_UNORM16
] = pack_ubyte_A_UNORM16
;
1995 table
[MESA_FORMAT_L_UNORM8
] = pack_ubyte_L_UNORM8
;
1996 table
[MESA_FORMAT_L_UNORM16
] = pack_ubyte_L_UNORM16
;
1997 table
[MESA_FORMAT_I_UNORM8
] = pack_ubyte_L_UNORM8
; /* reuse pack_ubyte_L_UNORM8 */
1998 table
[MESA_FORMAT_I_UNORM16
] = pack_ubyte_L_UNORM16
; /* reuse pack_ubyte_L_UNORM16 */
1999 table
[MESA_FORMAT_YCBCR
] = pack_ubyte_YCBCR
;
2000 table
[MESA_FORMAT_YCBCR_REV
] = pack_ubyte_YCBCR_REV
;
2001 table
[MESA_FORMAT_R_UNORM8
] = pack_ubyte_R_UNORM8
;
2002 table
[MESA_FORMAT_R8G8_UNORM
] = pack_ubyte_R8G8_UNORM
;
2003 table
[MESA_FORMAT_G8R8_UNORM
] = pack_ubyte_G8R8_UNORM
;
2004 table
[MESA_FORMAT_R_UNORM16
] = pack_ubyte_R_UNORM16
;
2005 table
[MESA_FORMAT_R16G16_UNORM
] = pack_ubyte_R16G16_UNORM
;
2006 table
[MESA_FORMAT_G16R16_UNORM
] = pack_ubyte_G16R16_UNORM
;
2007 table
[MESA_FORMAT_B10G10R10A2_UNORM
] = pack_ubyte_B10G10R10A2_UNORM
;
2008 table
[MESA_FORMAT_R10G10B10A2_UINT
] = pack_ubyte_R10G10B10A2_UINT
;
2010 /* should never convert RGBA to these formats */
2011 table
[MESA_FORMAT_S8_UINT_Z24_UNORM
] = NULL
;
2012 table
[MESA_FORMAT_Z24_UNORM_S8_UINT
] = NULL
;
2013 table
[MESA_FORMAT_Z_UNORM16
] = NULL
;
2014 table
[MESA_FORMAT_Z24_UNORM_X8_UINT
] = NULL
;
2015 table
[MESA_FORMAT_X8_UINT_Z24_UNORM
] = NULL
;
2016 table
[MESA_FORMAT_Z_UNORM32
] = NULL
;
2017 table
[MESA_FORMAT_S_UINT8
] = NULL
;
2020 table
[MESA_FORMAT_BGR_SRGB8
] = pack_ubyte_BGR_SRGB8
;
2021 table
[MESA_FORMAT_A8B8G8R8_SRGB
] = pack_ubyte_A8B8G8R8_SRGB
;
2022 table
[MESA_FORMAT_B8G8R8A8_SRGB
] = pack_ubyte_B8G8R8A8_SRGB
;
2023 table
[MESA_FORMAT_A8R8G8B8_SRGB
] = pack_ubyte_A8R8G8B8_SRGB
;
2024 table
[MESA_FORMAT_R8G8B8A8_SRGB
] = pack_ubyte_R8G8B8A8_SRGB
;
2025 table
[MESA_FORMAT_L_SRGB8
] = pack_ubyte_L_SRGB8
;
2026 table
[MESA_FORMAT_L8A8_SRGB
] = pack_ubyte_L8A8_SRGB
;
2027 table
[MESA_FORMAT_A8L8_SRGB
] = pack_ubyte_A8L8_SRGB
;
2029 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
; /* pack_ubyte_SRGB_DXT1; */
2030 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
; /* pack_ubyte_SRGBA_DXT1; */
2031 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
; /* pack_ubyte_SRGBA_DXT3; */
2032 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
; /* pack_ubyte_SRGBA_DXT5; */
2034 table
[MESA_FORMAT_RGB_FXT1
] = NULL
; /* pack_ubyte_RGB_FXT1; */
2035 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
; /* pack_ubyte_RGBA_FXT1; */
2036 table
[MESA_FORMAT_RGB_DXT1
] = NULL
; /* pack_ubyte_RGB_DXT1; */
2037 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
; /* pack_ubyte_RGBA_DXT1; */
2038 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
; /* pack_ubyte_RGBA_DXT3; */
2039 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
; /* pack_ubyte_RGBA_DXT5; */
2041 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_ubyte_RGBA_FLOAT32
;
2042 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_ubyte_RGBA_FLOAT16
;
2043 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_ubyte_RGB_FLOAT32
;
2044 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_ubyte_RGB_FLOAT16
;
2045 table
[MESA_FORMAT_A_FLOAT32
] = pack_ubyte_A_FLOAT32
;
2046 table
[MESA_FORMAT_A_FLOAT16
] = pack_ubyte_A_FLOAT16
;
2047 table
[MESA_FORMAT_L_FLOAT32
] = pack_ubyte_L_FLOAT32
;
2048 table
[MESA_FORMAT_L_FLOAT16
] = pack_ubyte_L_FLOAT16
;
2049 table
[MESA_FORMAT_LA_FLOAT32
] = pack_ubyte_LA_FLOAT32
;
2050 table
[MESA_FORMAT_LA_FLOAT16
] = pack_ubyte_LA_FLOAT16
;
2051 table
[MESA_FORMAT_I_FLOAT32
] = pack_ubyte_L_FLOAT32
;
2052 table
[MESA_FORMAT_I_FLOAT16
] = pack_ubyte_L_FLOAT16
;
2053 table
[MESA_FORMAT_R_FLOAT32
] = pack_ubyte_L_FLOAT32
;
2054 table
[MESA_FORMAT_R_FLOAT16
] = pack_ubyte_L_FLOAT16
;
2055 table
[MESA_FORMAT_RG_FLOAT32
] = pack_ubyte_RG_FLOAT32
;
2056 table
[MESA_FORMAT_RG_FLOAT16
] = pack_ubyte_RG_FLOAT16
;
2059 table
[MESA_FORMAT_RGBA_SINT8
] = NULL
; /* pack_ubyte_RGBA_INT8 */
2060 table
[MESA_FORMAT_RGBA_SINT16
] = NULL
; /* pack_ubyte_RGBA_INT16 */
2061 table
[MESA_FORMAT_RGBA_SINT32
] = NULL
; /* pack_ubyte_RGBA_INT32 */
2062 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
; /* pack_ubyte_RGBA_UINT8 */
2063 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
; /* pack_ubyte_RGBA_UINT16 */
2064 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
; /* pack_ubyte_RGBA_UINT32 */
2066 table
[MESA_FORMAT_RGBA_UNORM16
] = pack_ubyte_RGBA_16
;
2069 table
[MESA_FORMAT_R_SNORM8
] = NULL
;
2070 table
[MESA_FORMAT_R8G8_SNORM
] = NULL
;
2071 table
[MESA_FORMAT_X8B8G8R8_SNORM
] = NULL
;
2072 table
[MESA_FORMAT_A8B8G8R8_SNORM
] = NULL
;
2073 table
[MESA_FORMAT_R8G8B8A8_SNORM
] = NULL
;
2074 table
[MESA_FORMAT_R_SNORM16
] = NULL
;
2075 table
[MESA_FORMAT_R16G16_SNORM
] = NULL
;
2076 table
[MESA_FORMAT_RGB_SNORM16
] = NULL
;
2077 table
[MESA_FORMAT_RGBA_SNORM16
] = NULL
;
2078 table
[MESA_FORMAT_A_SNORM8
] = NULL
;
2079 table
[MESA_FORMAT_L_SNORM8
] = NULL
;
2080 table
[MESA_FORMAT_L8A8_SNORM
] = NULL
;
2081 table
[MESA_FORMAT_A8L8_SNORM
] = NULL
;
2082 table
[MESA_FORMAT_I_SNORM8
] = NULL
;
2083 table
[MESA_FORMAT_A_SNORM16
] = NULL
;
2084 table
[MESA_FORMAT_L_SNORM16
] = NULL
;
2085 table
[MESA_FORMAT_LA_SNORM16
] = NULL
;
2086 table
[MESA_FORMAT_I_SNORM16
] = NULL
;
2089 table
[MESA_FORMAT_RGBA_UNORM16
] = pack_ubyte_RGBA_16
;
2091 table
[MESA_FORMAT_R9G9B9E5_FLOAT
] = pack_ubyte_R9G9B9E5_FLOAT
;
2092 table
[MESA_FORMAT_R11G11B10_FLOAT
] = pack_ubyte_R11G11B10_FLOAT
;
2094 table
[MESA_FORMAT_B4G4R4X4_UNORM
] = pack_ubyte_XRGB4444_UNORM
;
2095 table
[MESA_FORMAT_B5G5R5X1_UNORM
] = pack_ubyte_XRGB1555_UNORM
;
2096 table
[MESA_FORMAT_R8G8B8X8_SNORM
] = NULL
;
2097 table
[MESA_FORMAT_R8G8B8X8_SRGB
] = NULL
;
2098 table
[MESA_FORMAT_X8B8G8R8_SRGB
] = NULL
;
2099 table
[MESA_FORMAT_RGBX_UINT8
] = NULL
;
2100 table
[MESA_FORMAT_RGBX_SINT8
] = NULL
;
2101 table
[MESA_FORMAT_B10G10R10X2_UNORM
] = pack_ubyte_B10G10R10X2_UNORM
;
2102 table
[MESA_FORMAT_RGBX_UNORM16
] = pack_ubyte_RGBX_UNORM16
;
2103 table
[MESA_FORMAT_RGBX_SNORM16
] = NULL
;
2104 table
[MESA_FORMAT_RGBX_FLOAT16
] = NULL
;
2105 table
[MESA_FORMAT_RGBX_UINT16
] = NULL
;
2106 table
[MESA_FORMAT_RGBX_SINT16
] = NULL
;
2107 table
[MESA_FORMAT_RGBX_FLOAT32
] = NULL
;
2108 table
[MESA_FORMAT_RGBX_UINT32
] = NULL
;
2109 table
[MESA_FORMAT_RGBX_SINT32
] = NULL
;
2111 table
[MESA_FORMAT_R10G10B10A2_UNORM
] = pack_ubyte_R10G10B10A2_UNORM
;
2113 table
[MESA_FORMAT_B8G8R8X8_SRGB
] = NULL
;
2114 table
[MESA_FORMAT_X8R8G8B8_SRGB
] = NULL
;
2116 initialized
= GL_TRUE
;
2119 return table
[format
];
2125 * Return a function that can pack a GLfloat rgba[4] color.
2127 gl_pack_float_rgba_func
2128 _mesa_get_pack_float_rgba_function(mesa_format format
)
2130 static gl_pack_float_rgba_func table
[MESA_FORMAT_COUNT
];
2131 static GLboolean initialized
= GL_FALSE
;
2134 memset(table
, 0, sizeof(table
));
2136 table
[MESA_FORMAT_NONE
] = NULL
;
2138 table
[MESA_FORMAT_A8B8G8R8_UNORM
] = pack_float_A8B8G8R8_UNORM
;
2139 table
[MESA_FORMAT_R8G8B8A8_UNORM
] = pack_float_R8G8B8A8_UNORM
;
2140 table
[MESA_FORMAT_B8G8R8A8_UNORM
] = pack_float_B8G8R8A8_UNORM
;
2141 table
[MESA_FORMAT_A8R8G8B8_UNORM
] = pack_float_A8R8G8B8_UNORM
;
2142 table
[MESA_FORMAT_X8B8G8R8_UNORM
] = pack_float_A8B8G8R8_UNORM
; /* reused */
2143 table
[MESA_FORMAT_R8G8B8X8_UNORM
] = pack_float_R8G8B8A8_UNORM
; /* reused */
2144 table
[MESA_FORMAT_B8G8R8X8_UNORM
] = pack_float_B8G8R8X8_UNORM
;
2145 table
[MESA_FORMAT_X8R8G8B8_UNORM
] = pack_float_X8R8G8B8_UNORM
;
2146 table
[MESA_FORMAT_BGR_UNORM8
] = pack_float_BGR_UNORM8
;
2147 table
[MESA_FORMAT_RGB_UNORM8
] = pack_float_RGB_UNORM8
;
2148 table
[MESA_FORMAT_B5G6R5_UNORM
] = pack_float_B5G6R5_UNORM
;
2149 table
[MESA_FORMAT_R5G6B5_UNORM
] = pack_float_R5G6B5_UNORM
;
2150 table
[MESA_FORMAT_B4G4R4A4_UNORM
] = pack_float_B4G4R4A4_UNORM
;
2151 table
[MESA_FORMAT_A4R4G4B4_UNORM
] = pack_float_A4R4G4B4_UNORM
;
2152 table
[MESA_FORMAT_A1B5G5R5_UNORM
] = pack_float_A1B5G5R5_UNORM
;
2153 table
[MESA_FORMAT_B5G5R5A1_UNORM
] = pack_float_B5G5R5A1_UNORM
;
2154 table
[MESA_FORMAT_A1R5G5B5_UNORM
] = pack_float_A1R5G5B5_UNORM
;
2156 table
[MESA_FORMAT_L4A4_UNORM
] = pack_float_L4A4_UNORM
;
2157 table
[MESA_FORMAT_L8A8_UNORM
] = pack_float_L8A8_UNORM
;
2158 table
[MESA_FORMAT_A8L8_UNORM
] = pack_float_A8L8_UNORM
;
2159 table
[MESA_FORMAT_L16A16_UNORM
] = pack_float_L16A16_UNORM
;
2160 table
[MESA_FORMAT_A16L16_UNORM
] = pack_float_A16L16_UNORM
;
2161 table
[MESA_FORMAT_B2G3R3_UNORM
] = pack_float_B2G3R3_UNORM
;
2162 table
[MESA_FORMAT_A_UNORM8
] = pack_float_A_UNORM8
;
2163 table
[MESA_FORMAT_A_UNORM16
] = pack_float_A_UNORM16
;
2164 table
[MESA_FORMAT_L_UNORM8
] = pack_float_L_UNORM8
;
2165 table
[MESA_FORMAT_L_UNORM16
] = pack_float_L_UNORM16
;
2166 table
[MESA_FORMAT_I_UNORM8
] = pack_float_L_UNORM8
; /* reuse pack_float_L_UNORM8 */
2167 table
[MESA_FORMAT_I_UNORM16
] = pack_float_L_UNORM16
; /* reuse pack_float_L_UNORM16 */
2168 table
[MESA_FORMAT_YCBCR
] = pack_float_YCBCR
;
2169 table
[MESA_FORMAT_YCBCR_REV
] = pack_float_YCBCR_REV
;
2170 table
[MESA_FORMAT_R_UNORM8
] = pack_float_R_UNORM8
;
2171 table
[MESA_FORMAT_R8G8_UNORM
] = pack_float_R8G8_UNORM
;
2172 table
[MESA_FORMAT_G8R8_UNORM
] = pack_float_G8R8_UNORM
;
2173 table
[MESA_FORMAT_R_UNORM16
] = pack_float_R_UNORM16
;
2174 table
[MESA_FORMAT_R16G16_UNORM
] = pack_float_R16G16_UNORM
;
2175 table
[MESA_FORMAT_G16R16_UNORM
] = pack_float_G16R16_UNORM
;
2176 table
[MESA_FORMAT_B10G10R10A2_UNORM
] = pack_float_B10G10R10A2_UNORM
;
2177 table
[MESA_FORMAT_R10G10B10A2_UINT
] = pack_float_R10G10B10A2_UINT
;
2179 /* should never convert RGBA to these formats */
2180 table
[MESA_FORMAT_S8_UINT_Z24_UNORM
] = NULL
;
2181 table
[MESA_FORMAT_Z24_UNORM_S8_UINT
] = NULL
;
2182 table
[MESA_FORMAT_Z_UNORM16
] = NULL
;
2183 table
[MESA_FORMAT_Z24_UNORM_X8_UINT
] = NULL
;
2184 table
[MESA_FORMAT_X8_UINT_Z24_UNORM
] = NULL
;
2185 table
[MESA_FORMAT_Z_UNORM32
] = NULL
;
2186 table
[MESA_FORMAT_S_UINT8
] = NULL
;
2188 table
[MESA_FORMAT_BGR_SRGB8
] = pack_float_BGR_SRGB8
;
2189 table
[MESA_FORMAT_A8B8G8R8_SRGB
] = pack_float_A8B8G8R8_SRGB
;
2190 table
[MESA_FORMAT_B8G8R8A8_SRGB
] = pack_float_B8G8R8A8_SRGB
;
2191 table
[MESA_FORMAT_A8R8G8B8_SRGB
] = pack_float_A8R8G8B8_SRGB
;
2192 table
[MESA_FORMAT_R8G8B8A8_SRGB
] = pack_float_R8G8B8A8_SRGB
;
2193 table
[MESA_FORMAT_L_SRGB8
] = pack_float_L_SRGB8
;
2194 table
[MESA_FORMAT_L8A8_SRGB
] = pack_float_L8A8_SRGB
;
2195 table
[MESA_FORMAT_A8L8_SRGB
] = pack_float_A8L8_SRGB
;
2198 table
[MESA_FORMAT_SRGB_DXT1
] = NULL
;
2199 table
[MESA_FORMAT_SRGBA_DXT1
] = NULL
;
2200 table
[MESA_FORMAT_SRGBA_DXT3
] = NULL
;
2201 table
[MESA_FORMAT_SRGBA_DXT5
] = NULL
;
2203 table
[MESA_FORMAT_RGB_FXT1
] = NULL
;
2204 table
[MESA_FORMAT_RGBA_FXT1
] = NULL
;
2205 table
[MESA_FORMAT_RGB_DXT1
] = NULL
;
2206 table
[MESA_FORMAT_RGBA_DXT1
] = NULL
;
2207 table
[MESA_FORMAT_RGBA_DXT3
] = NULL
;
2208 table
[MESA_FORMAT_RGBA_DXT5
] = NULL
;
2210 table
[MESA_FORMAT_RGBA_FLOAT32
] = pack_float_RGBA_FLOAT32
;
2211 table
[MESA_FORMAT_RGBA_FLOAT16
] = pack_float_RGBA_FLOAT16
;
2212 table
[MESA_FORMAT_RGB_FLOAT32
] = pack_float_RGB_FLOAT32
;
2213 table
[MESA_FORMAT_RGB_FLOAT16
] = pack_float_RGB_FLOAT16
;
2214 table
[MESA_FORMAT_A_FLOAT32
] = pack_float_A_FLOAT32
;
2215 table
[MESA_FORMAT_A_FLOAT16
] = pack_float_A_FLOAT16
;
2216 table
[MESA_FORMAT_L_FLOAT32
] = pack_float_L_FLOAT32
;
2217 table
[MESA_FORMAT_L_FLOAT16
] = pack_float_L_FLOAT16
;
2218 table
[MESA_FORMAT_LA_FLOAT32
] = pack_float_LA_FLOAT32
;
2219 table
[MESA_FORMAT_LA_FLOAT16
] = pack_float_LA_FLOAT16
;
2221 table
[MESA_FORMAT_I_FLOAT32
] = pack_float_L_FLOAT32
;
2222 table
[MESA_FORMAT_I_FLOAT16
] = pack_float_L_FLOAT16
;
2223 table
[MESA_FORMAT_R_FLOAT32
] = pack_float_L_FLOAT32
;
2224 table
[MESA_FORMAT_R_FLOAT16
] = pack_float_L_FLOAT16
;
2225 table
[MESA_FORMAT_RG_FLOAT32
] = pack_float_RG_FLOAT32
;
2226 table
[MESA_FORMAT_RG_FLOAT16
] = pack_float_RG_FLOAT16
;
2229 table
[MESA_FORMAT_RGBA_SINT8
] = NULL
;
2230 table
[MESA_FORMAT_RGBA_SINT16
] = NULL
;
2231 table
[MESA_FORMAT_RGBA_SINT32
] = NULL
;
2232 table
[MESA_FORMAT_RGBA_UINT8
] = NULL
;
2233 table
[MESA_FORMAT_RGBA_UINT16
] = NULL
;
2234 table
[MESA_FORMAT_RGBA_UINT32
] = NULL
;
2236 table
[MESA_FORMAT_RGBA_UNORM16
] = pack_float_RGBA_16
;
2238 table
[MESA_FORMAT_R_SNORM8
] = pack_float_R_SNORM8
;
2239 table
[MESA_FORMAT_R8G8_SNORM
] = pack_float_R8G8_SNORM
;
2240 table
[MESA_FORMAT_X8B8G8R8_SNORM
] = pack_float_X8B8G8R8_SNORM
;
2241 table
[MESA_FORMAT_A8B8G8R8_SNORM
] = pack_float_A8B8G8R8_SNORM
;
2242 table
[MESA_FORMAT_R8G8B8A8_SNORM
] = pack_float_R8G8B8A8_SNORM
;
2243 table
[MESA_FORMAT_R_SNORM16
] = pack_float_R_SNORM16
;
2244 table
[MESA_FORMAT_R16G16_SNORM
] = pack_float_R16G16_SNORM
;
2245 table
[MESA_FORMAT_RGB_SNORM16
] = pack_float_RGB_SNORM16
;
2246 table
[MESA_FORMAT_RGBA_SNORM16
] = pack_float_RGBA_SNORM16
;
2247 table
[MESA_FORMAT_A_SNORM8
] = pack_float_A_SNORM8
;
2248 table
[MESA_FORMAT_L_SNORM8
] = pack_float_L_SNORM8
;
2249 table
[MESA_FORMAT_L8A8_SNORM
] = pack_float_L8A8_SNORM
;
2250 table
[MESA_FORMAT_A8L8_SNORM
] = pack_float_A8L8_SNORM
;
2251 table
[MESA_FORMAT_I_SNORM8
] = pack_float_L_SNORM8
; /* reused */
2252 table
[MESA_FORMAT_A_SNORM16
] = pack_float_A_SNORM16
;
2253 table
[MESA_FORMAT_L_SNORM16
] = pack_float_L_SNORM16
;
2254 table
[MESA_FORMAT_LA_SNORM16
] = pack_float_LA_SNORM16
;
2255 table
[MESA_FORMAT_I_SNORM16
] = pack_float_L_SNORM16
; /* reused */
2257 table
[MESA_FORMAT_R9G9B9E5_FLOAT
] = pack_float_R9G9B9E5_FLOAT
;
2258 table
[MESA_FORMAT_R11G11B10_FLOAT
] = pack_float_R11G11B10_FLOAT
;
2260 table
[MESA_FORMAT_B4G4R4X4_UNORM
] = pack_float_XRGB4444_UNORM
;
2261 table
[MESA_FORMAT_B5G5R5X1_UNORM
] = pack_float_XRGB1555_UNORM
;
2262 table
[MESA_FORMAT_R8G8B8X8_SNORM
] = pack_float_XBGR8888_SNORM
;
2263 table
[MESA_FORMAT_R8G8B8X8_SRGB
] = pack_float_R8G8B8X8_SRGB
;
2264 table
[MESA_FORMAT_X8B8G8R8_SRGB
] = pack_float_X8B8G8R8_SRGB
;
2265 table
[MESA_FORMAT_RGBX_UINT8
] = NULL
;
2266 table
[MESA_FORMAT_RGBX_SINT8
] = NULL
;
2267 table
[MESA_FORMAT_B10G10R10X2_UNORM
] = pack_float_B10G10R10X2_UNORM
;
2268 table
[MESA_FORMAT_RGBX_UNORM16
] = pack_float_RGBX_UNORM16
;
2269 table
[MESA_FORMAT_RGBX_SNORM16
] = pack_float_RGBX_SNORM16
;
2270 table
[MESA_FORMAT_RGBX_FLOAT16
] = pack_float_XBGR16161616_FLOAT
;
2271 table
[MESA_FORMAT_RGBX_UINT16
] = NULL
;
2272 table
[MESA_FORMAT_RGBX_SINT16
] = NULL
;
2273 table
[MESA_FORMAT_RGBX_FLOAT32
] = pack_float_RGBX_FLOAT32
;
2274 table
[MESA_FORMAT_RGBX_UINT32
] = NULL
;
2275 table
[MESA_FORMAT_RGBX_SINT32
] = NULL
;
2277 table
[MESA_FORMAT_R10G10B10A2_UNORM
] = pack_float_R10G10B10A2_UNORM
;
2279 table
[MESA_FORMAT_G8R8_SNORM
] = pack_float_G8R8_SNORM
;
2280 table
[MESA_FORMAT_G16R16_SNORM
] = pack_float_G16R16_SNORM
;
2282 table
[MESA_FORMAT_B8G8R8X8_SRGB
] = pack_float_B8G8R8X8_SRGB
;
2283 table
[MESA_FORMAT_X8R8G8B8_SRGB
] = pack_float_X8R8G8B8_SRGB
;
2285 initialized
= GL_TRUE
;
2288 return table
[format
];
2293 static pack_float_rgba_row_func
2294 get_pack_float_rgba_row_function(mesa_format format
)
2296 static pack_float_rgba_row_func table
[MESA_FORMAT_COUNT
];
2297 static GLboolean initialized
= GL_FALSE
;
2300 /* We don't need a special row packing function for each format.
2301 * There's a generic fallback which uses a per-pixel packing function.
2303 memset(table
, 0, sizeof(table
));
2305 table
[MESA_FORMAT_A8B8G8R8_UNORM
] = pack_row_float_A8B8G8R8_UNORM
;
2306 table
[MESA_FORMAT_R8G8B8A8_UNORM
] = pack_row_float_R8G8B8A8_UNORM
;
2307 table
[MESA_FORMAT_B8G8R8A8_UNORM
] = pack_row_float_B8G8R8A8_UNORM
;
2308 table
[MESA_FORMAT_A8R8G8B8_UNORM
] = pack_row_float_A8R8G8B8_UNORM
;
2309 table
[MESA_FORMAT_X8B8G8R8_UNORM
] = pack_row_float_A8B8G8R8_UNORM
; /* reused */
2310 table
[MESA_FORMAT_R8G8B8X8_UNORM
] = pack_row_float_R8G8B8A8_UNORM
; /* reused */
2311 table
[MESA_FORMAT_B8G8R8X8_UNORM
] = pack_row_float_B8G8R8X8_UNORM
;
2312 table
[MESA_FORMAT_X8R8G8B8_UNORM
] = pack_row_float_X8R8G8B8_UNORM
;
2313 table
[MESA_FORMAT_BGR_UNORM8
] = pack_row_float_BGR_UNORM8
;
2314 table
[MESA_FORMAT_RGB_UNORM8
] = pack_row_float_RGB_UNORM8
;
2315 table
[MESA_FORMAT_B5G6R5_UNORM
] = pack_row_float_B5G6R5_UNORM
;
2316 table
[MESA_FORMAT_R5G6B5_UNORM
] = pack_row_float_R5G6B5_UNORM
;
2318 initialized
= GL_TRUE
;
2321 return table
[format
];
2326 static pack_ubyte_rgba_row_func
2327 get_pack_ubyte_rgba_row_function(mesa_format format
)
2329 static pack_ubyte_rgba_row_func table
[MESA_FORMAT_COUNT
];
2330 static GLboolean initialized
= GL_FALSE
;
2333 /* We don't need a special row packing function for each format.
2334 * There's a generic fallback which uses a per-pixel packing function.
2336 memset(table
, 0, sizeof(table
));
2338 table
[MESA_FORMAT_A8B8G8R8_UNORM
] = pack_row_ubyte_A8B8G8R8_UNORM
;
2339 table
[MESA_FORMAT_R8G8B8A8_UNORM
] = pack_row_ubyte_R8G8B8A8_UNORM
;
2340 table
[MESA_FORMAT_B8G8R8A8_UNORM
] = pack_row_ubyte_B8G8R8A8_UNORM
;
2341 table
[MESA_FORMAT_A8R8G8B8_UNORM
] = pack_row_ubyte_A8R8G8B8_UNORM
;
2342 table
[MESA_FORMAT_X8B8G8R8_UNORM
] = pack_row_ubyte_A8B8G8R8_UNORM
; /* reused */
2343 table
[MESA_FORMAT_R8G8B8X8_UNORM
] = pack_row_ubyte_R8G8B8A8_UNORM
; /* reused */
2344 table
[MESA_FORMAT_B8G8R8X8_UNORM
] = pack_row_ubyte_B8G8R8X8_UNORM
;
2345 table
[MESA_FORMAT_X8R8G8B8_UNORM
] = pack_row_ubyte_X8R8G8B8_UNORM
;
2346 table
[MESA_FORMAT_BGR_UNORM8
] = pack_row_ubyte_BGR_UNORM8
;
2347 table
[MESA_FORMAT_RGB_UNORM8
] = pack_row_ubyte_RGB_UNORM8
;
2348 table
[MESA_FORMAT_B5G6R5_UNORM
] = pack_row_ubyte_B5G6R5_UNORM
;
2349 table
[MESA_FORMAT_R5G6B5_UNORM
] = pack_row_ubyte_R5G6B5_UNORM
;
2351 initialized
= GL_TRUE
;
2354 return table
[format
];
2360 * Pack a row of GLfloat rgba[4] values to the destination.
2363 _mesa_pack_float_rgba_row(mesa_format format
, GLuint n
,
2364 const GLfloat src
[][4], void *dst
)
2366 pack_float_rgba_row_func packrow
= get_pack_float_rgba_row_function(format
);
2368 /* use "fast" function */
2369 packrow(n
, src
, dst
);
2372 /* slower fallback */
2373 gl_pack_float_rgba_func pack
= _mesa_get_pack_float_rgba_function(format
);
2374 GLuint dstStride
= _mesa_get_format_bytes(format
);
2375 GLubyte
*dstPtr
= (GLubyte
*) dst
;
2382 for (i
= 0; i
< n
; i
++) {
2383 pack(src
[i
], dstPtr
);
2384 dstPtr
+= dstStride
;
2391 * Pack a row of GLubyte rgba[4] values to the destination.
2394 _mesa_pack_ubyte_rgba_row(mesa_format format
, GLuint n
,
2395 const GLubyte src
[][4], void *dst
)
2397 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2399 /* use "fast" function */
2400 packrow(n
, src
, dst
);
2403 /* slower fallback */
2404 gl_pack_ubyte_rgba_func pack
= _mesa_get_pack_ubyte_rgba_function(format
);
2405 const GLuint stride
= _mesa_get_format_bytes(format
);
2406 GLubyte
*d
= ((GLubyte
*) dst
);
2413 for (i
= 0; i
< n
; i
++) {
2422 * Pack a 2D image of ubyte RGBA pixels in the given format.
2423 * \param srcRowStride source image row stride in bytes
2424 * \param dstRowStride destination image row stride in bytes
2427 _mesa_pack_ubyte_rgba_rect(mesa_format format
, GLuint width
, GLuint height
,
2428 const GLubyte
*src
, GLint srcRowStride
,
2429 void *dst
, GLint dstRowStride
)
2431 pack_ubyte_rgba_row_func packrow
= get_pack_ubyte_rgba_row_function(format
);
2432 GLubyte
*dstUB
= (GLubyte
*) dst
;
2436 if (srcRowStride
== width
* 4 * sizeof(GLubyte
) &&
2437 dstRowStride
== _mesa_format_row_stride(format
, width
)) {
2438 /* do whole image at once */
2439 packrow(width
* height
, (const GLubyte (*)[4]) src
, dst
);
2443 for (i
= 0; i
< height
; i
++) {
2444 packrow(width
, (const GLubyte (*)[4]) src
, dstUB
);
2445 src
+= srcRowStride
;
2446 dstUB
+= dstRowStride
;
2451 /* slower fallback */
2452 for (i
= 0; i
< height
; i
++) {
2453 _mesa_pack_ubyte_rgba_row(format
, width
,
2454 (const GLubyte (*)[4]) src
, dstUB
);
2455 src
+= srcRowStride
;
2456 dstUB
+= dstRowStride
;
2464 ** Pack float Z pixels
2468 pack_float_S8_UINT_Z24_UNORM(const GLfloat
*src
, void *dst
)
2470 /* don't disturb the stencil values */
2471 GLuint
*d
= ((GLuint
*) dst
);
2472 const GLdouble scale
= (GLdouble
) 0xffffff;
2473 GLuint s
= *d
& 0xff;
2474 GLuint z
= (GLuint
) (*src
* scale
);
2475 assert(z
<= 0xffffff);
2480 pack_float_Z24_UNORM_S8_UINT(const GLfloat
*src
, void *dst
)
2482 /* don't disturb the stencil values */
2483 GLuint
*d
= ((GLuint
*) dst
);
2484 const GLdouble scale
= (GLdouble
) 0xffffff;
2485 GLuint s
= *d
& 0xff000000;
2486 GLuint z
= (GLuint
) (*src
* scale
);
2487 assert(z
<= 0xffffff);
2492 pack_float_Z_UNORM16(const GLfloat
*src
, void *dst
)
2494 GLushort
*d
= ((GLushort
*) dst
);
2495 const GLfloat scale
= (GLfloat
) 0xffff;
2496 *d
= (GLushort
) (*src
* scale
);
2500 pack_float_Z_UNORM32(const GLfloat
*src
, void *dst
)
2502 GLuint
*d
= ((GLuint
*) dst
);
2503 const GLdouble scale
= (GLdouble
) 0xffffffff;
2504 *d
= (GLuint
) (*src
* scale
);
2508 pack_float_Z_FLOAT32(const GLfloat
*src
, void *dst
)
2510 GLfloat
*d
= (GLfloat
*) dst
;
2514 gl_pack_float_z_func
2515 _mesa_get_pack_float_z_func(mesa_format format
)
2518 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
2519 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
2520 return pack_float_S8_UINT_Z24_UNORM
;
2521 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
2522 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
2523 return pack_float_Z24_UNORM_S8_UINT
;
2524 case MESA_FORMAT_Z_UNORM16
:
2525 return pack_float_Z_UNORM16
;
2526 case MESA_FORMAT_Z_UNORM32
:
2527 return pack_float_Z_UNORM32
;
2528 case MESA_FORMAT_Z_FLOAT32
:
2529 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2530 return pack_float_Z_FLOAT32
;
2533 "unexpected format in _mesa_get_pack_float_z_func()");
2541 ** Pack uint Z pixels. The incoming src value is always in
2542 ** the range [0, 2^32-1].
2546 pack_uint_S8_UINT_Z24_UNORM(const GLuint
*src
, void *dst
)
2548 /* don't disturb the stencil values */
2549 GLuint
*d
= ((GLuint
*) dst
);
2550 GLuint s
= *d
& 0xff;
2551 GLuint z
= *src
& 0xffffff00;
2556 pack_uint_Z24_UNORM_S8_UINT(const GLuint
*src
, void *dst
)
2558 /* don't disturb the stencil values */
2559 GLuint
*d
= ((GLuint
*) dst
);
2560 GLuint s
= *d
& 0xff000000;
2561 GLuint z
= *src
>> 8;
2566 pack_uint_Z_UNORM16(const GLuint
*src
, void *dst
)
2568 GLushort
*d
= ((GLushort
*) dst
);
2573 pack_uint_Z_UNORM32(const GLuint
*src
, void *dst
)
2575 GLuint
*d
= ((GLuint
*) dst
);
2580 pack_uint_Z_FLOAT32(const GLuint
*src
, void *dst
)
2582 GLuint
*d
= ((GLuint
*) dst
);
2583 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2584 *d
= (GLuint
) (*src
* scale
);
2590 pack_uint_Z_FLOAT32_X24S8(const GLuint
*src
, void *dst
)
2592 GLfloat
*d
= ((GLfloat
*) dst
);
2593 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2594 *d
= (GLfloat
) (*src
* scale
);
2600 _mesa_get_pack_uint_z_func(mesa_format format
)
2603 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
2604 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
2605 return pack_uint_S8_UINT_Z24_UNORM
;
2606 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
2607 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
2608 return pack_uint_Z24_UNORM_S8_UINT
;
2609 case MESA_FORMAT_Z_UNORM16
:
2610 return pack_uint_Z_UNORM16
;
2611 case MESA_FORMAT_Z_UNORM32
:
2612 return pack_uint_Z_UNORM32
;
2613 case MESA_FORMAT_Z_FLOAT32
:
2614 return pack_uint_Z_FLOAT32
;
2615 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2616 return pack_uint_Z_FLOAT32_X24S8
;
2618 _mesa_problem(NULL
, "unexpected format in _mesa_get_pack_uint_z_func()");
2625 ** Pack ubyte stencil pixels
2629 pack_ubyte_stencil_Z24_S8(const GLubyte
*src
, void *dst
)
2631 /* don't disturb the Z values */
2632 GLuint
*d
= ((GLuint
*) dst
);
2634 GLuint z
= *d
& 0xffffff00;
2639 pack_ubyte_stencil_S8_Z24(const GLubyte
*src
, void *dst
)
2641 /* don't disturb the Z values */
2642 GLuint
*d
= ((GLuint
*) dst
);
2643 GLuint s
= *src
<< 24;
2644 GLuint z
= *d
& 0xffffff;
2649 pack_ubyte_stencil_S8(const GLubyte
*src
, void *dst
)
2651 GLubyte
*d
= (GLubyte
*) dst
;
2656 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte
*src
, void *dst
)
2658 GLfloat
*d
= ((GLfloat
*) dst
);
2663 gl_pack_ubyte_stencil_func
2664 _mesa_get_pack_ubyte_stencil_func(mesa_format format
)
2667 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
2668 return pack_ubyte_stencil_Z24_S8
;
2669 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
2670 return pack_ubyte_stencil_S8_Z24
;
2671 case MESA_FORMAT_S_UINT8
:
2672 return pack_ubyte_stencil_S8
;
2673 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2674 return pack_ubyte_stencil_Z32_FLOAT_X24S8
;
2677 "unexpected format in _mesa_pack_ubyte_stencil_func()");
2685 _mesa_pack_float_z_row(mesa_format format
, GLuint n
,
2686 const GLfloat
*src
, void *dst
)
2689 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
2690 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
2692 /* don't disturb the stencil values */
2693 GLuint
*d
= ((GLuint
*) dst
);
2694 const GLdouble scale
= (GLdouble
) 0xffffff;
2696 for (i
= 0; i
< n
; i
++) {
2697 GLuint s
= d
[i
] & 0xff;
2698 GLuint z
= (GLuint
) (src
[i
] * scale
);
2699 assert(z
<= 0xffffff);
2700 d
[i
] = (z
<< 8) | s
;
2704 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
2705 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
2707 /* don't disturb the stencil values */
2708 GLuint
*d
= ((GLuint
*) dst
);
2709 const GLdouble scale
= (GLdouble
) 0xffffff;
2711 for (i
= 0; i
< n
; i
++) {
2712 GLuint s
= d
[i
] & 0xff000000;
2713 GLuint z
= (GLuint
) (src
[i
] * scale
);
2714 assert(z
<= 0xffffff);
2719 case MESA_FORMAT_Z_UNORM16
:
2721 GLushort
*d
= ((GLushort
*) dst
);
2722 const GLfloat scale
= (GLfloat
) 0xffff;
2724 for (i
= 0; i
< n
; i
++) {
2725 d
[i
] = (GLushort
) (src
[i
] * scale
);
2729 case MESA_FORMAT_Z_UNORM32
:
2731 GLuint
*d
= ((GLuint
*) dst
);
2732 const GLdouble scale
= (GLdouble
) 0xffffffff;
2734 for (i
= 0; i
< n
; i
++) {
2735 d
[i
] = (GLuint
) (src
[i
] * scale
);
2739 case MESA_FORMAT_Z_FLOAT32
:
2740 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2742 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2744 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2746 for (i
= 0; i
< n
; i
++) {
2752 _mesa_problem(NULL
, "unexpected format in _mesa_pack_float_z_row()");
2758 * The incoming Z values are always in the range [0, 0xffffffff].
2761 _mesa_pack_uint_z_row(mesa_format format
, GLuint n
,
2762 const GLuint
*src
, void *dst
)
2765 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
2766 case MESA_FORMAT_X8_UINT_Z24_UNORM
:
2768 /* don't disturb the stencil values */
2769 GLuint
*d
= ((GLuint
*) dst
);
2771 for (i
= 0; i
< n
; i
++) {
2772 GLuint s
= d
[i
] & 0xff;
2773 GLuint z
= src
[i
] & 0xffffff00;
2778 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
2779 case MESA_FORMAT_Z24_UNORM_X8_UINT
:
2781 /* don't disturb the stencil values */
2782 GLuint
*d
= ((GLuint
*) dst
);
2784 for (i
= 0; i
< n
; i
++) {
2785 GLuint s
= d
[i
] & 0xff000000;
2786 GLuint z
= src
[i
] >> 8;
2791 case MESA_FORMAT_Z_UNORM16
:
2793 GLushort
*d
= ((GLushort
*) dst
);
2795 for (i
= 0; i
< n
; i
++) {
2796 d
[i
] = src
[i
] >> 16;
2800 case MESA_FORMAT_Z_UNORM32
:
2801 memcpy(dst
, src
, n
* sizeof(GLfloat
));
2803 case MESA_FORMAT_Z_FLOAT32
:
2805 GLuint
*d
= ((GLuint
*) dst
);
2806 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2808 for (i
= 0; i
< n
; i
++) {
2809 d
[i
] = (GLuint
) (src
[i
] * scale
);
2810 assert(d
[i
] >= 0.0f
);
2811 assert(d
[i
] <= 1.0f
);
2815 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2817 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2818 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffffff;
2820 for (i
= 0; i
< n
; i
++) {
2821 d
[i
].z
= (GLfloat
) (src
[i
] * scale
);
2822 assert(d
[i
].z
>= 0.0f
);
2823 assert(d
[i
].z
<= 1.0f
);
2828 _mesa_problem(NULL
, "unexpected format in _mesa_pack_uint_z_row()");
2834 _mesa_pack_ubyte_stencil_row(mesa_format format
, GLuint n
,
2835 const GLubyte
*src
, void *dst
)
2838 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
2840 /* don't disturb the Z values */
2841 GLuint
*d
= ((GLuint
*) dst
);
2843 for (i
= 0; i
< n
; i
++) {
2845 GLuint z
= d
[i
] & 0xffffff00;
2850 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
2852 /* don't disturb the Z values */
2853 GLuint
*d
= ((GLuint
*) dst
);
2855 for (i
= 0; i
< n
; i
++) {
2856 GLuint s
= src
[i
] << 24;
2857 GLuint z
= d
[i
] & 0xffffff;
2862 case MESA_FORMAT_S_UINT8
:
2863 memcpy(dst
, src
, n
* sizeof(GLubyte
));
2865 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2867 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2869 for (i
= 0; i
< n
; i
++) {
2870 d
[i
].x24s8
= src
[i
];
2875 _mesa_problem(NULL
, "unexpected format in _mesa_pack_ubyte_stencil_row()");
2881 * Incoming Z/stencil values are always in uint_24_8 format.
2884 _mesa_pack_uint_24_8_depth_stencil_row(mesa_format format
, GLuint n
,
2885 const GLuint
*src
, void *dst
)
2888 case MESA_FORMAT_S8_UINT_Z24_UNORM
:
2889 memcpy(dst
, src
, n
* sizeof(GLuint
));
2891 case MESA_FORMAT_Z24_UNORM_S8_UINT
:
2893 GLuint
*d
= ((GLuint
*) dst
);
2895 for (i
= 0; i
< n
; i
++) {
2896 GLuint s
= src
[i
] << 24;
2897 GLuint z
= src
[i
] >> 8;
2902 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT
:
2904 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
2905 struct z32f_x24s8
*d
= (struct z32f_x24s8
*) dst
;
2907 for (i
= 0; i
< n
; i
++) {
2908 GLfloat z
= (GLfloat
) ((src
[i
] >> 8) * scale
);
2910 d
[i
].x24s8
= src
[i
];
2915 _mesa_problem(NULL
, "bad format %s in _mesa_pack_ubyte_s_row",
2916 _mesa_get_format_name(format
));
2924 * Convert a boolean color mask to a packed color where each channel of
2925 * the packed value at dst will be 0 or ~0 depending on the colorMask.
2928 _mesa_pack_colormask(mesa_format format
, const GLubyte colorMask
[4], void *dst
)
2930 GLfloat maskColor
[4];
2932 switch (_mesa_get_format_datatype(format
)) {
2933 case GL_UNSIGNED_NORMALIZED
:
2934 /* simple: 1.0 will convert to ~0 in the right bit positions */
2935 maskColor
[0] = colorMask
[0] ? 1.0f
: 0.0f
;
2936 maskColor
[1] = colorMask
[1] ? 1.0f
: 0.0f
;
2937 maskColor
[2] = colorMask
[2] ? 1.0f
: 0.0f
;
2938 maskColor
[3] = colorMask
[3] ? 1.0f
: 0.0f
;
2939 _mesa_pack_float_rgba_row(format
, 1,
2940 (const GLfloat (*)[4]) maskColor
, dst
);
2942 case GL_SIGNED_NORMALIZED
:
2944 /* These formats are harder because it's hard to know the floating
2945 * point values that will convert to ~0 for each color channel's bits.
2946 * This solution just generates a non-zero value for each color channel
2947 * then fixes up the non-zero values to be ~0.
2948 * Note: we'll need to add special case code if we ever have to deal
2949 * with formats with unequal color channel sizes, like R11_G11_B10.
2950 * We issue a warning below for channel sizes other than 8,16,32.
2953 GLuint bits
= _mesa_get_format_max_bits(format
); /* bits per chan */
2954 GLuint bytes
= _mesa_get_format_bytes(format
);
2957 /* this should put non-zero values into the channels of dst */
2958 maskColor
[0] = colorMask
[0] ? -1.0f
: 0.0f
;
2959 maskColor
[1] = colorMask
[1] ? -1.0f
: 0.0f
;
2960 maskColor
[2] = colorMask
[2] ? -1.0f
: 0.0f
;
2961 maskColor
[3] = colorMask
[3] ? -1.0f
: 0.0f
;
2962 _mesa_pack_float_rgba_row(format
, 1,
2963 (const GLfloat (*)[4]) maskColor
, dst
);
2965 /* fix-up the dst channels by converting non-zero values to ~0 */
2967 GLubyte
*d
= (GLubyte
*) dst
;
2968 for (i
= 0; i
< bytes
; i
++) {
2969 d
[i
] = d
[i
] ? 0xff : 0x0;
2972 else if (bits
== 16) {
2973 GLushort
*d
= (GLushort
*) dst
;
2974 for (i
= 0; i
< bytes
/ 2; i
++) {
2975 d
[i
] = d
[i
] ? 0xffff : 0x0;
2978 else if (bits
== 32) {
2979 GLuint
*d
= (GLuint
*) dst
;
2980 for (i
= 0; i
< bytes
/ 4; i
++) {
2981 d
[i
] = d
[i
] ? 0xffffffffU
: 0x0;
2985 _mesa_problem(NULL
, "unexpected size in _mesa_pack_colormask()");
2991 _mesa_problem(NULL
, "unexpected format data type in gen_color_mask()");