added missing \'s
[mesa.git] / src / mesa / swrast / s_copypix.c
index 1a8c0a069c27ddb65e2579fdf32fdb2c3f684a19..ab8198945ce992ed48b01447fc8d7797c6879faa 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_copypix.c,v 1.15 2001/03/12 00:48:41 gareth Exp $ */
+/* $Id: s_copypix.c,v 1.21 2001/06/26 21:15:36 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -37,6 +37,7 @@
 
 #include "s_context.h"
 #include "s_depth.h"
+#include "s_fog.h"
 #include "s_histogram.h"
 #include "s_pixeltex.h"
 #include "s_span.h"
@@ -96,7 +97,9 @@ static void
 copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                       GLint width, GLint height, GLint destx, GLint desty)
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLdepth zspan[MAX_WIDTH];
+   GLfloat fogSpan[MAX_WIDTH];
    GLboolean quick_draw;
    GLint row;
    GLboolean changeBuffer;
@@ -107,11 +110,18 @@ copy_conv_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->DepthMax);
+      GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
+      GLfloat fog;
       GLint i;
+
+      if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterFogCoord);
+      else
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+
       for (i = 0; i < width; i++) {
          zspan[i] = z;
+         fogSpan[i] = fog;
       }
    }
 
@@ -147,7 +157,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    dest = tmpImage;
 
    if (changeBuffer) {
-      (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+      (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                     ctx->Pixel.DriverReadBuffer );
       if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT)
          ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha;
@@ -176,7 +186,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
    /* read from the draw buffer again (in case of blending) */
    if (changeBuffer) {
-      (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+      (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
                                     ctx->Color.DriverDrawBuffer );
       ctx->ReadBuffer->Alpha = saveReadAlpha;
    }
@@ -277,15 +287,16 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
       dy = desty + row;
       if (quick_draw && dy >= 0 && dy < ctx->DrawBuffer->Height) {
-         (*ctx->Driver.WriteRGBASpan)( ctx, width, destx, dy,
+         (*swrast->Driver.WriteRGBASpan)( ctx, width, destx, dy,
                                       (const GLchan (*)[4])rgba, NULL );
       }
       else if (zoom) {
-         _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0,
+         _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, fogSpan,
                                    (const GLchan (*)[4])rgba, desty);
       }
       else {
-         _mesa_write_rgba_span( ctx, width, destx, dy, zspan, 0, rgba, GL_BITMAP );
+         _mesa_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, rgba,
+                                NULL, GL_BITMAP );
       }
    }
 
@@ -300,7 +311,9 @@ static void
 copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                  GLint width, GLint height, GLint destx, GLint desty)
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLdepth zspan[MAX_WIDTH];
+   GLfloat fogSpan[MAX_WIDTH];
    GLchan rgba[MAX_WIDTH][4];
    GLchan *tmpImage,*p;
    GLboolean quick_draw;
@@ -337,8 +350,16 @@ 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->DepthMax);
+      GLfloat fog;
+
+      if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterFogCoord);
+      else
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+
       for (i=0;i<width;i++) {
          zspan[i] = z;
+         fogSpan[i] = fog;
       }
    }
 
@@ -357,7 +378,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
                   || ctx->DrawBuffer != ctx->ReadBuffer;
 
