Some initial RGB and RGBA floating point texture formats.
[mesa.git] / src / mesa / main / texstate.c
index 2c1d155f52ece56e98515e316b81353a0ce42f81..e27c42e07b65e1effcf63bc692d82cf4e7ccddc2 100644 (file)
@@ -151,7 +151,7 @@ _mesa_print_texunit_state( GLcontext *ctx, GLuint unit )
 /**********************************************************************/
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -525,8 +525,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
         if (texUnit->LodBias == param[0])
            return;
         FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-         texUnit->LodBias = CLAMP(param[0], -ctx->Const.MaxTextureLodBias,
-                                  ctx->Const.MaxTextureLodBias);
+         texUnit->LodBias = param[0];
       }
       else {
          TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
@@ -581,7 +580,7 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
 {
    _mesa_TexEnvfv( target, pname, &param );
@@ -589,7 +588,7 @@ _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
 
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
 {
    GLfloat p[4];
@@ -599,7 +598,7 @@ _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
 {
    GLfloat p[4];
@@ -617,7 +616,7 @@ _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -828,7 +827,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1049,15 +1048,44 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
 /*                       Texture Parameters                           */
 /**********************************************************************/
 
+static GLboolean 
+_mesa_validate_texture_wrap_mode(GLcontext * ctx,
+                                GLenum target, GLenum eparam)
+{
+   const struct gl_extensions * const e = & ctx->Extensions;
+
+   if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
+       (eparam == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
+      /* any texture target */
+      return GL_TRUE;
+   }
+   else if (target != GL_TEXTURE_RECTANGLE_NV &&
+           (eparam == GL_REPEAT ||
+            (eparam == GL_MIRRORED_REPEAT &&
+             e->ARB_texture_mirrored_repeat) ||
+            (eparam == GL_MIRROR_CLAMP_EXT &&
+             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+            (eparam == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
+             (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
+            (eparam == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
+             (e->EXT_texture_mirror_clamp)))) {
+      /* non-rectangle texture */
+      return GL_TRUE;
+   }
 
-void
+   _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
+   return GL_FALSE;
+}
+
+
+void GLAPIENTRY
 _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
 {
    _mesa_TexParameterfv(target, pname, &param);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1142,81 +1170,34 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
       case GL_TEXTURE_WRAP_S:
          if (texObj->WrapS == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapS = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapS = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
             return;
          }
          break;
       case GL_TEXTURE_WRAP_T:
          if (texObj->WrapT == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapT = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapT = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
             return;
          }
          break;
       case GL_TEXTURE_WRAP_R:
          if (texObj->WrapR == eparam)
             return;
-         if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
-             (eparam == GL_CLAMP_TO_BORDER &&
-              ctx->Extensions.ARB_texture_border_clamp)) {
-            /* any texture target */
-            FLUSH_VERTICES(ctx, _NEW_TEXTURE);
-            texObj->WrapR = eparam;
-         }
-         else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
-                  (eparam == GL_REPEAT ||
-                   (eparam == GL_MIRRORED_REPEAT &&
-                    ctx->Extensions.ARB_texture_mirrored_repeat) ||
-                   (eparam == GL_MIRROR_CLAMP_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once) ||
-                   (eparam == GL_MIRROR_CLAMP_TO_EDGE_ATI &&
-                    ctx->Extensions.ATI_texture_mirror_once))) {
-            /* non-rectangle texture */
+         if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
             FLUSH_VERTICES(ctx, _NEW_TEXTURE);
             texObj->WrapR = eparam;
          }
          else {
-            _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
+           return;
          }
          break;
       case GL_TEXTURE_BORDER_COLOR:
@@ -1402,9 +1383,10 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
       case GL_TEXTURE_LOD_BIAS:
          /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
          if (ctx->Extensions.EXT_texture_lod_bias) {
-            texObj->LodBias = CLAMP(params[0],
-                                    -ctx->Const.MaxTextureLodBias,
-                                    ctx->Const.MaxTextureLodBias);
+            if (texObj->LodBias != params[0]) {
+               FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+               texObj->LodBias = params[0];
+            }
          }
          break;
 
@@ -1422,7 +1404,7 @@ _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexParameteri( GLenum target, GLenum pname, GLint param )
 {
    GLfloat fparam[4];
@@ -1435,7 +1417,7 @@ _mesa_TexParameteri( GLenum target, GLenum pname, GLint param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
 {
    GLfloat fparam[4];
@@ -1456,7 +1438,7 @@ _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
                               GLenum pname, GLfloat *params )
 {
@@ -1498,7 +1480,7 @@ tex_image_dimensions(GLcontext *ctx, GLenum target)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
                               GLenum pname, GLint *params )
 {
@@ -1674,7 +1656,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1798,7 +1780,7 @@ _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1935,7 +1917,7 @@ _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
 /**********************************************************************/
 
 #if FEATURE_texgen
-void
+void GLAPIENTRY
 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2174,7 +2156,7 @@ _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
 {
    GLfloat p[4];
@@ -2191,7 +2173,7 @@ _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
 {
    GLfloat p = (GLfloat) param;
@@ -2199,7 +2181,7 @@ _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
 {
    GLfloat p[4];
@@ -2216,14 +2198,14 @@ _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
 {
    _mesa_TexGenfv(coord, pname, &param);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
 {
    _mesa_TexGeniv( coord, pname, &param );
@@ -2231,7 +2213,7 @@ _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2308,7 +2290,7 @@ _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2385,7 +2367,7 @@ _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2486,7 +2468,7 @@ _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
 #endif
 
 /* GL_ARB_multitexture */
-void
+void GLAPIENTRY
 _mesa_ActiveTextureARB( GLenum target )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2521,7 +2503,7 @@ _mesa_ActiveTextureARB( GLenum target )
 
 
 /* GL_ARB_multitexture */
-void
+void GLAPIENTRY
 _mesa_ClientActiveTextureARB( GLenum target )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2543,7 +2525,7 @@ _mesa_ClientActiveTextureARB( GLenum target )
 /*                     Pixel Texgen Extensions                        */
 /**********************************************************************/
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenSGIX(GLenum mode)
 {
    GLenum newRgbSource, newAlphaSource;
@@ -2582,21 +2564,21 @@ _mesa_PixelTexGenSGIX(GLenum mode)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameterfSGIS(GLenum target, GLfloat value)
 {
    _mesa_PixelTexGenParameteriSGIS(target, (GLint) value);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameterfvSGIS(GLenum target, const GLfloat *value)
 {
    _mesa_PixelTexGenParameteriSGIS(target, (GLint) *value);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2627,14 +2609,14 @@ _mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTexGenParameterivSGIS(GLenum target, const GLint *value)
 {
   _mesa_PixelTexGenParameteriSGIS(target, *value);
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2652,7 +2634,7 @@ _mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -2721,6 +2703,10 @@ update_texture_state( GLcontext *ctx )
 {
    GLuint unit;
 
+   ctx->NewState |= _NEW_TEXTURE; /* TODO: only set this if there are 
+                                  * actual changes. 
+                                  */
+
    ctx->Texture._EnabledUnits = 0;
    ctx->Texture._GenFlags = 0;
    ctx->Texture._TexMatEnabled = 0;
@@ -2734,6 +2720,7 @@ update_texture_state( GLcontext *ctx )
       struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
       GLuint enableBits;
 
+      texUnit->_Current = NULL;
       texUnit->_ReallyEnabled = 0;
       texUnit->_GenFlags = 0;
 
@@ -2751,7 +2738,7 @@ update_texture_state( GLcontext *ctx )
        * complete.  That's the one we'll use for texturing.  If we're using
        * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
        */
-      if (texUnit->Enabled & TEXTURE_CUBE_BIT) {
+      if (enableBits & TEXTURE_CUBE_BIT) {
          struct gl_texture_object *texObj = texUnit->CurrentCubeMap;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
@@ -2762,7 +2749,7 @@ update_texture_state( GLcontext *ctx )
          }
       }
 
-      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_3D_BIT)) {
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_3D_BIT)) {
          struct gl_texture_object *texObj = texUnit->Current3D;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
@@ -2773,7 +2760,7 @@ update_texture_state( GLcontext *ctx )
          }
       }
 
-      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_RECT_BIT)) {
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_RECT_BIT)) {
          struct gl_texture_object *texObj = texUnit->CurrentRect;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
@@ -2784,7 +2771,7 @@ update_texture_state( GLcontext *ctx )
          }
       }
 
-      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_2D_BIT)) {
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_2D_BIT)) {
          struct gl_texture_object *texObj = texUnit->Current2D;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
@@ -2795,7 +2782,7 @@ update_texture_state( GLcontext *ctx )
          }
       }
 
-      if (!texUnit->_ReallyEnabled && (texUnit->Enabled & TEXTURE_1D_BIT)) {
+      if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_1D_BIT)) {
          struct gl_texture_object *texObj = texUnit->Current1D;
          if (!texObj->Complete) {
             _mesa_test_texobj_completeness(ctx, texObj);
@@ -2807,8 +2794,7 @@ update_texture_state( GLcontext *ctx )
       }
 
       if (!texUnit->_ReallyEnabled) {
-        texUnit->_Current = NULL;
-        continue;
+         continue;
       }
 
       if (texUnit->_ReallyEnabled)
@@ -2852,7 +2838,7 @@ void _mesa_update_texture( GLcontext *ctx, GLuint new_state )
    if (new_state & _NEW_TEXTURE_MATRIX)
       update_texture_matrices( ctx );
 
-   if (new_state & _NEW_TEXTURE)
+   if (new_state & (_NEW_TEXTURE | _NEW_PROGRAM))
       update_texture_state( ctx );
 }