Fix typo
[mesa.git] / src / mesa / swrast / s_copypix.c
index eddfe390371d7fe90ede70cdd757ed981b282b2e..22fcd3c2a83a08d60443b8acc03c25811386510b 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: s_copypix.c,v 1.1 2000/10/31 18:00:04 keithw Exp $ */
+/* $Id: s_copypix.c,v 1.13 2001/03/03 20:33:30 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  3.5
  * 
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2001  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"),
@@ -35,8 +35,9 @@
 #include "mmath.h"
 #include "pixel.h"
 
+#include "s_context.h"
 #include "s_depth.h"
-#include "s_imaging.h"
+#include "s_histogram.h"
 #include "s_pixeltex.h"
 #include "s_span.h"
 #include "s_stencil.h"
 
 
 /*
- * Determine if there's overlap in an image copy
+ * Determine if there's overlap in an image copy.
+ * This test also compensates for the fact that copies are done from
+ * bottom to top and overlaps can sometimes be handled correctly
+ * without making a temporary image copy.
  */
 static GLboolean
-regions_overlap(int srcx, int srcy, int dstx, int dsty, int width, int height,
-                float zoomX, float zoomY)
+regions_overlap(GLint srcx, GLint srcy,
+                GLint dstx, GLint dsty,
+                GLint width, GLint height,
+                GLfloat zoomX, GLfloat zoomY)
 {
-   if ((srcx > dstx + (width * zoomX) + 1) || (srcx + width + 1 < dstx)) {
-      return GL_FALSE;
-   }
-   else if ((srcy < dsty) && (srcy + height < dsty + (height * zoomY))) {
-      return GL_FALSE;
-   }
-   else if ((srcy > dsty) && (srcy + height > dsty + (height * zoomY))) {
-      return GL_FALSE;
+   if (zoomX == 1.0 && zoomY == 1.0) {
+      /* no zoom */
+      if (srcx >= dstx + width || (srcx + width <= dstx)) {
+         return GL_FALSE;
+      }
+      else if (srcy < dsty) { /* this is OK */
+         return GL_FALSE;
+      }
+      else {
+         return GL_TRUE;
+      }
    }
    else {
-      return GL_TRUE;
+      /* add one pixel of slop when zooming, just to be safe */
+      if ((srcx > dstx + (width * zoomX) + 1) || (srcx + width + 1 < dstx)) {
+         return GL_FALSE;
+      }
+      else if ((srcy < dsty) && (srcy + height < dsty + (height * zoomY))) {
+         return GL_FALSE;
+      }
+      else if ((srcy > dsty) && (srcy + height > dsty + (height * zoomY))) {
+         return GL_FALSE;
+      }
+      else {
+         return GL_TRUE;
+      }
    }
 }
 
@@ -81,20 +102,20 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    GLboolean changeBuffer;
    GLchan *saveReadAlpha;
    const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
-   const GLuint transferOps = ctx->ImageTransferState;
+   const GLuint transferOps = ctx->_ImageTransferState;
    GLfloat *dest, *tmpImage, *convImage;
 
    if (ctx->Depth.Test || ctx->Fog.Enabled) {
       /* fill in array of z values */
       GLdepth z = (GLdepth)
-         (ctx->Current.RasterPos[2] * ctx->Visual.DepthMax);
+         (ctx->Current.RasterPos[2] * ctx->DepthMax);
       GLint i;
       for (i = 0; i < width; i++) {
          zspan[i] = z;
       }
    }
 
-   if (ctx->RasterMask == 0
+   if (SWRAST_CONTEXT(ctx)->_RasterMask == 0
        && !zoom
        && destx >= 0
        && destx + width <= ctx->DrawBuffer->Width) {
@@ -113,13 +134,13 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    /* allocate space for GLfloat image */
    tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
    if (!tmpImage) {
-      gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
       return;
    }
    convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
    if (!convImage) {
       FREE(tmpImage);
-      gl_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
       return;
    }
 
@@ -143,7 +164,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    for (row = 0; row < height; row++) {
       GLchan rgba[MAX_WIDTH][4];
       GLint i;
-      gl_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx, srcy + row, rgba);
+      _mesa_read_rgba_span(ctx, ctx->ReadBuffer, width, srcx, srcy + row, rgba);
       /* convert GLchan to GLfloat */
       for (i = 0; i < width; i++) {
          *dest++ = (GLfloat) rgba[i][RCOMP] * (1.0F / CHAN_MAXF);
@@ -166,7 +187,11 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
       /* scale & bias */
       if (transferOps & IMAGE_SCALE_BIAS_BIT) {
-         _mesa_scale_and_bias_rgba(ctx, width, rgba);
+         _mesa_scale_and_bias_rgba(ctx, width, rgba,
+                                   ctx->Pixel.RedScale, ctx->Pixel.GreenScale,
+                                   ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale,
+                                   ctx->Pixel.RedBias, ctx->Pixel.GreenBias,
+                                   ctx->Pixel.BlueBias, ctx->Pixel.AlphaBias);
       }
       /* color map lookup */
       if (transferOps & IMAGE_MAP_COLOR_BIT) {
@@ -231,7 +256,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX);
       }
 
-      if (ctx->Texture.ReallyEnabled && ctx->Pixel.PixelTextureEnabled) {
+      if (ctx->Texture._ReallyEnabled && ctx->Pixel.PixelTextureEnabled) {
          GLfloat s[MAX_WIDTH], t[MAX_WIDTH], r[MAX_WIDTH], q[MAX_WIDTH];
          GLchan primary_rgba[MAX_WIDTH][4];
          GLuint unit;
@@ -239,11 +264,12 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
          MEMCPY(primary_rgba, rgba, 4 * width * sizeof(GLchan));
 
-         for (unit = 0; unit < MAX_TEXTURE_UNITS; unit++) {
+         for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
             _mesa_pixeltexgen(ctx, width, (const GLchan (*)[4]) rgba,
                               s, t, r, q);
-            gl_texture_pixels(ctx, unit, width, s, t, r, NULL,
-                              primary_rgba, rgba);
+            _swrast_texture_fragments(ctx, unit, width, s, t, r, NULL,
+                                      (CONST GLchan (*)[4]) primary_rgba,
+                                      rgba);
          }
       }
 
@@ -255,11 +281,11 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                                       (const GLchan (*)[4])rgba, NULL );
       }
       else if (zoom) {
-         gl_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0, 
+         _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0, 
                                    (const GLchan (*)[4])rgba, desty);
       }
       else {
-         gl_write_rgba_span( ctx, width, destx, dy, zspan, 0, rgba, GL_BITMAP );
+         _mesa_write_rgba_span( ctx, width, destx, dy, zspan, 0, rgba, GL_BITMAP );
       }
    }
 
