Fix pow <small> and a very stypid bug with dummy srcs(0 equals to tmp0.x)</small...
[mesa.git] / src / mesa / main / texstate.c
index cf17a6b1e725775aaa73a10e97f23d1b2c710fd3..608dbc1088a8d7b549f7568db3e3a9418ddb047b 100644 (file)
 #include "colortab.h"
 #include "context.h"
 #include "enums.h"
-#include "extensions.h"
 #include "macros.h"
-#include "nvfragprog.h"
 #include "texobj.h"
 #include "teximage.h"
 #include "texstate.h"
 #include "texenvprogram.h"
 #include "mtypes.h"
 #include "math/m_xform.h"
-#include "math/m_matrix.h"
 
 
 
-#ifdef SPECIALCAST
-/* Needed for an Amiga compiler */
 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
-#else
-/* all other compilers */
-#define ENUM_TO_FLOAT(X) ((GLfloat)(X))
-#define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
-#endif
+
 
 /**
  * Default texture combine environment state.  This is used to initialize
@@ -1656,32 +1647,10 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
       return;
    }
 
-   switch (target) {
-   case GL_TEXTURE_1D:
-   case GL_PROXY_TEXTURE_1D:
-   case GL_TEXTURE_2D:
-   case GL_PROXY_TEXTURE_2D:
-      maxLevels = ctx->Const.MaxTextureLevels;
-      break;
-   case GL_TEXTURE_3D:
-   case GL_PROXY_TEXTURE_3D:
-      maxLevels = ctx->Const.Max3DTextureLevels;
-      break;
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
-   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
-   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
-   case GL_PROXY_TEXTURE_CUBE_MAP:
-      maxLevels = ctx->Const.MaxCubeTextureLevels;
-      break;
-   case GL_TEXTURE_RECTANGLE_NV:
-   case GL_PROXY_TEXTURE_RECTANGLE_NV:
-      maxLevels = 1;
-      break;
-   default:
-      _mesa_problem(ctx, "switch in _mesa_GetTexLevelParameter");
+   maxLevels = _mesa_max_texture_levels(ctx, target);
+   if (maxLevels == 0) {
+      /* should not happen since <target> was just checked above */
+      _mesa_problem(ctx, "maxLevels=0 in _mesa_GetTexLevelParameter");
       return;
    }
 
@@ -1700,11 +1669,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
       return;
    }
 