-   (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+   (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                  ctx->Pixel.DriverReadBuffer );
 
    if (overlapping) {
@@ -369,7 +390,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       }
       p = tmpImage;
       if (changeBuffer) {
-         (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+         (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                        ctx->Pixel.DriverReadBuffer );
          if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT)
             ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha;
@@ -402,7 +423,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       else {
          /* get from framebuffer */
          if (changeBuffer) {
-            (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+            (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                           ctx->Pixel.DriverReadBuffer );
             if (ctx->Pixel.DriverReadBuffer == GL_FRONT_LEFT) {
                ctx->ReadBuffer->Alpha = ctx->ReadBuffer->FrontLeftAlpha;
@@ -422,15 +443,17 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
       if (changeBuffer) {
          /* read from the draw buffer again (in case of blending) */
-         (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+         (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
                                        ctx->Color.DriverDrawBuffer );
          ctx->ReadBuffer->Alpha = saveReadAlpha;
       }
 
       if (transferOps) {
          const GLfloat scale = (1.0F / CHAN_MAXF);
-         GLfloat rgbaFloat[MAX_WIDTH][4];
          GLint k;
+         DEFMARRAY(GLfloat, rgbaFloat, MAX_WIDTH, 4);  /* mac 32k limitation */
+         CHECKARRAY(rgbaFloat, return);
+
          /* convert chan to float */
          for (k = 0; k < width; k++) {
             rgbaFloat[k][RCOMP] = (GLfloat) rgba[k][RCOMP] * scale;
@@ -501,14 +524,22 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
             rgba[k][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX);
             rgba[k][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX);
          }
+         UNDEFARRAY(rgbaFloat);  /* mac 32k limitation */
       }
 
       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;
-         /* XXX not sure how multitexture is supposed to work here */
+         GLchan primary_rgba[MAX_WIDTH][4];
+         DEFARRAY(GLfloat, s, MAX_WIDTH);  /* mac 32k limitation */
+         DEFARRAY(GLfloat, t, MAX_WIDTH);  /* mac 32k limitation */
+         DEFARRAY(GLfloat, r, MAX_WIDTH);  /* mac 32k limitation */
+         DEFARRAY(GLfloat, q, MAX_WIDTH);  /* mac 32k limitation */
+         CHECKARRAY(s, return); /* mac 32k limitation */
+         CHECKARRAY(t, return);
+         CHECKARRAY(r, return);
+         CHECKARRAY(q, return);
 
+         /* XXX not sure how multitexture is supposed to work here */
          MEMCPY(primary_rgba, rgba, 4 * width * sizeof(GLchan));
 
          for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
@@ -518,23 +549,29 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                                       (CONST GLchan (*)[4]) primary_rgba,
                                       rgba);
          }
+
+         UNDEFARRAY(s);  /* mac 32k limitation */
+         UNDEFARRAY(t);
+         UNDEFARRAY(r);
+         UNDEFARRAY(q);
       }
 
       if (quick_draw && dy >= 0 && dy < ctx->DrawBuffer->Height) {
-         (*ctx->Driver.WriteRGBASpan)( ctx, width, destx, dy,
+         (*swrast->Driver.WriteRGBASpan)( ctx, width, destx, dy,
                                       (const GLchan (*)[4])rgba, NULL );
       }
       else if (zoom) {
-         _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0,
+         _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, fogSpan,
                                    (const GLchan (*)[4])rgba, desty);
       }
       else {
-         _mesa_write_rgba_span( ctx, width, destx, dy, zspan, 0, rgba, GL_BITMAP );
+         _mesa_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, rgba,
+                                NULL, GL_BITMAP );
       }
    }
 
    /* Restore pixel source to be the draw buffer (for blending, etc) */
-   (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+   (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
                                  ctx->Color.DriverDrawBuffer );
 
    if (overlapping)
@@ -546,7 +583,9 @@ static void copy_ci_pixels( GLcontext *ctx,
                             GLint srcx, GLint srcy, GLint width, GLint height,
                             GLint destx, GLint desty )
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLdepth zspan[MAX_WIDTH];
+   GLfloat fogSpan[MAX_WIDTH];
    GLuint *tmpImage,*p;
    GLint sy, dy, stepy;
    GLint i, j;
@@ -575,8 +614,16 @@ 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->DepthMax);
+      GLfloat fog;
+
+      if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterFogCoord);
+      else
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+
       for (i=0;i<width;i++) {
          zspan[i] = z;
+         fogSpan[i] = fog;
       }
    }
 