@@ -284,7 +310,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    GLchan *saveReadAlpha;
    const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
    GLint overlapping;
-   const GLuint transferOps = ctx->ImageTransferState;
+   const GLuint transferOps = ctx->_ImageTransferState;
 
    if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
       copy_conv_rgba_pixels(ctx, srcx, srcy, width, height, destx, desty);
@@ -310,13 +336,13 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
    if (ctx->Depth.Test || ctx->Fog.Enabled) {
       /* fill in array of z values */
-      GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual.DepthMax);
+      GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
       for (i=0;i<width;i++) {
          zspan[i] = z;
       }
    }
 
-   if (ctx->RasterMask == 0
+   if (SWRAST_CONTEXT(ctx)->_RasterMask == 0
        && !zoom
        && destx >= 0
        && destx + width <= ctx->DrawBuffer->Width) {
@@ -329,13 +355,16 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    /* If read and draw buffer are different we must do buffer switching */
    saveReadAlpha = ctx->ReadBuffer->Alpha;
    changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
-               || ctx->DrawBuffer != ctx->ReadBuffer;
+                  || ctx->DrawBuffer != ctx->ReadBuffer;
+
+   (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+                                 ctx->Pixel.DriverReadBuffer );
 
    if (overlapping) {
       GLint ssy = sy;
       tmpImage = (GLchan *) MALLOC(width * height * sizeof(GLchan) * 4);
       if (!tmpImage) {
-         gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+         _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
       }
       p = tmpImage;
@@ -352,7 +381,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
             ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackRightAlpha;
       }
       for (j = 0; j < height; j++, ssy += stepy) {
-         gl_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, ssy,
+         _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, ssy,
                             (GLchan (*)[4]) p );
          p += (width * sizeof(GLchan) * 4);
       }
@@ -388,7 +417,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                ctx->ReadBuffer->Alpha = ctx->ReadBuffer->BackRightAlpha;
             }
          }
