Fix pow <small> and a very stypid bug with dummy srcs(0 equals to tmp0.x)</small...
[mesa.git] / src / mesa / main / pixel.c
index 2b1434b62a4cd91e863e354da8e37468deceb2f7..3b1f848e8c36c599518749a7dd60a6e44076b664 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  *
- * Copyright (C) 1999-2004  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"),
@@ -264,13 +264,13 @@ pixelmap(GLcontext *ctx, GLenum map, GLsizei mapsize, const GLfloat *values)
       case GL_PIXEL_MAP_S_TO_S:
          ctx->Pixel.MapStoSsize = mapsize;
          for (i = 0; i < mapsize; i++) {
-           ctx->Pixel.MapStoS[i] = (GLint) values[i];
+           ctx->Pixel.MapStoS[i] = IROUND(values[i]);
         }
         break;
       case GL_PIXEL_MAP_I_TO_I:
          ctx->Pixel.MapItoIsize = mapsize;
          for (i = 0; i < mapsize; i++) {
-           ctx->Pixel.MapItoI[i] = (GLint) values[i];
+           ctx->Pixel.MapItoI[i] = values[i];
         }
         break;
       case GL_PIXEL_MAP_I_TO_R:
@@ -615,9 +615,7 @@ _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
 
    switch (map) {
       case GL_PIXEL_MAP_I_TO_I:
-         for (i = 0; i < mapsize; i++) {
-           values[i] = (GLfloat) ctx->Pixel.MapItoI[i];
-        }
+         MEMCPY(values, ctx->Pixel.MapItoI, mapsize * sizeof(GLfloat));
         break;
       case GL_PIXEL_MAP_S_TO_S:
          for (i = 0; i < mapsize; i++) {
@@ -698,7 +696,9 @@ _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
 
    switch (map) {
       case GL_PIXEL_MAP_I_TO_I:
-         MEMCPY(values, ctx->Pixel.MapItoI, mapsize * sizeof(GLint));
+        for (i = 0; i < mapsize; i++) {
+           values[i] = FLOAT_TO_UINT( ctx->Pixel.MapItoI[i] );
+        }
         break;
       case GL_PIXEL_MAP_S_TO_S:
          MEMCPY(values, ctx->Pixel.MapStoS, mapsize * sizeof(GLint));
@@ -795,52 +795,52 @@ _mesa_GetPixelMapusv( GLenum map, GLushort *values )
    switch (map) {
       case GL_PIXEL_MAP_I_TO_I:
         for (i = 0; i < mapsize; i++) {
-           values[i] = (GLushort) ctx->Pixel.MapItoI[i];
+            values[i] = (GLushort) CLAMP(ctx->Pixel.MapItoI[i], 0.0, 65535.0);
         }
         break;
       case GL_PIXEL_MAP_S_TO_S:
         for (i = 0; i < mapsize; i++) {
-           values[i] = (GLushort) ctx->Pixel.MapStoS[i];
+            values[i] = (GLushort) CLAMP(ctx->Pixel.MapStoS[i], 0.0, 65535.0);
         }
         break;
       case GL_PIXEL_MAP_I_TO_R:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoR[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoR[i] );
         }
         break;
       case GL_PIXEL_MAP_I_TO_G:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoG[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoG[i] );
         }
         break;
       case GL_PIXEL_MAP_I_TO_B:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoB[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoB[i] );
         }
         break;
       case GL_PIXEL_MAP_I_TO_A:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapItoA[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapItoA[i] );
         }
         break;
       case GL_PIXEL_MAP_R_TO_R:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapRtoR[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapRtoR[i] );
         }
         break;
       case GL_PIXEL_MAP_G_TO_G:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapGtoG[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapGtoG[i] );
         }
         break;
       case GL_PIXEL_MAP_B_TO_B:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapBtoB[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapBtoB[i] );
         }
         break;
       case GL_PIXEL_MAP_A_TO_A:
         for (i = 0; i < mapsize; i++) {
-           values[i] = FLOAT_TO_USHORT( ctx->Pixel.MapAtoA[i] );
+           CLAMPED_FLOAT_TO_USHORT(values[i] , ctx->Pixel.MapAtoA[i] );
         }
         break;
       default:
