GC a bit of dead code I noticed while looking at texwrap.
[mesa.git] / src / mesa / drivers / dri / r300 / r300_tex.c
index c3010d3cebc2f0037c0a2909a19be31a3d873813..0d51d6da374432a5e76c6620fd6c9edffaaa0683 100644 (file)
@@ -64,7 +64,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                           GLenum rwrap)
 {
-       GLboolean is_clamp = GL_FALSE;
        unsigned long hw_swrap=0, hw_twrap=0, hw_qwrap=0;
 
        t->filter &=
@@ -76,7 +75,6 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                break;
        case GL_CLAMP:
                hw_swrap |= R300_TX_CLAMP;
-               is_clamp = GL_TRUE;
                break;
        case GL_CLAMP_TO_EDGE:
                hw_swrap |= R300_TX_CLAMP_TO_EDGE;
@@ -89,7 +87,6 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                break;
        case GL_MIRROR_CLAMP_EXT:
                hw_swrap |= R300_TX_CLAMP | R300_TX_MIRRORED;
-               is_clamp = GL_TRUE;
                break;
        case GL_MIRROR_CLAMP_TO_EDGE_EXT:
                hw_swrap |= R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
@@ -107,7 +104,6 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                break;
        case GL_CLAMP:
                hw_twrap |= R300_TX_CLAMP;
-               is_clamp = GL_TRUE;
                break;
        case GL_CLAMP_TO_EDGE:
                hw_twrap |= R300_TX_CLAMP_TO_EDGE;
@@ -120,7 +116,6 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                break;
        case GL_MIRROR_CLAMP_EXT:
                hw_twrap |= R300_TX_CLAMP | R300_TX_MIRRORED;
-               is_clamp = GL_TRUE;
                break;
        case GL_MIRROR_CLAMP_TO_EDGE_EXT:
                hw_twrap |= R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
@@ -138,7 +133,6 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                break;
        case GL_CLAMP:
                hw_qwrap |= R300_TX_CLAMP;
-               is_clamp = GL_TRUE;
                break;
        case GL_CLAMP_TO_EDGE:
                hw_qwrap |= R300_TX_CLAMP_TO_EDGE;
@@ -151,7 +145,6 @@ static void r300SetTexWrap(r300TexObjPtr t, GLenum swrap, GLenum twrap,
                break;
        case GL_MIRROR_CLAMP_EXT:
                hw_qwrap |= R300_TX_CLAMP | R300_TX_MIRRORED;
-               is_clamp = GL_TRUE;
                break;
        case GL_MIRROR_CLAMP_TO_EDGE_EXT:
                hw_qwrap |= R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
@@ -220,10 +213,10 @@ static void r300SetTexFilter(r300TexObjPtr t, GLenum minf, GLenum magf)
                        t->filter |= R300_TX_MIN_FILTER_NEAREST_MIP_NEAREST;
                        break;
                case GL_NEAREST_MIPMAP_LINEAR:
-                       t->filter |= R300_TX_MIN_FILTER_LINEAR_MIP_NEAREST;
+                       t->filter |= R300_TX_MIN_FILTER_NEAREST_MIP_LINEAR;
                        break;
                case GL_LINEAR_MIPMAP_NEAREST:
-                       t->filter |= R300_TX_MIN_FILTER_NEAREST_MIP_LINEAR;
+                       t->filter |= R300_TX_MIN_FILTER_LINEAR_MIP_NEAREST;
                        break;
                case GL_LINEAR_MIPMAP_LINEAR:
                        t->filter |= R300_TX_MIN_FILTER_LINEAR_MIP_LINEAR;
@@ -433,6 +426,22 @@ static const struct gl_texture_format *r300ChooseTextureFormat(GLcontext * ctx,
                else
                        return &_mesa_texformat_ycbcr_rev;
 
+       case GL_RGB_S3TC:
+       case GL_RGB4_S3TC:
+       case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+         return &_mesa_texformat_rgb_dxt1;
+         
+       case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+         return &_mesa_texformat_rgba_dxt1;
+         
+       case GL_RGBA_S3TC:
+       case GL_RGBA4_S3TC:
+       case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+         return &_mesa_texformat_rgba_dxt3;
+         
+       case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+         return &_mesa_texformat_rgba_dxt5;
+         
        default:
                _mesa_problem(ctx,
                              "unexpected internalFormat 0x%x in r300ChooseTextureFormat",
@@ -706,6 +715,115 @@ static void r300TexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
        t->dirty_images[face] |= (1 << level);
 }
 
+static void r300CompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
+                              GLint internalFormat,
+                              GLint width, GLint height, GLint border,
+                              GLsizei imageSize, const GLvoid *data,
+                              struct gl_texture_object *texObj,
+                              struct gl_texture_image *texImage )
+{
+   driTextureObject * t = (driTextureObject *) texObj->DriverData;
+   GLuint face;
+
+   /* which cube face or ordinary 2D image */
+   switch (target) {
+   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:
+      face = (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
+      ASSERT(face < 6);
+      break;
+   default:
+      face = 0;
+   }
+
+   if ( t != NULL ) {
+      driSwapOutTextureObject( t );
+   }
+   else {
+      t = (driTextureObject *) r300AllocTexObj( texObj );
+      if (!t) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
+         return;
+      }
+   }
+
+   texImage->IsClientData = GL_FALSE;
+/* can't call this, different parameters. Would never evaluate to true anyway currently
+   if (r300ValidateClientStorage( ctx, target, 
+                                 internalFormat,
+                                 width, height,
+                                 format, type, pixels,
+                                 packing, texObj, texImage)) {
+      if (RADEON_DEBUG & DEBUG_TEXTURE)
+        fprintf(stderr, "%s: Using client storage\n", __FUNCTION__);
+   }
+   else */{
+      if (RADEON_DEBUG & DEBUG_TEXTURE)
+        fprintf(stderr, "%s: Using normal storage\n", __FUNCTION__);
+
+      /* Normal path: copy (to cached memory) and eventually upload
+       * via another copy to GART memory and then a blit...  Could
+       * eliminate one copy by going straight to (permanent) GART.
+       *
+       * Note, this will call r300ChooseTextureFormat.
+       */
+      _mesa_store_compressed_teximage2d(ctx, target, level, internalFormat, width,
+                                 height, border, imageSize, data, texObj, texImage);
+
+      t->dirty_images[face] |= (1 << level);
+   }
+}
+
+
+static void r300CompressedTexSubImage2D( GLcontext *ctx, GLenum target, GLint level,
+                                 GLint xoffset, GLint yoffset,
+                                 GLsizei width, GLsizei height,
+                                 GLenum format,
+                                 GLsizei imageSize, const GLvoid *data,
+                                 struct gl_texture_object *texObj,
+                                 struct gl_texture_image *texImage )
+{
+   driTextureObject * t = (driTextureObject *) texObj->DriverData;
+   GLuint face;
+
+
+   /* which cube face or ordinary 2D image */
+   switch (target) {
+   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:
+      face = (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
+      ASSERT(face < 6);
+      break;
+   default:
+      face = 0;
+   }
+
+   assert( t ); /* this _should_ be true */
+   if ( t ) {
+      driSwapOutTextureObject( t );
+   }
+   else {
+      t = (driTextureObject *) r300AllocTexObj( texObj );
+      if (!t) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage3D");
+         return;
+      }
+   }
+
+   _mesa_store_compressed_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
+                            height, format, imageSize, data, texObj, texImage);
+
+   t->dirty_images[face] |= (1 << level);
+}
+
 #if ENABLE_HW_3D_TEXTURE
 static void r300TexImage3D(GLcontext * ctx, GLenum target, GLint level,
                           GLint internalFormat,
@@ -803,7 +921,6 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        GLuint unit = ctx->Texture.CurrentUnit;
-       struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
 
        if (RADEON_DEBUG & DEBUG_STATE) {
                fprintf(stderr, "%s( %s )\n",
@@ -816,7 +933,7 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
         */
        switch (pname) {
        case GL_TEXTURE_ENV_COLOR:{
-               fprintf(stderr, "%s:%s I am broken - Fixme !\n", __FILE__, __FUNCTION__);
+               WARN_ONCE("I am broken - Fixme !\n");
                /*
                        GLubyte c[4];
                        GLuint envColor;
@@ -826,9 +943,9 @@ static void r300TexEnv(GLcontext * ctx, GLenum target,
                                R200_STATECHANGE(rmesa, tf);
                                rmesa->hw.tf.cmd[TF_TFACTOR_0 + unit] =
                                    envColor;
-                       }
+                       }*/
                        break;
-               */}
+               }
 
        case GL_TEXTURE_LOD_BIAS_EXT:{
                        GLfloat bias, min;
@@ -959,27 +1076,6 @@ static void r300DeleteTexture(GLcontext * ctx, struct gl_texture_object *texObj)
        _mesa_delete_texture_object(ctx, texObj);
 }
 
-/* Need:
- *  - Same GEN_MODE for all active bits
- *  - Same EyePlane/ObjPlane for all active bits when using Eye/Obj
- *  - STRQ presumably all supported (matrix means incoming R values
- *    can end up in STQ, this has implications for vertex support,
- *    presumably ok if maos is used, though?)
- *
- * Basically impossible to do this on the fly - just collect some
- * basic info & do the checks from ValidateState().
- */
-static void r300TexGen(GLcontext * ctx,
-                      GLenum coord, GLenum pname, const GLfloat * params)
-{
-       r300ContextPtr rmesa = R300_CONTEXT(ctx);
-       GLuint unit = ctx->Texture.CurrentUnit;
-#if 0 /* Disable this for now - looks like we will be recalculating everything
-                anyway */
-       rmesa->recheck_texgen[unit] = GL_TRUE;
-#endif
-}
-
 /**
  * Allocate a new texture object.
  * Called via ctx->Driver.NewTextureObject.
@@ -1031,7 +1127,9 @@ void r300InitTextureFuncs(struct dd_function_table *functions)
 
        functions->TexEnv = r300TexEnv;
        functions->TexParameter = r300TexParameter;
-       functions->TexGen = r300TexGen;
+       
+       functions->CompressedTexImage2D = r300CompressedTexImage2D;
+       functions->CompressedTexSubImage2D      = r300CompressedTexSubImage2D;
 
        driInitTextureFormats();