e734e31a7986a4b36d967cab1fee5ed145b766b9
3 from mako
.template
import Template
7 * Mesa 3-D graphics library
9 * Copyright (c) 2011 VMware, Inc.
10 * Copyright (c) 2014 Intel Corporation.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
33 * Color, depth, stencil packing functions.
34 * Used to pack basic color, depth and stencil formats to specific
37 * There are both per-pixel and per-row packing functions:
38 * - The former will be used by swrast to write values to the color, depth,
39 * stencil buffers when drawing points, lines and masked spans.
40 * - The later will be used for image-oriented functions like glDrawPixels,
41 * glAccum, and glTexImage.
47 #include "format_pack.h"
48 #include "format_utils.h"
50 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
51 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
52 #include "util/format_srgb.h"
54 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
55 #define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET))
58 import format_parser as parser
60 formats = parser.parse(argv[1])
64 if f.name == 'MESA_FORMAT_NONE':
66 if f.colorspace not in ('rgb', 'srgb'):
72 /* ubyte packing functions */
74 %for f in rgb_formats:
75 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
77 %elif f.is_compressed():
82 pack_ubyte_${f.short_name()}(const GLubyte src[4], void *dst)
84 %for (i, c) in enumerate(f.channels):
85 <% i = f.swizzle.inverse()[i] %>
90 ${c.datatype()} ${c.name} =
91 %if not f.is_normalized() and f.is_int():
92 %if c.type == parser.SIGNED:
93 _mesa_unsigned_to_signed(src[${i}], ${c.size});
95 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
97 %elif c.type == parser.UNSIGNED:
98 %if f.colorspace == 'srgb' and c.name in 'rgb':
99 <% assert c.size == 8 %>
100 util_format_linear_to_srgb_8unorm(src[${i}]);
102 _mesa_unorm_to_unorm(src[${i}], 8, ${c.size});
104 %elif c.type == parser.SIGNED:
105 _mesa_unorm_to_snorm(src[${i}], 8, ${c.size});
106 %elif c.type == parser.FLOAT:
108 _mesa_unorm_to_float(src[${i}], 8);
110 _mesa_unorm_to_half(src[${i}], 8);
119 %if f.layout == parser.ARRAY:
120 ${f.datatype()} *d = (${f.datatype()} *)dst;
121 %for (i, c) in enumerate(f.channels):
127 %elif f.layout == parser.PACKED:
128 ${f.datatype()} d = 0;
129 %for (i, c) in enumerate(f.channels):
133 d |= PACK(${c.name}, ${c.shift}, ${c.size});
135 (*(${f.datatype()} *)dst) = d;
143 pack_ubyte_r9g9b9e5_float(const GLubyte src[4], void *dst)
145 GLuint *d = (GLuint *) dst;
147 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
148 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
149 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
150 *d = float3_to_rgb9e5(rgb);
154 pack_ubyte_r11g11b10_float(const GLubyte src[4], void *dst)
156 GLuint *d = (GLuint *) dst;
158 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
159 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
160 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
161 *d = float3_to_r11g11b10f(rgb);
164 /* uint packing functions */
166 %for f in rgb_formats:
169 %elif f.is_normalized():
171 %elif f.is_compressed():
176 pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
178 %for (i, c) in enumerate(f.channels):
179 <% i = f.swizzle.inverse()[i] %>
184 ${c.datatype()} ${c.name} =
185 %if c.type == parser.SIGNED:
186 _mesa_signed_to_signed(src[${i}], ${c.size});
187 %elif c.type == parser.UNSIGNED:
188 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
190 assert(!"Invalid type: only integer types are allowed");
194 %if f.layout == parser.ARRAY:
195 ${f.datatype()} *d = (${f.datatype()} *)dst;
196 %for (i, c) in enumerate(f.channels):
202 %elif f.layout == parser.PACKED:
203 ${f.datatype()} d = 0;
204 %for (i, c) in enumerate(f.channels):
208 d |= PACK(${c.name}, ${c.shift}, ${c.size});
210 (*(${f.datatype()} *)dst) = d;
217 /* int packing functions */
219 %for f in rgb_formats:
222 %elif f.is_normalized():
224 %elif f.is_compressed():
229 pack_int_${f.short_name()}(const GLint src[4], void *dst)
231 %for (i, c) in enumerate(f.channels):
232 <% i = f.swizzle.inverse()[i] %>
237 ${c.datatype()} ${c.name} =
238 %if c.type == parser.SIGNED:
239 _mesa_signed_to_signed(src[${i}], ${c.size});
240 %elif c.type == parser.UNSIGNED:
241 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
243 assert(!"Invalid type: only integer types are allowed");
247 %if f.layout == parser.ARRAY:
248 ${f.datatype()} *d = (${f.datatype()} *)dst;
249 %for (i, c) in enumerate(f.channels):
255 %elif f.layout == parser.PACKED:
256 ${f.datatype()} d = 0;
257 %for (i, c) in enumerate(f.channels):
261 d |= PACK(${c.name}, ${c.shift}, ${c.size});
263 (*(${f.datatype()} *)dst) = d;
270 /* float packing functions */
272 %for f in rgb_formats:
273 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
275 %elif f.is_int() and not f.is_normalized():
277 %elif f.is_compressed():
282 pack_float_${f.short_name()}(const GLfloat src[4], void *dst)
284 %for (i, c) in enumerate(f.channels):
285 <% i = f.swizzle.inverse()[i] %>
290 ${c.datatype()} ${c.name} =
291 %if c.type == parser.UNSIGNED:
292 %if f.colorspace == 'srgb' and c.name in 'rgb':
293 <% assert c.size == 8 %>
294 util_format_linear_float_to_srgb_8unorm(src[${i}]);
296 _mesa_float_to_unorm(src[${i}], ${c.size});
298 %elif c.type == parser.SIGNED:
299 _mesa_float_to_snorm(src[${i}], ${c.size});
300 %elif c.type == parser.FLOAT:
304 _mesa_float_to_half(src[${i}]);
313 %if f.layout == parser.ARRAY:
314 ${f.datatype()} *d = (${f.datatype()} *)dst;
315 %for (i, c) in enumerate(f.channels):
321 %elif f.layout == parser.PACKED:
322 ${f.datatype()} d = 0;
323 %for (i, c) in enumerate(f.channels):
327 d |= PACK(${c.name}, ${c.shift}, ${c.size});
329 (*(${f.datatype()} *)dst) = d;
337 pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
339 GLuint *d = (GLuint *) dst;
340 *d = float3_to_rgb9e5(src);
344 pack_float_r11g11b10_float(const GLfloat src[4], void *dst)
346 GLuint *d = (GLuint *) dst;
347 *d = float3_to_r11g11b10f(src);
351 * Return a function that can pack a GLubyte rgba[4] color.
353 gl_pack_ubyte_rgba_func
354 _mesa_get_pack_ubyte_rgba_function(mesa_format format)
357 %for f in rgb_formats:
358 %if f.is_compressed():
363 return pack_ubyte_${f.short_name()};
371 * Return a function that can pack a GLfloat rgba[4] color.
373 gl_pack_float_rgba_func
374 _mesa_get_pack_float_rgba_function(mesa_format format)
377 %for f in rgb_formats:
378 %if f.is_compressed():
380 %elif f.is_int() and not f.is_normalized():
385 return pack_float_${f.short_name()};
393 * Pack a row of GLubyte rgba[4] values to the destination.
396 _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
397 const GLubyte src[][4], void *dst)
403 %for f in rgb_formats:
404 %if f.is_compressed():
409 for (i = 0; i < n; ++i) {
410 pack_ubyte_${f.short_name()}(src[i], d);
411 d += ${f.block_size() / 8};
416 assert(!"Invalid format");
421 * Pack a row of GLuint rgba[4] values to the destination.
424 _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
425 const GLuint src[][4], void *dst)
431 %for f in rgb_formats:
434 %elif f.is_normalized():
436 %elif f.is_compressed():
441 for (i = 0; i < n; ++i) {
442 pack_uint_${f.short_name()}(src[i], d);
443 d += ${f.block_size() / 8};
448 assert(!"Invalid format");
453 * Pack a row of GLint rgba[4] values to the destination.
456 _mesa_pack_int_rgba_row(mesa_format format, GLuint n,
457 const GLint src[][4], void *dst)
463 %for f in rgb_formats:
466 %elif f.is_normalized():
468 %elif f.is_compressed():
473 for (i = 0; i < n; ++i) {
474 pack_int_${f.short_name()}(src[i], d);
475 d += ${f.block_size() / 8};
480 assert(!"Invalid format");
485 * Pack a row of GLfloat rgba[4] values to the destination.
488 _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
489 const GLfloat src[][4], void *dst)
495 %for f in rgb_formats:
496 %if f.is_compressed():
498 %elif f.is_int() and not f.is_normalized():
503 for (i = 0; i < n; ++i) {
504 pack_float_${f.short_name()}(src[i], d);
505 d += ${f.block_size() / 8};
510 assert(!"Invalid format");
515 * Pack a 2D image of ubyte RGBA pixels in the given format.
516 * \param srcRowStride source image row stride in bytes
517 * \param dstRowStride destination image row stride in bytes
520 _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
521 const GLubyte *src, GLint srcRowStride,
522 void *dst, GLint dstRowStride)
524 GLubyte *dstUB = dst;
527 if (srcRowStride == width * 4 * sizeof(GLubyte) &&
528 dstRowStride == _mesa_format_row_stride(format, width)) {
529 /* do whole image at once */
530 _mesa_pack_ubyte_rgba_row(format, width * height,
531 (const GLubyte (*)[4]) src, dst);
535 for (i = 0; i < height; i++) {
536 _mesa_pack_ubyte_rgba_row(format, width,
537 (const GLubyte (*)[4]) src, dstUB);
539 dstUB += dstRowStride;
545 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
554 ** Pack float Z pixels
558 pack_float_S8_UINT_Z24_UNORM(const GLfloat *src, void *dst)
560 /* don't disturb the stencil values */
561 GLuint *d = ((GLuint *) dst);
562 const GLdouble scale = (GLdouble) 0xffffff;
563 GLuint s = *d & 0xff;
564 GLuint z = (GLuint) (*src * scale);
565 assert(z <= 0xffffff);
570 pack_float_Z24_UNORM_S8_UINT(const GLfloat *src, void *dst)
572 /* don't disturb the stencil values */
573 GLuint *d = ((GLuint *) dst);
574 const GLdouble scale = (GLdouble) 0xffffff;
575 GLuint s = *d & 0xff000000;
576 GLuint z = (GLuint) (*src * scale);
577 assert(z <= 0xffffff);
582 pack_float_Z_UNORM16(const GLfloat *src, void *dst)
584 GLushort *d = ((GLushort *) dst);
585 const GLfloat scale = (GLfloat) 0xffff;
586 *d = (GLushort) (*src * scale);
590 pack_float_Z_UNORM32(const GLfloat *src, void *dst)
592 GLuint *d = ((GLuint *) dst);
593 const GLdouble scale = (GLdouble) 0xffffffff;
594 *d = (GLuint) (*src * scale);
598 pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
600 GLfloat *d = (GLfloat *) dst;
605 _mesa_get_pack_float_z_func(mesa_format format)
608 case MESA_FORMAT_S8_UINT_Z24_UNORM:
609 case MESA_FORMAT_X8_UINT_Z24_UNORM:
610 return pack_float_S8_UINT_Z24_UNORM;
611 case MESA_FORMAT_Z24_UNORM_S8_UINT:
612 case MESA_FORMAT_Z24_UNORM_X8_UINT:
613 return pack_float_Z24_UNORM_S8_UINT;
614 case MESA_FORMAT_Z_UNORM16:
615 return pack_float_Z_UNORM16;
616 case MESA_FORMAT_Z_UNORM32:
617 return pack_float_Z_UNORM32;
618 case MESA_FORMAT_Z_FLOAT32:
619 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
620 return pack_float_Z_FLOAT32;
623 "unexpected format in _mesa_get_pack_float_z_func()");
631 ** Pack uint Z pixels. The incoming src value is always in
632 ** the range [0, 2^32-1].
636 pack_uint_S8_UINT_Z24_UNORM(const GLuint *src, void *dst)
638 /* don't disturb the stencil values */
639 GLuint *d = ((GLuint *) dst);
640 GLuint s = *d & 0xff;
641 GLuint z = *src & 0xffffff00;
646 pack_uint_Z24_UNORM_S8_UINT(const GLuint *src, void *dst)
648 /* don't disturb the stencil values */
649 GLuint *d = ((GLuint *) dst);
650 GLuint s = *d & 0xff000000;
651 GLuint z = *src >> 8;
656 pack_uint_Z_UNORM16(const GLuint *src, void *dst)
658 GLushort *d = ((GLushort *) dst);
663 pack_uint_Z_UNORM32(const GLuint *src, void *dst)
665 GLuint *d = ((GLuint *) dst);
670 pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
672 GLuint *d = ((GLuint *) dst);
673 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
674 *d = (GLuint) (*src * scale);
680 pack_uint_Z_FLOAT32_X24S8(const GLuint *src, void *dst)
682 GLfloat *d = ((GLfloat *) dst);
683 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
684 *d = (GLfloat) (*src * scale);
690 _mesa_get_pack_uint_z_func(mesa_format format)
693 case MESA_FORMAT_S8_UINT_Z24_UNORM:
694 case MESA_FORMAT_X8_UINT_Z24_UNORM:
695 return pack_uint_S8_UINT_Z24_UNORM;
696 case MESA_FORMAT_Z24_UNORM_S8_UINT:
697 case MESA_FORMAT_Z24_UNORM_X8_UINT:
698 return pack_uint_Z24_UNORM_S8_UINT;
699 case MESA_FORMAT_Z_UNORM16:
700 return pack_uint_Z_UNORM16;
701 case MESA_FORMAT_Z_UNORM32:
702 return pack_uint_Z_UNORM32;
703 case MESA_FORMAT_Z_FLOAT32:
704 return pack_uint_Z_FLOAT32;
705 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
706 return pack_uint_Z_FLOAT32_X24S8;
708 _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
715 ** Pack ubyte stencil pixels
719 pack_ubyte_stencil_Z24_S8(const GLubyte *src, void *dst)
721 /* don't disturb the Z values */
722 GLuint *d = ((GLuint *) dst);
724 GLuint z = *d & 0xffffff00;
729 pack_ubyte_stencil_S8_Z24(const GLubyte *src, void *dst)
731 /* don't disturb the Z values */
732 GLuint *d = ((GLuint *) dst);
733 GLuint s = *src << 24;
734 GLuint z = *d & 0xffffff;
739 pack_ubyte_stencil_S8(const GLubyte *src, void *dst)
741 GLubyte *d = (GLubyte *) dst;
746 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte *src, void *dst)
748 GLfloat *d = ((GLfloat *) dst);
753 gl_pack_ubyte_stencil_func
754 _mesa_get_pack_ubyte_stencil_func(mesa_format format)
757 case MESA_FORMAT_S8_UINT_Z24_UNORM:
758 return pack_ubyte_stencil_Z24_S8;
759 case MESA_FORMAT_Z24_UNORM_S8_UINT:
760 return pack_ubyte_stencil_S8_Z24;
761 case MESA_FORMAT_S_UINT8:
762 return pack_ubyte_stencil_S8;
763 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
764 return pack_ubyte_stencil_Z32_FLOAT_X24S8;
767 "unexpected format in _mesa_pack_ubyte_stencil_func()");
775 _mesa_pack_float_z_row(mesa_format format, GLuint n,
776 const GLfloat *src, void *dst)
779 case MESA_FORMAT_S8_UINT_Z24_UNORM:
780 case MESA_FORMAT_X8_UINT_Z24_UNORM:
782 /* don't disturb the stencil values */
783 GLuint *d = ((GLuint *) dst);
784 const GLdouble scale = (GLdouble) 0xffffff;
786 for (i = 0; i < n; i++) {
787 GLuint s = d[i] & 0xff;
788 GLuint z = (GLuint) (src[i] * scale);
789 assert(z <= 0xffffff);
794 case MESA_FORMAT_Z24_UNORM_S8_UINT:
795 case MESA_FORMAT_Z24_UNORM_X8_UINT:
797 /* don't disturb the stencil values */
798 GLuint *d = ((GLuint *) dst);
799 const GLdouble scale = (GLdouble) 0xffffff;
801 for (i = 0; i < n; i++) {
802 GLuint s = d[i] & 0xff000000;
803 GLuint z = (GLuint) (src[i] * scale);
804 assert(z <= 0xffffff);
809 case MESA_FORMAT_Z_UNORM16:
811 GLushort *d = ((GLushort *) dst);
812 const GLfloat scale = (GLfloat) 0xffff;
814 for (i = 0; i < n; i++) {
815 d[i] = (GLushort) (src[i] * scale);
819 case MESA_FORMAT_Z_UNORM32:
821 GLuint *d = ((GLuint *) dst);
822 const GLdouble scale = (GLdouble) 0xffffffff;
824 for (i = 0; i < n; i++) {
825 d[i] = (GLuint) (src[i] * scale);
829 case MESA_FORMAT_Z_FLOAT32:
830 memcpy(dst, src, n * sizeof(GLfloat));
832 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
834 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
836 for (i = 0; i < n; i++) {
842 _mesa_problem(NULL, "unexpected format in _mesa_pack_float_z_row()");
848 * The incoming Z values are always in the range [0, 0xffffffff].
851 _mesa_pack_uint_z_row(mesa_format format, GLuint n,
852 const GLuint *src, void *dst)
855 case MESA_FORMAT_S8_UINT_Z24_UNORM:
856 case MESA_FORMAT_X8_UINT_Z24_UNORM:
858 /* don't disturb the stencil values */
859 GLuint *d = ((GLuint *) dst);
861 for (i = 0; i < n; i++) {
862 GLuint s = d[i] & 0xff;
863 GLuint z = src[i] & 0xffffff00;
868 case MESA_FORMAT_Z24_UNORM_S8_UINT:
869 case MESA_FORMAT_Z24_UNORM_X8_UINT:
871 /* don't disturb the stencil values */
872 GLuint *d = ((GLuint *) dst);
874 for (i = 0; i < n; i++) {
875 GLuint s = d[i] & 0xff000000;
876 GLuint z = src[i] >> 8;
881 case MESA_FORMAT_Z_UNORM16:
883 GLushort *d = ((GLushort *) dst);
885 for (i = 0; i < n; i++) {
890 case MESA_FORMAT_Z_UNORM32:
891 memcpy(dst, src, n * sizeof(GLfloat));
893 case MESA_FORMAT_Z_FLOAT32:
895 GLuint *d = ((GLuint *) dst);
896 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
898 for (i = 0; i < n; i++) {
899 d[i] = (GLuint) (src[i] * scale);
900 assert(d[i] >= 0.0f);
901 assert(d[i] <= 1.0f);
905 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
907 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
908 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
910 for (i = 0; i < n; i++) {
911 d[i].z = (GLfloat) (src[i] * scale);
912 assert(d[i].z >= 0.0f);
913 assert(d[i].z <= 1.0f);
918 _mesa_problem(NULL, "unexpected format in _mesa_pack_uint_z_row()");
924 _mesa_pack_ubyte_stencil_row(mesa_format format, GLuint n,
925 const GLubyte *src, void *dst)
928 case MESA_FORMAT_S8_UINT_Z24_UNORM:
930 /* don't disturb the Z values */
931 GLuint *d = ((GLuint *) dst);
933 for (i = 0; i < n; i++) {
935 GLuint z = d[i] & 0xffffff00;
940 case MESA_FORMAT_Z24_UNORM_S8_UINT:
942 /* don't disturb the Z values */
943 GLuint *d = ((GLuint *) dst);
945 for (i = 0; i < n; i++) {
946 GLuint s = src[i] << 24;
947 GLuint z = d[i] & 0xffffff;
952 case MESA_FORMAT_S_UINT8:
953 memcpy(dst, src, n * sizeof(GLubyte));
955 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
957 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
959 for (i = 0; i < n; i++) {
965 _mesa_problem(NULL, "unexpected format in _mesa_pack_ubyte_stencil_row()");
971 * Incoming Z/stencil values are always in uint_24_8 format.
974 _mesa_pack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
975 const GLuint *src, void *dst)
978 case MESA_FORMAT_S8_UINT_Z24_UNORM:
979 memcpy(dst, src, n * sizeof(GLuint));
981 case MESA_FORMAT_Z24_UNORM_S8_UINT:
983 GLuint *d = ((GLuint *) dst);
985 for (i = 0; i < n; i++) {
986 GLuint s = src[i] << 24;
987 GLuint z = src[i] >> 8;
992 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
994 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
995 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
997 for (i = 0; i < n; i++) {
998 GLfloat z = (GLfloat) ((src[i] >> 8) * scale);
1000 d[i].x24s8 = src[i];
1005 _mesa_problem(NULL, "bad format %s in _mesa_pack_ubyte_s_row",
1006 _mesa_get_format_name(format));
1014 * Convert a boolean color mask to a packed color where each channel of
1015 * the packed value at dst will be 0 or ~0 depending on the colorMask.
1018 _mesa_pack_colormask(mesa_format format, const GLubyte colorMask[4], void *dst)
1020 GLfloat maskColor[4];
1022 switch (_mesa_get_format_datatype(format)) {
1023 case GL_UNSIGNED_NORMALIZED:
1024 /* simple: 1.0 will convert to ~0 in the right bit positions */
1025 maskColor[0] = colorMask[0] ? 1.0f : 0.0f;
1026 maskColor[1] = colorMask[1] ? 1.0f : 0.0f;
1027 maskColor[2] = colorMask[2] ? 1.0f : 0.0f;
1028 maskColor[3] = colorMask[3] ? 1.0f : 0.0f;
1029 _mesa_pack_float_rgba_row(format, 1,
1030 (const GLfloat (*)[4]) maskColor, dst);
1032 case GL_SIGNED_NORMALIZED:
1034 /* These formats are harder because it's hard to know the floating
1035 * point values that will convert to ~0 for each color channel's bits.
1036 * This solution just generates a non-zero value for each color channel
1037 * then fixes up the non-zero values to be ~0.
1038 * Note: we'll need to add special case code if we ever have to deal
1039 * with formats with unequal color channel sizes, like R11_G11_B10.
1040 * We issue a warning below for channel sizes other than 8,16,32.
1043 GLuint bits = _mesa_get_format_max_bits(format); /* bits per chan */
1044 GLuint bytes = _mesa_get_format_bytes(format);
1047 /* this should put non-zero values into the channels of dst */
1048 maskColor[0] = colorMask[0] ? -1.0f : 0.0f;
1049 maskColor[1] = colorMask[1] ? -1.0f : 0.0f;
1050 maskColor[2] = colorMask[2] ? -1.0f : 0.0f;
1051 maskColor[3] = colorMask[3] ? -1.0f : 0.0f;
1052 _mesa_pack_float_rgba_row(format, 1,
1053 (const GLfloat (*)[4]) maskColor, dst);
1055 /* fix-up the dst channels by converting non-zero values to ~0 */
1057 GLubyte *d = (GLubyte *) dst;
1058 for (i = 0; i < bytes; i++) {
1059 d[i] = d[i] ? 0xff : 0x0;
1062 else if (bits == 16) {
1063 GLushort *d = (GLushort *) dst;
1064 for (i = 0; i < bytes / 2; i++) {
1065 d[i] = d[i] ? 0xffff : 0x0;
1068 else if (bits == 32) {
1069 GLuint *d = (GLuint *) dst;
1070 for (i = 0; i < bytes / 4; i++) {
1071 d[i] = d[i] ? 0xffffffffU : 0x0;
1075 _mesa_problem(NULL, "unexpected size in _mesa_pack_colormask()");
1081 _mesa_problem(NULL, "unexpected format data type in gen_color_mask()");
1087 template
= Template(string
);
1089 print template
.render(argv
= argv
[0:])