fix GL_DOT3_RGBA texture combiner mode in generated fragment programs (bug #11030)
[mesa.git] / src / mesa / swrast / s_imaging.c
index b9c413687b17197039d5e972372f147602f2adc3..73aaba1ec9fe4919f3f11814af3ead827c9bc975 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  6.5
  *
- * Copyright (C) 1999-2002  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"),
 
 #include "s_context.h"
 #include "s_span.h"
+#include "colortab.h"
+#include "convolve.h"
+
 
 void
 _swrast_CopyColorTable( GLcontext *ctx, 
                        GLenum target, GLenum internalformat,
                        GLint x, GLint y, GLsizei width)
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLchan data[MAX_WIDTH][4];
+   struct gl_buffer_object *bufferSave;
 
-   /* Select buffer to read from */
-   _swrast_use_read_buffer(ctx);
+   if (!ctx->ReadBuffer->_ColorReadBuffer) {
+      /* no readbuffer - OK */
+      return;
+   }
 
    if (width > MAX_WIDTH)
       width = MAX_WIDTH;
 
+   RENDER_START( swrast, ctx );
+
    /* read the data from framebuffer */
-   _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
+   _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
+                           width, x, y, CHAN_TYPE, data );
 
-   /* Restore reading from draw buffer (the default) */
-   _swrast_use_draw_buffer(ctx);
+   RENDER_FINISH(swrast,ctx);
+
+   /* save PBO binding */
+   bufferSave = ctx->Unpack.BufferObj;
+   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+
+   _mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
 
-   glColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
+   /* restore PBO binding */
+   ctx->Unpack.BufferObj = bufferSave;
 }
 
+
 void
 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
                           GLint x, GLint y, GLsizei width)
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLchan data[MAX_WIDTH][4];
+   struct gl_buffer_object *bufferSave;
 
-   /* Select buffer to read from */
-   _swrast_use_read_buffer(ctx);
+   if (!ctx->ReadBuffer->_ColorReadBuffer) {
+      /* no readbuffer - OK */
+      return;
+   }
 
    if (width > MAX_WIDTH)
       width = MAX_WIDTH;
 
+   RENDER_START( swrast, ctx );
+
    /* read the data from framebuffer */
-   _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
+   _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
+                           width, x, y, CHAN_TYPE, data );
+
+   RENDER_FINISH(swrast,ctx);
+
+   /* save PBO binding */
+   bufferSave = ctx->Unpack.BufferObj;
+   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
 
-   /* Restore reading from draw buffer (the default) */
-   _swrast_use_draw_buffer(ctx);
+   _mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
 
-   glColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
+   /* restore PBO binding */
+   ctx->Unpack.BufferObj = bufferSave;
 }
 
 
@@ -82,24 +111,31 @@ _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
+   struct gl_buffer_object *bufferSave;
 
-   /* Select buffer to read from */
-   _swrast_use_read_buffer(ctx);
+   if (!ctx->ReadBuffer->_ColorReadBuffer) {
+      /* no readbuffer - OK */
+      return;
+   }
 
    RENDER_START( swrast, ctx );
 
    /* read the data from framebuffer */
-   _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y,
-                               (GLchan (*)[4]) rgba );
+   _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
+                           width, x, y, CHAN_TYPE, rgba );
    
    RENDER_FINISH( swrast, ctx );
 
-   /* Restore reading from draw buffer (the default) */
-   _swrast_use_draw_buffer(ctx);
+   /* save PBO binding */
+   bufferSave = ctx->Unpack.BufferObj;
+   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
 
    /* store as convolution filter */
-   glConvolutionFilter1D(target, internalFormat, width,
-                        GL_RGBA, CHAN_TYPE, rgba);
+   _mesa_ConvolutionFilter1D(target, internalFormat, width,
+                             GL_RGBA, CHAN_TYPE, rgba);
+
+   /* restore PBO binding */
+   ctx->Unpack.BufferObj = bufferSave;
 }
 
 
@@ -112,23 +148,23 @@ _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
    struct gl_pixelstore_attrib packSave;
    GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
    GLint i;
+   struct gl_buffer_object *bufferSave;
 
-   /* Select buffer to read from */
-   _swrast_use_read_buffer(ctx);
+   if (!ctx->ReadBuffer->_ColorReadBuffer) {
+      /* no readbuffer - OK */
+      return;
+   }
 
    RENDER_START(swrast,ctx);
    
    /* read pixels from framebuffer */
    for (i = 0; i < height; i++) {
-      _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i,
-                               (GLchan (*)[4]) rgba[i] );
+      _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
+                              width, x, y + i, CHAN_TYPE, rgba[i] );
    }
 
    RENDER_FINISH(swrast,ctx);
 
-   /* Restore reading from draw buffer (the default) */
-   _swrast_use_draw_buffer(ctx);
-
    /*
     * HACK: save & restore context state so we can store this as a
     * convolution filter via the GL api.  Doesn't call any callbacks
@@ -145,10 +181,18 @@ _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
    ctx->Unpack.SkipImages = 0;
    ctx->Unpack.SwapBytes = GL_FALSE;
    ctx->Unpack.LsbFirst = GL_FALSE;
+   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
    ctx->NewState |= _NEW_PACKUNPACK;
 
-   glConvolutionFilter2D(target, internalFormat, width, height,
-                        GL_RGBA, CHAN_TYPE, rgba);
+   /* save PBO binding */
+   bufferSave = ctx->Unpack.BufferObj;
+   ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
+
+   _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
+                             GL_RGBA, CHAN_TYPE, rgba);
+
+   /* restore PBO binding */
+   ctx->Unpack.BufferObj = bufferSave;
 
    ctx->Unpack = packSave;  /* restore pixel packing params */
    ctx->NewState |= _NEW_PACKUNPACK;