-         gl_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, sy, rgba );
+         _mesa_read_rgba_span( ctx, ctx->ReadBuffer, width, srcx, sy, rgba );
       }
 
       if (changeBuffer) {
@@ -411,7 +440,11 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          }
          /* scale & bias */
          if (transferOps & IMAGE_SCALE_BIAS_BIT) {
-            _mesa_scale_and_bias_rgba(ctx, width, rgbaFloat);
+            _mesa_scale_and_bias_rgba(ctx, width, rgbaFloat,
+                                   ctx->Pixel.RedScale, ctx->Pixel.GreenScale,
+                                   ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale,
+                                   ctx->Pixel.RedBias, ctx->Pixel.GreenBias,
+                                   ctx->Pixel.BlueBias, ctx->Pixel.AlphaBias);
          }
          /* color map lookup */
          if (transferOps & IMAGE_MAP_COLOR_BIT) {
@@ -425,6 +458,18 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          if (transferOps & IMAGE_CONVOLUTION_BIT) {
             /* XXX to do */
          }
+         /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */
+         if (transferOps & IMAGE_POST_CONVOLUTION_SCALE_BIAS) {
+            _mesa_scale_and_bias_rgba(ctx, width, rgbaFloat,
+                                      ctx->Pixel.PostConvolutionScale[RCOMP],
+                                      ctx->Pixel.PostConvolutionScale[GCOMP],
+                                      ctx->Pixel.PostConvolutionScale[BCOMP],
+                                      ctx->Pixel.PostConvolutionScale[ACOMP],
+                                      ctx->Pixel.PostConvolutionBias[RCOMP],
+                                      ctx->Pixel.PostConvolutionBias[GCOMP],
+                                      ctx->Pixel.PostConvolutionBias[BCOMP],
+                                      ctx->Pixel.PostConvolutionBias[ACOMP]);
+         }
          /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */
          if (transferOps & IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT) {
             _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, width, rgbaFloat);
@@ -458,7 +503,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          }
       }
 
-      if (ctx->Texture.ReallyEnabled && ctx->Pixel.PixelTextureEnabled) {
+      if (ctx->Texture._ReallyEnabled && ctx->Pixel.PixelTextureEnabled) {
          GLfloat s[MAX_WIDTH], t[MAX_WIDTH], r[MAX_WIDTH], q[MAX_WIDTH];
          GLchan primary_rgba[MAX_WIDTH][4];
          GLuint unit;
@@ -466,11 +511,12 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
          MEMCPY(primary_rgba, rgba, 4 * width * sizeof(GLchan));
 
-         for (unit = 0; unit < MAX_TEXTURE_UNITS; unit++) {
+         for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
             _mesa_pixeltexgen(ctx, width, (const GLchan (*)[4]) rgba,
                               s, t, r, q);
-            gl_texture_pixels(ctx, unit, width, s, t, r, NULL,
-                              primary_rgba, rgba);
+            _swrast_texture_fragments(ctx, unit, width, s, t, r, NULL,
+                                      (CONST GLchan (*)[4]) primary_rgba,
+                                      rgba);
          }
       }
 
@@ -479,14 +525,18 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                                       (const GLchan (*)[4])rgba, NULL );
       }
       else if (zoom) {
-         gl_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0,
+         _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0,
                                    (const GLchan (*)[4])rgba, desty);
       }
       else {
-         gl_write_rgba_span( ctx, width, destx, dy, zspan, 0, rgba, GL_BITMAP );
+         _mesa_write_rgba_span( ctx, width, destx, dy, zspan, 0, rgba, GL_BITMAP );
       }
    }
 
