added missing \'s
[mesa.git] / src / mesa / swrast / s_copypix.c
index f85af995d32323a9055e7efc530d4f544b12aa44..ab8198945ce992ed48b01447fc8d7797c6879faa 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: s_copypix.c,v 1.16 2001/03/19 02:25:36 keithw 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"
@@ -98,6 +99,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLdepth zspan[MAX_WIDTH];
+   GLfloat fogSpan[MAX_WIDTH];
    GLboolean quick_draw;
    GLint row;
    GLboolean changeBuffer;
@@ -108,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;
       }
    }
 
@@ -282,11 +291,12 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                                       (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 );
       }
    }
 
@@ -303,6 +313,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLdepth zspan[MAX_WIDTH];
+   GLfloat fogSpan[MAX_WIDTH];
    GLchan rgba[MAX_WIDTH][4];
    GLchan *tmpImage,*p;
    GLboolean quick_draw;
@@ -339,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;
       }
    }
 
@@ -431,8 +450,10 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
 
       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;
@@ -503,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++) {
@@ -520,6 +549,11 @@ 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) {
@@ -527,11 +561,12 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
                                       (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 );
       }
    }
 
@@ -550,6 +585,7 @@ static void copy_ci_pixels( GLcontext *ctx,
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLdepth zspan[MAX_WIDTH];
+   GLfloat fogSpan[MAX_WIDTH];
    GLuint *tmpImage,*p;
    GLint sy, dy, stepy;
    GLint i, j;
@@ -578,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;
       }
    }
 
@@ -641,10 +685,12 @@ 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);
       }
    }
 
@@ -667,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;
    }
 
@@ -711,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;
@@ -746,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);
 }