1 | /* $Id: masking.c,v 1.2 2000-03-01 18:49:31 jeroen Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Mesa 3-D graphics library
|
---|
5 | * Version: 3.1
|
---|
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 | #ifndef XFree86Server
|
---|
40 | #include <string.h>
|
---|
41 | #include <stdio.h>
|
---|
42 | #else
|
---|
43 | #include "GL/xf86glx.h"
|
---|
44 | #endif
|
---|
45 | #include "alphabuf.h"
|
---|
46 | #include "types.h"
|
---|
47 | #include "context.h"
|
---|
48 | #include "enums.h"
|
---|
49 | #include "macros.h"
|
---|
50 | #include "masking.h"
|
---|
51 | #include "pb.h"
|
---|
52 | #include "span.h"
|
---|
53 | #endif
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | void gl_IndexMask( GLcontext *ctx, GLuint mask )
|
---|
58 | {
|
---|
59 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glIndexMask");
|
---|
60 | ctx->Color.IndexMask = mask;
|
---|
61 | ctx->NewState |= NEW_RASTER_OPS;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | void gl_ColorMask( GLcontext *ctx, GLboolean red, GLboolean green,
|
---|
67 | GLboolean blue, GLboolean alpha )
|
---|
68 | {
|
---|
69 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glColorMask");
|
---|
70 |
|
---|
71 | if (MESA_VERBOSE & VERBOSE_API)
|
---|
72 | fprintf(stderr, "glColorMask %d %d %d %d\n", red, green, blue, alpha);
|
---|
73 |
|
---|
74 | ctx->Color.ColorMask[RCOMP] = red ? 0xff : 0x0;
|
---|
75 | ctx->Color.ColorMask[GCOMP] = green ? 0xff : 0x0;
|
---|
76 | ctx->Color.ColorMask[BCOMP] = blue ? 0xff : 0x0;
|
---|
77 | ctx->Color.ColorMask[ACOMP] = alpha ? 0xff : 0x0;
|
---|
78 |
|
---|
79 | if (ctx->Driver.ColorMask)
|
---|
80 | ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
|
---|
81 |
|
---|
82 | ctx->NewState |= NEW_RASTER_OPS;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * Apply glColorMask to a span of RGBA pixels.
|
---|
90 | */
|
---|
91 | void gl_mask_rgba_span( GLcontext *ctx,
|
---|
92 | GLuint n, GLint x, GLint y, GLubyte rgba[][4] )
|
---|
93 | {
|
---|
94 | GLubyte dest[MAX_WIDTH][4];
|
---|
95 | GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
|
---|
96 | GLuint dstMask = ~srcMask;
|
---|
97 | GLuint *rgba32 = (GLuint *) rgba;
|
---|
98 | GLuint *dest32 = (GLuint *) dest;
|
---|
99 | GLuint i;
|
---|
100 |
|
---|
101 | gl_read_rgba_span( ctx, n, x, y, dest );
|
---|
102 |
|
---|
103 | for (i=0; i<n; i++) {
|
---|
104 | rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * Apply glColorMask to an array of RGBA pixels.
|
---|
112 | */
|
---|
113 | void gl_mask_rgba_pixels( GLcontext *ctx,
|
---|
114 | GLuint n, const GLint x[], const GLint y[],
|
---|
115 | GLubyte rgba[][4], const GLubyte mask[] )
|
---|
116 | {
|
---|
117 | GLubyte dest[PB_SIZE][4];
|
---|
118 | GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
|
---|
119 | GLuint dstMask = ~srcMask;
|
---|
120 | GLuint *rgba32 = (GLuint *) rgba;
|
---|
121 | GLuint *dest32 = (GLuint *) dest;
|
---|
122 | GLuint i;
|
---|
123 |
|
---|
124 | (*ctx->Driver.ReadRGBAPixels)( ctx, n, x, y, dest, mask );
|
---|
125 | if (ctx->RasterMask & ALPHABUF_BIT) {
|
---|
126 | gl_read_alpha_pixels( ctx, n, x, y, dest, mask );
|
---|
127 | }
|
---|
128 |
|
---|
129 | for (i=0; i<n; i++) {
|
---|
130 | rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 | /*
|
---|
137 | * Apply glIndexMask to a span of CI pixels.
|
---|
138 | */
|
---|
139 | void gl_mask_index_span( GLcontext *ctx,
|
---|
140 | GLuint n, GLint x, GLint y, GLuint index[] )
|
---|
141 | {
|
---|
142 | GLuint i;
|
---|
143 | GLuint fbindexes[MAX_WIDTH];
|
---|
144 | GLuint msrc, mdest;
|
---|
145 |
|
---|
146 | gl_read_index_span( ctx, n, x, y, fbindexes );
|
---|
147 |
|
---|
148 | msrc = ctx->Color.IndexMask;
|
---|
149 | mdest = ~msrc;
|
---|
150 |
|
---|
151 | for (i=0;i<n;i++) {
|
---|
152 | index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 | /*
|
---|
159 | * Apply glIndexMask to an array of CI pixels.
|
---|
160 | */
|
---|
161 | void gl_mask_index_pixels( GLcontext *ctx,
|
---|
162 | GLuint n, const GLint x[], const GLint y[],
|
---|
163 | GLuint index[], const GLubyte mask[] )
|
---|
164 | {
|
---|
165 | GLuint i;
|
---|
166 | GLuint fbindexes[PB_SIZE];
|
---|
167 | GLuint msrc, mdest;
|
---|
168 |
|
---|
169 | (*ctx->Driver.ReadCI32Pixels)( ctx, n, x, y, fbindexes, mask );
|
---|
170 |
|
---|
171 | msrc = ctx->Color.IndexMask;
|
---|
172 | mdest = ~msrc;
|
---|
173 |
|
---|
174 | for (i=0;i<n;i++) {
|
---|
175 | index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|