+   /* Restore pixel source to be the draw buffer (for blending, etc) */
+   (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+                                 ctx->Color.DriverDrawBuffer );
+
    if (overlapping)
       FREE(tmpImage);
 }
@@ -524,7 +574,7 @@ static void copy_ci_pixels( GLcontext *ctx,
 
    if (ctx->Depth.Test || ctx->Fog.Enabled) {
       /* fill in array of z values */
-      GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->Visual.DepthMax);
+      GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
       for (i=0;i<width;i++) {
          zspan[i] = z;
       }
@@ -534,11 +584,14 @@ static void copy_ci_pixels( GLcontext *ctx,
    changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
                || ctx->DrawBuffer != ctx->ReadBuffer;
 
+   (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+                                 ctx->Pixel.DriverReadBuffer );
+
    if (overlapping) {
       GLint ssy = sy;
       tmpImage = (GLuint *) MALLOC(width * height * sizeof(GLuint));
       if (!tmpImage) {
-         gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+         _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
       }
       p = tmpImage;
@@ -547,7 +600,7 @@ static void copy_ci_pixels( GLcontext *ctx,
                                        ctx->Pixel.DriverReadBuffer );
       }
       for (j = 0; j < height; j++, ssy += stepy) {
-         gl_read_index_span( ctx, ctx->ReadBuffer, width, srcx, ssy, p );
+         _mesa_read_index_span( ctx, ctx->ReadBuffer, width, srcx, ssy, p );
          p += width;
       }
       p = tmpImage;
@@ -568,7 +621,7 @@ static void copy_ci_pixels( GLcontext *ctx,
             (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                           ctx->Pixel.DriverReadBuffer );
          }
-         gl_read_index_span( ctx, ctx->ReadBuffer, width, srcx, sy, indexes );
+         _mesa_read_index_span( ctx, ctx->ReadBuffer, width, srcx, sy, indexes );
       }
 
       if (changeBuffer) {
@@ -585,13 +638,17 @@ static void copy_ci_pixels( GLcontext *ctx,
       }
 
       if (zoom) {
-         gl_write_zoomed_index_span( ctx, width, destx, dy, zspan, 0, indexes, desty );
+         _mesa_write_zoomed_index_span( ctx, width, destx, dy, zspan, 0, indexes, desty );
       }
       else {
-         gl_write_index_span(ctx, width, destx, dy, zspan, 0, indexes, GL_BITMAP);
+         _mesa_write_index_span(ctx, width, destx, dy, zspan, 0, indexes, GL_BITMAP);
       }
    }
 
+   /* Restore pixel source to be the draw buffer (for blending, etc) */
+   (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+                                 ctx->Color.DriverDrawBuffer );
+
    if (overlapping)
       FREE(tmpImage);
 }
@@ -615,8 +672,8 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
    GLint overlapping;
 