@@ -584,7 +631,7 @@ static void copy_ci_pixels( GLcontext *ctx,
    changeBuffer = ctx->Pixel.ReadBuffer != ctx->Color.DrawBuffer
                || ctx->DrawBuffer != ctx->ReadBuffer;
 
-   (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+   (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                  ctx->Pixel.DriverReadBuffer );
 
    if (overlapping) {
@@ -596,7 +643,7 @@ static void copy_ci_pixels( GLcontext *ctx,
       }
       p = tmpImage;
       if (changeBuffer) {
-         (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+         (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                        ctx->Pixel.DriverReadBuffer );
       }
       for (j = 0; j < height; j++, ssy += stepy) {
@@ -618,7 +665,7 @@ static void copy_ci_pixels( GLcontext *ctx,
       }
       else {
          if (changeBuffer) {
-            (*ctx->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
+            (*swrast->Driver.SetReadBuffer)( ctx, ctx->ReadBuffer,
                                           ctx->Pixel.DriverReadBuffer );
          }
          _mesa_read_index_span( ctx, ctx->ReadBuffer, width, srcx, sy, indexes );
@@ -626,7 +673,7 @@ static void copy_ci_pixels( GLcontext *ctx,
 
       if (changeBuffer) {
          /* set read buffer back to draw buffer (in case of logicops) */
-         (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+         (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
                                        ctx->Color.DriverDrawBuffer );
       }
 
@@ -638,15 +685,17 @@ static void copy_ci_pixels( GLcontext *ctx,
       }
 
       if (zoom) {
-         _mesa_write_zoomed_index_span( ctx, width, destx, dy, zspan, 0, indexes, desty );
+         _mesa_write_zoomed_index_span(ctx, width, destx, dy, zspan, fogSpan,
+                                       indexes, desty );
       }
       else {
-         _mesa_write_index_span(ctx, width, destx, dy, zspan, 0, indexes, GL_BITMAP);
+         _mesa_write_index_span(ctx, width, destx, dy, zspan, fogSpan, indexes,
+                                NULL, GL_BITMAP);
       }
    }
 
    /* Restore pixel source to be the draw buffer (for blending, etc) */
-   (*ctx->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
+   (*swrast->Driver.SetReadBuffer)( ctx, ctx->DrawBuffer,
                                  ctx->Color.DriverDrawBuffer );
 
    if (overlapping)
@@ -664,16 +713,19 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 {
    GLfloat depth[MAX_WIDTH];
    GLdepth zspan[MAX_WIDTH];
+   GLfloat fogSpan[MAX_WIDTH];
    GLfloat *p, *tmpImage;
    GLuint indexes[MAX_WIDTH];
-   GLchan rgba[MAX_WIDTH][4];
    GLint sy, dy, stepy;
    GLint i, j;
    const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
    GLint overlapping;
+   DEFMARRAY(GLubyte, rgba, MAX_WIDTH, 4);  /* mac 32k limitation */
+   CHECKARRAY(rgba, return);  /* mac 32k limitation */
 
    if (!ctx->Visual.depthBits) {
       _mesa_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" );
+      UNDEFARRAY(rgba);  /* mac 32k limitation */
       return;
    }
 
@@ -708,11 +760,25 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       }
    }
 
+   if (ctx->Fog.Enabled) {
+      GLfloat fog;
+
+      if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterFogCoord);
+      else
+         fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+
+      for (i = 0; i < width; i++) {
+         fogSpan[i] = fog;
+      }
+   }
+
    if (overlapping) {
       GLint ssy = sy;
       tmpImage = (GLfloat *) MALLOC(width * height * sizeof(GLfloat));
       if (!tmpImage) {
          _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
+         UNDEFARRAY(rgba);  /* mac 32k limitation */
          return;
       }
       p = tmpImage;
@@ -743,28 +809,30 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
       if (ctx->Visual.rgbMode) {
          if (zoom) {
-            _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan, 0,
-                                      (const GLchan (*)[4])rgba, desty );
+            _mesa_write_zoomed_rgba_span( ctx, width, destx, dy, zspan,
+                                   fogSpan, (const GLchan (*)[4])rgba, desty );
          }
          else {
-            _mesa_write_rgba_span( ctx, width, destx, dy, zspan, 0,
-                               rgba, GL_BITMAP);
+            _mesa_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan,
+                                   rgba, NULL, GL_BITMAP);
          }
       }
       else {
          if (zoom) {
             _mesa_write_zoomed_index_span( ctx, width, destx, dy,
-                                        zspan, 0, indexes, desty );
+                                           zspan, fogSpan, indexes, desty );
          }
          else {
             _mesa_write_index_span( ctx, width, destx, dy,
-                                 zspan, 0, indexes, GL_BITMAP );
+                                    zspan, fogSpan, indexes, NULL, GL_BITMAP );
          }
       }
    }
 
-  if (overlapping)
-     FREE(tmpImage);
+   UNDEFARRAY(rgba);  /* mac 32k limitation */
+
+   if (overlapping)
+      FREE(tmpImage);
 }
 
 
@@ -860,7 +928,10 @@ _swrast_CopyPixels( GLcontext *ctx,
                    GLint destx, GLint desty,
                    GLenum type )
 {
-   if (SWRAST_CONTEXT(ctx)->NewState)
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   RENDER_START(swrast,ctx);
+      
+   if (swrast->NewState)
       _swrast_validate_derived( ctx );
 
    if (type == GL_COLOR && ctx->Visual.rgbMode) {
@@ -878,4 +949,6 @@ _swrast_CopyPixels( GLcontext *ctx,
    else {
       _mesa_error( ctx, GL_INVALID_ENUM, "glCopyPixels" );
    }
+
+   RENDER_FINISH(swrast,ctx);
 }