-   isProxy = (target == GL_PROXY_TEXTURE_1D) ||
-             (target == GL_PROXY_TEXTURE_2D) ||
-             (target == GL_PROXY_TEXTURE_3D) ||
-             (target == GL_PROXY_TEXTURE_CUBE_MAP) ||
-             (target == GL_PROXY_TEXTURE_RECTANGLE_NV);
+   isProxy = _mesa_is_proxy_texture(target);
 
    switch (pname) {
       case GL_TEXTURE_WIDTH:
@@ -1717,38 +1682,39 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
          *params = img->Depth;
          return;
       case GL_TEXTURE_INTERNAL_FORMAT:
-         *params = img->IntFormat;
+         *params = img->InternalFormat;
          return;
       case GL_TEXTURE_BORDER:
          *params = img->Border;
          return;
       case GL_TEXTURE_RED_SIZE:
-         if (img->Format == GL_RGB || img->Format == GL_RGBA)
+         if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
             *params = img->TexFormat->RedBits;
          else
             *params = 0;
          return;
       case GL_TEXTURE_GREEN_SIZE:
-         if (img->Format == GL_RGB || img->Format == GL_RGBA)
+         if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
             *params = img->TexFormat->GreenBits;
          else
             *params = 0;
          return;
       case GL_TEXTURE_BLUE_SIZE:
-         if (img->Format == GL_RGB || img->Format == GL_RGBA)
+         if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
             *params = img->TexFormat->BlueBits;
          else
             *params = 0;
          return;
       case GL_TEXTURE_ALPHA_SIZE:
-         if (img->Format == GL_ALPHA || img->Format == GL_LUMINANCE_ALPHA ||
-             img->Format == GL_RGBA)
+         if (img->_BaseFormat == GL_ALPHA ||
+             img->_BaseFormat == GL_LUMINANCE_ALPHA ||
+             img->_BaseFormat == GL_RGBA)
             *params = img->TexFormat->AlphaBits;
          else
             *params = 0;
          return;
       case GL_TEXTURE_INTENSITY_SIZE:
-         if (img->Format != GL_INTENSITY)
+         if (img->_BaseFormat != GL_INTENSITY)
             *params = 0;
          else if (img->TexFormat->IntensityBits > 0)
             *params = img->TexFormat->IntensityBits;
@@ -1756,8 +1722,8 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
             *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
          return;
       case GL_TEXTURE_LUMINANCE_SIZE:
-         if (img->Format != GL_LUMINANCE &&
-             img->Format != GL_LUMINANCE_ALPHA)
+         if (img->_BaseFormat != GL_LUMINANCE &&
+             img->_BaseFormat != GL_LUMINANCE_ALPHA)
             *params = 0;
          else if (img->TexFormat->LuminanceBits > 0)
             *params = img->TexFormat->LuminanceBits;
@@ -1765,12 +1731,12 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
             *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
          return;
       case GL_TEXTURE_INDEX_SIZE_EXT:
-         if (img->Format == GL_COLOR_INDEX)
+         if (img->_BaseFormat == GL_COLOR_INDEX)
             *params = img->TexFormat->IndexBits;
          else
             *params = 0;
          return;
-      case GL_DEPTH_BITS:
+      case GL_TEXTURE_DEPTH_SIZE_ARB:
          if (ctx->Extensions.SGIX_depth_texture ||
              ctx->Extensions.ARB_depth_texture)
             *params = img->TexFormat->DepthBits;
@@ -1778,6 +1744,15 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
             _mesa_error(ctx, GL_INVALID_ENUM,
                         "glGetTexLevelParameter[if]v(pname)");
          return;
+      case GL_TEXTURE_STENCIL_SIZE_EXT:
+         if (ctx->Extensions.EXT_packed_depth_stencil) {
+            *params = img->TexFormat->StencilBits;
+         }
+         else {
+            _mesa_error(ctx, GL_INVALID_ENUM,
+                        "glGetTexLevelParameter[if]v(pname)");
+         }
+         return;
 
       /* GL_ARB_texture_compression */
       case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
@@ -1867,6 +1842,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
                         "glGetTexLevelParameter[if]v(pname)");
          }
          return;
+
       default:
          _mesa_error(ctx, GL_INVALID_ENUM,
                      "glGetTexLevelParameter[if]v(pname)");
