diff options
Diffstat (limited to 'src/mesa/swrast/s_accum.c')
-rw-r--r-- | src/mesa/swrast/s_accum.c | 802 |
1 files changed, 432 insertions, 370 deletions
diff --git a/src/mesa/swrast/s_accum.c b/src/mesa/swrast/s_accum.c index 55ba8310590..b0af0f95d4f 100644 --- a/src/mesa/swrast/s_accum.c +++ b/src/mesa/swrast/s_accum.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.0.1 + * Version: 6.3 * - * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2005 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"), @@ -27,20 +27,23 @@ #include "context.h" #include "macros.h" #include "imports.h" +#include "fbobject.h" #include "s_accum.h" -#include "s_alphabuf.h" #include "s_context.h" #include "s_masking.h" #include "s_span.h" +#define ACCUM_SCALE16 32767.0 + + /* * Accumulation buffer notes * * Normally, accumulation buffer values are GLshorts with values in * [-32767, 32767] which represent floating point colors in [-1, 1], - * as suggested by the OpenGL specification. + * as defined by the OpenGL specification. * * We optimize for the common case used for full-scene antialiasing: * // start with accum buffer cleared to zero @@ -54,68 +57,61 @@ * In this scenario, we can simply store unscaled integer values in * the accum buffer instead of scaled integers. We'll also keep track * of the w value so when we do GL_RETURN we simply divide the accumulated - * values by n (=1/w). + * values by n (n=1/w). * This lets us avoid _many_ int->float->int conversions. */ -#if CHAN_BITS == 8 && ACCUM_BITS < 32 -#define USE_OPTIMIZED_ACCUM /* enable the optimization */ -#endif - - -void -_swrast_alloc_accum_buffer( GLframebuffer *buffer ) -{ - GET_CURRENT_CONTEXT(ctx); - GLint n; - - ASSERT(buffer->UseSoftwareAccumBuffer); - - if (buffer->Accum) { - MESA_PBUFFER_FREE( buffer->Accum ); - buffer->Accum = NULL; - } - - /* allocate accumulation buffer if not already present */ - 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( 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; +#if CHAN_BITS == 8 && ACCUM_BITS <= 32 +/* enable the optimization */ +#define USE_OPTIMIZED_ACCUM 1 #else - swrast->_IntegerAccumMode = GL_FALSE; +#define USE_OPTIMIZED_ACCUM 0 #endif - 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 * representing the range[-1, 1]. */ -static void rescale_accum( GLcontext *ctx ) +static void +rescale_accum( GLcontext *ctx ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); - const GLuint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height * 4; + struct gl_renderbuffer *rb + = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer; const GLfloat s = swrast->_IntegerAccumScaler * (32767.0F / CHAN_MAXF); - GLaccum *accum = ctx->DrawBuffer->Accum; - GLuint i; + assert(rb); + assert(rb->_BaseFormat == GL_RGBA); + /* add other types in future? */ + assert(rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT); assert(swrast->_IntegerAccumMode); - assert(accum); - for (i = 0; i < n; i++) { - accum[i] = (GLaccum) (accum[i] * s); + if (rb->GetPointer(ctx, rb, 0, 0)) { + /* directly-addressable memory */ + GLuint y; + for (y = 0; y < rb->Height; y++) { + GLuint i; + GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, 0, y); + for (i = 0; i < 4 * rb->Width; i++) { + acc[i] = (GLshort) (acc[i] * s); + } + } + } + else { + /* use get/put row funcs */ + GLuint y; + for (y = 0; y < rb->Height; y++) { + GLshort accRow[MAX_WIDTH * 4]; + GLuint i; + rb->GetRow(ctx, rb, rb->Width, 0, y, accRow); + for (i = 0; i < 4 * rb->Width; i++) { + accRow[i] = (GLshort) (accRow[i] * s); + } + rb->PutRow(ctx, rb, rb->Width, 0, y, accRow, NULL); + } } swrast->_IntegerAccumMode = GL_FALSE; @@ -123,406 +119,472 @@ static void rescale_accum( GLcontext *ctx ) - - - -/* +/** * Clear the accumulation Buffer. */ void -_swrast_clear_accum_buffer( GLcontext *ctx ) +_swrast_clear_accum_buffer( GLcontext *ctx, struct gl_renderbuffer *rb ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); - GLuint buffersize; - GLfloat acc_scale; + GLuint x, y, width, height; - if (ctx->Visual.accumRedBits==0) { - /* No accumulation buffer! */ + if (ctx->Visual.accumRedBits == 0) { + /* No accumulation buffer! Not an error. */ return; } - if (sizeof(GLaccum)==1) { - acc_scale = 127.0; - } - else if (sizeof(GLaccum)==2) { - acc_scale = 32767.0; + assert(rb); + assert(rb->_BaseFormat == GL_RGBA); + /* add other types in future? */ + assert(rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT); + + /* bounds, with scissor */ + x = ctx->DrawBuffer->_Xmin; + y = ctx->DrawBuffer->_Ymin; + width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin; + height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin; + + if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) { + const GLfloat accScale = 32767.0; + GLshort clearVal[4]; + GLuint i; + + clearVal[0] = (GLshort) (ctx->Accum.ClearColor[0] * accScale); + clearVal[1] = (GLshort) (ctx->Accum.ClearColor[1] * accScale); + clearVal[2] = (GLshort) (ctx->Accum.ClearColor[2] * accScale); + clearVal[3] = (GLshort) (ctx->Accum.ClearColor[3] * accScale); + + for (i = 0; i < height; i++) { + rb->PutMonoRow(ctx, rb, width, x, y + i, clearVal, NULL); + } } else { - acc_scale = 1.0F; + /* someday support other sizes */ } - /* number of pixels */ - buffersize = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height; - - if (!ctx->DrawBuffer->Accum) { - /* try to alloc accumulation buffer */ - ctx->DrawBuffer->Accum = (GLaccum *) - MALLOC( buffersize * 4 * sizeof(GLaccum) ); + /* update optimized accum state vars */ + if (ctx->Accum.ClearColor[0] == 0.0 && ctx->Accum.ClearColor[1] == 0.0 && + ctx->Accum.ClearColor[2] == 0.0 && ctx->Accum.ClearColor[3] == 0.0) { +#if USE_OPTIMIZED_ACCUM + swrast->_IntegerAccumMode = GL_TRUE; +#else + swrast->_IntegerAccumMode = GL_FALSE; +#endif + swrast->_IntegerAccumScaler = 0.0; /* denotes empty accum buffer */ } + else { + swrast->_IntegerAccumMode = GL_FALSE; + } +} - if (ctx->DrawBuffer->Accum) { - if (ctx->Scissor.Enabled) { - /* Limit clear to scissor box */ - const GLaccum r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale); - const GLaccum g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale); - const GLaccum b = (GLaccum) (ctx->Accum.ClearColor[2] * acc_scale); - const GLaccum a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale); - GLint i, j; - GLint width, height; - GLaccum *row; - /* size of region to clear */ - width = 4 * (ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin); - height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin; - /* ptr to first element to clear */ - row = ctx->DrawBuffer->Accum - + 4 * (ctx->DrawBuffer->_Ymin * ctx->DrawBuffer->Width - + ctx->DrawBuffer->_Xmin); - for (j=0;j<height;j++) { - for (i=0;i<width;i+=4) { - row[i+0] = r; - row[i+1] = g; - row[i+2] = b; - row[i+3] = a; - } - row += 4 * ctx->DrawBuffer->Width; - } + +static void +accum_add(GLcontext *ctx, GLfloat value, + GLint xpos, GLint ypos, GLint width, GLint height ) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + struct gl_renderbuffer *rb + = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer; + + assert(rb); + + /* Leave optimized accum buffer mode */ + if (swrast->_IntegerAccumMode) + rescale_accum(ctx); + + if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) { + const GLshort incr = (GLshort) (value * ACCUM_SCALE16); + if (rb->GetPointer(ctx, rb, 0, 0)) { + GLint i, j; + for (i = 0; i < height; i++) { + GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i); + for (j = 0; j < 4 * width; j++) { + acc[j] += incr; + } + } } else { - /* clear whole buffer */ - if (ctx->Accum.ClearColor[0]==0.0 && - ctx->Accum.ClearColor[1]==0.0 && - ctx->Accum.ClearColor[2]==0.0 && - ctx->Accum.ClearColor[3]==0.0) { - /* Black */ - _mesa_bzero( ctx->DrawBuffer->Accum, - buffersize * 4 * sizeof(GLaccum) ); - } - else { - /* Not black */ - const GLaccum r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale); - const GLaccum g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale); - const GLaccum b = (GLaccum) (ctx->Accum.ClearColor[2] * acc_scale); - const GLaccum a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale); - GLaccum *acc = ctx->DrawBuffer->Accum; - GLuint i; - for (i=0;i<buffersize;i++) { - *acc++ = r; - *acc++ = g; - *acc++ = b; - *acc++ = a; - } - } + GLint i, j; + for (i = 0; i < height; i++) { + GLshort accRow[4 * MAX_WIDTH]; + rb->GetRow(ctx, rb, width, xpos, ypos + i, accRow); + for (j = 0; j < 4 * width; j++) { + accRow[j] += incr; + } + rb->PutRow(ctx, rb, width, xpos, ypos + i, accRow, NULL); + } } + } + else { + /* other types someday */ + } +} - /* update optimized accum state vars */ - if (ctx->Accum.ClearColor[0] == 0.0 && ctx->Accum.ClearColor[1] == 0.0 && - ctx->Accum.ClearColor[2] == 0.0 && ctx->Accum.ClearColor[3] == 0.0) { -#ifdef USE_OPTIMIZED_ACCUM - swrast->_IntegerAccumMode = GL_TRUE; -#else - swrast->_IntegerAccumMode = GL_FALSE; -#endif - swrast->_IntegerAccumScaler = 0.0; /* denotes empty accum buffer */ + +static void +accum_mult(GLcontext *ctx, GLfloat mult, + GLint xpos, GLint ypos, GLint width, GLint height ) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + struct gl_renderbuffer *rb + = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer; + + assert(rb); + + /* Leave optimized accum buffer mode */ + if (swrast->_IntegerAccumMode) + rescale_accum(ctx); + + if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) { + if (rb->GetPointer(ctx, rb, 0, 0)) { + GLint i, j; + for (i = 0; i < height; i++) { + GLshort *acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i); + for (j = 0; j < 4 * width; j++) { + acc[j] = (GLshort) (acc[j] * mult); + } + } } else { - swrast->_IntegerAccumMode = GL_FALSE; + GLint i, j; + for (i = 0; i < height; i++) { + GLshort accRow[4 * MAX_WIDTH]; + rb->GetRow(ctx, rb, width, xpos, ypos + i, accRow); + for (j = 0; j < 4 * width; j++) { + accRow[j] = (GLshort) (accRow[j] * mult); + } + rb->PutRow(ctx, rb, width, xpos, ypos + i, accRow, NULL); + } } } + else { + /* other types someday */ + } } -void -_swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, - GLint xpos, GLint ypos, - GLint width, GLint height ) +static void +accum_accum(GLcontext *ctx, GLfloat value, + GLint xpos, GLint ypos, GLint width, GLint height ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); - GLuint width4; - GLfloat acc_scale; - GLchan rgba[MAX_WIDTH][4]; - const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); + struct gl_renderbuffer *rb + = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer; + const GLboolean directAccess = (rb->GetPointer(ctx, rb, 0, 0) != NULL); + assert(rb); - if (SWRAST_CONTEXT(ctx)->NewState) - _swrast_validate_derived( ctx ); - - if (!ctx->DrawBuffer->Accum) { - _mesa_warning(ctx, - "Calling glAccum() without an accumulation " - "buffer (low memory?)"); + if (!ctx->ReadBuffer->_ColorReadBuffer) { + /* no read buffer - OK */ return; } - if (sizeof(GLaccum)==1) { - acc_scale = 127.0; - } - else if (sizeof(GLaccum)==2) { - acc_scale = 32767.0; - } - else { - acc_scale = 1.0F; - } - - width4 = 4 * width; + /* May have to leave optimized accum buffer mode */ + if (swrast->_IntegerAccumScaler == 0.0 && value > 0.0 && value <= 1.0) + swrast->_IntegerAccumScaler = value; + if (swrast->_IntegerAccumMode && value != swrast->_IntegerAccumScaler) + rescale_accum(ctx); - switch (op) { - case GL_ADD: - if (value != 0.0F) { - const GLaccum val = (GLaccum) (value * acc_scale); - GLint j; - /* Leave optimized accum buffer mode */ - if (swrast->_IntegerAccumMode) - rescale_accum(ctx); - for (j = 0; j < height; j++) { - GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + 4*xpos; - GLuint i; - for (i = 0; i < width4; i++) { - acc[i] += val; - } - ypos++; - } - } - break; + _swrast_use_read_buffer(ctx); - case GL_MULT: - if (value != 1.0F) { - GLint j; - /* Leave optimized accum buffer mode */ - if (swrast->_IntegerAccumMode) - rescale_accum(ctx); - for (j = 0; j < height; j++) { - GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + 4 * xpos; - GLuint i; - for (i = 0; i < width4; i++) { - acc[i] = (GLaccum) ( (GLfloat) acc[i] * value ); - } - ypos++; - } - } - break; - - case GL_ACCUM: - if (value == 0.0F) - return; + if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) { + const GLfloat scale = value * ACCUM_SCALE16 / CHAN_MAXF; + GLshort accumRow[4 * MAX_WIDTH]; + GLchan rgba[MAX_WIDTH][4]; + GLint i; - _swrast_use_read_buffer(ctx); - - /* May have to leave optimized accum buffer mode */ - if (swrast->_IntegerAccumScaler == 0.0 && value > 0.0 && value <= 1.0) - swrast->_IntegerAccumScaler = value; - if (swrast->_IntegerAccumMode && value != swrast->_IntegerAccumScaler) - rescale_accum(ctx); + for (i = 0; i < height; i++) { + GLshort *acc; + if (directAccess) { + acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i); + } + else { + rb->GetRow(ctx, rb, width, xpos, ypos + i, accumRow); + acc = accumRow; + } - RENDER_START(swrast,ctx); + /* read colors from color buffer */ + _swrast_read_rgba_span(ctx, ctx->ReadBuffer->_ColorReadBuffer, width, + xpos, ypos + i, rgba); + /* do accumulation */ if (swrast->_IntegerAccumMode) { /* simply add integer color values into accum buffer */ GLint j; - GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; - assert(swrast->_IntegerAccumScaler > 0.0); - assert(swrast->_IntegerAccumScaler <= 1.0); - for (j = 0; j < height; j++) { - - GLint i, i4; - _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]; - acc[i4+2] += rgba[i][BCOMP]; - acc[i4+3] += rgba[i][ACOMP]; - } - acc += width4; - ypos++; + for (j = 0; j < width; j++) { + acc[j * 4 + 0] += rgba[j][RCOMP]; + acc[j * 4 + 1] += rgba[j][GCOMP]; + acc[j * 4 + 2] += rgba[j][BCOMP]; + acc[j * 4 + 3] += rgba[j][ACOMP]; } } else { /* scaled integer (or float) accum buffer */ - const GLfloat rscale = value * acc_scale / CHAN_MAXF; - const GLfloat gscale = value * acc_scale / CHAN_MAXF; - const GLfloat bscale = value * acc_scale / CHAN_MAXF; - const GLfloat ascale = value * acc_scale / CHAN_MAXF; GLint j; - for (j=0;j<height;j++) { - GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; - GLint i; - _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 ); - acc[2] += (GLaccum) ( (GLfloat) rgba[i][BCOMP] * bscale ); - acc[3] += (GLaccum) ( (GLfloat) rgba[i][ACOMP] * ascale ); - acc += 4; - } - ypos++; + for (j = 0; j < width; j++) { + acc[j * 4 + 0] += (GLshort) ((GLfloat) rgba[j][RCOMP] * scale); + acc[j * 4 + 1] += (GLshort) ((GLfloat) rgba[j][GCOMP] * scale); + acc[j * 4 + 2] += (GLshort) ((GLfloat) rgba[j][BCOMP] * scale); + acc[j * 4 + 3] += (GLshort) ((GLfloat) rgba[j][ACOMP] * scale); } } - /* restore read buffer = draw buffer (the default) */ - _swrast_use_draw_buffer(ctx); - RENDER_FINISH(swrast,ctx); - break; + if (!directAccess) { + rb->PutRow(ctx, rb, width, xpos, ypos + i, accumRow, NULL); + } + } + } + else { + /* other types someday */ + } - case GL_LOAD: - _swrast_use_read_buffer(ctx); + _swrast_use_draw_buffer(ctx); +} + + + +static void +accum_load(GLcontext *ctx, GLfloat value, + GLint xpos, GLint ypos, GLint width, GLint height ) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + struct gl_renderbuffer *rb + = ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer; + const GLboolean directAccess = (rb->GetPointer(ctx, rb, 0, 0) != NULL); - /* This is a change to go into optimized accum buffer mode */ - if (value > 0.0 && value <= 1.0) { -#ifdef USE_OPTIMIZED_ACCUM - swrast->_IntegerAccumMode = GL_TRUE; + assert(rb); + + if (!ctx->ReadBuffer->_ColorReadBuffer) { + /* no read buffer - OK */ + return; + } + + /* This is a change to go into optimized accum buffer mode */ + if (value > 0.0 && value <= 1.0) { +#if USE_OPTIMIZED_ACCUM + swrast->_IntegerAccumMode = GL_TRUE; #else - swrast->_IntegerAccumMode = GL_FALSE; + swrast->_IntegerAccumMode = GL_FALSE; #endif - swrast->_IntegerAccumScaler = value; + swrast->_IntegerAccumScaler = value; + } + else { + swrast->_IntegerAccumMode = GL_FALSE; + swrast->_IntegerAccumScaler = 0.0; + } + + _swrast_use_read_buffer(ctx); + + if (rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT) { + const GLfloat scale = value * ACCUM_SCALE16 / CHAN_MAXF; + GLshort accumRow[4 * MAX_WIDTH]; + GLchan rgba[MAX_WIDTH][4]; + GLint i; + + for (i = 0; i < height; i++) { + GLshort *acc; + if (directAccess) { + acc = (GLshort *) rb->GetPointer(ctx, rb, xpos, ypos + i); } else { - swrast->_IntegerAccumMode = GL_FALSE; - swrast->_IntegerAccumScaler = 0.0; + rb->GetRow(ctx, rb, width, xpos, ypos + i, accumRow); + acc = accumRow; } - RENDER_START(swrast,ctx); + /* read colors from color buffer */ + _swrast_read_rgba_span(ctx, ctx->ReadBuffer->_ColorReadBuffer, width, + xpos, ypos + i, rgba); + + /* do load */ if (swrast->_IntegerAccumMode) { - /* just copy values into accum buffer */ + /* just copy values in */ GLint j; - GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; assert(swrast->_IntegerAccumScaler > 0.0); assert(swrast->_IntegerAccumScaler <= 1.0); - for (j = 0; j < height; j++) { - GLint i, i4; - _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]; - acc[i4+2] = rgba[i][BCOMP]; - acc[i4+3] = rgba[i][ACOMP]; - } - acc += width4; - ypos++; + for (j = 0; j < width; j++) { + acc[j * 4 + 0] = rgba[j][RCOMP]; + acc[j * 4 + 1] = rgba[j][GCOMP]; + acc[j * 4 + 2] = rgba[j][BCOMP]; + acc[j * 4 + 3] = rgba[j][ACOMP]; } } else { /* scaled integer (or float) accum buffer */ - const GLfloat rscale = value * acc_scale / CHAN_MAXF; - const GLfloat gscale = value * acc_scale / CHAN_MAXF; - const GLfloat bscale = value * acc_scale / CHAN_MAXF; - const GLfloat ascale = value * acc_scale / CHAN_MAXF; -#if 0 - const GLfloat d = 3.0 / acc_scale; /* XXX what's this? */ -#endif - GLint i, j; - for (j = 0; j < height; j++) { - GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; - _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); - *acc++ = (GLaccum) ((GLfloat) rgba[i][GCOMP] * gscale + d); - *acc++ = (GLaccum) ((GLfloat) rgba[i][BCOMP] * bscale + d); - *acc++ = (GLaccum) ((GLfloat) rgba[i][ACOMP] * ascale + d); -#else - *acc++ = (GLaccum) ((GLfloat) rgba[i][RCOMP] * rscale); - *acc++ = (GLaccum) ((GLfloat) rgba[i][GCOMP] * gscale); - *acc++ = (GLaccum) ((GLfloat) rgba[i][BCOMP] * bscale); - *acc++ = (GLaccum) ((GLfloat) rgba[i][ACOMP] * ascale); -#endif - } - ypos++; + GLint j; + for (j = 0; j < width; j++) { + acc[j * 4 + 0] = (GLshort) ((GLfloat) rgba[j][RCOMP] * scale); + acc[j * 4 + 1] = (GLshort) ((GLfloat) rgba[j][GCOMP] * scale); + acc[j * 4 + 2] = (GLshort) ((GLfloat) rgba[j][BCOMP] * scale); + acc[j * 4 + 3] = (GLshort) ((GLfloat) rgba[j][ACOMP] * scale); } } - /* restore read buffer = draw buffer (the default) */ - _swrast_use_draw_buffer(ctx); + if (!directAccess) { + rb->PutRow(ctx, rb, width, xpos, ypos + i, accumRow, NULL); + } + } + } + else { + /* other types someday */ + } - RENDER_FINISH(swrast,ctx); - break; + _swrast_use_draw_buffer(ctx); +} - case GL_RETURN: - /* May have to leave optimized accum buffer mode */ - if (swrast->_IntegerAccumMode && value != 1.0) - rescale_accum(ctx); - - RENDER_START(swrast,ctx); -#ifdef USE_OPTIMIZED_ACCUM - if (swrast->_IntegerAccumMode && swrast->_IntegerAccumScaler > 0) { - /* build lookup table to avoid many floating point multiplies */ - static GLchan multTable[32768]; - static GLfloat prevMult = 0.0; - const GLfloat mult = swrast->_IntegerAccumScaler; - const GLint max = MIN2((GLint) (256 / mult), 32767); - GLint j; - if (mult != prevMult) { - for (j = 0; j < max; j++) - multTable[j] = IROUND((GLfloat) j * mult); - prevMult = mult; - } - assert(swrast->_IntegerAccumScaler > 0.0); - assert(swrast->_IntegerAccumScaler <= 1.0); - for (j = 0; j < height; j++) { - const GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos*4; - GLint i, i4; - for (i = i4 = 0; i < width; i++, i4 += 4) { - ASSERT(acc[i4+0] < max); - ASSERT(acc[i4+1] < max); - ASSERT(acc[i4+2] < max); - ASSERT(acc[i4+3] < max); - rgba[i][RCOMP] = multTable[acc[i4+0]]; - rgba[i][GCOMP] = multTable[acc[i4+1]]; - rgba[i][BCOMP] = multTable[acc[i4+2]]; - rgba[i][ACOMP] = multTable[acc[i4+3]]; - } - if (colorMask != 0xffffffff) { - _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]) { - _swrast_write_alpha_span(ctx, width, xpos, ypos, - (CONST GLchan (*)[4]) rgba, NULL); - } - ypos++; +static void +accum_return(GLcontext *ctx, GLfloat value, + GLint xpos, GLint ypos, GLint width, GLint height ) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + struct gl_framebuffer *fb = ctx->DrawBuffer; + struct gl_renderbuffer *accumRb = fb->Attachment[BUFFER_ACCUM].Renderbuffer; + const GLboolean directAccess + = (accumRb->GetPointer(ctx, accumRb, 0, 0) != NULL); + const GLboolean masking = (!ctx->Color.ColorMask[RCOMP] || + !ctx->Color.ColorMask[GCOMP] || + !ctx->Color.ColorMask[BCOMP] || + !ctx->Color.ColorMask[ACOMP]); + + static GLchan multTable[32768]; + static GLfloat prevMult = 0.0; + const GLfloat mult = swrast->_IntegerAccumScaler; + const GLint max = MIN2((GLint) (256 / mult), 32767); + + /* May have to leave optimized accum buffer mode */ + if (swrast->_IntegerAccumMode && value != 1.0) + rescale_accum(ctx); + + if (swrast->_IntegerAccumMode && swrast->_IntegerAccumScaler > 0) { + /* build lookup table to avoid many floating point multiplies */ + GLint j; + assert(swrast->_IntegerAccumScaler <= 1.0); + if (mult != prevMult) { + for (j = 0; j < max; j++) + multTable[j] = IROUND((GLfloat) j * mult); + prevMult = mult; + } + } + + if (accumRb->DataType == GL_SHORT || + accumRb->DataType == GL_UNSIGNED_SHORT) { + const GLfloat scale = value * CHAN_MAXF / ACCUM_SCALE16; + GLuint buffer, i; + + /* XXX maybe transpose the 'i' and 'buffer' loops??? */ + for (i = 0; i < height; i++) { + GLchan rgba[MAX_WIDTH][4]; + GLshort accumRow[4 * MAX_WIDTH]; + GLshort *acc; + + if (directAccess) { + acc = (GLshort *) accumRb->GetPointer(ctx, accumRb, xpos, ypos +i); + } + else { + accumRb->GetRow(ctx, accumRb, width, xpos, ypos + i, accumRow); + acc = accumRow; + } + + /* get the colors to return */ + if (swrast->_IntegerAccumMode) { + GLint j; + for (j = 0; j < width; j++) { + ASSERT(acc[j * 4 + 0] < max); + ASSERT(acc[j * 4 + 1] < max); + ASSERT(acc[j * 4 + 2] < max); + ASSERT(acc[j * 4 + 3] < max); + rgba[j][RCOMP] = multTable[acc[j * 4 + 0]]; + rgba[j][GCOMP] = multTable[acc[j * 4 + 1]]; + rgba[j][BCOMP] = multTable[acc[j * 4 + 2]]; + rgba[j][ACOMP] = multTable[acc[j * 4 + 3]]; } } - else -#endif /* USE_OPTIMIZED_ACCUM */ - { + else { /* scaled integer (or float) accum buffer */ - const GLfloat rscale = value / acc_scale * CHAN_MAXF; - const GLfloat gscale = value / acc_scale * CHAN_MAXF; - const GLfloat bscale = value / acc_scale * CHAN_MAXF; - const GLfloat ascale = value / acc_scale * CHAN_MAXF; - GLint i, j; - for (j=0;j<height;j++) { - const GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos*4; - for (i=0;i<width;i++) { - GLint r = IROUND( (GLfloat) (acc[0]) * rscale ); - GLint g = IROUND( (GLfloat) (acc[1]) * gscale ); - GLint b = IROUND( (GLfloat) (acc[2]) * bscale ); - GLint a = IROUND( (GLfloat) (acc[3]) * ascale ); - acc += 4; - rgba[i][RCOMP] = CLAMP( r, 0, CHAN_MAX ); - rgba[i][GCOMP] = CLAMP( g, 0, CHAN_MAX ); - rgba[i][BCOMP] = CLAMP( b, 0, CHAN_MAX ); - rgba[i][ACOMP] = CLAMP( a, 0, CHAN_MAX ); - } - if (colorMask != 0xffffffff) { - _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]) { - _swrast_write_alpha_span(ctx, width, xpos, ypos, - (CONST GLchan (*)[4]) rgba, NULL); - } - ypos++; + GLint j; + for (j = 0; j < width; j++) { + GLint r = IROUND( (GLfloat) (acc[j * 4 + 0]) * scale ); + GLint g = IROUND( (GLfloat) (acc[j * 4 + 1]) * scale ); + GLint b = IROUND( (GLfloat) (acc[j * 4 + 2]) * scale ); + GLint a = IROUND( (GLfloat) (acc[j * 4 + 3]) * scale ); + rgba[j][RCOMP] = CLAMP( r, 0, CHAN_MAX ); + rgba[j][GCOMP] = CLAMP( g, 0, CHAN_MAX ); + rgba[j][BCOMP] = CLAMP( b, 0, CHAN_MAX ); + rgba[j][ACOMP] = CLAMP( a, 0, CHAN_MAX ); } + } + + /* store colors */ + for (buffer = 0; buffer < fb->_NumColorDrawBuffers[0]; buffer++) { + struct gl_renderbuffer *rb = fb->_ColorDrawBuffers[0][buffer]; + if (masking) { + _swrast_mask_rgba_array(ctx, rb, width, xpos, ypos + i, rgba); + } +#if OLD_RENDERBUFFER + if (swrast->Driver.WriteRGBASpan) + swrast->Driver.WriteRGBASpan(ctx, rb, width, xpos, ypos + i, + (const GLchan (*)[4]) rgba, NULL); + else +#endif + rb->PutRow(ctx, rb, width, xpos, ypos + i, rgba, NULL); + } + } + } + else { + /* other types someday */ + } +} + + + +/** + * Software fallback for glAccum. + */ +void +_swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, + GLint xpos, GLint ypos, + GLint width, GLint height ) + +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + if (SWRAST_CONTEXT(ctx)->NewState) + _swrast_validate_derived( ctx ); + + if (!ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer) { + _mesa_warning(ctx, "Calling glAccum() without an accumulation buffer"); + return; + } + + RENDER_START(swrast, ctx); + + switch (op) { + case GL_ADD: + if (value != 0.0F) { + accum_add(ctx, value, xpos, ypos, width, height); } - RENDER_FINISH(swrast,ctx); break; - + case GL_MULT: + if (value != 1.0F) { + accum_mult(ctx, value, xpos, ypos, width, height); + } + break; + case GL_ACCUM: + if (value != 0.0F) { + accum_accum(ctx, value, xpos, ypos, width, height); + } + break; + case GL_LOAD: + accum_load(ctx, value, xpos, ypos, width, height); + break; + case GL_RETURN: + accum_return(ctx, value, xpos, ypos, width, height); + break; default: - _mesa_error( ctx, GL_INVALID_ENUM, "glAccum" ); + _mesa_problem(ctx, "invalid mode in _swrast_Accum()"); + break; } + + RENDER_FINISH(swrast, ctx); } |