- width4 = 4 * width;
-
- switch (op) {
- case GL_ADD:
- {
- const GLaccum intVal = (GLaccum) (value * acc_scale);
- GLuint j;
- /* Leave optimized accum buffer mode */
- if (ctx->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] += intVal;
- }
- ypos++;
- }
- }
- break;
-
- case GL_MULT:
- {
- GLuint j;
- /* Leave optimized accum buffer mode */
- if (ctx->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:
- (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
-
- /* May have to leave optimized accum buffer mode */
- if (ctx->IntegerAccumScaler == 0.0 && value > 0.0 && value <= 1.0)
- ctx->IntegerAccumScaler = value;
- if (ctx->IntegerAccumMode && value != ctx->IntegerAccumScaler)
- rescale_accum(ctx);
-
- if (ctx->IntegerAccumMode) {
- /* simply add integer color values into accum buffer */
- GLuint j;
- GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4;
- assert(ctx->IntegerAccumScaler > 0.0);
- assert(ctx->IntegerAccumScaler <= 1.0);
- for (j = 0; j < height; j++) {
-
- GLuint i, i4;
- gl_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++;
- }
- }
- else {
- /* scaled integer accum buffer */
- const GLfloat rscale = value * acc_scale / fChanMax;
- const GLfloat gscale = value * acc_scale / fChanMax;
- const GLfloat bscale = value * acc_scale / fChanMax;
- const GLfloat ascale = value * acc_scale / fChanMax;
- GLuint j;
- for (j=0;j<height;j++) {
- GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4;
- GLuint i;
- gl_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
- for (i=0;i<width;i++) {
- *acc += (GLaccum) ( (GLfloat) rgba[i][RCOMP] * rscale ); acc++;
- *acc += (GLaccum) ( (GLfloat) rgba[i][GCOMP] * gscale ); acc++;
- *acc += (GLaccum) ( (GLfloat) rgba[i][BCOMP] * bscale ); acc++;
- *acc += (GLaccum) ( (GLfloat) rgba[i][ACOMP] * ascale ); acc++;
- }
- ypos++;
- }
- }
- /* restore read buffer = draw buffer (the default) */
- (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
- break;
-
- case GL_LOAD:
- (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
- ctx->Pixel.DriverReadBuffer );
-
- /* This is a change to go into optimized accum buffer mode */
- if (value > 0.0 && value <= 1.0) {
-#ifdef USE_OPTIMIZED_ACCUM
- ctx->IntegerAccumMode = GL_TRUE;
-#else
- ctx->IntegerAccumMode = GL_FALSE;
-#endif
- ctx->IntegerAccumScaler = value;
- }
- else {
- ctx->IntegerAccumMode = GL_FALSE;
- ctx->IntegerAccumScaler = 0.0;
- }
-
- if (ctx->IntegerAccumMode) {
- /* just copy values into accum buffer */
- GLuint j;
- GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4;
- assert(ctx->IntegerAccumScaler > 0.0);
- assert(ctx->IntegerAccumScaler <= 1.0);
- for (j = 0; j < height; j++) {
- GLuint i, i4;
- gl_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++;
- }
- }
- else {
- /* scaled integer accum buffer */
- const GLfloat rscale = value * acc_scale / fChanMax;
- const GLfloat gscale = value * acc_scale / fChanMax;
- const GLfloat bscale = value * acc_scale / fChanMax;
- const GLfloat ascale = value * acc_scale / fChanMax;
- const GLfloat d = 3.0 / acc_scale;
- GLuint i, j;
- for (j = 0; j < height; j++) {
- GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4;
- gl_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba);
- for (i=0;i<width;i++) {
- *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);
- }
- ypos++;
- }
- }
-
- /* restore read buffer = draw buffer (the default) */
- (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
- ctx->Color.DriverDrawBuffer );
- break;
-
- case GL_RETURN:
- /* May have to leave optimized accum buffer mode */
- if (ctx->IntegerAccumMode && value != 1.0)
- rescale_accum(ctx);
-
- if (ctx->IntegerAccumMode && ctx->IntegerAccumScaler > 0) {
- /* build lookup table to avoid many floating point multiplies */
- const GLfloat mult = ctx->IntegerAccumScaler;
- static GLchan multTable[32768];
- static GLfloat prevMult = 0.0;
- GLuint j;
- const GLint max = (GLint) (256 / mult);
- if (mult != prevMult) {
- assert(max <= 32768);
- for (j = 0; j < max; j++)
- multTable[j] = (GLint) ((GLfloat) j * mult + 0.5F);
- prevMult = mult;
- }
-
- assert(ctx->IntegerAccumScaler > 0.0);
- assert(ctx->IntegerAccumScaler <= 1.0);
- for (j = 0; j < height; j++) {
- const GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos*4;
- GLuint 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 (ctx->Color.SWmasking) {
- gl_mask_rgba_span( ctx, width, xpos, ypos, rgba );
- }
- (*ctx->Driver.WriteRGBASpan)( ctx, width, xpos, ypos,
- (const GLubyte (*)[4])rgba, NULL );
- ypos++;
- }
- }
- else {
- const GLfloat rscale = value / acc_scale * fChanMax;
- const GLfloat gscale = value / acc_scale * fChanMax;
- const GLfloat bscale = value / acc_scale * fChanMax;
- const GLfloat ascale = value / acc_scale * fChanMax;
- GLuint 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, g, b, a;
- r = (GLint) ( (GLfloat) (*acc++) * rscale + 0.5F );
- g = (GLint) ( (GLfloat) (*acc++) * gscale + 0.5F );
- b = (GLint) ( (GLfloat) (*acc++) * bscale + 0.5F );
- a = (GLint) ( (GLfloat) (*acc++) * ascale + 0.5F );
- rgba[i][RCOMP] = CLAMP( r, 0, iChanMax );
- rgba[i][GCOMP] = CLAMP( g, 0, iChanMax );
- rgba[i][BCOMP] = CLAMP( b, 0, iChanMax );
- rgba[i][ACOMP] = CLAMP( a, 0, iChanMax );
- }
- if (ctx->Color.SWmasking) {
- gl_mask_rgba_span( ctx, width, xpos, ypos, rgba );
- }
- (*ctx->Driver.WriteRGBASpan)( ctx, width, xpos, ypos,
- (const GLubyte (*)[4])rgba, NULL );
- ypos++;
- }
- }
- break;
-
- default:
- gl_error( ctx, GL_INVALID_ENUM, "glAccum" );