-   if (!ctx->ReadBuffer->DepthBuffer || !ctx->DrawBuffer->DepthBuffer) {
-      gl_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" );
+   if (!ctx->Visual.depthBits) {
+      _mesa_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" );
       return;
    }
 
@@ -638,7 +695,7 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
                                  ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
 
    /* setup colors or indexes */
-   if (ctx->Visual.RGBAflag) {
+   if (ctx->Visual.rgbMode) {
       GLuint *rgba32 = (GLuint *) rgba;
       GLuint color = *(GLuint*)( ctx->Current.Color );
       for (i = 0; i < width; i++) {
@@ -655,7 +712,7 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       GLint ssy = sy;
       tmpImage = (GLfloat *) MALLOC(width * height * sizeof(GLfloat));
       if (!tmpImage) {
-         gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+         _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
       }
       p = tmpImage;
@@ -681,26 +738,26 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
       for (i = 0; i < width; i++) {
          GLfloat d = depth[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias;
-         zspan[i] = (GLdepth) (CLAMP(d, 0.0F, 1.0F) * ctx->Visual.DepthMax);
+         zspan[i] = (GLdepth) (CLAMP(d, 0.0F, 1.0F) * ctx->DepthMax);
       }
 
-      if (ctx->Visual.RGBAflag) {
+      if (ctx->Visual.rgbMode) {
          if (zoom) {
-            gl_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0,
+            _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0,
                                       (const GLchan (*)[4])rgba, desty );
          }
          else {
-            gl_write_rgba_span( ctx, width, destx, dy, zspan, 0, 
+            _mesa_write_rgba_span( ctx, width, destx, dy, zspan, 0, 
                                rgba, GL_BITMAP);
          }
       }
       else {
          if (zoom) {
-            gl_write_zoomed_index_span( ctx, width, destx, dy,
+            _mesa_write_zoomed_index_span( ctx, width, destx, dy,
                                         zspan, 0, indexes, desty );
          }
          else {
-            gl_write_index_span( ctx, width, destx, dy,
+            _mesa_write_index_span( ctx, width, destx, dy,
                                  zspan, 0, indexes, GL_BITMAP );
          }
       }
@@ -723,8 +780,8 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    const GLboolean shift_or_offset = ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset;
    GLint overlapping;
 
-   if (!ctx->DrawBuffer->Stencil || !ctx->ReadBuffer->Stencil) {
-      gl_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" );
+   if (!ctx->Visual.stencilBits) {
+      _mesa_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" );
       return;
    }
 
@@ -749,7 +806,7 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       GLint ssy = sy;
       tmpImage = (GLstencil *) MALLOC(width * height * sizeof(GLstencil));
       if (!tmpImage) {
-         gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+         _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
       }
       p = tmpImage;
@@ -783,7 +840,7 @@ static void copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       }
 
       if (zoom) {
-         gl_write_zoomed_stencil_span( ctx, width, destx, dy, stencil, desty );
+         _mesa_write_zoomed_stencil_span( ctx, width, destx, dy, stencil, desty );
       }
       else {
          _mesa_write_stencil_span( ctx, width, destx, dy, stencil );
@@ -803,10 +860,13 @@ _swrast_CopyPixels( GLcontext *ctx,
                    GLint destx, GLint desty,
                    GLenum type )
 {
-   if (type == GL_COLOR && ctx->Visual.RGBAflag) {
+   if (SWRAST_CONTEXT(ctx)->NewState)
+      _swrast_validate_derived( ctx );
+
+   if (type == GL_COLOR && ctx->Visual.rgbMode) {
       copy_rgba_pixels( ctx, srcx, srcy, width, height, destx, desty );
    }
-   else if (type == GL_COLOR && !ctx->Visual.RGBAflag) {
+   else if (type == GL_COLOR && !ctx->Visual.rgbMode) {
       copy_ci_pixels( ctx, srcx, srcy, width, height, destx, desty );
    }
    else if (type == GL_DEPTH) {
@@ -816,6 +876,6 @@ _swrast_CopyPixels( GLcontext *ctx,
       copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty );
    }
    else {
-      gl_error( ctx, GL_INVALID_ENUM, "glCopyPixels" );
+      _mesa_error( ctx, GL_INVALID_ENUM, "glCopyPixels" );
    }
 }