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 /* float packing functions */
219 %for f in rgb_formats:
220 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
222 %elif f.is_int() and not f.is_normalized():
224 %elif f.is_compressed():
229 pack_float_${f.short_name()}(const GLfloat 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.UNSIGNED:
239 %if f.colorspace == 'srgb' and c.name in 'rgb':
240 <% assert c.size == 8 %>
241 util_format_linear_float_to_srgb_8unorm(src[${i}]);
243 _mesa_float_to_unorm(src[${i}], ${c.size});
245 %elif c.type == parser.SIGNED:
246 _mesa_float_to_snorm(src[${i}], ${c.size});
247 %elif c.type == parser.FLOAT:
251 _mesa_float_to_half(src[${i}]);
260 %if f.layout == parser.ARRAY:
261 ${f.datatype()} *d = (${f.datatype()} *)dst;
262 %for (i, c) in enumerate(f.channels):
268 %elif f.layout == parser.PACKED:
269 ${f.datatype()} d = 0;
270 %for (i, c) in enumerate(f.channels):
274 d |= PACK(${c.name}, ${c.shift}, ${c.size});
276 (*(${f.datatype()} *)dst) = d;
284 pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
286 GLuint *d = (GLuint *) dst;
287 *d = float3_to_rgb9e5(src);
291 pack_float_r11g11b10_float(const GLfloat src[4], void *dst)
293 GLuint *d = (GLuint *) dst;
294 *d = float3_to_r11g11b10f(src);
298 * Return a function that can pack a GLubyte rgba[4] color.
300 gl_pack_ubyte_rgba_func
301 _mesa_get_pack_ubyte_rgba_function(mesa_format format)
304 %for f in rgb_formats:
305 %if f.is_compressed():
310 return pack_ubyte_${f.short_name()};
318 * Return a function that can pack a GLfloat rgba[4] color.
320 gl_pack_float_rgba_func
321 _mesa_get_pack_float_rgba_function(mesa_format format)
324 %for f in rgb_formats:
325 %if f.is_compressed():
327 %elif f.is_int() and not f.is_normalized():
332 return pack_float_${f.short_name()};
340 * Pack a row of GLubyte rgba[4] values to the destination.
343 _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
344 const GLubyte src[][4], void *dst)
350 %for f in rgb_formats:
351 %if f.is_compressed():
356 for (i = 0; i < n; ++i) {
357 pack_ubyte_${f.short_name()}(src[i], d);
358 d += ${f.block_size() / 8};
363 assert(!"Invalid format");
368 * Pack a row of GLuint rgba[4] values to the destination.
371 _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
372 const GLuint src[][4], void *dst)
378 %for f in rgb_formats:
381 %elif f.is_normalized():
383 %elif f.is_compressed():
388 for (i = 0; i < n; ++i) {
389 pack_uint_${f.short_name()}(src[i], d);
390 d += ${f.block_size() / 8};
395 assert(!"Invalid format");
400 * Pack a row of GLfloat rgba[4] values to the destination.
403 _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
404 const GLfloat src[][4], void *dst)
410 %for f in rgb_formats:
411 %if f.is_compressed():
413 %elif f.is_int() and not f.is_normalized():
418 for (i = 0; i < n; ++i) {
419 pack_float_${f.short_name()}(src[i], d);
420 d += ${f.block_size() / 8};
425 assert(!"Invalid format");
430 * Pack a 2D image of ubyte RGBA pixels in the given format.
431 * \param srcRowStride source image row stride in bytes
432 * \param dstRowStride destination image row stride in bytes
435 _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
436 const GLubyte *src, GLint srcRowStride,
437 void *dst, GLint dstRowStride)
439 GLubyte *dstUB = dst;
442 if (srcRowStride == width * 4 * sizeof(GLubyte) &&
443 dstRowStride == _mesa_format_row_stride(format, width)) {
444 /* do whole image at once */
445 _mesa_pack_ubyte_rgba_row(format, width * height,
446 (const GLubyte (*)[4]) src, dst);
450 for (i = 0; i < height; i++) {
451 _mesa_pack_ubyte_rgba_row(format, width,
452 (const GLubyte (*)[4]) src, dstUB);
454 dstUB += dstRowStride;
460 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
469 ** Pack float Z pixels
473 pack_float_S8_UINT_Z24_UNORM(const GLfloat *src, void *dst)
475 /* don't disturb the stencil values */
476 GLuint *d = ((GLuint *) dst);
477 const GLdouble scale = (GLdouble) 0xffffff;
478 GLuint s = *d & 0xff;
479 GLuint z = (GLuint) (*src * scale);
480 assert(z <= 0xffffff);
485 pack_float_Z24_UNORM_S8_UINT(const GLfloat *src, void *dst)
487 /* don't disturb the stencil values */
488 GLuint *d = ((GLuint *) dst);
489 const GLdouble scale = (GLdouble) 0xffffff;
490 GLuint s = *d & 0xff000000;
491 GLuint z = (GLuint) (*src * scale);
492 assert(z <= 0xffffff);
497 pack_float_Z_UNORM16(const GLfloat *src, void *dst)
499 GLushort *d = ((GLushort *) dst);
500 const GLfloat scale = (GLfloat) 0xffff;
501 *d = (GLushort) (*src * scale);
505 pack_float_Z_UNORM32(const GLfloat *src, void *dst)
507 GLuint *d = ((GLuint *) dst);
508 const GLdouble scale = (GLdouble) 0xffffffff;
509 *d = (GLuint) (*src * scale);
513 pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
515 GLfloat *d = (GLfloat *) dst;
520 _mesa_get_pack_float_z_func(mesa_format format)
523 case MESA_FORMAT_S8_UINT_Z24_UNORM:
524 case MESA_FORMAT_X8_UINT_Z24_UNORM:
525 return pack_float_S8_UINT_Z24_UNORM;
526 case MESA_FORMAT_Z24_UNORM_S8_UINT:
527 case MESA_FORMAT_Z24_UNORM_X8_UINT:
528 return pack_float_Z24_UNORM_S8_UINT;
529 case MESA_FORMAT_Z_UNORM16:
530 return pack_float_Z_UNORM16;
531 case MESA_FORMAT_Z_UNORM32:
532 return pack_float_Z_UNORM32;
533 case MESA_FORMAT_Z_FLOAT32:
534 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
535 return pack_float_Z_FLOAT32;
538 "unexpected format in _mesa_get_pack_float_z_func()");
546 ** Pack uint Z pixels. The incoming src value is always in
547 ** the range [0, 2^32-1].
551 pack_uint_S8_UINT_Z24_UNORM(const GLuint *src, void *dst)
553 /* don't disturb the stencil values */
554 GLuint *d = ((GLuint *) dst);
555 GLuint s = *d & 0xff;
556 GLuint z = *src & 0xffffff00;
561 pack_uint_Z24_UNORM_S8_UINT(const GLuint *src, void *dst)
563 /* don't disturb the stencil values */
564 GLuint *d = ((GLuint *) dst);
565 GLuint s = *d & 0xff000000;
566 GLuint z = *src >> 8;
571 pack_uint_Z_UNORM16(const GLuint *src, void *dst)
573 GLushort *d = ((GLushort *) dst);
578 pack_uint_Z_UNORM32(const GLuint *src, void *dst)
580 GLuint *d = ((GLuint *) dst);
585 pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
587 GLuint *d = ((GLuint *) dst);
588 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
589 *d = (GLuint) (*src * scale);
595 pack_uint_Z_FLOAT32_X24S8(const GLuint *src, void *dst)
597 GLfloat *d = ((GLfloat *) dst);
598 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
599 *d = (GLfloat) (*src * scale);
605 _mesa_get_pack_uint_z_func(mesa_format format)
608 case MESA_FORMAT_S8_UINT_Z24_UNORM:
609 case MESA_FORMAT_X8_UINT_Z24_UNORM:
610 return pack_uint_S8_UINT_Z24_UNORM;
611 case MESA_FORMAT_Z24_UNORM_S8_UINT:
612 case MESA_FORMAT_Z24_UNORM_X8_UINT:
613 return pack_uint_Z24_UNORM_S8_UINT;
614 case MESA_FORMAT_Z_UNORM16:
615 return pack_uint_Z_UNORM16;
616 case MESA_FORMAT_Z_UNORM32:
617 return pack_uint_Z_UNORM32;
618 case MESA_FORMAT_Z_FLOAT32:
619 return pack_uint_Z_FLOAT32;
620 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
621 return pack_uint_Z_FLOAT32_X24S8;
623 _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
630 ** Pack ubyte stencil pixels
634 pack_ubyte_stencil_Z24_S8(const GLubyte *src, void *dst)
636 /* don't disturb the Z values */
637 GLuint *d = ((GLuint *) dst);
639 GLuint z = *d & 0xffffff00;
644 pack_ubyte_stencil_S8_Z24(const GLubyte *src, void *dst)
646 /* don't disturb the Z values */
647 GLuint *d = ((GLuint *) dst);
648 GLuint s = *src << 24;
649 GLuint z = *d & 0xffffff;
654 pack_ubyte_stencil_S8(const GLubyte *src, void *dst)
656 GLubyte *d = (GLubyte *) dst;
661 pack_ubyte_stencil_Z32_FLOAT_X24S8(const GLubyte *src, void *dst)
663 GLfloat *d = ((GLfloat *) dst);
668 gl_pack_ubyte_stencil_func
669 _mesa_get_pack_ubyte_stencil_func(mesa_format format)
672 case MESA_FORMAT_S8_UINT_Z24_UNORM:
673 return pack_ubyte_stencil_Z24_S8;
674 case MESA_FORMAT_Z24_UNORM_S8_UINT:
675 return pack_ubyte_stencil_S8_Z24;
676 case MESA_FORMAT_S_UINT8:
677 return pack_ubyte_stencil_S8;
678 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
679 return pack_ubyte_stencil_Z32_FLOAT_X24S8;
682 "unexpected format in _mesa_pack_ubyte_stencil_func()");
690 _mesa_pack_float_z_row(mesa_format format, GLuint n,
691 const GLfloat *src, void *dst)
694 case MESA_FORMAT_S8_UINT_Z24_UNORM:
695 case MESA_FORMAT_X8_UINT_Z24_UNORM:
697 /* don't disturb the stencil values */
698 GLuint *d = ((GLuint *) dst);
699 const GLdouble scale = (GLdouble) 0xffffff;
701 for (i = 0; i < n; i++) {
702 GLuint s = d[i] & 0xff;
703 GLuint z = (GLuint) (src[i] * scale);
704 assert(z <= 0xffffff);
709 case MESA_FORMAT_Z24_UNORM_S8_UINT:
710 case MESA_FORMAT_Z24_UNORM_X8_UINT:
712 /* don't disturb the stencil values */
713 GLuint *d = ((GLuint *) dst);
714 const GLdouble scale = (GLdouble) 0xffffff;
716 for (i = 0; i < n; i++) {
717 GLuint s = d[i] & 0xff000000;
718 GLuint z = (GLuint) (src[i] * scale);
719 assert(z <= 0xffffff);
724 case MESA_FORMAT_Z_UNORM16:
726 GLushort *d = ((GLushort *) dst);
727 const GLfloat scale = (GLfloat) 0xffff;
729 for (i = 0; i < n; i++) {
730 d[i] = (GLushort) (src[i] * scale);
734 case MESA_FORMAT_Z_UNORM32:
736 GLuint *d = ((GLuint *) dst);
737 const GLdouble scale = (GLdouble) 0xffffffff;
739 for (i = 0; i < n; i++) {
740 d[i] = (GLuint) (src[i] * scale);
744 case MESA_FORMAT_Z_FLOAT32:
745 memcpy(dst, src, n * sizeof(GLfloat));
747 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
749 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
751 for (i = 0; i < n; i++) {
757 _mesa_problem(NULL, "unexpected format in _mesa_pack_float_z_row()");
763 * The incoming Z values are always in the range [0, 0xffffffff].
766 _mesa_pack_uint_z_row(mesa_format format, GLuint n,
767 const GLuint *src, void *dst)
770 case MESA_FORMAT_S8_UINT_Z24_UNORM:
771 case MESA_FORMAT_X8_UINT_Z24_UNORM:
773 /* don't disturb the stencil values */
774 GLuint *d = ((GLuint *) dst);
776 for (i = 0; i < n; i++) {
777 GLuint s = d[i] & 0xff;
778 GLuint z = src[i] & 0xffffff00;
783 case MESA_FORMAT_Z24_UNORM_S8_UINT:
784 case MESA_FORMAT_Z24_UNORM_X8_UINT:
786 /* don't disturb the stencil values */
787 GLuint *d = ((GLuint *) dst);
789 for (i = 0; i < n; i++) {
790 GLuint s = d[i] & 0xff000000;
791 GLuint z = src[i] >> 8;
796 case MESA_FORMAT_Z_UNORM16:
798 GLushort *d = ((GLushort *) dst);
800 for (i = 0; i < n; i++) {
805 case MESA_FORMAT_Z_UNORM32:
806 memcpy(dst, src, n * sizeof(GLfloat));
808 case MESA_FORMAT_Z_FLOAT32:
810 GLuint *d = ((GLuint *) dst);
811 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
813 for (i = 0; i < n; i++) {
814 d[i] = (GLuint) (src[i] * scale);
815 assert(d[i] >= 0.0f);
816 assert(d[i] <= 1.0f);
820 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
822 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
823 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
825 for (i = 0; i < n; i++) {
826 d[i].z = (GLfloat) (src[i] * scale);
827 assert(d[i].z >= 0.0f);
828 assert(d[i].z <= 1.0f);
833 _mesa_problem(NULL, "unexpected format in _mesa_pack_uint_z_row()");
839 _mesa_pack_ubyte_stencil_row(mesa_format format, GLuint n,
840 const GLubyte *src, void *dst)
843 case MESA_FORMAT_S8_UINT_Z24_UNORM:
845 /* don't disturb the Z values */
846 GLuint *d = ((GLuint *) dst);
848 for (i = 0; i < n; i++) {
850 GLuint z = d[i] & 0xffffff00;
855 case MESA_FORMAT_Z24_UNORM_S8_UINT:
857 /* don't disturb the Z values */
858 GLuint *d = ((GLuint *) dst);
860 for (i = 0; i < n; i++) {
861 GLuint s = src[i] << 24;
862 GLuint z = d[i] & 0xffffff;
867 case MESA_FORMAT_S_UINT8:
868 memcpy(dst, src, n * sizeof(GLubyte));
870 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
872 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
874 for (i = 0; i < n; i++) {
880 _mesa_problem(NULL, "unexpected format in _mesa_pack_ubyte_stencil_row()");
886 * Incoming Z/stencil values are always in uint_24_8 format.
889 _mesa_pack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
890 const GLuint *src, void *dst)
893 case MESA_FORMAT_S8_UINT_Z24_UNORM:
894 memcpy(dst, src, n * sizeof(GLuint));
896 case MESA_FORMAT_Z24_UNORM_S8_UINT:
898 GLuint *d = ((GLuint *) dst);
900 for (i = 0; i < n; i++) {
901 GLuint s = src[i] << 24;
902 GLuint z = src[i] >> 8;
907 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
909 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
910 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
912 for (i = 0; i < n; i++) {
913 GLfloat z = (GLfloat) ((src[i] >> 8) * scale);
920 _mesa_problem(NULL, "bad format %s in _mesa_pack_ubyte_s_row",
921 _mesa_get_format_name(format));
929 * Convert a boolean color mask to a packed color where each channel of
930 * the packed value at dst will be 0 or ~0 depending on the colorMask.
933 _mesa_pack_colormask(mesa_format format, const GLubyte colorMask[4], void *dst)
935 GLfloat maskColor[4];
937 switch (_mesa_get_format_datatype(format)) {
938 case GL_UNSIGNED_NORMALIZED:
939 /* simple: 1.0 will convert to ~0 in the right bit positions */
940 maskColor[0] = colorMask[0] ? 1.0f : 0.0f;
941 maskColor[1] = colorMask[1] ? 1.0f : 0.0f;
942 maskColor[2] = colorMask[2] ? 1.0f : 0.0f;
943 maskColor[3] = colorMask[3] ? 1.0f : 0.0f;
944 _mesa_pack_float_rgba_row(format, 1,
945 (const GLfloat (*)[4]) maskColor, dst);
947 case GL_SIGNED_NORMALIZED:
949 /* These formats are harder because it's hard to know the floating
950 * point values that will convert to ~0 for each color channel's bits.
951 * This solution just generates a non-zero value for each color channel
952 * then fixes up the non-zero values to be ~0.
953 * Note: we'll need to add special case code if we ever have to deal
954 * with formats with unequal color channel sizes, like R11_G11_B10.
955 * We issue a warning below for channel sizes other than 8,16,32.
958 GLuint bits = _mesa_get_format_max_bits(format); /* bits per chan */
959 GLuint bytes = _mesa_get_format_bytes(format);
962 /* this should put non-zero values into the channels of dst */
963 maskColor[0] = colorMask[0] ? -1.0f : 0.0f;
964 maskColor[1] = colorMask[1] ? -1.0f : 0.0f;
965 maskColor[2] = colorMask[2] ? -1.0f : 0.0f;
966 maskColor[3] = colorMask[3] ? -1.0f : 0.0f;
967 _mesa_pack_float_rgba_row(format, 1,
968 (const GLfloat (*)[4]) maskColor, dst);
970 /* fix-up the dst channels by converting non-zero values to ~0 */
972 GLubyte *d = (GLubyte *) dst;
973 for (i = 0; i < bytes; i++) {
974 d[i] = d[i] ? 0xff : 0x0;
977 else if (bits == 16) {
978 GLushort *d = (GLushort *) dst;
979 for (i = 0; i < bytes / 2; i++) {
980 d[i] = d[i] ? 0xffff : 0x0;
983 else if (bits == 32) {
984 GLuint *d = (GLuint *) dst;
985 for (i = 0; i < bytes / 4; i++) {
986 d[i] = d[i] ? 0xffffffffU : 0x0;
990 _mesa_problem(NULL, "unexpected size in _mesa_pack_colormask()");
996 _mesa_problem(NULL, "unexpected format data type in gen_color_mask()");
1002 template
= Template(string
);
1004 print template
.render(argv
= argv
[0:])