2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Implement the effect of glColorMask and glIndexMask in software.
32 * Apply the color mask to a span of rgba values.
35 _swrast_mask_rgba_span(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
38 const GLuint n
= span
->end
;
41 ASSERT(n
< MAX_WIDTH
);
42 ASSERT(span
->arrayMask
& SPAN_RGBA
);
44 rbPixels
= _swrast_get_dest_rgba(ctx
, rb
, span
);
47 * Do component masking.
48 * Note that we're not using span->array->mask[] here. We could...
50 if (span
->array
->ChanType
== GL_UNSIGNED_BYTE
) {
51 /* treat 4xGLubyte as 1xGLuint */
52 const GLuint srcMask
= *((GLuint
*) ctx
->Color
.ColorMask
);
53 const GLuint dstMask
= ~srcMask
;
54 const GLuint
*dst
= (const GLuint
*) rbPixels
;
55 GLuint
*src
= (GLuint
*) span
->array
->rgba8
;
57 for (i
= 0; i
< n
; i
++) {
58 src
[i
] = (src
[i
] & srcMask
) | (dst
[i
] & dstMask
);
61 else if (span
->array
->ChanType
== GL_UNSIGNED_SHORT
) {
62 /* 2-byte components */
63 /* XXX try to use 64-bit arithmetic someday */
64 const GLushort rMask
= ctx
->Color
.ColorMask
[RCOMP
] ? 0xffff : 0x0;
65 const GLushort gMask
= ctx
->Color
.ColorMask
[GCOMP
] ? 0xffff : 0x0;
66 const GLushort bMask
= ctx
->Color
.ColorMask
[BCOMP
] ? 0xffff : 0x0;
67 const GLushort aMask
= ctx
->Color
.ColorMask
[ACOMP
] ? 0xffff : 0x0;
68 const GLushort (*dst
)[4] = (const GLushort (*)[4]) rbPixels
;
69 GLushort (*src
)[4] = span
->array
->rgba16
;
71 for (i
= 0; i
< n
; i
++) {
72 src
[i
][RCOMP
] = (src
[i
][RCOMP
] & rMask
) | (dst
[i
][RCOMP
] & ~rMask
);
73 src
[i
][GCOMP
] = (src
[i
][GCOMP
] & gMask
) | (dst
[i
][GCOMP
] & ~gMask
);
74 src
[i
][BCOMP
] = (src
[i
][BCOMP
] & bMask
) | (dst
[i
][BCOMP
] & ~bMask
);
75 src
[i
][ACOMP
] = (src
[i
][ACOMP
] & aMask
) | (dst
[i
][ACOMP
] & ~aMask
);
79 /* 4-byte components */
80 const GLuint rMask
= ctx
->Color
.ColorMask
[RCOMP
] ? ~0x0 : 0x0;
81 const GLuint gMask
= ctx
->Color
.ColorMask
[GCOMP
] ? ~0x0 : 0x0;
82 const GLuint bMask
= ctx
->Color
.ColorMask
[BCOMP
] ? ~0x0 : 0x0;
83 const GLuint aMask
= ctx
->Color
.ColorMask
[ACOMP
] ? ~0x0 : 0x0;
84 const GLuint (*dst
)[4] = (const GLuint (*)[4]) rbPixels
;
85 GLuint (*src
)[4] = (GLuint (*)[4]) span
->array
->attribs
[FRAG_ATTRIB_COL
];
87 for (i
= 0; i
< n
; i
++) {
88 src
[i
][RCOMP
] = (src
[i
][RCOMP
] & rMask
) | (dst
[i
][RCOMP
] & ~rMask
);
89 src
[i
][GCOMP
] = (src
[i
][GCOMP
] & gMask
) | (dst
[i
][GCOMP
] & ~gMask
);
90 src
[i
][BCOMP
] = (src
[i
][BCOMP
] & bMask
) | (dst
[i
][BCOMP
] & ~bMask
);
91 src
[i
][ACOMP
] = (src
[i
][ACOMP
] & aMask
) | (dst
[i
][ACOMP
] & ~aMask
);