OSDN Git Service

mesa/swrast: Respect mfeatures.h.
[android-x86/external-mesa.git] / src / mesa / swrast / s_accum.c
index cf6dab9..c29ccf2 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.2
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  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 "imports.h"
-#include "fbobject.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/imports.h"
+#include "main/fbobject.h"
 
 #include "s_accum.h"
 #include "s_context.h"
@@ -35,6 +35,9 @@
 #include "s_span.h"
 
 
+/* XXX this would have to change for accum buffers with more or less
+ * than 16 bits per color channel.
+ */
 #define ACCUM_SCALE16 32767.0
 
 
@@ -70,6 +73,9 @@
 #endif
 
 
+#if FEATURE_accum
+
+
 /**
  * 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
@@ -133,7 +139,9 @@ _swrast_clear_accum_buffer( GLcontext *ctx, struct gl_renderbuffer *rb )
       return;
    }
 
-   assert(rb);
+   if (!rb || !rb->Data)
+      return;
+
    assert(rb->_BaseFormat == GL_RGBA);
    /* add other types in future? */
    assert(rb->DataType == GL_SHORT || rb->DataType == GL_UNSIGNED_SHORT);
@@ -304,7 +312,7 @@ accum_accum(GLcontext *ctx, GLfloat value,
 
          /* read colors from color buffer */
          _swrast_read_rgba_span(ctx, ctx->ReadBuffer->_ColorReadBuffer, width,
-                                xpos, ypos + i, rgba);
+                                xpos, ypos + i, CHAN_TYPE, rgba);
 
          /* do accumulation */
          if (swrast->_IntegerAccumMode) {
@@ -388,7 +396,7 @@ accum_load(GLcontext *ctx, GLfloat value,
 
          /* read colors from color buffer */
          _swrast_read_rgba_span(ctx, ctx->ReadBuffer->_ColorReadBuffer, width,
-                                xpos, ypos + i, rgba);
+                                xpos, ypos + i, CHAN_TYPE, rgba);
 
          /* do load */
          if (swrast->_IntegerAccumMode) {
@@ -419,9 +427,6 @@ accum_load(GLcontext *ctx, GLfloat value,
          }
       }
    }
-   else {
-      /* other types someday */
-   }
 }
 
 
@@ -462,13 +467,21 @@ accum_return(GLcontext *ctx, GLfloat value,
    if (accumRb->DataType == GL_SHORT ||
        accumRb->DataType == GL_UNSIGNED_SHORT) {
       const GLfloat scale = value * CHAN_MAXF / ACCUM_SCALE16;
-      GLuint buffer, i;
+      GLuint buffer;
+      GLint 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;
+         SWspan span;
+
+         /* init color span */
+         INIT_SPAN(span, GL_BITMAP);
+         span.end = width;
+         span.arrayMask = SPAN_RGBA;
+         span.x = xpos;
+         span.y = ypos + i;
 
          if (directAccess) {
             acc = (GLshort *) accumRb->GetPointer(ctx, accumRb, xpos, ypos +i);
@@ -486,34 +499,41 @@ accum_return(GLcontext *ctx, GLfloat value,
                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]];
+               span.array->rgba[j][RCOMP] = multTable[acc[j * 4 + 0]];
+               span.array->rgba[j][GCOMP] = multTable[acc[j * 4 + 1]];
+               span.array->rgba[j][BCOMP] = multTable[acc[j * 4 + 2]];
+               span.array->rgba[j][ACOMP] = multTable[acc[j * 4 + 3]];
             }
          }
          else {
             /* scaled integer (or float) accum buffer */
             GLint j;
             for (j = 0; j < width; j++) {
+#if CHAN_BITS==32
+               GLchan r = acc[j * 4 + 0] * scale;
+               GLchan g = acc[j * 4 + 1] * scale;
+               GLchan b = acc[j * 4 + 2] * scale;
+               GLchan a = acc[j * 4 + 3] * scale;
+#else
                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 );
+#endif
+               span.array->rgba[j][RCOMP] = CLAMP( r, 0, CHAN_MAX );
+               span.array->rgba[j][GCOMP] = CLAMP( g, 0, CHAN_MAX );
+               span.array->rgba[j][BCOMP] = CLAMP( b, 0, CHAN_MAX );
+               span.array->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];
+         for (buffer = 0; buffer < fb->_NumColorDrawBuffers; buffer++) {
+            struct gl_renderbuffer *rb = fb->_ColorDrawBuffers[buffer];
             if (masking) {
-               _swrast_mask_rgba_array(ctx, rb, width, xpos, ypos + i, rgba);
+               _swrast_mask_rgba_span(ctx, rb, &span);
             }
-            rb->PutRow(ctx, rb, width, xpos, ypos + i, rgba, NULL);
+            rb->PutRow(ctx, rb, width, xpos, ypos + i, span.array->rgba, NULL);
          }
       }
    }
@@ -528,14 +548,12 @@ accum_return(GLcontext *ctx, GLfloat value,
  * Software fallback for glAccum.
  */
 void
-_swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value,
-              GLint xpos, GLint ypos,
-              GLint width, GLint height )
-
+_swrast_Accum(GLcontext *ctx, GLenum op, GLfloat value)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   GLint xpos, ypos, width, height;
 
-   if (SWRAST_CONTEXT(ctx)->NewState)
+   if (swrast->NewState)
       _swrast_validate_derived( ctx );
 
    if (!ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer) {
@@ -543,7 +561,15 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value,
       return;
    }
 
-   RENDER_START(swrast, ctx);
+   swrast_render_start(ctx);
+
+   /* Compute region after calling swrast_render_start() so that we know the
+    * drawbuffer's size/bounds are up to date.
+    */
+   xpos = ctx->DrawBuffer->_Xmin;
+   ypos = ctx->DrawBuffer->_Ymin;
+   width =  ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin;
+   height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin;
 
    switch (op) {
       case GL_ADD:
@@ -572,5 +598,8 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value,
          break;
    }
 
-   RENDER_FINISH(swrast, ctx);
+   swrast_render_finish(ctx);
 }
+
+
+#endif /* FEATURE_accum */