@@ -1174,7 +1174,7 @@ _mesa_lookup_rgba_float(const struct gl_color_table *table,
    if (!table->Table || table->Size == 0)
       return;
 
-   switch (table->Format) {
+   switch (table->_BaseFormat) {
       case GL_INTENSITY:
          /* replace RGBA with I */
          if (table->Type == GL_FLOAT) {
@@ -1385,7 +1385,7 @@ _mesa_lookup_rgba_chan(const struct gl_color_table *table,
    if (!table->Table || table->Size == 0)
       return;
 
-   switch (table->Format) {
+   switch (table->_BaseFormat) {
       case GL_INTENSITY:
          /* replace RGBA with I */
          if (table->Type == GL_FLOAT) {
@@ -1680,10 +1680,11 @@ _mesa_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] )
 void
 _mesa_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] )
 {
-   GLuint mask = ctx->Pixel.MapItoIsize - 1;
+   const GLuint mask = ctx->Pixel.MapItoIsize - 1;
    GLuint i;
-   for (i=0;i<n;i++) {
-      index[i] = ctx->Pixel.MapItoI[ index[i] & mask ];
+   for (i = 0; i < n; i++) {
+      const GLuint j = index[i] & mask;
+      index[i] = IROUND(ctx->Pixel.MapItoI[j]);
    }
 }
 
@@ -1837,6 +1838,19 @@ _mesa_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] )
 }
 
 
+void
+_mesa_scale_and_bias_depth(const GLcontext *ctx, GLuint n,
+                           GLfloat depthValues[])
+{
+   const GLfloat scale = ctx->Pixel.DepthScale;
+   const GLfloat bias = ctx->Pixel.DepthBias;
+   GLuint i;
+   for (i = 0; i < n; i++) {
+      GLfloat d = depthValues[i] * scale + bias;
+      depthValues[i] = CLAMP(d, 0.0F, 1.0F);
+   }
+}
+
 
 /*
  * This function converts an array of GLchan colors to GLfloat colors.
@@ -2009,7 +2023,7 @@ _mesa_init_pixel( GLcontext *ctx )
    ctx->Pixel.MapBtoBsize = 1;
    ctx->Pixel.MapAtoAsize = 1;
    ctx->Pixel.MapStoS[0] = 0;
-   ctx->Pixel.MapItoI[0] = 0;
+   ctx->Pixel.MapItoI[0] = 0.0;
    ctx->Pixel.MapItoR[0] = 0.0;
    ctx->Pixel.MapItoG[0] = 0.0;
    ctx->Pixel.MapItoB[0] = 0.0;
@@ -2024,9 +2038,6 @@ _mesa_init_pixel( GLcontext *ctx )
    ctx->Pixel.MapAtoA[0] = 0.0;
    ctx->Pixel.HistogramEnabled = GL_FALSE;
    ctx->Pixel.MinMaxEnabled = GL_FALSE;
-   ctx->Pixel.PixelTextureEnabled = GL_FALSE;
-   ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
-   ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
    ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
    ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
    ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
@@ -2108,11 +2119,9 @@ _mesa_init_pixel( GLcontext *ctx )
 
    if (ctx->Visual.doubleBufferMode) {
       ctx->Pixel.ReadBuffer = GL_BACK;
-      ctx->Pixel._ReadSrcMask = DD_BACK_LEFT_BIT;
    }
    else {
       ctx->Pixel.ReadBuffer = GL_FRONT;
-      ctx->Pixel._ReadSrcMask = DD_FRONT_LEFT_BIT;
    }
 
    /* Miscellaneous */