-/* $Id: s_accum.c,v 1.13 2001/09/19 20:30:44 kschultz Exp $ */
+/* $Id: s_accum.c,v 1.22 2003/03/25 02:23:44 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.5
+ * Version: 4.1
*
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "glheader.h"
#include "context.h"
#include "macros.h"
-#include "mmath.h"
-#include "mem.h"
+#include "imports.h"
#include "s_accum.h"
#include "s_alphabuf.h"
*/
-#if CHAN_BITS == 8
+#if CHAN_BITS == 8 && ACCUM_BITS < 32
#define USE_OPTIMIZED_ACCUM /* enable the optimization */
#endif
-
void
-_mesa_alloc_accum_buffer( GLcontext *ctx )
+_swrast_alloc_accum_buffer( GLframebuffer *buffer )
{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ GET_CURRENT_CONTEXT(ctx);
GLint n;
- if (ctx->DrawBuffer->Accum) {
- FREE( ctx->DrawBuffer->Accum );
- ctx->DrawBuffer->Accum = NULL;
+ if (buffer->Accum) {
+ MESA_PBUFFER_FREE( buffer->Accum );
+ buffer->Accum = NULL;
}
/* allocate accumulation buffer if not already present */
- n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height * 4 * sizeof(GLaccum);
- ctx->DrawBuffer->Accum = (GLaccum *) MALLOC( n );
- if (!ctx->DrawBuffer->Accum) {
+ n = buffer->Width * buffer->Height * 4 * sizeof(GLaccum);
+ buffer->Accum = (GLaccum *) MESA_PBUFFER_ALLOC( n );
+ if (!buffer->Accum) {
/* unable to setup accumulation buffer */
- _mesa_error( ctx, GL_OUT_OF_MEMORY, "glAccum" );
+ _mesa_error( NULL, GL_OUT_OF_MEMORY, "glAccum" );
}
+
+ if (ctx) {
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ /* XXX these fields should probably be in the GLframebuffer */
#ifdef USE_OPTIMIZED_ACCUM
- swrast->_IntegerAccumMode = GL_TRUE;
+ swrast->_IntegerAccumMode = GL_TRUE;
#else
- swrast->_IntegerAccumMode = GL_FALSE;
+ swrast->_IntegerAccumMode = GL_FALSE;
#endif
- swrast->_IntegerAccumScaler = 0.0;
+ swrast->_IntegerAccumScaler = 0.0;
+ }
}
-
-
-
-
/*
* This is called when we fall out of optimized/unscaled accum buffer mode.
* That is, we convert each unscaled accum buffer value into a scaled value
* Clear the accumulation Buffer.
*/
void
-_mesa_clear_accum_buffer( GLcontext *ctx )
+_swarst_clear_accum_buffer( GLcontext *ctx )
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
GLuint buffersize;
ctx->Accum.ClearColor[2]==0.0 &&
ctx->Accum.ClearColor[3]==0.0) {
/* Black */
- BZERO( ctx->DrawBuffer->Accum, buffersize * 4 * sizeof(GLaccum) );
+ _mesa_bzero( ctx->DrawBuffer->Accum,
+ buffersize * 4 * sizeof(GLaccum) );
}
else {
/* Not black */
if (value == 0.0F)
return;
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
+ _swrast_use_read_buffer(ctx);
/* May have to leave optimized accum buffer mode */
if (swrast->_IntegerAccumScaler == 0.0 && value > 0.0 && value <= 1.0)
for (j = 0; j < height; j++) {
GLint i, i4;
- _mesa_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
+ _swrast_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
for (i = i4 = 0; i < width; i++, i4+=4) {
acc[i4+0] += rgba[i][RCOMP];
acc[i4+1] += rgba[i][GCOMP];
for (j=0;j<height;j++) {
GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4;
GLint i;
- _mesa_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
+ _swrast_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
for (i=0;i<width;i++) {
acc[0] += (GLaccum) ( (GLfloat) rgba[i][RCOMP] * rscale );
acc[1] += (GLaccum) ( (GLfloat) rgba[i][GCOMP] * gscale );
}
}
/* restore read buffer = draw buffer (the default) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
+
RENDER_FINISH(swrast,ctx);
break;
case GL_LOAD:
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
+ _swrast_use_read_buffer(ctx);
/* This is a change to go into optimized accum buffer mode */
if (value > 0.0 && value <= 1.0) {
assert(swrast->_IntegerAccumScaler <= 1.0);
for (j = 0; j < height; j++) {
GLint i, i4;
- _mesa_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
+ _swrast_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
for (i = i4 = 0; i < width; i++, i4 += 4) {
acc[i4+0] = rgba[i][RCOMP];
acc[i4+1] = rgba[i][GCOMP];
GLint i, j;
for (j = 0; j < height; j++) {
GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4;
- _mesa_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
+ _swrast_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
for (i=0;i<width;i++) {
#if 0
*acc++ = (GLaccum) ((GLfloat) rgba[i][RCOMP] * rscale + d);
}
/* restore read buffer = draw buffer (the default) */
- (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
+ _swrast_use_draw_buffer(ctx);
+
RENDER_FINISH(swrast,ctx);
break;
rgba[i][ACOMP] = multTable[acc[i4+3]];
}
if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, width, xpos, ypos, rgba );
+ _swrast_mask_rgba_array( ctx, width, xpos, ypos, rgba );
}
(*swrast->Driver.WriteRGBASpan)( ctx, width, xpos, ypos,
(const GLchan (*)[4])rgba, NULL );
if (ctx->DrawBuffer->UseSoftwareAlphaBuffers
&& ctx->Color.ColorMask[ACOMP]) {
- _mesa_write_alpha_span(ctx, width, xpos, ypos,
+ _swrast_write_alpha_span(ctx, width, xpos, ypos,
(CONST GLchan (*)[4]) rgba, NULL);
}
ypos++;
rgba[i][ACOMP] = CLAMP( a, 0, CHAN_MAX );
}
if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, width, xpos, ypos, rgba );
+ _swrast_mask_rgba_array( ctx, width, xpos, ypos, rgba );
}
(*swrast->Driver.WriteRGBASpan)( ctx, width, xpos, ypos,
(const GLchan (*)[4])rgba, NULL );
if (ctx->DrawBuffer->UseSoftwareAlphaBuffers
&& ctx->Color.ColorMask[ACOMP]) {
- _mesa_write_alpha_span(ctx, width, xpos, ypos,
+ _swrast_write_alpha_span(ctx, width, xpos, ypos,
(CONST GLchan (*)[4]) rgba, NULL);
}
ypos++;