3
* Mesa 3-D graphics library
6
* Copyright (C) 1999-2001 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
* Apply glColorMask to a span of RGBA pixels.
47
_mesa_mask_rgba_span( GLcontext *ctx,
48
GLuint n, GLint x, GLint y, GLchan rgba[][4] )
50
GLchan dest[MAX_WIDTH][4];
55
GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
56
GLuint dstMask = ~srcMask;
57
GLuint *rgba32 = (GLuint *) rgba;
58
GLuint *dest32 = (GLuint *) dest;
60
_mesa_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
61
for (i = 0; i < n; i++) {
62
rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
67
const GLint rMask = ctx->Color.ColorMask[RCOMP];
68
const GLint gMask = ctx->Color.ColorMask[GCOMP];
69
const GLint bMask = ctx->Color.ColorMask[BCOMP];
70
const GLint aMask = ctx->Color.ColorMask[ACOMP];
72
_mesa_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
73
for (i = 0; i < n; i++) {
74
if (!rMask) rgba[i][RCOMP] = dest[i][RCOMP];
75
if (!gMask) rgba[i][GCOMP] = dest[i][GCOMP];
76
if (!bMask) rgba[i][BCOMP] = dest[i][BCOMP];
77
if (!aMask) rgba[i][ACOMP] = dest[i][ACOMP];
86
* Apply glColorMask to an array of RGBA pixels.
89
_mesa_mask_rgba_pixels( GLcontext *ctx,
90
GLuint n, const GLint x[], const GLint y[],
91
GLchan rgba[][4], const GLubyte mask[] )
93
SWcontext *swrast = SWRAST_CONTEXT(ctx);
94
GLchan dest[PB_SIZE][4];
99
GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
100
GLuint dstMask = ~srcMask;
101
GLuint *rgba32 = (GLuint *) rgba;
102
GLuint *dest32 = (GLuint *) dest;
104
(*swrast->Driver.ReadRGBAPixels)( ctx, n, x, y, dest, mask );
105
if (SWRAST_CONTEXT(ctx)->_RasterMask & ALPHABUF_BIT) {
106
_mesa_read_alpha_pixels( ctx, n, x, y, dest, mask );
109
for (i=0; i<n; i++) {
110
rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
115
const GLint rMask = ctx->Color.ColorMask[RCOMP];
116
const GLint gMask = ctx->Color.ColorMask[GCOMP];
117
const GLint bMask = ctx->Color.ColorMask[BCOMP];
118
const GLint aMask = ctx->Color.ColorMask[ACOMP];
120
(*swrast->Driver.ReadRGBAPixels)( ctx, n, x, y, dest, mask );
121
if (SWRAST_CONTEXT(ctx)->_RasterMask & ALPHABUF_BIT) {
122
_mesa_read_alpha_pixels( ctx, n, x, y, dest, mask );
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
* Apply glIndexMask to a span of CI pixels.
141
_mesa_mask_index_span( GLcontext *ctx,
142
GLuint n, GLint x, GLint y, GLuint index[] )
145
GLuint fbindexes[MAX_WIDTH];
148
_mesa_read_index_span( ctx, ctx->DrawBuffer, n, x, y, fbindexes );
150
msrc = ctx->Color.IndexMask;
154
index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
161
* Apply glIndexMask to an array of CI pixels.
164
_mesa_mask_index_pixels( GLcontext *ctx,
165
GLuint n, const GLint x[], const GLint y[],
166
GLuint index[], const GLubyte mask[] )
168
SWcontext *swrast = SWRAST_CONTEXT(ctx);
170
GLuint fbindexes[PB_SIZE];
173
(*swrast->Driver.ReadCI32Pixels)( ctx, n, x, y, fbindexes, mask );
175
msrc = ctx->Color.IndexMask;
179
index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);