2 from mako
.template
import Template
6 * Mesa 3-D graphics library
8 * Copyright (c) 2011 VMware, Inc.
9 * Copyright (c) 2014 Intel Corporation.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
32 * Color, depth, stencil packing functions.
33 * Used to pack basic color, depth and stencil formats to specific
36 * There are both per-pixel and per-row packing functions:
37 * - The former will be used by swrast to write values to the color, depth,
38 * stencil buffers when drawing points, lines and masked spans.
39 * - The later will be used for image-oriented functions like glDrawPixels,
40 * glAccum, and glTexImage.
45 #include "format_pack.h"
46 #include "format_utils.h"
48 #include "util/format_rgb9e5.h"
49 #include "util/format_r11g11b10f.h"
50 #include "util/format_srgb.h"
52 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
53 #define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET))
56 import format_parser as parser
58 formats = parser.parse(argv[1])
62 if f.name == 'MESA_FORMAT_NONE':
64 if f.colorspace not in ('rgb', 'srgb'):
70 /* ubyte packing functions */
72 %for f in rgb_formats:
73 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
75 %elif f.is_compressed():
80 pack_ubyte_${f.short_name()}(const GLubyte src[4], void *dst)
82 %for (i, c) in enumerate(f.channels):
83 <% i = f.swizzle.inverse()[i] %>
88 ${c.datatype()} ${c.name} =
89 %if not f.is_normalized() and f.is_int():
90 %if c.type == parser.SIGNED:
91 _mesa_unsigned_to_signed(src[${i}], ${c.size});
93 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
95 %elif c.type == parser.UNSIGNED:
96 %if f.colorspace == 'srgb' and c.name in 'rgb':
97 <% assert c.size == 8 %>
98 util_format_linear_to_srgb_8unorm(src[${i}]);
100 _mesa_unorm_to_unorm(src[${i}], 8, ${c.size});
102 %elif c.type == parser.SIGNED:
103 _mesa_unorm_to_snorm(src[${i}], 8, ${c.size});
104 %elif c.type == parser.FLOAT:
106 _mesa_unorm_to_float(src[${i}], 8);
108 _mesa_unorm_to_half(src[${i}], 8);
117 %if f.layout == parser.ARRAY:
118 ${f.datatype()} *d = (${f.datatype()} *)dst;
119 %for (i, c) in enumerate(f.channels):
125 %elif f.layout == parser.PACKED:
126 ${f.datatype()} d = 0;
127 %for (i, c) in enumerate(f.channels):
131 d |= PACK(${c.name}, ${c.shift}, ${c.size});
133 (*(${f.datatype()} *)dst) = d;
141 pack_ubyte_r9g9b9e5_float(const GLubyte src[4], void *dst)
143 GLuint *d = (GLuint *) dst;
145 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
146 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
147 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
148 *d = float3_to_rgb9e5(rgb);
152 pack_ubyte_r11g11b10_float(const GLubyte src[4], void *dst)
154 GLuint *d = (GLuint *) dst;
156 rgb[0] = _mesa_unorm_to_float(src[RCOMP], 8);
157 rgb[1] = _mesa_unorm_to_float(src[GCOMP], 8);
158 rgb[2] = _mesa_unorm_to_float(src[BCOMP], 8);
159 *d = float3_to_r11g11b10f(rgb);
162 /* uint packing functions */
164 %for f in rgb_formats:
167 %elif f.is_normalized():
169 %elif f.is_compressed():
174 pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
176 %for (i, c) in enumerate(f.channels):
177 <% i = f.swizzle.inverse()[i] %>
182 ${c.datatype()} ${c.name} =
183 %if c.type == parser.SIGNED:
184 _mesa_signed_to_signed(src[${i}], ${c.size});
185 %elif c.type == parser.UNSIGNED:
186 _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
188 assert(!"Invalid type: only integer types are allowed");
192 %if f.layout == parser.ARRAY:
193 ${f.datatype()} *d = (${f.datatype()} *)dst;
194 %for (i, c) in enumerate(f.channels):
200 %elif f.layout == parser.PACKED:
201 ${f.datatype()} d = 0;
202 %for (i, c) in enumerate(f.channels):
206 d |= PACK(${c.name}, ${c.shift}, ${c.size});
208 (*(${f.datatype()} *)dst) = d;
215 /* float packing functions */
217 %for f in rgb_formats:
218 %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT', 'MESA_FORMAT_R11G11B10_FLOAT'):
220 %elif f.is_int() and not f.is_normalized():
222 %elif f.is_compressed():
227 pack_float_${f.short_name()}(const GLfloat src[4], void *dst)
229 %for (i, c) in enumerate(f.channels):
230 <% i = f.swizzle.inverse()[i] %>
235 ${c.datatype()} ${c.name} =
236 %if c.type == parser.UNSIGNED:
237 %if f.colorspace == 'srgb' and c.name in 'rgb':
238 <% assert c.size == 8 %>
239 util_format_linear_float_to_srgb_8unorm(src[${i}]);
241 _mesa_float_to_unorm(src[${i}], ${c.size});
243 %elif c.type == parser.SIGNED:
244 _mesa_float_to_snorm(src[${i}], ${c.size});
245 %elif c.type == parser.FLOAT:
249 _mesa_float_to_half(src[${i}]);
258 %if f.layout == parser.ARRAY:
259 ${f.datatype()} *d = (${f.datatype()} *)dst;
260 %for (i, c) in enumerate(f.channels):
266 %elif f.layout == parser.PACKED:
267 ${f.datatype()} d = 0;
268 %for (i, c) in enumerate(f.channels):
272 d |= PACK(${c.name}, ${c.shift}, ${c.size});
274 (*(${f.datatype()} *)dst) = d;
282 pack_float_r9g9b9e5_float(const GLfloat src[4], void *dst)
284 GLuint *d = (GLuint *) dst;
285 *d = float3_to_rgb9e5(src);
289 pack_float_r11g11b10_float(const GLfloat src[4], void *dst)
291 GLuint *d = (GLuint *) dst;
292 *d = float3_to_r11g11b10f(src);
296 * Return a function that can pack a GLubyte rgba[4] color.
298 gl_pack_ubyte_rgba_func
299 _mesa_get_pack_ubyte_rgba_function(mesa_format format)
302 %for f in rgb_formats:
303 %if f.is_compressed():
308 return pack_ubyte_${f.short_name()};
316 * Return a function that can pack a GLfloat rgba[4] color.
318 gl_pack_float_rgba_func
319 _mesa_get_pack_float_rgba_function(mesa_format format)
322 %for f in rgb_formats:
323 %if f.is_compressed():
325 %elif f.is_int() and not f.is_normalized():
330 return pack_float_${f.short_name()};
338 * Pack a row of GLubyte rgba[4] values to the destination.
341 _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
342 const GLubyte src[][4], void *dst)
348 %for f in rgb_formats:
349 %if f.is_compressed():
354 for (i = 0; i < n; ++i) {
355 pack_ubyte_${f.short_name()}(src[i], d);
356 d += ${f.block_size() / 8};
361 assert(!"Invalid format");
366 * Pack a row of GLuint rgba[4] values to the destination.
369 _mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
370 const GLuint src[][4], void *dst)
376 %for f in rgb_formats:
379 %elif f.is_normalized():
381 %elif f.is_compressed():
386 for (i = 0; i < n; ++i) {
387 pack_uint_${f.short_name()}(src[i], d);
388 d += ${f.block_size() / 8};
393 assert(!"Invalid format");
398 * Pack a row of GLfloat rgba[4] values to the destination.
401 _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
402 const GLfloat src[][4], void *dst)
408 %for f in rgb_formats:
409 %if f.is_compressed():
411 %elif f.is_int() and not f.is_normalized():
416 for (i = 0; i < n; ++i) {
417 pack_float_${f.short_name()}(src[i], d);
418 d += ${f.block_size() / 8};
423 assert(!"Invalid format");
428 * Pack a 2D image of ubyte RGBA pixels in the given format.
429 * \param srcRowStride source image row stride in bytes
430 * \param dstRowStride destination image row stride in bytes
433 _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
434 const GLubyte *src, GLint srcRowStride,
435 void *dst, GLint dstRowStride)
437 GLubyte *dstUB = dst;
440 if (srcRowStride == width * 4 * sizeof(GLubyte) &&
441 dstRowStride == _mesa_format_row_stride(format, width)) {
442 /* do whole image at once */
443 _mesa_pack_ubyte_rgba_row(format, width * height,
444 (const GLubyte (*)[4]) src, dst);
448 for (i = 0; i < height; i++) {
449 _mesa_pack_ubyte_rgba_row(format, width,
450 (const GLubyte (*)[4]) src, dstUB);
452 dstUB += dstRowStride;
458 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
467 ** Pack float Z pixels
471 pack_float_S8_UINT_Z24_UNORM(const GLfloat *src, void *dst)
473 /* don't disturb the stencil values */
474 GLuint *d = ((GLuint *) dst);
475 const GLdouble scale = (GLdouble) 0xffffff;
476 GLuint s = *d & 0xff;
477 GLuint z = (GLuint) (*src * scale);
478 assert(z <= 0xffffff);
483 pack_float_Z24_UNORM_S8_UINT(const GLfloat *src, void *dst)
485 /* don't disturb the stencil values */
486 GLuint *d = ((GLuint *) dst);
487 const GLdouble scale = (GLdouble) 0xffffff;
488 GLuint s = *d & 0xff000000;
489 GLuint z = (GLuint) (*src * scale);
490 assert(z <= 0xffffff);
495 pack_float_Z_UNORM16(const GLfloat *src, void *dst)
497 GLushort *d = ((GLushort *) dst);
498 const GLfloat scale = (GLfloat) 0xffff;
499 *d = (GLushort) (*src * scale);
503 pack_float_Z_UNORM32(const GLfloat *src, void *dst)
505 GLuint *d = ((GLuint *) dst);
506 const GLdouble scale = (GLdouble) 0xffffffff;
507 *d = (GLuint) (*src * scale);
511 pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
513 GLfloat *d = (GLfloat *) dst;
518 _mesa_get_pack_float_z_func(mesa_format format)
521 case MESA_FORMAT_S8_UINT_Z24_UNORM:
522 case MESA_FORMAT_X8_UINT_Z24_UNORM:
523 return pack_float_S8_UINT_Z24_UNORM;
524 case MESA_FORMAT_Z24_UNORM_S8_UINT:
525 case MESA_FORMAT_Z24_UNORM_X8_UINT:
526 return pack_float_Z24_UNORM_S8_UINT;
527 case MESA_FORMAT_Z_UNORM16:
528 return pack_float_Z_UNORM16;
529 case MESA_FORMAT_Z_UNORM32:
530 return pack_float_Z_UNORM32;
531 case MESA_FORMAT_Z_FLOAT32:
532 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
533 return pack_float_Z_FLOAT32;
536 "unexpected format in _mesa_get_pack_float_z_func()");
544 ** Pack uint Z pixels. The incoming src value is always in
545 ** the range [0, 2^32-1].
549 pack_uint_S8_UINT_Z24_UNORM(const GLuint *src, void *dst)
551 /* don't disturb the stencil values */
552 GLuint *d = ((GLuint *) dst);
553 GLuint s = *d & 0xff;
554 GLuint z = *src & 0xffffff00;
559 pack_uint_Z24_UNORM_S8_UINT(const GLuint *src, void *dst)
561 /* don't disturb the stencil values */
562 GLuint *d = ((GLuint *) dst);
563 GLuint s = *d & 0xff000000;
564 GLuint z = *src >> 8;
569 pack_uint_Z_UNORM16(const GLuint *src, void *dst)
571 GLushort *d = ((GLushort *) dst);
576 pack_uint_Z_UNORM32(const GLuint *src, void *dst)
578 GLuint *d = ((GLuint *) dst);
583 pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
585 GLuint *d = ((GLuint *) dst);
586 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
587 *d = (GLuint) (*src * scale);
593 pack_uint_Z_FLOAT32_X24S8(const GLuint *src, void *dst)
595 GLfloat *d = ((GLfloat *) dst);
596 const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
597 *d = (GLfloat) (*src * scale);
603 _mesa_get_pack_uint_z_func(mesa_format format)
606 case MESA_FORMAT_S8_UINT_Z24_UNORM:
607 case MESA_FORMAT_X8_UINT_Z24_UNORM:
608 return pack_uint_S8_UINT_Z24_UNORM;
609 case MESA_FORMAT_Z24_UNORM_S8_UINT:
610 case MESA_FORMAT_Z24_UNORM_X8_UINT:
611 return pack_uint_Z24_UNORM_S8_UINT;
612 case MESA_FORMAT_Z_UNORM16:
613 return pack_uint_Z_UNORM16;
614 case MESA_FORMAT_Z_UNORM32:
615 return pack_uint_Z_UNORM32;
616 case MESA_FORMAT_Z_FLOAT32:
617 return pack_uint_Z_FLOAT32;
618 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
619 return pack_uint_Z_FLOAT32_X24S8;
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
);
1002 print template
.render(argv
= argv
[0:])