1 /* $Id: masking.c,v 1.5 1997/07/24 01:23:16 brianp Exp $ */
4 * Mesa 3-D graphics library
6 * Copyright (C) 1995-1997 Brian Paul
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Revision 1.5 1997/07/24 01:23:16 brianp
27 * changed precompiled header symbol from PCH to PC_HEADER
29 * Revision 1.4 1997/05/28 03:25:43 brianp
30 * added precompiled header (PCH) support
32 * Revision 1.3 1996/11/06 04:19:40 brianp
33 * now call gl_read_color/index_span() instead of device driver function
35 * Revision 1.2 1996/10/25 00:07:46 brianp
36 * changed MAX_WIDTH to PB_SIZE in gl_mask_index_pixels()
38 * Revision 1.1 1996/09/13 01:38:16 brianp
45 * Implement the effect of glColorMask and glIndexMask in software.
64 void gl_IndexMask( GLcontext
*ctx
, GLuint mask
)
66 if (INSIDE_BEGIN_END(ctx
)) {
67 gl_error( ctx
, GL_INVALID_OPERATION
, "glIndexMask" );
70 ctx
->Color
.IndexMask
= mask
;
71 ctx
->NewState
|= NEW_RASTER_OPS
;
76 void gl_ColorMask( GLcontext
*ctx
, GLboolean red
, GLboolean green
,
77 GLboolean blue
, GLboolean alpha
)
79 if (INSIDE_BEGIN_END(ctx
)) {
80 gl_error( ctx
, GL_INVALID_OPERATION
, "glColorMask" );
83 ctx
->Color
.ColorMask
= (red
<< 3) | (green
<< 2) | (blue
<< 1) | alpha
;
84 ctx
->NewState
|= NEW_RASTER_OPS
;
91 * Apply glColorMask to a span of RGBA pixels.
93 void gl_mask_color_span( GLcontext
*ctx
,
94 GLuint n
, GLint x
, GLint y
,
95 GLubyte red
[], GLubyte green
[],
96 GLubyte blue
[], GLubyte alpha
[] )
98 GLubyte r
[MAX_WIDTH
], g
[MAX_WIDTH
], b
[MAX_WIDTH
], a
[MAX_WIDTH
];
100 gl_read_color_span( ctx
, n
, x
, y
, r
, g
, b
, a
);
102 if ((ctx
->Color
.ColorMask
& 8) == 0) {
103 /* replace source reds with frame buffer reds */
106 if ((ctx
->Color
.ColorMask
& 4) == 0) {
107 /* replace source greens with frame buffer greens */
108 MEMCPY( green
, g
, n
);
110 if ((ctx
->Color
.ColorMask
& 2) == 0) {
111 /* replace source blues with frame buffer blues */
112 MEMCPY( blue
, b
, n
);
114 if ((ctx
->Color
.ColorMask
& 1) == 0) {
115 /* replace source alphas with frame buffer alphas */
116 MEMCPY( alpha
, a
, n
);
123 * Apply glColorMask to an array of RGBA pixels.
125 void gl_mask_color_pixels( GLcontext
*ctx
,
126 GLuint n
, const GLint x
[], const GLint y
[],
127 GLubyte red
[], GLubyte green
[],
128 GLubyte blue
[], GLubyte alpha
[],
129 const GLubyte mask
[] )
131 GLubyte r
[PB_SIZE
], g
[PB_SIZE
], b
[PB_SIZE
], a
[PB_SIZE
];
133 (*ctx
->Driver
.ReadColorPixels
)( ctx
, n
, x
, y
, r
, g
, b
, a
, mask
);
134 if (ctx
->RasterMask
& ALPHABUF_BIT
) {
135 gl_read_alpha_pixels( ctx
, n
, x
, y
, a
, mask
);
138 if ((ctx
->Color
.ColorMask
& 8) == 0) {
139 /* replace source reds with frame buffer reds */
142 if ((ctx
->Color
.ColorMask
& 4) == 0) {
143 /* replace source greens with frame buffer greens */
144 MEMCPY( green
, g
, n
);
146 if ((ctx
->Color
.ColorMask
& 2) == 0) {
147 /* replace source blues with frame buffer blues */
148 MEMCPY( blue
, b
, n
);
150 if ((ctx
->Color
.ColorMask
& 1) == 0) {
151 /* replace source alphas with frame buffer alphas */
152 MEMCPY( alpha
, a
, n
);
159 * Apply glIndexMask to a span of CI pixels.
161 void gl_mask_index_span( GLcontext
*ctx
,
162 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
165 GLuint fbindexes
[MAX_WIDTH
];
168 gl_read_index_span( ctx
, n
, x
, y
, fbindexes
);
170 msrc
= ctx
->Color
.IndexMask
;
174 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);
181 * Apply glIndexMask to an array of CI pixels.
183 void gl_mask_index_pixels( GLcontext
*ctx
,
184 GLuint n
, const GLint x
[], const GLint y
[],
185 GLuint index
[], const GLubyte mask
[] )
188 GLuint fbindexes
[PB_SIZE
];
191 (*ctx
->Driver
.ReadIndexPixels
)( ctx
, n
, x
, y
, fbindexes
, mask
);
193 msrc
= ctx
->Color
.IndexMask
;
197 index
[i
] = (index
[i
] & msrc
) | (fbindexes
[i
] & mdest
);