@@ -2155,7 +2131,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
       case GL_S:
          if (pname==GL_TEXTURE_GEN_MODE) {
            GLenum mode = (GLenum) (GLint) *params;
-           GLuint bits;
+           GLbitfield bits;
            switch (mode) {
            case GL_OBJECT_LINEAR:
               bits = TEXGEN_OBJ_LINEAR;
@@ -2186,14 +2162,10 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
            if (TEST_EQ_4V(texUnit->ObjectPlaneS, params))
                return;
            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-           texUnit->ObjectPlaneS[0] = params[0];
-           texUnit->ObjectPlaneS[1] = params[1];
-           texUnit->ObjectPlaneS[2] = params[2];
-           texUnit->ObjectPlaneS[3] = params[3];
+            COPY_4FV(texUnit->ObjectPlaneS, params);
         }
         else if (pname==GL_EYE_PLANE) {
            GLfloat tmp[4];
-
             /* Transform plane equation by the inverse modelview matrix */
             if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
                _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
@@ -2212,7 +2184,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
       case GL_T:
          if (pname==GL_TEXTURE_GEN_MODE) {
            GLenum mode = (GLenum) (GLint) *params;
-           GLuint bitt;
+           GLbitfield bitt;
            switch (mode) {
                case GL_OBJECT_LINEAR:
                   bitt = TEXGEN_OBJ_LINEAR;
@@ -2243,10 +2215,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
            if (TEST_EQ_4V(texUnit->ObjectPlaneT, params))
                return;
            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-           texUnit->ObjectPlaneT[0] = params[0];
-           texUnit->ObjectPlaneT[1] = params[1];
-           texUnit->ObjectPlaneT[2] = params[2];
-           texUnit->ObjectPlaneT[3] = params[3];
+            COPY_4FV(texUnit->ObjectPlaneT, params);
         }
         else if (pname==GL_EYE_PLANE) {
            GLfloat tmp[4];
@@ -2268,7 +2237,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
       case GL_R:
          if (pname==GL_TEXTURE_GEN_MODE) {
            GLenum mode = (GLenum) (GLint) *params;
-           GLuint bitr;
+           GLbitfield bitr;
            switch (mode) {
            case GL_OBJECT_LINEAR:
               bitr = TEXGEN_OBJ_LINEAR;
@@ -2296,10 +2265,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
            if (TEST_EQ_4V(texUnit->ObjectPlaneR, params))
                return;
            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-           texUnit->ObjectPlaneR[0] = params[0];
-           texUnit->ObjectPlaneR[1] = params[1];
-           texUnit->ObjectPlaneR[2] = params[2];
-           texUnit->ObjectPlaneR[3] = params[3];
+           COPY_4FV(texUnit->ObjectPlaneR, params);
         }
         else if (pname==GL_EYE_PLANE) {
            GLfloat tmp[4];
@@ -2321,7 +2287,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
       case GL_Q:
          if (pname==GL_TEXTURE_GEN_MODE) {
            GLenum mode = (GLenum) (GLint) *params;
-           GLuint bitq;
+           GLbitfield bitq;
            switch (mode) {
            case GL_OBJECT_LINEAR:
               bitq = TEXGEN_OBJ_LINEAR;
@@ -2343,10 +2309,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
            if (TEST_EQ_4V(texUnit->ObjectPlaneQ, params))
                return;
            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-           texUnit->ObjectPlaneQ[0] = params[0];
-           texUnit->ObjectPlaneQ[1] = params[1];
-           texUnit->ObjectPlaneQ[2] = params[2];
-           texUnit->ObjectPlaneQ[3] = params[3];
+            COPY_4FV(texUnit->ObjectPlaneQ, params);
         }
         else if (pname==GL_EYE_PLANE) {
            GLfloat tmp[4];
@@ -2740,138 +2703,6 @@ _mesa_ClientActiveTextureARB( GLenum target )
 
 
 
-/**********************************************************************/
-/*                     Pixel Texgen Extensions                        */
-/**********************************************************************/
-
-void GLAPIENTRY
-_mesa_PixelTexGenSGIX(GLenum mode)
-{
-   GLenum newRgbSource, newAlphaSource;
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   switch (mode) {
-      case GL_NONE:
-         newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
-         newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
-         break;
-      case GL_ALPHA:
-         newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
-         newAlphaSource = GL_CURRENT_RASTER_COLOR;
-         break;
-      case GL_RGB:
-         newRgbSource = GL_CURRENT_RASTER_COLOR;
-         newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
-         break;
-      case GL_RGBA:
-         newRgbSource = GL_CURRENT_RASTER_COLOR;
-         newAlphaSource = GL_CURRENT_RASTER_COLOR;
-         break;
-      default:
-         _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenSGIX(mode)");
-         return;
-   }
-
-   if (newRgbSource == ctx->Pixel.FragmentRgbSource &&
-       newAlphaSource == ctx->Pixel.FragmentAlphaSource)
-      return;
-
-   FLUSH_VERTICES(ctx, _NEW_PIXEL);
-   ctx->Pixel.FragmentRgbSource = newRgbSource;
-   ctx->Pixel.FragmentAlphaSource = newAlphaSource;
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameterfSGIS(GLenum target, GLfloat value)
-{
-   _mesa_PixelTexGenParameteriSGIS(target, (GLint) value);
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameterfvSGIS(GLenum target, const GLfloat *value)
-{
-   _mesa_PixelTexGenParameteriSGIS(target, (GLint) *value);
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (value != GL_CURRENT_RASTER_COLOR && value != GL_PIXEL_GROUP_COLOR_SGIS) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(value)");
-      return;
-   }
-
-   switch (target) {
-   case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS:
-      if (ctx->Pixel.FragmentRgbSource == (GLenum) value)
-        return;
-      FLUSH_VERTICES(ctx, _NEW_PIXEL);
-      ctx->Pixel.FragmentRgbSource = (GLenum) value;
-      break;
-   case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS:
-      if (ctx->Pixel.FragmentAlphaSource == (GLenum) value)
-        return;
-      FLUSH_VERTICES(ctx, _NEW_PIXEL);
-      ctx->Pixel.FragmentAlphaSource = (GLenum) value;
-      break;
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(target)");
-      return;
-   }
-}
-
-
-void GLAPIENTRY
-_mesa_PixelTexGenParameterivSGIS(GLenum target, const GLint *value)
-{
-  _mesa_PixelTexGenParameteriSGIS(target, *value);
-}
-
-
-void GLAPIENTRY
-_mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
-      *value = (GLfloat) ctx->Pixel.FragmentRgbSource;
-   }
-   else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
-      *value = (GLfloat) ctx->Pixel.FragmentAlphaSource;
-   }
-   else {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterfvSGIS(target)");
-   }
-}
-
-
-void GLAPIENTRY
-_mesa_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
-{
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
-      *value = (GLint) ctx->Pixel.FragmentRgbSource;
-   }
-   else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
-      *value = (GLint) ctx->Pixel.FragmentAlphaSource;
-   }
-   else {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterivSGIS(target)");
-   }
-}
-
-
-
 /**********************************************************************/
 /*****                    State management                        *****/
 /**********************************************************************/
@@ -2907,8 +2738,6 @@ update_texture_matrices( GLcontext *ctx )
 }
 
 
-
-
 /**
  * \note This routine refers to derived texture matrix values to
  * compute the ENABLE_TEXMAT flags, but is only called on
@@ -2937,7 +2766,7 @@ update_texture_state( GLcontext *ctx )
     */
    for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
       struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-      GLuint enableBits;
+      GLbitfield enableBits;
 
       texUnit->_Current = NULL;
       texUnit->_ReallyEnabled = 0;
@@ -3023,11 +2852,12 @@ update_texture_state( GLcontext *ctx )
         texUnit->_CurrentCombine = & texUnit->Combine;
       }
       else {
-         GLenum format = texUnit->_Current->Image[0][0]->Format;
+         GLenum format = texUnit->_Current->Image[0][0]->_BaseFormat;
          if (format == GL_COLOR_INDEX) {
             format = GL_RGBA;  /* a bit of a hack */
          }
-         else if (format == GL_DEPTH_COMPONENT) {
+         else if (format == GL_DEPTH_COMPONENT
+                  || format == GL_DEPTH_STENCIL_EXT) {
             format = texUnit->_Current->DepthMode;
          }
         calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format);
@@ -3110,7 +2940,7 @@ update_texture_state( GLcontext *ctx )
     */
    if (ctx->FragmentProgram._Enabled) {
       ctx->Texture._EnabledCoordUnits |=
-         (ctx->FragmentProgram.Current->InputsRead >> FRAG_ATTRIB_TEX0);
+         (ctx->FragmentProgram.Current->Base.InputsRead >> FRAG_ATTRIB_TEX0);
    }
 }
 
@@ -3124,6 +2954,7 @@ void _mesa_update_texture( GLcontext *ctx, GLuint new_state )
       update_texture_state( ctx );
 }
 
+
 /**********************************************************************/
 /*****                      Initialization                        *****/
 /**********************************************************************/
@@ -3224,9 +3055,13 @@ init_texture_unit( GLcontext *ctx, GLuint unit )
 }
 
 
-GLboolean _mesa_init_texture( GLcontext * ctx )
+/**
+ * Initialize texture state for the given context.
+ */
+GLboolean
+_mesa_init_texture(GLcontext *ctx)
 {
-   int i;
+   GLuint i;
 
    assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
    assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
@@ -3253,9 +3088,14 @@ GLboolean _mesa_init_texture( GLcontext * ctx )
    return GL_TRUE;
 }
 
-void _mesa_free_texture_data( GLcontext *ctx )
+
+/**
+ * Free dynamically-allocted texture data attached to the given context.
+ */
+void
+_mesa_free_texture_data(GLcontext *ctx)
 {
-   int i;
+   GLuint i;
 
    /* Free proxy texture objects */
    (ctx->Driver.DeleteTexture)(ctx,  ctx->Texture.Proxy1D );