added GL_SGIX/SGIS_pixel_texture
[mesa.git] / src / mesa / main / accum.c
index 8e6f3cae0ff41cabda2e684b57e091da4020d8bf..6654a6314ba37834495b95dbcd702f1424f2959a 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: accum.c,v 1.12 1999/11/24 18:48:30 brianp Exp $ */
+/* $Id: accum.c,v 1.20 2000/04/05 14:40:04 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  3.3
  * 
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2000  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"),
@@ -34,6 +34,7 @@
 #include "mem.h"
 #include "masking.h"
 #include "span.h"
+#include "state.h"
 #include "types.h"
 #endif
 
@@ -66,7 +67,8 @@
 
 
 
-void gl_alloc_accum_buffer( GLcontext *ctx )
+void
+_mesa_alloc_accum_buffer( GLcontext *ctx )
 {
    GLint n;
 
@@ -143,7 +145,7 @@ _mesa_Accum( GLenum op, GLfloat value )
    
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glAccum");
 
-   if (ctx->Visual->AccumBits == 0 || ctx->DrawBuffer != ctx->ReadBuffer) {
+   if (ctx->Visual->AccumRedBits == 0 || ctx->DrawBuffer != ctx->ReadBuffer) {
       gl_error(ctx, GL_INVALID_OPERATION, "glAccum");
       return;
    }
@@ -221,7 +223,8 @@ _mesa_Accum( GLenum op, GLfloat value )
         break;
 
       case GL_ACCUM:
-         (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
+         (*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)
@@ -269,11 +272,14 @@ _mesa_Accum( GLenum op, GLfloat value )
                ypos++;
             }
          }
-         (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
+         /* restore read buffer = draw buffer (the default) */
+         (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+                                       ctx->Color.DriverDrawBuffer );
         break;
 
       case GL_LOAD:
-         (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );
+         (*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) {
@@ -328,7 +334,10 @@ _mesa_Accum( GLenum op, GLfloat value )
                ypos++;
             }
          }
-         (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
+
+         /* restore read buffer = draw buffer (the default) */
+         (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+                                       ctx->Color.DriverDrawBuffer );
         break;
 
       case GL_RETURN:
@@ -336,13 +345,13 @@ _mesa_Accum( GLenum op, GLfloat value )
          if (ctx->IntegerAccumMode && value != 1.0)
             rescale_accum(ctx);
 
-         if (ctx->IntegerAccumMode) {
+         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 = 256 / mult;
+            const GLint max = (GLint) (256 / mult);
             if (mult != prevMult) {
                assert(max <= 32768);
                for (j = 0; j < max; j++)
@@ -366,7 +375,7 @@ _mesa_Accum( GLenum op, GLfloat value )
                   rgba[i][ACOMP] = multTable[acc[i4+3]];
                }
                if (ctx->Color.SWmasking) {
-                  gl_mask_rgba_span( ctx, width, xpos, ypos, rgba );
+                  _mesa_mask_rgba_span( ctx, width, xpos, ypos, rgba );
                }
                (*ctx->Driver.WriteRGBASpan)( ctx, width, xpos, ypos, 
                                              (const GLubyte (*)[4])rgba, NULL );
@@ -393,7 +402,7 @@ _mesa_Accum( GLenum op, GLfloat value )
                   rgba[i][ACOMP] = CLAMP( a, 0, iChanMax );
                }
                if (ctx->Color.SWmasking) {
-                  gl_mask_rgba_span( ctx, width, xpos, ypos, rgba );
+                  _mesa_mask_rgba_span( ctx, width, xpos, ypos, rgba );
                }
                (*ctx->Driver.WriteRGBASpan)( ctx, width, xpos, ypos, 
                                              (const GLubyte (*)[4])rgba, NULL );
@@ -412,12 +421,13 @@ _mesa_Accum( GLenum op, GLfloat value )
 /*
  * Clear the accumulation Buffer.
  */
-void gl_clear_accum_buffer( GLcontext *ctx )
+void
+_mesa_clear_accum_buffer( GLcontext *ctx )
 {
    GLuint buffersize;
    GLfloat acc_scale;
 
-   if (ctx->Visual->AccumBits==0) {
+   if (ctx->Visual->AccumRedBits==0) {
       /* No accumulation buffer! */
       return;
    }
@@ -477,7 +487,7 @@ void gl_clear_accum_buffer( GLcontext *ctx )
             ctx->Accum.ClearColor[2]==0.0 &&
             ctx->Accum.ClearColor[3]==0.0) {
            /* Black */
-           MEMSET( ctx->DrawBuffer->Accum, 0, buffersize * 4 * sizeof(GLaccum) );
+           BZERO( ctx->DrawBuffer->Accum, buffersize * 4 * sizeof(GLaccum) );
         }
         else {
            /* Not black */