2 * Mesa 3-D graphics library
4 * Copyright (C) 2014 Intel Corporation All Rights Reserved.
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.
25 #include "format_utils.h"
26 #include "glformats.h"
28 static const uint8_t map_identity
[7] = { 0, 1, 2, 3, 4, 5, 6 };
29 static const uint8_t map_3210
[7] = { 3, 2, 1, 0, 4, 5, 6 };
30 static const uint8_t map_1032
[7] = { 1, 0, 3, 2, 4, 5, 6 };
33 * Describes a format as an array format, if possible
35 * A helper function for figuring out if a (possibly packed) format is
36 * actually an array format and, if so, what the array parameters are.
38 * \param[in] format the mesa format
39 * \param[out] type the GL type of the array (GL_BYTE, etc.)
40 * \param[out] num_components the number of components in the array
41 * \param[out] swizzle a swizzle describing how to get from the
42 * given format to RGBA
43 * \param[out] normalized for integer formats, this represents whether
44 * the format is a normalized integer or a
46 * \return true if this format is an array format, false otherwise
49 _mesa_format_to_array(mesa_format format
, GLenum
*type
, int *num_components
,
50 uint8_t swizzle
[4], bool *normalized
)
53 GLuint format_components
;
54 uint8_t packed_swizzle
[4];
55 const uint8_t *endian
;
57 if (_mesa_is_format_compressed(format
))
60 *normalized
= !_mesa_is_format_integer(format
);
62 _mesa_format_to_type_and_comps(format
, type
, &format_components
);
64 switch (_mesa_get_format_layout(format
)) {
65 case MESA_FORMAT_LAYOUT_ARRAY
:
66 *num_components
= format_components
;
67 _mesa_get_format_swizzle(format
, swizzle
);
69 case MESA_FORMAT_LAYOUT_PACKED
:
71 case GL_UNSIGNED_BYTE
:
73 if (_mesa_get_format_max_bits(format
) != 8)
75 *num_components
= _mesa_get_format_bytes(format
);
76 switch (*num_components
) {
78 endian
= map_identity
;
81 endian
= _mesa_little_endian() ? map_identity
: map_1032
;
84 endian
= _mesa_little_endian() ? map_identity
: map_3210
;
87 endian
= map_identity
;
88 assert(!"Invalid number of components");
91 case GL_UNSIGNED_SHORT
:
94 if (_mesa_get_format_max_bits(format
) != 16)
96 *num_components
= _mesa_get_format_bytes(format
) / 2;
97 switch (*num_components
) {
99 endian
= map_identity
;
102 endian
= _mesa_little_endian() ? map_identity
: map_1032
;
105 endian
= map_identity
;
106 assert(!"Invalid number of components");
109 case GL_UNSIGNED_INT
:
112 /* This isn't packed. At least not really. */
113 assert(format_components
== 1);
114 if (_mesa_get_format_max_bits(format
) != 32)
116 *num_components
= format_components
;
117 endian
= map_identity
;
123 _mesa_get_format_swizzle(format
, packed_swizzle
);
125 for (i
= 0; i
< 4; ++i
)
126 swizzle
[i
] = endian
[packed_swizzle
[i
]];
129 case MESA_FORMAT_LAYOUT_OTHER
:
135 /* A bunch of format conversion macros and helper functions used below */
137 /* Only guaranteed to work for BITS <= 32 */
138 #define MAX_UINT(BITS) ((BITS) == 32 ? UINT32_MAX : ((1u << (BITS)) - 1))
139 #define MAX_INT(BITS) ((int)MAX_UINT((BITS) - 1))
141 /* Extends an integer of size SRC_BITS to one of size DST_BITS linearly */
142 #define EXTEND_NORMALIZED_INT(X, SRC_BITS, DST_BITS) \
143 (((X) * (int)(MAX_UINT(DST_BITS) / MAX_UINT(SRC_BITS))) + \
144 ((DST_BITS % SRC_BITS) ? ((X) >> (SRC_BITS - DST_BITS % SRC_BITS)) : 0))
147 unorm_to_float(unsigned x
, unsigned src_bits
)
149 return x
* (1.0f
/ (float)MAX_UINT(src_bits
));
153 snorm_to_float(int x
, unsigned src_bits
)
155 if (x
== -MAX_INT(src_bits
))
158 return x
* (1.0f
/ (float)MAX_INT(src_bits
));
161 static inline uint16_t
162 unorm_to_half(unsigned x
, unsigned src_bits
)
164 return _mesa_float_to_half(unorm_to_float(x
, src_bits
));
167 static inline uint16_t
168 snorm_to_half(int x
, unsigned src_bits
)
170 return _mesa_float_to_half(snorm_to_float(x
, src_bits
));
173 static inline unsigned
174 float_to_unorm(float x
, unsigned dst_bits
)
179 return MAX_UINT(dst_bits
);
181 return F_TO_I(x
* MAX_UINT(dst_bits
));
184 static inline unsigned
185 half_to_unorm(uint16_t x
, unsigned dst_bits
)
187 return float_to_unorm(_mesa_half_to_float(x
), dst_bits
);
190 static inline unsigned
191 unorm_to_unorm(unsigned x
, unsigned src_bits
, unsigned dst_bits
)
193 if (src_bits
< dst_bits
)
194 return EXTEND_NORMALIZED_INT(x
, src_bits
, dst_bits
);
196 return x
>> (src_bits
- dst_bits
);
199 static inline unsigned
200 snorm_to_unorm(int x
, unsigned src_bits
, unsigned dst_bits
)
205 return unorm_to_unorm(x
, src_bits
- 1, dst_bits
);
209 float_to_snorm(float x
, unsigned dst_bits
)
212 return -MAX_INT(dst_bits
);
214 return MAX_INT(dst_bits
);
216 return F_TO_I(x
* MAX_INT(dst_bits
));
220 half_to_snorm(uint16_t x
, unsigned dst_bits
)
222 return float_to_snorm(_mesa_half_to_float(x
), dst_bits
);
226 unorm_to_snorm(unsigned x
, unsigned src_bits
, unsigned dst_bits
)
228 return unorm_to_unorm(x
, src_bits
, dst_bits
- 1);
232 snorm_to_snorm(int x
, unsigned src_bits
, unsigned dst_bits
)
234 if (x
< -MAX_INT(src_bits
))
235 return -MAX_INT(dst_bits
);
236 else if (src_bits
< dst_bits
)
237 return EXTEND_NORMALIZED_INT(x
, src_bits
- 1, dst_bits
- 1);
239 return x
>> (src_bits
- dst_bits
);
242 static inline unsigned
243 float_to_uint(float x
)
251 static inline unsigned
252 half_to_uint(uint16_t x
)
254 if (_mesa_half_is_negative(x
))
257 return _mesa_float_to_half(x
);
261 * Attempts to perform the given swizzle-and-convert operation with memcpy
263 * This function determines if the given swizzle-and-convert operation can
264 * be done with a simple memcpy and, if so, does the memcpy. If not, it
265 * returns false and we fall back to the standard version below.
267 * The arguments are exactly the same as for _mesa_swizzle_and_convert
269 * \return true if it successfully performed the swizzle-and-convert
270 * operation with memcpy, false otherwise
273 swizzle_convert_try_memcpy(void *dst
, GLenum dst_type
, int num_dst_channels
,
274 const void *src
, GLenum src_type
, int num_src_channels
,
275 const uint8_t swizzle
[4], bool normalized
, int count
)
279 if (src_type
!= dst_type
)
281 if (num_src_channels
!= num_dst_channels
)
284 for (i
= 0; i
< num_dst_channels
; ++i
)
285 if (swizzle
[i
] != i
&& swizzle
[i
] != MESA_FORMAT_SWIZZLE_NONE
)
288 memcpy(dst
, src
, count
* num_src_channels
* _mesa_sizeof_type(src_type
));
294 * Represents a single instance of the standard swizzle-and-convert loop
296 * Any swizzle-and-convert operation simply loops through the pixels and
297 * performs the transformation operation one pixel at a time. This macro
298 * embodies one instance of the conversion loop. This way we can do all
299 * control flow outside of the loop and allow the compiler to unroll
300 * everything inside the loop.
302 * Note: This loop is carefully crafted for performance. Be careful when
303 * changing it and run some benchmarks to ensure no performance regressions
306 * \param DST_TYPE the C datatype of the destination
307 * \param DST_CHANS the number of destination channels
308 * \param SRC_TYPE the C datatype of the source
309 * \param SRC_CHANS the number of source channels
310 * \param CONV an expression for converting from the source data,
311 * storred in the variable "src", to the destination
314 #define SWIZZLE_CONVERT_LOOP(DST_TYPE, DST_CHANS, SRC_TYPE, SRC_CHANS, CONV) \
315 for (s = 0; s < count; ++s) { \
316 for (j = 0; j < SRC_CHANS; ++j) { \
317 SRC_TYPE src = typed_src[j]; \
321 typed_dst[0] = tmp[swizzle_x]; \
322 if (DST_CHANS > 1) { \
323 typed_dst[1] = tmp[swizzle_y]; \
324 if (DST_CHANS > 2) { \
325 typed_dst[2] = tmp[swizzle_z]; \
326 if (DST_CHANS > 3) { \
327 typed_dst[3] = tmp[swizzle_w]; \
331 typed_src += SRC_CHANS; \
332 typed_dst += DST_CHANS; \
336 * Represents a single swizzle-and-convert operation
338 * This macro represents everything done in a single swizzle-and-convert
339 * operation. The actual work is done by the SWIZZLE_CONVERT_LOOP macro.
340 * This macro acts as a wrapper that uses a nested switch to ensure that
341 * all looping parameters get unrolled.
343 * This macro makes assumptions about variables etc. in the calling
344 * function. Changes to _mesa_swizzle_and_convert may require changes to
347 * \param DST_TYPE the C datatype of the destination
348 * \param SRC_TYPE the C datatype of the source
349 * \param CONV an expression for converting from the source data,
350 * storred in the variable "src", to the destination
353 #define SWIZZLE_CONVERT(DST_TYPE, SRC_TYPE, CONV) \
355 const SRC_TYPE *typed_src = void_src; \
356 DST_TYPE *typed_dst = void_dst; \
360 switch (num_dst_channels) { \
362 switch (num_src_channels) { \
364 SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 1, CONV) \
367 SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 2, CONV) \
370 SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 3, CONV) \
373 SWIZZLE_CONVERT_LOOP(DST_TYPE, 1, SRC_TYPE, 4, CONV) \
378 switch (num_src_channels) { \
380 SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 1, CONV) \
383 SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 2, CONV) \
386 SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 3, CONV) \
389 SWIZZLE_CONVERT_LOOP(DST_TYPE, 2, SRC_TYPE, 4, CONV) \
394 switch (num_src_channels) { \
396 SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 1, CONV) \
399 SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 2, CONV) \
402 SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 3, CONV) \
405 SWIZZLE_CONVERT_LOOP(DST_TYPE, 3, SRC_TYPE, 4, CONV) \
410 switch (num_src_channels) { \
412 SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 1, CONV) \
415 SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 2, CONV) \
418 SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 3, CONV) \
421 SWIZZLE_CONVERT_LOOP(DST_TYPE, 4, SRC_TYPE, 4, CONV) \
429 * Convert between array-based color formats.
431 * Most format conversion operations required by GL can be performed by
432 * converting one channel at a time, shuffling the channels around, and
433 * optionally filling missing channels with zeros and ones. This function
434 * does just that in a general, yet efficient, way.
436 * The swizzle parameter is an array of 4 numbers (see
437 * _mesa_get_format_swizzle) that describes where each channel in the
438 * destination should come from in the source. If swizzle[i] < 4 then it
439 * means that dst[i] = CONVERT(src[swizzle[i]]). If swizzle[i] is
440 * MESA_FORMAT_SWIZZLE_ZERO or MESA_FORMAT_SWIZZLE_ONE, the corresponding
441 * dst[i] will be filled with the appropreate representation of zero or one
444 * Under most circumstances, the source and destination images must be
445 * different as no care is taken not to clobber one with the other.
446 * However, if they have the same number of bits per pixel, it is safe to
447 * do an in-place conversion.
449 * \param[out] dst pointer to where the converted data should
452 * \param[in] dst_type the destination GL type of the converted
453 * data (GL_BYTE, etc.)
455 * \param[in] num_dst_channels the number of channels in the converted
458 * \param[in] src pointer to the source data
460 * \param[in] src_type the GL type of the source data (GL_BYTE,
463 * \param[in] num_src_channels the number of channels in the source data
464 * (the number of channels total, not just
467 * \param[in] swizzle describes how to get the destination data
468 * from the source data.
470 * \param[in] normalized for integer types, this indicates whether
471 * the data should be considered as integers
472 * or as normalized integers;
474 * \param[in] count the number of pixels to convert
477 _mesa_swizzle_and_convert(void *void_dst
, GLenum dst_type
, int num_dst_channels
,
478 const void *void_src
, GLenum src_type
, int num_src_channels
,
479 const uint8_t swizzle
[4], bool normalized
, int count
)
482 register uint8_t swizzle_x
, swizzle_y
, swizzle_z
, swizzle_w
;
484 if (swizzle_convert_try_memcpy(void_dst
, dst_type
, num_dst_channels
,
485 void_src
, src_type
, num_src_channels
,
486 swizzle
, normalized
, count
))
489 swizzle_x
= swizzle
[0];
490 swizzle_y
= swizzle
[1];
491 swizzle_z
= swizzle
[2];
492 swizzle_w
= swizzle
[3];
497 const float one
= 1.0f
;
500 SWIZZLE_CONVERT(float, float, src
)
503 SWIZZLE_CONVERT(float, uint16_t, _mesa_half_to_float(src
))
505 case GL_UNSIGNED_BYTE
:
507 SWIZZLE_CONVERT(float, uint8_t, unorm_to_float(src
, 8))
509 SWIZZLE_CONVERT(float, uint8_t, src
)
514 SWIZZLE_CONVERT(float, int8_t, snorm_to_float(src
, 8))
516 SWIZZLE_CONVERT(float, int8_t, src
)
519 case GL_UNSIGNED_SHORT
:
521 SWIZZLE_CONVERT(float, uint16_t, unorm_to_float(src
, 16))
523 SWIZZLE_CONVERT(float, uint16_t, src
)
528 SWIZZLE_CONVERT(float, int16_t, snorm_to_float(src
, 16))
530 SWIZZLE_CONVERT(float, int16_t, src
)
533 case GL_UNSIGNED_INT
:
535 SWIZZLE_CONVERT(float, uint32_t, unorm_to_float(src
, 32))
537 SWIZZLE_CONVERT(float, uint32_t, src
)
542 SWIZZLE_CONVERT(float, int32_t, snorm_to_float(src
, 32))
544 SWIZZLE_CONVERT(float, int32_t, src
)
548 assert(!"Invalid channel type combination");
554 const uint16_t one
= _mesa_float_to_half(1.0f
);
557 SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_half(src
))
560 SWIZZLE_CONVERT(uint16_t, uint16_t, src
)
562 case GL_UNSIGNED_BYTE
:
564 SWIZZLE_CONVERT(uint16_t, uint8_t, unorm_to_half(src
, 8))
566 SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_float_to_half(src
))
571 SWIZZLE_CONVERT(uint16_t, int8_t, snorm_to_half(src
, 8))
573 SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_float_to_half(src
))
576 case GL_UNSIGNED_SHORT
:
578 SWIZZLE_CONVERT(uint16_t, uint16_t, unorm_to_half(src
, 16))
580 SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_float_to_half(src
))
585 SWIZZLE_CONVERT(uint16_t, int16_t, snorm_to_half(src
, 16))
587 SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_float_to_half(src
))
590 case GL_UNSIGNED_INT
:
592 SWIZZLE_CONVERT(uint16_t, uint32_t, unorm_to_half(src
, 32))
594 SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_float_to_half(src
))
599 SWIZZLE_CONVERT(uint16_t, int32_t, snorm_to_half(src
, 32))
601 SWIZZLE_CONVERT(uint16_t, int32_t, _mesa_float_to_half(src
))
605 assert(!"Invalid channel type combination");
609 case GL_UNSIGNED_BYTE
:
611 const uint8_t one
= normalized
? UINT8_MAX
: 1;
615 SWIZZLE_CONVERT(uint8_t, float, float_to_unorm(src
, 8))
617 SWIZZLE_CONVERT(uint8_t, float, (src
< 0) ? 0 : src
)
622 SWIZZLE_CONVERT(uint8_t, uint16_t, half_to_unorm(src
, 8))
624 SWIZZLE_CONVERT(uint8_t, uint16_t, half_to_uint(src
))
627 case GL_UNSIGNED_BYTE
:
628 SWIZZLE_CONVERT(uint8_t, uint8_t, src
)
632 SWIZZLE_CONVERT(uint8_t, int8_t, snorm_to_unorm(src
, 8, 8))
634 SWIZZLE_CONVERT(uint8_t, int8_t, (src
< 0) ? 0 : src
)
637 case GL_UNSIGNED_SHORT
:
639 SWIZZLE_CONVERT(uint8_t, uint16_t, unorm_to_unorm(src
, 16, 8))
641 SWIZZLE_CONVERT(uint8_t, uint16_t, src
)
646 SWIZZLE_CONVERT(uint8_t, int16_t, snorm_to_unorm(src
, 16, 8))
648 SWIZZLE_CONVERT(uint8_t, int16_t, (src
< 0) ? 0 : src
)
651 case GL_UNSIGNED_INT
:
653 SWIZZLE_CONVERT(uint8_t, uint32_t, unorm_to_unorm(src
, 32, 8))
655 SWIZZLE_CONVERT(uint8_t, uint32_t, src
)
660 SWIZZLE_CONVERT(uint8_t, int32_t, snorm_to_unorm(src
, 32, 8))
662 SWIZZLE_CONVERT(uint8_t, int32_t, (src
< 0) ? 0 : src
)
666 assert(!"Invalid channel type combination");
672 const int8_t one
= normalized
? INT8_MAX
: 1;
676 SWIZZLE_CONVERT(uint8_t, float, float_to_snorm(src
, 8))
678 SWIZZLE_CONVERT(uint8_t, float, src
)
683 SWIZZLE_CONVERT(uint8_t, uint16_t, half_to_snorm(src
, 8))
685 SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_float(src
))
688 case GL_UNSIGNED_BYTE
:
690 SWIZZLE_CONVERT(int8_t, uint8_t, unorm_to_snorm(src
, 8, 8))
692 SWIZZLE_CONVERT(int8_t, uint8_t, src
)
696 SWIZZLE_CONVERT(int8_t, int8_t, src
)
698 case GL_UNSIGNED_SHORT
:
700 SWIZZLE_CONVERT(int8_t, uint16_t, unorm_to_snorm(src
, 16, 8))
702 SWIZZLE_CONVERT(int8_t, uint16_t, src
)
707 SWIZZLE_CONVERT(int8_t, int16_t, snorm_to_snorm(src
, 16, 8))
709 SWIZZLE_CONVERT(int8_t, int16_t, src
)
712 case GL_UNSIGNED_INT
:
714 SWIZZLE_CONVERT(int8_t, uint32_t, unorm_to_snorm(src
, 32, 8))
716 SWIZZLE_CONVERT(int8_t, uint32_t, src
)
721 SWIZZLE_CONVERT(int8_t, int32_t, snorm_to_snorm(src
, 32, 8))
723 SWIZZLE_CONVERT(int8_t, int32_t, src
)
727 assert(!"Invalid channel type combination");
731 case GL_UNSIGNED_SHORT
:
733 const uint16_t one
= normalized
? UINT16_MAX
: 1;
737 SWIZZLE_CONVERT(uint16_t, float, float_to_unorm(src
, 16))
739 SWIZZLE_CONVERT(uint16_t, float, (src
< 0) ? 0 : src
)
744 SWIZZLE_CONVERT(uint16_t, uint16_t, half_to_unorm(src
, 16))
746 SWIZZLE_CONVERT(uint16_t, uint16_t, half_to_uint(src
))
749 case GL_UNSIGNED_BYTE
:
751 SWIZZLE_CONVERT(uint16_t, uint8_t, unorm_to_unorm(src
, 8, 16))
753 SWIZZLE_CONVERT(uint16_t, uint8_t, src
)
758 SWIZZLE_CONVERT(uint16_t, int8_t, snorm_to_unorm(src
, 8, 16))
760 SWIZZLE_CONVERT(uint16_t, int8_t, (src
< 0) ? 0 : src
)
763 case GL_UNSIGNED_SHORT
:
764 SWIZZLE_CONVERT(uint16_t, uint16_t, src
)
768 SWIZZLE_CONVERT(uint16_t, int16_t, snorm_to_unorm(src
, 16, 16))
770 SWIZZLE_CONVERT(uint16_t, int16_t, (src
< 0) ? 0 : src
)
773 case GL_UNSIGNED_INT
:
775 SWIZZLE_CONVERT(uint16_t, uint32_t, unorm_to_unorm(src
, 32, 16))
777 SWIZZLE_CONVERT(uint16_t, uint32_t, src
)
782 SWIZZLE_CONVERT(uint16_t, int32_t, snorm_to_unorm(src
, 32, 16))
784 SWIZZLE_CONVERT(uint16_t, int32_t, (src
< 0) ? 0 : src
)
788 assert(!"Invalid channel type combination");
794 const int16_t one
= normalized
? INT16_MAX
: 1;
798 SWIZZLE_CONVERT(uint16_t, float, float_to_snorm(src
, 16))
800 SWIZZLE_CONVERT(uint16_t, float, src
)
805 SWIZZLE_CONVERT(uint16_t, uint16_t, half_to_snorm(src
, 16))
807 SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_float(src
))
810 case GL_UNSIGNED_BYTE
:
812 SWIZZLE_CONVERT(int16_t, uint8_t, unorm_to_snorm(src
, 8, 16))
814 SWIZZLE_CONVERT(int16_t, uint8_t, src
)
819 SWIZZLE_CONVERT(int16_t, int8_t, snorm_to_snorm(src
, 8, 16))
821 SWIZZLE_CONVERT(int16_t, int8_t, src
)
824 case GL_UNSIGNED_SHORT
:
826 SWIZZLE_CONVERT(int16_t, uint16_t, unorm_to_snorm(src
, 16, 16))
828 SWIZZLE_CONVERT(int16_t, uint16_t, src
)
832 SWIZZLE_CONVERT(int16_t, int16_t, src
)
834 case GL_UNSIGNED_INT
:
836 SWIZZLE_CONVERT(int16_t, uint32_t, unorm_to_snorm(src
, 32, 16))
838 SWIZZLE_CONVERT(int16_t, uint32_t, src
)
843 SWIZZLE_CONVERT(int16_t, int32_t, snorm_to_snorm(src
, 32, 16))
845 SWIZZLE_CONVERT(int16_t, int32_t, src
)
849 assert(!"Invalid channel type combination");
853 case GL_UNSIGNED_INT
:
855 const uint32_t one
= normalized
? UINT32_MAX
: 1;
856 switch (src_type
) { case GL_FLOAT
:
858 SWIZZLE_CONVERT(uint32_t, float, float_to_unorm(src
, 32))
860 SWIZZLE_CONVERT(uint32_t, float, (src
< 0) ? 0 : src
)
865 SWIZZLE_CONVERT(uint32_t, uint16_t, half_to_unorm(src
, 32))
867 SWIZZLE_CONVERT(uint32_t, uint16_t, half_to_uint(src
))
870 case GL_UNSIGNED_BYTE
:
872 SWIZZLE_CONVERT(uint32_t, uint8_t, unorm_to_unorm(src
, 8, 32))
874 SWIZZLE_CONVERT(uint32_t, uint8_t, src
)
879 SWIZZLE_CONVERT(uint32_t, int8_t, snorm_to_unorm(src
, 8, 32))
881 SWIZZLE_CONVERT(uint32_t, int8_t, (src
< 0) ? 0 : src
)
884 case GL_UNSIGNED_SHORT
:
886 SWIZZLE_CONVERT(uint32_t, uint16_t, unorm_to_unorm(src
, 16, 32))
888 SWIZZLE_CONVERT(uint32_t, uint16_t, src
)
893 SWIZZLE_CONVERT(uint32_t, int16_t, snorm_to_unorm(src
, 16, 32))
895 SWIZZLE_CONVERT(uint32_t, int16_t, (src
< 0) ? 0 : src
)
898 case GL_UNSIGNED_INT
:
899 SWIZZLE_CONVERT(uint32_t, uint32_t, src
)
903 SWIZZLE_CONVERT(uint32_t, int32_t, snorm_to_unorm(src
, 32, 32))
905 SWIZZLE_CONVERT(uint32_t, int32_t, (src
< 0) ? 0 : src
)
909 assert(!"Invalid channel type combination");
915 const int32_t one
= normalized
? INT32_MAX
: 1;
919 SWIZZLE_CONVERT(uint32_t, float, float_to_snorm(src
, 32))
921 SWIZZLE_CONVERT(uint32_t, float, src
)
926 SWIZZLE_CONVERT(uint32_t, uint16_t, half_to_snorm(src
, 32))
928 SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_float(src
))
931 case GL_UNSIGNED_BYTE
:
933 SWIZZLE_CONVERT(int32_t, uint8_t, unorm_to_snorm(src
, 8, 32))
935 SWIZZLE_CONVERT(int32_t, uint8_t, src
)
940 SWIZZLE_CONVERT(int32_t, int8_t, snorm_to_snorm(src
, 8, 32))
942 SWIZZLE_CONVERT(int32_t, int8_t, src
)
945 case GL_UNSIGNED_SHORT
:
947 SWIZZLE_CONVERT(int32_t, uint16_t, unorm_to_snorm(src
, 16, 32))
949 SWIZZLE_CONVERT(int32_t, uint16_t, src
)
954 SWIZZLE_CONVERT(int32_t, int16_t, snorm_to_snorm(src
, 16, 32))
956 SWIZZLE_CONVERT(int32_t, int16_t, src
)
959 case GL_UNSIGNED_INT
:
961 SWIZZLE_CONVERT(int32_t, uint32_t, unorm_to_snorm(src
, 32, 32))
963 SWIZZLE_CONVERT(int32_t, uint32_t, src
)
967 SWIZZLE_CONVERT(int32_t, int32_t, src
)
970 assert(!"Invalid channel type combination");
975 assert(!"Invalid channel type");