source: trunk/src/opengl/mesa/masking.c@ 3721

Last change on this file since 3721 was 3598, checked in by jeroen, 25 years ago

* empty log message *

File size: 4.5 KB
Line 
1/* $Id: masking.c,v 1.3 2000-05-23 20:40:40 jeroen Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28
29
30
31/*
32 * Implement the effect of glColorMask and glIndexMask in software.
33 */
34
35
36#ifdef PC_HEADER
37#include "all.h"
38#else
39#include "glheader.h"
40#include "alphabuf.h"
41#include "types.h"
42#include "context.h"
43#include "enums.h"
44#include "macros.h"
45#include "masking.h"
46#include "pb.h"
47#include "span.h"
48#endif
49
50
51
52void
53_mesa_IndexMask( GLuint mask )
54{
55 GET_CURRENT_CONTEXT(ctx);
56 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glIndexMask");
57 ctx->Color.IndexMask = mask;
58 ctx->NewState |= NEW_RASTER_OPS;
59}
60
61
62
63void
64_mesa_ColorMask( GLboolean red, GLboolean green,
65 GLboolean blue, GLboolean alpha )
66{
67 GET_CURRENT_CONTEXT(ctx);
68 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorMask");
69
70 if (MESA_VERBOSE & VERBOSE_API)
71 fprintf(stderr, "glColorMask %d %d %d %d\n", red, green, blue, alpha);
72
73 ctx->Color.ColorMask[RCOMP] = red ? 0xff : 0x0;
74 ctx->Color.ColorMask[GCOMP] = green ? 0xff : 0x0;
75 ctx->Color.ColorMask[BCOMP] = blue ? 0xff : 0x0;
76 ctx->Color.ColorMask[ACOMP] = alpha ? 0xff : 0x0;
77
78 if (ctx->Driver.ColorMask)
79 ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
80
81 ctx->NewState |= NEW_RASTER_OPS;
82}
83
84
85
86
87/*
88 * Apply glColorMask to a span of RGBA pixels.
89 */
90void gl_mask_rgba_span( GLcontext *ctx,
91 GLuint n, GLint x, GLint y, GLubyte rgba[][4] )
92{
93 GLubyte dest[MAX_WIDTH][4];
94 GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
95 GLuint dstMask = ~srcMask;
96 GLuint *rgba32 = (GLuint *) rgba;
97 GLuint *dest32 = (GLuint *) dest;
98 GLuint i;
99
100 gl_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
101
102 for (i=0; i<n; i++) {
103 rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
104 }
105}
106
107
108
109/*
110 * Apply glColorMask to an array of RGBA pixels.
111 */
112void gl_mask_rgba_pixels( GLcontext *ctx,
113 GLuint n, const GLint x[], const GLint y[],
114 GLubyte rgba[][4], const GLubyte mask[] )
115{
116 GLubyte dest[PB_SIZE][4];
117 GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
118 GLuint dstMask = ~srcMask;
119 GLuint *rgba32 = (GLuint *) rgba;
120 GLuint *dest32 = (GLuint *) dest;
121 GLuint i;
122
123 (*ctx->Driver.ReadRGBAPixels)( ctx, n, x, y, dest, mask );
124 if (ctx->RasterMask & ALPHABUF_BIT) {
125 gl_read_alpha_pixels( ctx, n, x, y, dest, mask );
126 }
127
128 for (i=0; i<n; i++) {
129 rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
130 }
131}
132
133
134
135/*
136 * Apply glIndexMask to a span of CI pixels.
137 */
138void gl_mask_index_span( GLcontext *ctx,
139 GLuint n, GLint x, GLint y, GLuint index[] )
140{
141 GLuint i;
142 GLuint fbindexes[MAX_WIDTH];
143 GLuint msrc, mdest;
144
145 gl_read_index_span( ctx, ctx->DrawBuffer, n, x, y, fbindexes );
146
147 msrc = ctx->Color.IndexMask;
148 mdest = ~msrc;
149
150 for (i=0;i<n;i++) {
151 index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
152 }
153}
154
155
156
157/*
158 * Apply glIndexMask to an array of CI pixels.
159 */
160void gl_mask_index_pixels( GLcontext *ctx,
161 GLuint n, const GLint x[], const GLint y[],
162 GLuint index[], const GLubyte mask[] )
163{
164 GLuint i;
165 GLuint fbindexes[PB_SIZE];
166 GLuint msrc, mdest;
167
168 (*ctx->Driver.ReadCI32Pixels)( ctx, n, x, y, fbindexes, mask );
169
170 msrc = ctx->Color.IndexMask;
171 mdest = ~msrc;
172
173 for (i=0;i<n;i++) {
174 index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
175 }
176}
177
Note: See TracBrowser for help on using the repository browser.