3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Implement the effect of glColorMask and glIndexMask in software.
36 #include "s_alphabuf.h"
37 #include "s_context.h"
38 #include "s_masking.h"
44 _swrast_mask_rgba_span( GLcontext
*ctx
, const struct sw_span
*span
,
47 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
48 GLchan dest
[MAX_WIDTH
][4];
50 GLuint srcMask
= *((GLuint
*)ctx
->Color
.ColorMask
);
51 GLuint dstMask
= ~srcMask
;
52 GLuint
*rgba32
= (GLuint
*) rgba
;
53 GLuint
*dest32
= (GLuint
*) dest
;
55 const GLboolean rMask
= ctx
->Color
.ColorMask
[RCOMP
];
56 const GLboolean gMask
= ctx
->Color
.ColorMask
[GCOMP
];
57 const GLboolean bMask
= ctx
->Color
.ColorMask
[BCOMP
];
58 const GLboolean aMask
= ctx
->Color
.ColorMask
[ACOMP
];
60 const GLuint n
= span
->end
;
63 ASSERT(n
< MAX_WIDTH
);
64 ASSERT(span
->arrayMask
& SPAN_RGBA
);
66 if (span
->arrayMask
& SPAN_XY
) {
67 (*swrast
->Driver
.ReadRGBAPixels
)(ctx
, n
, span
->array
->x
, span
->array
->y
,
68 dest
, span
->array
->mask
);
69 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
70 _swrast_read_alpha_pixels(ctx
, n
, span
->array
->x
, span
->array
->y
,
71 dest
, span
->array
->mask
);
75 _swrast_read_rgba_span(ctx
, ctx
->DrawBuffer
, n
, span
->x
, span
->y
, dest
);
79 for (i
= 0; i
< n
; i
++) {
80 rgba32
[i
] = (rgba32
[i
] & srcMask
) | (dest32
[i
] & dstMask
);
83 for (i
= 0; i
< n
; i
++) {
84 if (!rMask
) rgba
[i
][RCOMP
] = dest
[i
][RCOMP
];
85 if (!gMask
) rgba
[i
][GCOMP
] = dest
[i
][GCOMP
];
86 if (!bMask
) rgba
[i
][BCOMP
] = dest
[i
][BCOMP
];
87 if (!aMask
) rgba
[i
][ACOMP
] = dest
[i
][ACOMP
];
96 * Apply glColorMask to a span of RGBA pixels.
99 _swrast_mask_rgba_array( GLcontext
*ctx
,
100 GLuint n
, GLint x
, GLint y
, GLchan rgba
[][4] )
102 GLchan dest
[MAX_WIDTH
][4];
107 GLuint srcMask
= *((GLuint
*)ctx
->Color
.ColorMask
);
108 GLuint dstMask
= ~srcMask
;
109 GLuint
*rgba32
= (GLuint
*) rgba
;
110 GLuint
*dest32
= (GLuint
*) dest
;
112 _swrast_read_rgba_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, dest
);
113 for (i
= 0; i
< n
; i
++) {
114 rgba32
[i
] = (rgba32
[i
] & srcMask
) | (dest32
[i
] & dstMask
);
119 const GLint rMask
= ctx
->Color
.ColorMask
[RCOMP
];
120 const GLint gMask
= ctx
->Color
.ColorMask
[GCOMP
];
121 const GLint bMask
= ctx
->Color
.ColorMask
[BCOMP
];
122 const GLint aMask
= ctx
->Color
.ColorMask
[ACOMP
];
124 _swrast_read_rgba_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, dest
);
125 for (i
= 0; i
< n
; i
++) {
126 if (!rMask
) rgba
[i
][RCOMP
] = dest
[i
][RCOMP
];
127 if (!gMask
) rgba
[i
][GCOMP
] = dest
[i
][GCOMP
];
128 if (!bMask
) rgba
[i
][BCOMP
] = dest
[i
][BCOMP
];
129 if (!aMask
) rgba
[i
][ACOMP
] = dest
[i
][ACOMP
];
138 _swrast_mask_index_span( GLcontext
*ctx
, const struct sw_span
*span
,
141 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
142 const GLuint msrc
= ctx
->Color
.IndexMask
;
143 const GLuint mdest
= ~msrc
;
144 GLuint fbindexes
[MAX_WIDTH
];
147 ASSERT(span
->arrayMask
& SPAN_INDEX
);
148 ASSERT(span
->end
< MAX_WIDTH
);
150 if (span
->arrayMask
& SPAN_XY
) {
152 (*swrast
->Driver
.ReadCI32Pixels
)(ctx
, span
->end
, span
->array
->x
,
153 span
->array
->y
, fbindexes
,
156 for (i
= 0; i
< span
->end
; i
++) {
157 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);
161 _swrast_read_index_span(ctx
, ctx
->DrawBuffer
, span
->end
, span
->x
, span
->y
,
164 for (i
= 0; i
< span
->end
; i
++) {
165 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);
173 * Apply glIndexMask to a span of CI pixels.
176 _swrast_mask_index_array( GLcontext
*ctx
,
177 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
180 GLuint fbindexes
[MAX_WIDTH
];
183 _swrast_read_index_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, fbindexes
);
185 msrc
= ctx
->Color
.IndexMask
;
189 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);