1 /* $Id: s_masking.c,v 1.8 2002/08/07 00:45:07 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Implement the effect of glColorMask and glIndexMask in software.
37 #include "s_alphabuf.h"
38 #include "s_context.h"
39 #include "s_masking.h"
45 _mesa_mask_rgba_span( GLcontext
*ctx
, const struct sw_span
*span
,
48 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
49 GLchan dest
[MAX_WIDTH
][4];
51 GLuint srcMask
= *((GLuint
*)ctx
->Color
.ColorMask
);
52 GLuint dstMask
= ~srcMask
;
53 GLuint
*rgba32
= (GLuint
*) rgba
;
54 GLuint
*dest32
= (GLuint
*) dest
;
56 const GLboolean rMask
= ctx
->Color
.ColorMask
[RCOMP
];
57 const GLboolean gMask
= ctx
->Color
.ColorMask
[GCOMP
];
58 const GLboolean bMask
= ctx
->Color
.ColorMask
[BCOMP
];
59 const GLboolean aMask
= ctx
->Color
.ColorMask
[ACOMP
];
61 const GLuint n
= span
->end
;
64 ASSERT(n
< MAX_WIDTH
);
65 ASSERT(span
->arrayMask
& SPAN_RGBA
);
67 if (span
->arrayMask
& SPAN_XY
) {
68 (*swrast
->Driver
.ReadRGBAPixels
)(ctx
, n
, span
->array
->x
, span
->array
->y
,
69 dest
, span
->array
->mask
);
70 if (SWRAST_CONTEXT(ctx
)->_RasterMask
& ALPHABUF_BIT
) {
71 _mesa_read_alpha_pixels(ctx
, n
, span
->array
->x
, span
->array
->y
,
72 dest
, span
->array
->mask
);
76 _mesa_read_rgba_span(ctx
, ctx
->DrawBuffer
, n
, span
->x
, span
->y
, dest
);
80 for (i
= 0; i
< n
; i
++) {
81 rgba32
[i
] = (rgba32
[i
] & srcMask
) | (dest32
[i
] & dstMask
);
84 for (i
= 0; i
< n
; i
++) {
85 if (!rMask
) rgba
[i
][RCOMP
] = dest
[i
][RCOMP
];
86 if (!gMask
) rgba
[i
][GCOMP
] = dest
[i
][GCOMP
];
87 if (!bMask
) rgba
[i
][BCOMP
] = dest
[i
][BCOMP
];
88 if (!aMask
) rgba
[i
][ACOMP
] = dest
[i
][ACOMP
];
97 * Apply glColorMask to a span of RGBA pixels.
100 _mesa_mask_rgba_array( GLcontext
*ctx
,
101 GLuint n
, GLint x
, GLint y
, GLchan rgba
[][4] )
103 GLchan dest
[MAX_WIDTH
][4];
108 GLuint srcMask
= *((GLuint
*)ctx
->Color
.ColorMask
);
109 GLuint dstMask
= ~srcMask
;
110 GLuint
*rgba32
= (GLuint
*) rgba
;
111 GLuint
*dest32
= (GLuint
*) dest
;
113 _mesa_read_rgba_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, dest
);
114 for (i
= 0; i
< n
; i
++) {
115 rgba32
[i
] = (rgba32
[i
] & srcMask
) | (dest32
[i
] & dstMask
);
120 const GLint rMask
= ctx
->Color
.ColorMask
[RCOMP
];
121 const GLint gMask
= ctx
->Color
.ColorMask
[GCOMP
];
122 const GLint bMask
= ctx
->Color
.ColorMask
[BCOMP
];
123 const GLint aMask
= ctx
->Color
.ColorMask
[ACOMP
];
125 _mesa_read_rgba_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, dest
);
126 for (i
= 0; i
< n
; i
++) {
127 if (!rMask
) rgba
[i
][RCOMP
] = dest
[i
][RCOMP
];
128 if (!gMask
) rgba
[i
][GCOMP
] = dest
[i
][GCOMP
];
129 if (!bMask
) rgba
[i
][BCOMP
] = dest
[i
][BCOMP
];
130 if (!aMask
) rgba
[i
][ACOMP
] = dest
[i
][ACOMP
];
139 _mesa_mask_index_span( GLcontext
*ctx
, const struct sw_span
*span
,
142 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
143 const GLuint msrc
= ctx
->Color
.IndexMask
;
144 const GLuint mdest
= ~msrc
;
145 GLuint fbindexes
[MAX_WIDTH
];
148 ASSERT(span
->arrayMask
& SPAN_INDEX
);
149 ASSERT(span
->end
< MAX_WIDTH
);
151 if (span
->arrayMask
& SPAN_XY
) {
153 (*swrast
->Driver
.ReadCI32Pixels
)(ctx
, span
->end
, span
->array
->x
,
154 span
->array
->y
, fbindexes
,
157 for (i
= 0; i
< span
->end
; i
++) {
158 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);
162 _mesa_read_index_span(ctx
, ctx
->DrawBuffer
, span
->end
, span
->x
, span
->y
,
165 for (i
= 0; i
< span
->end
; i
++) {
166 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);
174 * Apply glIndexMask to a span of CI pixels.
177 _mesa_mask_index_array( GLcontext
*ctx
,
178 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
181 GLuint fbindexes
[MAX_WIDTH
];
184 _mesa_read_index_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, fbindexes
);
186 msrc
= ctx
->Color
.IndexMask
;
190 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);