3
* Mesa 3-D graphics library
6
* Copyright (C) 1999-2002 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
* Software alpha planes. Many frame buffers don't have alpha bits so
29
* we simulate them in software.
37
#include "s_alphabuf.h"
40
#define ALPHA_DRAW_ADDR(X,Y) \
41
(ctx->DrawBuffer->Alpha + (Y) * ctx->DrawBuffer->Width + (X))
43
#define ALPHA_READ_ADDR(X,Y) \
44
(ctx->ReadBuffer->Alpha + (Y) * ctx->ReadBuffer->Width + (X))
48
* Allocate a new front and back alpha buffer.
51
_mesa_alloc_alpha_buffers( GLframebuffer *buffer )
53
GET_CURRENT_CONTEXT(ctx);
54
const GLint bytes = buffer->Width * buffer->Height * sizeof(GLchan);
56
ASSERT(buffer->UseSoftwareAlphaBuffers);
58
if (buffer->FrontLeftAlpha) {
59
MESA_PBUFFER_FREE( buffer->FrontLeftAlpha );
61
buffer->FrontLeftAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
62
if (!buffer->FrontLeftAlpha) {
64
_mesa_error( NULL, GL_OUT_OF_MEMORY,
65
"Couldn't allocate front-left alpha buffer" );
68
if (buffer->Visual.doubleBufferMode) {
69
if (buffer->BackLeftAlpha) {
70
MESA_PBUFFER_FREE( buffer->BackLeftAlpha );
72
buffer->BackLeftAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
73
if (!buffer->BackLeftAlpha) {
75
_mesa_error( NULL, GL_OUT_OF_MEMORY,
76
"Couldn't allocate back-left alpha buffer" );
80
if (buffer->Visual.stereoMode) {
81
if (buffer->FrontRightAlpha) {
82
MESA_PBUFFER_FREE( buffer->FrontRightAlpha );
84
buffer->FrontRightAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
85
if (!buffer->FrontRightAlpha) {
87
_mesa_error( NULL, GL_OUT_OF_MEMORY,
88
"Couldn't allocate front-right alpha buffer" );
91
if (buffer->Visual.doubleBufferMode) {
92
if (buffer->BackRightAlpha) {
93
MESA_PBUFFER_FREE( buffer->BackRightAlpha );
95
buffer->BackRightAlpha = (GLchan *) MESA_PBUFFER_ALLOC( bytes );
96
if (!buffer->BackRightAlpha) {
98
_mesa_error( NULL, GL_OUT_OF_MEMORY,
99
"Couldn't allocate back-right alpha buffer" );
105
if (ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT)
106
buffer->Alpha = buffer->FrontLeftAlpha;
107
else if (ctx->Color.DriverDrawBuffer == GL_BACK_LEFT)
108
buffer->Alpha = buffer->BackLeftAlpha;
109
else if (ctx->Color.DriverDrawBuffer == GL_FRONT_RIGHT)
110
buffer->Alpha = buffer->FrontRightAlpha;
111
else if (ctx->Color.DriverDrawBuffer == GL_BACK_RIGHT)
112
buffer->Alpha = buffer->BackRightAlpha;
118
* Clear all the alpha buffers
121
_mesa_clear_alpha_buffers( GLcontext *ctx )
123
const GLchan aclear = ctx->Color.ClearColor[3];
126
ASSERT(ctx->DrawBuffer->UseSoftwareAlphaBuffers);
127
ASSERT(ctx->Color.ColorMask[ACOMP]);
129
/* loop over four possible alpha buffers */
130
for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) {
131
if (bufferBit & ctx->Color.DrawDestMask) {
133
if (bufferBit == FRONT_LEFT_BIT) {
134
buffer = ctx->DrawBuffer->FrontLeftAlpha;
136
else if (bufferBit == FRONT_RIGHT_BIT) {
137
buffer = ctx->DrawBuffer->FrontRightAlpha;
139
else if (bufferBit == BACK_LEFT_BIT) {
140
buffer = ctx->DrawBuffer->BackLeftAlpha;
143
buffer = ctx->DrawBuffer->BackRightAlpha;
146
if (ctx->Scissor.Enabled) {
147
/* clear scissor region */
149
GLint rowLen = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
150
GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
151
GLint width = ctx->DrawBuffer->Width;
152
GLchan *aptr = buffer
153
+ ctx->DrawBuffer->_Ymin * ctx->DrawBuffer->Width
154
+ ctx->DrawBuffer->_Xmin;
155
for (j = 0; j < rows; j++) {
157
MEMSET( aptr, aclear, rowLen );
158
#elif CHAN_BITS == 16
159
MEMSET16( aptr, aclear, rowLen );
162
for (i = 0; i < rowLen; i++) {
170
/* clear whole buffer */
171
GLuint pixels = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height;
173
MEMSET(buffer, aclear, pixels);
174
#elif CHAN_BITS == 16
175
MEMSET16(buffer, aclear, pixels);
178
for (i = 0; i < pixels; i++) {
190
_mesa_write_alpha_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
191
CONST GLchan rgba[][4], const GLubyte mask[] )
193
GLchan *aptr = ALPHA_DRAW_ADDR( x, y );
199
*aptr = rgba[i][ACOMP];
206
*aptr++ = rgba[i][ACOMP];
213
_mesa_write_mono_alpha_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
214
GLchan alpha, const GLubyte mask[] )
216
GLchan *aptr = ALPHA_DRAW_ADDR( x, y );
236
_mesa_write_alpha_pixels( GLcontext *ctx,
237
GLuint n, const GLint x[], const GLint y[],
238
CONST GLchan rgba[][4], const GLubyte mask[] )
245
GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
246
*aptr = rgba[i][ACOMP];
252
GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
253
*aptr = rgba[i][ACOMP];
260
_mesa_write_mono_alpha_pixels( GLcontext *ctx,
261
GLuint n, const GLint x[], const GLint y[],
262
GLchan alpha, const GLubyte mask[] )
269
GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
276
GLchan *aptr = ALPHA_DRAW_ADDR( x[i], y[i] );
285
_mesa_read_alpha_span( GLcontext *ctx,
286
GLuint n, GLint x, GLint y, GLchan rgba[][4] )
288
GLchan *aptr = ALPHA_READ_ADDR( x, y );
291
rgba[i][ACOMP] = *aptr++;
297
_mesa_read_alpha_pixels( GLcontext *ctx,
298
GLuint n, const GLint x[], const GLint y[],
299
GLchan rgba[][4], const GLubyte mask[] )
304
GLchan *aptr = ALPHA_READ_ADDR( x[i], y[i] );
305
rgba[i][ACOMP] = *aptr;