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.
46 #include "format_pack.h"
47 #include "format_utils.h"
49 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
50 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
51 #include "util/format_srgb.h"
53 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
54 #define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET))
57 import format_parser as parser
59 formats = parser.parse(argv[1])
63 if f.name == 'MESA_FORMAT_NONE':
65 if f.colorspace not in ('rgb', 'srgb'):
71 /* ubyte packing functions */
73 %for f in rgb_formats:
74 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
76 %elif f.is_compressed():
81 pack_ubyte_${f.short_name()}(const GLubyte src[4], void *dst)
83 %for (i, c) in enumerate(f.channels):
84 <% i = f.swizzle.inverse()[i] %>
89 ${c.datatype()} ${c.name} =
90 %if not f.is_normalized() and f.is_int():
91 %if c.type == parser.SIGNED:
92 _mesa_unsigned_to_signed(src[${i}], ${c.size});
94 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
96 %elif c.type == parser.UNSIGNED:
97 %if f.colorspace == 'srgb' and c.name in 'rgb':
98 <% assert c.size == 8 %>
99 util_format_linear_to_srgb_8unorm(src[${i}]);
101 _mesa_unorm_to_unorm(src[${i}], 8, ${c.size});
103 %elif c.type == parser.SIGNED:
104 _mesa_unorm_to_snorm(src[${i}], 8, ${c.size});
105 %elif c.type == parser.FLOAT:
107 _mesa_unorm_to_float(src[${i}], 8);
109 _mesa_unorm_to_half(src[${i}], 8);
118 %if f.layout == parser.ARRAY:
119 ${f.datatype()} *d = (${f.datatype()} *)dst;
120 %for (i, c) in enumerate(f.channels):
126 %elif f.layout == parser.PACKED:
127 ${f.datatype()} d = 0;
128 %for (i, c) in enumerate(f.channels):
132 d |= PACK(${c.name}, ${c.shift}, ${c.size});
134 (*(${f.datatype()} *)dst) = d;
142 pack_ubyte_r9g9b9e5_float(const GLubyte src[4], void *dst)
144 GLuint *d = (GLuint *) dst;
146 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
147 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
148 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
149 *d = float3_to_rgb9e5(rgb);
153 pack_ubyte_r11g11b10_float(const GLubyte src[4], void *dst)
155 GLuint *d = (GLuint *) dst;
157 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
158 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
159 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
160 *d = float3_to_r11g11b10f(rgb);
163 /* uint packing functions */
165 %for f in rgb_formats:
168 %elif f.is_normalized():
170 %elif f.is_compressed():
175 pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
177 %for (i, c) in enumerate(f.channels):
178 <% i = f.swizzle.inverse()[i] %>
183 ${c.datatype()} ${c.name} =
184 %if c.type == parser.SIGNED:
185 _mesa_signed_to_signed(src[${i}], ${c.size});
186 %elif c.type == parser.UNSIGNED:
187 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
189 assert(!"Invalid type: only integer types are allowed");
193 %if f.layout == parser.ARRAY:
194 ${f.datatype()} *d = (${f.datatype()} *)dst;
195 %for (i, c) in enumerate(f.channels):
201 %elif f.layout == parser.PACKED:
202 ${f.datatype()} d = 0;
203 %for (i, c) in enumerate(f.channels):
207 d |= PACK(${c.name}, ${c.shift}, ${c.size});
209 (*(${f.datatype()} *)dst) = d;
216 /* float packing functions */
218 %for f in rgb_formats:
219 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
221 %elif f.is_int() and not f.is_normalized():
223 %elif f.is_compressed():
228 pack_float_${f.short_name()}(const GLfloat src[4], void *dst)
230 %for (i, c) in enumerate(f.channels):
231 <% i = f.swizzle.inverse()[i] %>
236 ${c.datatype()} ${c.name} =
237 %if c.type == parser.UNSIGNED:
238 %if f.colorspace == 'srgb' and c.name in 'rgb':
239 <% assert c.size == 8 %>
240 util_format_linear_float_to_srgb_8unorm(src[${i}]);
242 _mesa_float_to_unorm(src[${i}], ${c.size});
244 %elif c.type == parser.SIGNED:
245 _mesa_float_to_snorm(src[${i}], ${c.size});
246 %elif c.type == parser.FLOAT:
250 _mesa_float_to_half(src[${i}]);
259 %if f.layout == parser.ARRAY:
260 ${f.datatype()} *d = (${f.datatype()} *)dst;
261 %for (i, c) in enumerate(f.channels):
267 %elif f.layout == parser.PACKED:
268 ${f.datatype()} d = 0;
269 %for (i, c) in enumerate(f.channels):
273 d |= PACK(${c.name}, ${c.shift}, ${c.size});
275 (*(${f.datatype()} *)dst) = d;
283 pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
285 GLuint *d = (GLuint *) dst;
286 *d = float3_to_rgb9e5(src);
290 pack_float_r11g11b10_float(const GLfloat src[4], void *dst)
292 GLuint *d = (GLuint *) dst;
293 *d = float3_to_r11g11b10f(src);
297 * Return a function that can pack a GLubyte rgba[4] color.
299 gl_pack_ubyte_rgba_func
300 _mesa_get_pack_ubyte_rgba_function(mesa_format format)
303 %for f in rgb_formats:
304 %if f.is_compressed():
309 return pack_ubyte_${f.short_name()};
317 * Return a function that can pack a GLfloat rgba[4] color.
319 gl_pack_float_rgba_func
320 _mesa_get_pack_float_rgba_function(mesa_format format)
323 %for f in rgb_formats:
324 %if f.is_compressed():
326 %elif f.is_int() and not f.is_normalized():
331 return pack_float_${f.short_name()};
339 * Pack a row of GLubyte rgba[4] values to the destination.
342 _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
343 const GLubyte src[][4], void *dst)
349 %for f in rgb_formats:
350 %if f.is_compressed():
355 for (i = 0; i < n; ++i) {
356 pack_ubyte_${f.short_name()}(src[i], d);
357 d += ${f.block_size() / 8};
362 assert(!"Invalid format");
367 * Pack a row of GLuint rgba[4] values to the destination.
370 _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
371 const GLuint src[][4], void *dst)
377 %for f in rgb_formats:
380 %elif f.is_normalized():
382 %elif f.is_compressed():
387 for (i = 0; i < n; ++i) {
388 pack_uint_${f.short_name()}(src[i], d);
389 d += ${f.block_size() / 8};
394 assert(!"Invalid format");
399 * Pack a row of GLfloat rgba[4] values to the destination.
402 _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
403 const GLfloat src[][4], void *dst)
409 %for f in rgb_formats:
410 %if f.is_compressed():
412 %elif f.is_int() and not f.is_normalized():
417 for (i = 0; i < n; ++i) {
418 pack_float_${f.short_name()}(src[i], d);
419 d += ${f.block_size() / 8};
424 assert(!"Invalid format");
429 * Pack a 2D image of ubyte RGBA pixels in the given format.
430 * \param srcRowStride source image row stride in bytes
431 * \param dstRowStride destination image row stride in bytes
434 _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
435 const GLubyte *src, GLint srcRowStride,
436 void *dst, GLint dstRowStride)
438 GLubyte *dstUB = dst;
441 if (srcRowStride == width * 4 * sizeof(GLubyte) &&
442 dstRowStride == _mesa_format_row_stride(format, width)) {
443 /* do whole image at once */
444 _mesa_pack_ubyte_rgba_row(format, width * height,
445 (const GLubyte (*)[4]) src, dst);
449 for (i = 0; i < height; i++) {
450 _mesa_pack_ubyte_rgba_row(format, width,
451 (const GLubyte (*)[4]) src, dstUB);
453 dstUB += dstRowStride;
459 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
468 ** Pack float Z pixels
472 pack_float_S8_UINT_Z24_UNORM(const GLfloat *src, void *dst)
474 /* don't disturb the stencil values */
475 GLuint *d = ((GLuint *) dst);
476 const GLdouble scale = (GLdouble) 0xffffff;
477 GLuint s = *d & 0xff;
478 GLuint z = (GLuint) (*src * scale);
479 assert(z <= 0xffffff);
484 pack_float_Z24_UNORM_S8_UINT(const GLfloat *src, void *dst)
486 /* don't disturb the stencil values */
487 GLuint *d = ((GLuint *) dst);
488 const GLdouble scale = (GLdouble) 0xffffff;
489 GLuint s = *d & 0xff000000;
490 GLuint z = (GLuint) (*src * scale);
491 assert(z <= 0xffffff);
496 pack_float_Z_UNORM16(const GLfloat *src, void *dst)
498 GLushort *d = ((GLushort *) dst);
499 const GLfloat scale = (GLfloat) 0xffff;
500 *d = (GLushort) (*src * scale);
504 pack_float_Z_UNORM32(const GLfloat *src, void *dst)
506 GLuint *d = ((GLuint *) dst);
507 const GLdouble scale = (GLdouble) 0xffffffff;
508 *d = (GLuint) (*src * scale);
512 pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
514 GLfloat *d = (GLfloat *) dst;
519 _mesa_get_pack_float_z_func(mesa_format format)
522 case MESA_FORMAT_S8_UINT_Z24_UNORM:
523 case MESA_FORMAT_X8_UINT_Z24_UNORM:
524 return pack_float_S8_UINT_Z24_UNORM;
525 case MESA_FORMAT_Z24_UNORM_S8_UINT:
526 case MESA_FORMAT_Z24_UNORM_X8_UINT:
527 return pack_float_Z24_UNORM_S8_UINT;
528 case MESA_FORMAT_Z_UNORM16:
529 return pack_float_Z_UNORM16;
530 case MESA_FORMAT_Z_UNORM32:
531 return pack_float_Z_UNORM32;
532 case MESA_FORMAT_Z_FLOAT32:
533 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
534 return pack_float_Z_FLOAT32;
537 "unexpected format in _mesa_get_pack_float_z_func()");
545 ** Pack uint Z pixels. The incoming src value is always in
546 ** the range [0, 2^32-1].
550 pack_uint_S8_UINT_Z24_UNORM(const GLuint *src, void *dst)
552 /* don't disturb the stencil values */
553 GLuint *d = ((GLuint *) dst);
554 GLuint s = *d & 0xff;
555 GLuint z = *src & 0xffffff00;
560 pack_uint_Z24_UNORM_S8_UINT(const GLuint *src, void *dst)
562 /* don't disturb the stencil values */
563 GLuint *d = ((GLuint *) dst);
564 GLuint s = *d & 0xff000000;
565 GLuint z = *src >> 8;
570 pack_uint_Z_UNORM16(const GLuint *src, void *dst)
572 GLushort *d = ((GLushort *) dst);
577 pack_uint_Z_UNORM32(const GLuint *src, void *dst)
579 GLuint *d = ((GLuint *) dst);
584 pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
586 GLuint *d = ((GLuint *) dst);
587 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
588 *d = (GLuint) (*src * scale);
594 pack_uint_Z_FLOAT32_X24S8(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 return pack_uint_Z_FLOAT32;
619 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
620 return pack_uint_Z_FLOAT32_X24S8;
622 _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
629 ** Pack ubyte stencil pixels
633 pack_ubyte_stencil_Z24_S8(const GLubyte *src, void *dst)
635 /* don't disturb the Z values */
636 GLuint *d = ((GLuint *) dst);
638 GLuint z = *d & 0xffffff00;
643 pack_ubyte_stencil_S8_Z24(const GLubyte *src, void *dst)
645 /* don't disturb the Z values */
646 GLuint *d = ((GLuint *) dst);
647 GLuint s = *src << 24;
648 GLuint z = *d & 0xffffff;
653 pack_ubyte_stencil_S8(const GLubyte *src, void *dst)
655 GLubyte *d = (GLubyte *) dst;
660 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte *src, void *dst)
662 GLfloat *d = ((GLfloat *) dst);
667 gl_pack_ubyte_stencil_func
668 _mesa_get_pack_ubyte_stencil_func(mesa_format format)
671 case MESA_FORMAT_S8_UINT_Z24_UNORM:
672 return pack_ubyte_stencil_Z24_S8;
673 case MESA_FORMAT_Z24_UNORM_S8_UINT:
674 return pack_ubyte_stencil_S8_Z24;
675 case MESA_FORMAT_S_UINT8:
676 return pack_ubyte_stencil_S8;
677 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
678 return pack_ubyte_stencil_Z32_FLOAT_X24S8;
681 "unexpected format in _mesa_pack_ubyte_stencil_func()");
689 _mesa_pack_float_z_row(mesa_format format, GLuint n,
690 const GLfloat *src, void *dst)
693 case MESA_FORMAT_S8_UINT_Z24_UNORM:
694 case MESA_FORMAT_X8_UINT_Z24_UNORM:
696 /* don't disturb the stencil values */
697 GLuint *d = ((GLuint *) dst);
698 const GLdouble scale = (GLdouble) 0xffffff;
700 for (i = 0; i < n; i++) {
701 GLuint s = d[i] & 0xff;
702 GLuint z = (GLuint) (src[i] * scale);
703 assert(z <= 0xffffff);
708 case MESA_FORMAT_Z24_UNORM_S8_UINT:
709 case MESA_FORMAT_Z24_UNORM_X8_UINT:
711 /* don't disturb the stencil values */
712 GLuint *d = ((GLuint *) dst);
713 const GLdouble scale = (GLdouble) 0xffffff;
715 for (i = 0; i < n; i++) {
716 GLuint s = d[i] & 0xff000000;
717 GLuint z = (GLuint) (src[i] * scale);
718 assert(z <= 0xffffff);
723 case MESA_FORMAT_Z_UNORM16:
725 GLushort *d = ((GLushort *) dst);
726 const GLfloat scale = (GLfloat) 0xffff;
728 for (i = 0; i < n; i++) {
729 d[i] = (GLushort) (src[i] * scale);
733 case MESA_FORMAT_Z_UNORM32:
735 GLuint *d = ((GLuint *) dst);
736 const GLdouble scale = (GLdouble) 0xffffffff;
738 for (i = 0; i < n; i++) {
739 d[i] = (GLuint) (src[i] * scale);
743 case MESA_FORMAT_Z_FLOAT32:
744 memcpy(dst, src, n * sizeof(GLfloat));
746 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
748 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
750 for (i = 0; i < n; i++) {
756 _mesa_problem(NULL, "unexpected format in _mesa_pack_float_z_row()");
762 * The incoming Z values are always in the range [0, 0xffffffff].
765 _mesa_pack_uint_z_row(mesa_format format, GLuint n,
766 const GLuint *src, void *dst)
769 case MESA_FORMAT_S8_UINT_Z24_UNORM:
770 case MESA_FORMAT_X8_UINT_Z24_UNORM:
772 /* don't disturb the stencil values */
773 GLuint *d = ((GLuint *) dst);
775 for (i = 0; i < n; i++) {
776 GLuint s = d[i] & 0xff;
777 GLuint z = src[i] & 0xffffff00;
782 case MESA_FORMAT_Z24_UNORM_S8_UINT:
783 case MESA_FORMAT_Z24_UNORM_X8_UINT:
785 /* don't disturb the stencil values */
786 GLuint *d = ((GLuint *) dst);
788 for (i = 0; i < n; i++) {
789 GLuint s = d[i] & 0xff000000;
790 GLuint z = src[i] >> 8;
795 case MESA_FORMAT_Z_UNORM16:
797 GLushort *d = ((GLushort *) dst);
799 for (i = 0; i < n; i++) {
804 case MESA_FORMAT_Z_UNORM32:
805 memcpy(dst, src, n * sizeof(GLfloat));
807 case MESA_FORMAT_Z_FLOAT32:
809 GLuint *d = ((GLuint *) dst);
810 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
812 for (i = 0; i < n; i++) {
813 d[i] = (GLuint) (src[i] * scale);
814 assert(d[i] >= 0.0f);
815 assert(d[i] <= 1.0f);
819 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
821 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
822 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
824 for (i = 0; i < n; i++) {
825 d[i].z = (GLfloat) (src[i] * scale);
826 assert(d[i].z >= 0.0f);
827 assert(d[i].z <= 1.0f);
832 _mesa_problem(NULL, "unexpected format in _mesa_pack_uint_z_row()");
838 _mesa_pack_ubyte_stencil_row(mesa_format format, GLuint n,
839 const GLubyte *src, void *dst)
842 case MESA_FORMAT_S8_UINT_Z24_UNORM:
844 /* don't disturb the Z values */
845 GLuint *d = ((GLuint *) dst);
847 for (i = 0; i < n; i++) {
849 GLuint z = d[i] & 0xffffff00;
854 case MESA_FORMAT_Z24_UNORM_S8_UINT:
856 /* don't disturb the Z values */
857 GLuint *d = ((GLuint *) dst);
859 for (i = 0; i < n; i++) {
860 GLuint s = src[i] << 24;
861 GLuint z = d[i] & 0xffffff;
866 case MESA_FORMAT_S_UINT8:
867 memcpy(dst, src, n * sizeof(GLubyte));
869 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
871 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
873 for (i = 0; i < n; i++) {
879 _mesa_problem(NULL, "unexpected format in _mesa_pack_ubyte_stencil_row()");
885 * Incoming Z/stencil values are always in uint_24_8 format.
888 _mesa_pack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
889 const GLuint *src, void *dst)
892 case MESA_FORMAT_S8_UINT_Z24_UNORM:
893 memcpy(dst, src, n * sizeof(GLuint));
895 case MESA_FORMAT_Z24_UNORM_S8_UINT:
897 GLuint *d = ((GLuint *) dst);
899 for (i = 0; i < n; i++) {
900 GLuint s = src[i] << 24;
901 GLuint z = src[i] >> 8;
906 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
908 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
909 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
911 for (i = 0; i < n; i++) {
912 GLfloat z = (GLfloat) ((src[i] >> 8) * scale);
919 _mesa_problem(NULL, "bad format %s in _mesa_pack_ubyte_s_row",
920 _mesa_get_format_name(format));
928 * Convert a boolean color mask to a packed color where each channel of
929 * the packed value at dst will be 0 or ~0 depending on the colorMask.
932 _mesa_pack_colormask(mesa_format format, const GLubyte colorMask[4], void *dst)
934 GLfloat maskColor[4];
936 switch (_mesa_get_format_datatype(format)) {
937 case GL_UNSIGNED_NORMALIZED:
938 /* simple: 1.0 will convert to ~0 in the right bit positions */
939 maskColor[0] = colorMask[0] ? 1.0f : 0.0f;
940 maskColor[1] = colorMask[1] ? 1.0f : 0.0f;
941 maskColor[2] = colorMask[2] ? 1.0f : 0.0f;
942 maskColor[3] = colorMask[3] ? 1.0f : 0.0f;
943 _mesa_pack_float_rgba_row(format, 1,
944 (const GLfloat (*)[4]) maskColor, dst);
946 case GL_SIGNED_NORMALIZED:
948 /* These formats are harder because it's hard to know the floating
949 * point values that will convert to ~0 for each color channel's bits.
950 * This solution just generates a non-zero value for each color channel
951 * then fixes up the non-zero values to be ~0.
952 * Note: we'll need to add special case code if we ever have to deal
953 * with formats with unequal color channel sizes, like R11_G11_B10.
954 * We issue a warning below for channel sizes other than 8,16,32.
957 GLuint bits = _mesa_get_format_max_bits(format); /* bits per chan */
958 GLuint bytes = _mesa_get_format_bytes(format);
961 /* this should put non-zero values into the channels of dst */
962 maskColor[0] = colorMask[0] ? -1.0f : 0.0f;
963 maskColor[1] = colorMask[1] ? -1.0f : 0.0f;
964 maskColor[2] = colorMask[2] ? -1.0f : 0.0f;
965 maskColor[3] = colorMask[3] ? -1.0f : 0.0f;
966 _mesa_pack_float_rgba_row(format, 1,
967 (const GLfloat (*)[4]) maskColor, dst);
969 /* fix-up the dst channels by converting non-zero values to ~0 */
971 GLubyte *d = (GLubyte *) dst;
972 for (i = 0; i < bytes; i++) {
973 d[i] = d[i] ? 0xff : 0x0;
976 else if (bits == 16) {
977 GLushort *d = (GLushort *) dst;
978 for (i = 0; i < bytes / 2; i++) {
979 d[i] = d[i] ? 0xffff : 0x0;
982 else if (bits == 32) {
983 GLuint *d = (GLuint *) dst;
984 for (i = 0; i < bytes / 4; i++) {
985 d[i] = d[i] ? 0xffffffffU : 0x0;
989 _mesa_problem(NULL, "unexpected size in _mesa_pack_colormask()");
995 _mesa_problem(NULL, "unexpected format data type in gen_color_mask()");
1001 template
= Template(string
);
1003 print template
.render(argv
= argv
[0:])