2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "s_auxbuffer.h"
30 #include "s_context.h"
35 * Allocate memory for the software auxillary buffers associated with
36 * the given GLframebuffer. Free any currently allocated aux buffers
40 _swrast_alloc_aux_buffers( GLframebuffer
*buffer
)
44 for (i
= 0; i
< buffer
->Visual
.numAuxBuffers
; i
++) {
45 if (buffer
->AuxBuffers
[i
]) {
46 _mesa_free(buffer
->AuxBuffers
[i
]);
47 buffer
->AuxBuffers
[i
] = NULL
;
50 buffer
->AuxBuffers
[i
] = (GLchan
*) _mesa_malloc(buffer
->Width
51 * buffer
->Height
* 4 * sizeof(GLchan
));
58 #define NAME(PREFIX) PREFIX##_aux
60 const SWcontext *swrast = SWRAST_CONTEXT(ctx);
61 #define INIT_PIXEL_PTR(P, X, Y) \
62 GLchan *P = swrast->CurAuxBuffer + ((Y) * ctx->DrawBuffer->Width + (X)) * 4; \
63 assert(swrast->CurAuxBuffer);
65 #define INC_PIXEL_PTR(P) P += 4
66 #if CHAN_TYPE == GL_FLOAT
67 #define STORE_RGB_PIXEL(P, X, Y, R, G, B) \
68 P[0] = MAX2((R), 0.0F); \
69 P[1] = MAX2((G), 0.0F); \
70 P[2] = MAX2((B), 0.0F); \
72 #define STORE_RGBA_PIXEL(P, X, Y, R, G, B, A) \
73 P[0] = MAX2((R), 0.0F); \
74 P[1] = MAX2((G), 0.0F); \
75 P[2] = MAX2((B), 0.0F); \
76 P[3] = CLAMP((A), 0.0F, CHAN_MAXF)
78 #define STORE_RGB_PIXEL(P, X, Y, R, G, B) \
79 P[0] = R; P[1] = G; P[2] = B; P[3] = CHAN_MAX
80 #define STORE_RGBA_PIXEL(P, X, Y, R, G, B, A) \
81 P[0] = R; P[1] = G; P[2] = B; P[3] = A
83 #define FETCH_RGBA_PIXEL(R, G, B, A, P) \
84 R = P[0]; G = P[1]; B = P[2]; A = P[3]
85 #include "swrast/s_spantemp.h"
90 * Called from driver's SetBuffer() function to choose an aux buffer.
93 _swrast_use_aux_buffer(GLcontext
*ctx
, GLframebuffer
*buffer
, GLuint bufferBit
)
95 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
100 ASSERT(buffer
->Visual
.numAuxBuffers
>= 1);
101 swrast
->CurAuxBuffer
= ctx
->DrawBuffer
->AuxBuffers
[0];
104 ASSERT(buffer
->Visual
.numAuxBuffers
>= 2);
105 swrast
->CurAuxBuffer
= ctx
->DrawBuffer
->AuxBuffers
[1];
108 ASSERT(buffer
->Visual
.numAuxBuffers
>= 3);
109 swrast
->CurAuxBuffer
= ctx
->DrawBuffer
->AuxBuffers
[2];
112 ASSERT(buffer
->Visual
.numAuxBuffers
>= 4);
113 swrast
->CurAuxBuffer
= ctx
->DrawBuffer
->AuxBuffers
[3];
116 swrast
->CurAuxBuffer
= NULL
;
119 swrast
->Driver
.WriteRGBASpan
= write_rgba_span_aux
;
120 swrast
->Driver
.WriteRGBSpan
= write_rgb_span_aux
;
121 swrast
->Driver
.WriteMonoRGBASpan
= write_monorgba_span_aux
;
122 swrast
->Driver
.WriteRGBAPixels
= write_rgba_pixels_aux
;
123 swrast
->Driver
.WriteMonoRGBAPixels
= write_monorgba_pixels_aux
;
124 swrast
->Driver
.ReadRGBASpan
= read_rgba_span_aux
;
125 swrast
->Driver
.ReadRGBAPixels
= read_rgba_pixels_aux
;