1 from __future__
import print_function
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.
48 #include "format_pack.h"
49 #include "format_utils.h"
51 #include "util/format_rgb9e5.h"
52 #include "util/format_r11g11b10f.h"
53 #include "util/format_srgb.h"
55 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
56 #define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET))
59 import format_parser as parser
61 formats = parser.parse(argv[1])
65 if f.name == 'MESA_FORMAT_NONE':
67 if f.colorspace not in ('rgb', 'srgb'):
73 /* ubyte packing functions */
75 %for f in rgb_formats:
76 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
78 %elif f.is_compressed():
83 pack_ubyte_${f.short_name()}(const GLubyte src[4], void *dst)
85 %for (i, c) in enumerate(f.channels):
86 <% i = f.swizzle.inverse()[i] %>
91 ${c.datatype()} ${c.name} =
92 %if not f.is_normalized() and f.is_int():
93 %if c.type == parser.SIGNED:
94 _mesa_unsigned_to_signed(src[${i}], ${c.size});
96 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
98 %elif c.type == parser.UNSIGNED:
99 %if f.colorspace == 'srgb' and c.name in 'rgb':
100 <% assert c.size == 8 %>
101 util_format_linear_to_srgb_8unorm(src[${i}]);
103 _mesa_unorm_to_unorm(src[${i}], 8, ${c.size});
105 %elif c.type == parser.SIGNED:
106 _mesa_unorm_to_snorm(src[${i}], 8, ${c.size});
107 %elif c.type == parser.FLOAT:
109 _mesa_unorm_to_float(src[${i}], 8);
111 _mesa_unorm_to_half(src[${i}], 8);
120 %if f.layout == parser.ARRAY:
121 ${f.datatype()} *d = (${f.datatype()} *)dst;
122 %for (i, c) in enumerate(f.channels):
128 %elif f.layout == parser.PACKED:
129 ${f.datatype()} d = 0;
130 %for (i, c) in enumerate(f.channels):
134 d |= PACK(${c.name}, ${c.shift}, ${c.size});
136 (*(${f.datatype()} *)dst) = d;
144 pack_ubyte_r9g9b9e5_float(const GLubyte src[4], void *dst)
146 GLuint *d = (GLuint *) dst;
148 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
149 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
150 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
151 *d = float3_to_rgb9e5(rgb);
155 pack_ubyte_r11g11b10_float(const GLubyte src[4], void *dst)
157 GLuint *d = (GLuint *) dst;
159 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
160 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
161 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
162 *d = float3_to_r11g11b10f(rgb);
165 /* uint packing functions */
167 %for f in rgb_formats:
170 %elif f.is_normalized():
172 %elif f.is_compressed():
177 pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
179 %for (i, c) in enumerate(f.channels):
180 <% i = f.swizzle.inverse()[i] %>
185 ${c.datatype()} ${c.name} =
186 %if c.type == parser.SIGNED:
187 _mesa_signed_to_signed(src[${i}], ${c.size});
188 %elif c.type == parser.UNSIGNED:
189 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
191 assert(!"Invalid type: only integer types are allowed");
195 %if f.layout == parser.ARRAY:
196 ${f.datatype()} *d = (${f.datatype()} *)dst;
197 %for (i, c) in enumerate(f.channels):
203 %elif f.layout == parser.PACKED:
204 ${f.datatype()} d = 0;
205 %for (i, c) in enumerate(f.channels):
209 d |= PACK(${c.name}, ${c.shift}, ${c.size});
211 (*(${f.datatype()} *)dst) = d;
218 /* float packing functions */
220 %for f in rgb_formats:
221 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
223 %elif f.is_int() and not f.is_normalized():
225 %elif f.is_compressed():
230 pack_float_${f.short_name()}(const GLfloat src[4], void *dst)
232 %for (i, c) in enumerate(f.channels):
233 <% i = f.swizzle.inverse()[i] %>
238 ${c.datatype()} ${c.name} =
239 %if c.type == parser.UNSIGNED:
240 %if f.colorspace == 'srgb' and c.name in 'rgb':
241 <% assert c.size == 8 %>
242 util_format_linear_float_to_srgb_8unorm(src[${i}]);
244 _mesa_float_to_unorm(src[${i}], ${c.size});
246 %elif c.type == parser.SIGNED:
247 _mesa_float_to_snorm(src[${i}], ${c.size});
248 %elif c.type == parser.FLOAT:
252 _mesa_float_to_half(src[${i}]);
261 %if f.layout == parser.ARRAY:
262 ${f.datatype()} *d = (${f.datatype()} *)dst;
263 %for (i, c) in enumerate(f.channels):
269 %elif f.layout == parser.PACKED:
270 ${f.datatype()} d = 0;
271 %for (i, c) in enumerate(f.channels):
275 d |= PACK(${c.name}, ${c.shift}, ${c.size});
277 (*(${f.datatype()} *)dst) = d;
285 pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
287 GLuint *d = (GLuint *) dst;
288 *d = float3_to_rgb9e5(src);
292 pack_float_r11g11b10_float(const GLfloat src[4], void *dst)
294 GLuint *d = (GLuint *) dst;
295 *d = float3_to_r11g11b10f(src);
299 * Return a function that can pack a GLubyte rgba[4] color.
301 gl_pack_ubyte_rgba_func
302 _mesa_get_pack_ubyte_rgba_function(mesa_format format)
305 %for f in rgb_formats:
306 %if f.is_compressed():
311 return pack_ubyte_${f.short_name()};
319 * Return a function that can pack a GLfloat rgba[4] color.
321 gl_pack_float_rgba_func
322 _mesa_get_pack_float_rgba_function(mesa_format format)
325 %for f in rgb_formats:
326 %if f.is_compressed():
328 %elif f.is_int() and not f.is_normalized():
333 return pack_float_${f.short_name()};
341 * Pack a row of GLubyte rgba[4] values to the destination.
344 _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
345 const GLubyte src[][4], void *dst)
351 %for f in rgb_formats:
352 %if f.is_compressed():
357 for (i = 0; i < n; ++i) {
358 pack_ubyte_${f.short_name()}(src[i], d);
359 d += ${f.block_size() // 8};
364 assert(!"Invalid format");
369 * Pack a row of GLuint rgba[4] values to the destination.
372 _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
373 const GLuint src[][4], void *dst)
379 %for f in rgb_formats:
382 %elif f.is_normalized():
384 %elif f.is_compressed():
389 for (i = 0; i < n; ++i) {
390 pack_uint_${f.short_name()}(src[i], d);
391 d += ${f.block_size() // 8};
396 assert(!"Invalid format");
401 * Pack a row of GLfloat rgba[4] values to the destination.
404 _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
405 const GLfloat src[][4], void *dst)
411 %for f in rgb_formats:
412 %if f.is_compressed():
414 %elif f.is_int() and not f.is_normalized():
419 for (i = 0; i < n; ++i) {
420 pack_float_${f.short_name()}(src[i], d);
421 d += ${f.block_size() // 8};
426 assert(!"Invalid format");
431 * Pack a 2D image of ubyte RGBA pixels in the given format.
432 * \param srcRowStride source image row stride in bytes
433 * \param dstRowStride destination image row stride in bytes
436 _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
437 const GLubyte *src, GLint srcRowStride,
438 void *dst, GLint dstRowStride)
440 GLubyte *dstUB = dst;
443 if (srcRowStride == width * 4 * sizeof(GLubyte) &&
444 dstRowStride == _mesa_format_row_stride(format, width)) {
445 /* do whole image at once */
446 _mesa_pack_ubyte_rgba_row(format, width * height,
447 (const GLubyte (*)[4]) src, dst);
451 for (i = 0; i < height; i++) {
452 _mesa_pack_ubyte_rgba_row(format, width,
453 (const GLubyte (*)[4]) src, dstUB);
455 dstUB += dstRowStride;
461 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
470 ** Pack float Z pixels
474 pack_float_S8_UINT_Z24_UNORM(const GLfloat *src, void *dst)
476 /* don't disturb the stencil values */
477 GLuint *d = ((GLuint *) dst);
478 const GLdouble scale = (GLdouble) 0xffffff;
479 GLuint s = *d & 0xff;
480 GLuint z = (GLuint) (*src * scale);
481 assert(z <= 0xffffff);
486 pack_float_Z24_UNORM_S8_UINT(const GLfloat *src, void *dst)
488 /* don't disturb the stencil values */
489 GLuint *d = ((GLuint *) dst);
490 const GLdouble scale = (GLdouble) 0xffffff;
491 GLuint s = *d & 0xff000000;
492 GLuint z = (GLuint) (*src * scale);
493 assert(z <= 0xffffff);
498 pack_float_Z_UNORM16(const GLfloat *src, void *dst)
500 GLushort *d = ((GLushort *) dst);
501 const GLfloat scale = (GLfloat) 0xffff;
502 *d = (GLushort) (*src * scale);
506 pack_float_Z_UNORM32(const GLfloat *src, void *dst)
508 GLuint *d = ((GLuint *) dst);
509 const GLdouble scale = (GLdouble) 0xffffffff;
510 *d = (GLuint) (*src * scale);
514 ** Pack float to Z_FLOAT32 or Z_FLOAT32_X24S8.
518 pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
520 GLfloat *d = (GLfloat *) dst;
525 _mesa_get_pack_float_z_func(mesa_format format)
528 case MESA_FORMAT_S8_UINT_Z24_UNORM:
529 case MESA_FORMAT_X8_UINT_Z24_UNORM:
530 return pack_float_S8_UINT_Z24_UNORM;
531 case MESA_FORMAT_Z24_UNORM_S8_UINT:
532 case MESA_FORMAT_Z24_UNORM_X8_UINT:
533 return pack_float_Z24_UNORM_S8_UINT;
534 case MESA_FORMAT_Z_UNORM16:
535 return pack_float_Z_UNORM16;
536 case MESA_FORMAT_Z_UNORM32:
537 return pack_float_Z_UNORM32;
538 case MESA_FORMAT_Z_FLOAT32:
539 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
540 return pack_float_Z_FLOAT32;
543 "unexpected format in _mesa_get_pack_float_z_func()");
551 ** Pack uint Z pixels. The incoming src value is always in
552 ** the range [0, 2^32-1].
556 pack_uint_S8_UINT_Z24_UNORM(const GLuint *src, void *dst)
558 /* don't disturb the stencil values */
559 GLuint *d = ((GLuint *) dst);
560 GLuint s = *d & 0xff;
561 GLuint z = *src & 0xffffff00;
566 pack_uint_Z24_UNORM_S8_UINT(const GLuint *src, void *dst)
568 /* don't disturb the stencil values */
569 GLuint *d = ((GLuint *) dst);
570 GLuint s = *d & 0xff000000;
571 GLuint z = *src >> 8;
576 pack_uint_Z_UNORM16(const GLuint *src, void *dst)
578 GLushort *d = ((GLushort *) dst);
583 pack_uint_Z_UNORM32(const GLuint *src, void *dst)
585 GLuint *d = ((GLuint *) dst);
590 ** Pack uint to Z_FLOAT32 or Z_FLOAT32_X24S8.
594 pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
596 GLfloat *d = ((GLfloat *) dst);
597 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
598 *d = (GLfloat) (*src * scale);
604 _mesa_get_pack_uint_z_func(mesa_format format)
607 case MESA_FORMAT_S8_UINT_Z24_UNORM:
608 case MESA_FORMAT_X8_UINT_Z24_UNORM:
609 return pack_uint_S8_UINT_Z24_UNORM;
610 case MESA_FORMAT_Z24_UNORM_S8_UINT:
611 case MESA_FORMAT_Z24_UNORM_X8_UINT:
612 return pack_uint_Z24_UNORM_S8_UINT;
613 case MESA_FORMAT_Z_UNORM16:
614 return pack_uint_Z_UNORM16;
615 case MESA_FORMAT_Z_UNORM32:
616 return pack_uint_Z_UNORM32;
617 case MESA_FORMAT_Z_FLOAT32:
618 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
619 return pack_uint_Z_FLOAT32;
621 _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
628 ** Pack ubyte stencil pixels
632 pack_ubyte_stencil_Z24_S8(const GLubyte *src, void *dst)
634 /* don't disturb the Z values */
635 GLuint *d = ((GLuint *) dst);
637 GLuint z = *d & 0xffffff00;
642 pack_ubyte_stencil_S8_Z24(const GLubyte *src, void *dst)
644 /* don't disturb the Z values */
645 GLuint *d = ((GLuint *) dst);
646 GLuint s = *src << 24;
647 GLuint z = *d & 0xffffff;
652 pack_ubyte_stencil_S8(const GLubyte *src, void *dst)
654 GLubyte *d = (GLubyte *) dst;
659 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte *src, void *dst)
661 GLfloat *d = ((GLfloat *) dst);
666 gl_pack_ubyte_stencil_func
667 _mesa_get_pack_ubyte_stencil_func(mesa_format format)
670 case MESA_FORMAT_S8_UINT_Z24_UNORM:
671 return pack_ubyte_stencil_Z24_S8;
672 case MESA_FORMAT_Z24_UNORM_S8_UINT:
673 return pack_ubyte_stencil_S8_Z24;
674 case MESA_FORMAT_S_UINT8:
675 return pack_ubyte_stencil_S8;
676 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
677 return pack_ubyte_stencil_Z32_FLOAT_X24S8;
680 "unexpected format in _mesa_pack_ubyte_stencil_func()");
688 _mesa_pack_float_z_row(mesa_format format, GLuint n,
689 const GLfloat *src, void *dst)
692 case MESA_FORMAT_S8_UINT_Z24_UNORM:
693 case MESA_FORMAT_X8_UINT_Z24_UNORM:
695 /* don't disturb the stencil values */
696 GLuint *d = ((GLuint *) dst);
697 const GLdouble scale = (GLdouble) 0xffffff;
699 for (i = 0; i < n; i++) {
700 GLuint s = d[i] & 0xff;
701 GLuint z = (GLuint) (src[i] * scale);
702 assert(z <= 0xffffff);
707 case MESA_FORMAT_Z24_UNORM_S8_UINT:
708 case MESA_FORMAT_Z24_UNORM_X8_UINT:
710 /* don't disturb the stencil values */
711 GLuint *d = ((GLuint *) dst);
712 const GLdouble scale = (GLdouble) 0xffffff;
714 for (i = 0; i < n; i++) {
715 GLuint s = d[i] & 0xff000000;
716 GLuint z = (GLuint) (src[i] * scale);
717 assert(z <= 0xffffff);
722 case MESA_FORMAT_Z_UNORM16:
724 GLushort *d = ((GLushort *) dst);
725 const GLfloat scale = (GLfloat) 0xffff;
727 for (i = 0; i < n; i++) {
728 d[i] = (GLushort) (src[i] * scale);
732 case MESA_FORMAT_Z_UNORM32:
734 GLuint *d = ((GLuint *) dst);
735 const GLdouble scale = (GLdouble) 0xffffffff;
737 for (i = 0; i < n; i++) {
738 d[i] = (GLuint) (src[i] * scale);
742 case MESA_FORMAT_Z_FLOAT32:
743 memcpy(dst, src, n * sizeof(GLfloat));
745 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
747 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
749 for (i = 0; i < n; i++) {
755 _mesa_problem(NULL, "unexpected format in _mesa_pack_float_z_row()");
761 * The incoming Z values are always in the range [0, 0xffffffff].
764 _mesa_pack_uint_z_row(mesa_format format, GLuint n,
765 const GLuint *src, void *dst)
768 case MESA_FORMAT_S8_UINT_Z24_UNORM:
769 case MESA_FORMAT_X8_UINT_Z24_UNORM:
771 /* don't disturb the stencil values */
772 GLuint *d = ((GLuint *) dst);
774 for (i = 0; i < n; i++) {
775 GLuint s = d[i] & 0xff;
776 GLuint z = src[i] & 0xffffff00;
781 case MESA_FORMAT_Z24_UNORM_S8_UINT:
782 case MESA_FORMAT_Z24_UNORM_X8_UINT:
784 /* don't disturb the stencil values */
785 GLuint *d = ((GLuint *) dst);
787 for (i = 0; i < n; i++) {
788 GLuint s = d[i] & 0xff000000;
789 GLuint z = src[i] >> 8;
794 case MESA_FORMAT_Z_UNORM16:
796 GLushort *d = ((GLushort *) dst);
798 for (i = 0; i < n; i++) {
803 case MESA_FORMAT_Z_UNORM32:
804 memcpy(dst, src, n * sizeof(GLfloat));
806 case MESA_FORMAT_Z_FLOAT32:
808 GLuint *d = ((GLuint *) dst);
809 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
811 for (i = 0; i < n; i++) {
812 d[i] = (GLuint) (src[i] * scale);
813 assert(d[i] >= 0.0f);
814 assert(d[i] <= 1.0f);
818 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
820 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
821 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
823 for (i = 0; i < n; i++) {
824 d[i].z = (GLfloat) (src[i] * scale);
825 assert(d[i].z >= 0.0f);
826 assert(d[i].z <= 1.0f);
831 _mesa_problem(NULL, "unexpected format in _mesa_pack_uint_z_row()");
837 _mesa_pack_ubyte_stencil_row(mesa_format format, GLuint n,
838 const GLubyte *src, void *dst)
841 case MESA_FORMAT_S8_UINT_Z24_UNORM:
843 /* don't disturb the Z values */
844 GLuint *d = ((GLuint *) dst);
846 for (i = 0; i < n; i++) {
848 GLuint z = d[i] & 0xffffff00;
853 case MESA_FORMAT_Z24_UNORM_S8_UINT:
855 /* don't disturb the Z values */
856 GLuint *d = ((GLuint *) dst);
858 for (i = 0; i < n; i++) {
859 GLuint s = src[i] << 24;
860 GLuint z = d[i] & 0xffffff;
865 case MESA_FORMAT_S_UINT8:
866 memcpy(dst, src, n * sizeof(GLubyte));
868 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
870 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
872 for (i = 0; i < n; i++) {
878 _mesa_problem(NULL, "unexpected format in _mesa_pack_ubyte_stencil_row()");
884 * Incoming Z/stencil values are always in uint_24_8 format.
887 _mesa_pack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
888 const GLuint *src, void *dst)
891 case MESA_FORMAT_S8_UINT_Z24_UNORM:
892 memcpy(dst, src, n * sizeof(GLuint));
894 case MESA_FORMAT_Z24_UNORM_S8_UINT:
896 GLuint *d = ((GLuint *) dst);
898 for (i = 0; i < n; i++) {
899 GLuint s = src[i] << 24;
900 GLuint z = src[i] >> 8;
905 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
907 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
908 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
910 for (i = 0; i < n; i++) {
911 GLfloat z = (GLfloat) ((src[i] >> 8) * scale);
918 _mesa_problem(NULL, "bad format %s in _mesa_pack_ubyte_s_row",
919 _mesa_get_format_name(format));
927 * Convert a boolean color mask to a packed color where each channel of
928 * the packed value at dst will be 0 or ~0 depending on the colorMask.
931 _mesa_pack_colormask(mesa_format format, const GLubyte colorMask[4], void *dst)
933 GLfloat maskColor[4];
935 switch (_mesa_get_format_datatype(format)) {
936 case GL_UNSIGNED_NORMALIZED:
937 /* simple: 1.0 will convert to ~0 in the right bit positions */
938 maskColor[0] = colorMask[0] ? 1.0f : 0.0f;
939 maskColor[1] = colorMask[1] ? 1.0f : 0.0f;
940 maskColor[2] = colorMask[2] ? 1.0f : 0.0f;
941 maskColor[3] = colorMask[3] ? 1.0f : 0.0f;
942 _mesa_pack_float_rgba_row(format, 1,
943 (const GLfloat (*)[4]) maskColor, dst);
945 case GL_SIGNED_NORMALIZED:
947 /* These formats are harder because it's hard to know the floating
948 * point values that will convert to ~0 for each color channel's bits.
949 * This solution just generates a non-zero value for each color channel
950 * then fixes up the non-zero values to be ~0.
951 * Note: we'll need to add special case code if we ever have to deal
952 * with formats with unequal color channel sizes, like R11_G11_B10.
953 * We issue a warning below for channel sizes other than 8,16,32.
956 GLuint bits = _mesa_get_format_max_bits(format); /* bits per chan */
957 GLuint bytes = _mesa_get_format_bytes(format);
960 /* this should put non-zero values into the channels of dst */
961 maskColor[0] = colorMask[0] ? -1.0f : 0.0f;
962 maskColor[1] = colorMask[1] ? -1.0f : 0.0f;
963 maskColor[2] = colorMask[2] ? -1.0f : 0.0f;
964 maskColor[3] = colorMask[3] ? -1.0f : 0.0f;
965 _mesa_pack_float_rgba_row(format, 1,
966 (const GLfloat (*)[4]) maskColor, dst);
968 /* fix-up the dst channels by converting non-zero values to ~0 */
970 GLubyte *d = (GLubyte *) dst;
971 for (i = 0; i < bytes; i++) {
972 d[i] = d[i] ? 0xff : 0x0;
975 else if (bits == 16) {
976 GLushort *d = (GLushort *) dst;
977 for (i = 0; i < bytes / 2; i++) {
978 d[i] = d[i] ? 0xffff : 0x0;
981 else if (bits == 32) {
982 GLuint *d = (GLuint *) dst;
983 for (i = 0; i < bytes / 4; i++) {
984 d[i] = d[i] ? 0xffffffffU : 0x0;
988 _mesa_problem(NULL, "unexpected size in _mesa_pack_colormask()");
994 _mesa_problem(NULL, "unexpected format data type in gen_color_mask()");
1000 template
= Template(string
, future_imports
=['division']);
1002 print(template
.render(argv
= argv
[0:]))