drivers: don't include texformat.h
[mesa.git] / src / mesa / drivers / dri / r128 / r128_tex.c
index 51c55141d805e7c6f41a4340d89209b52f3c8cbc..0a1207fb89f041987c004f0ffe65ce22d281fb68 100644 (file)
@@ -1,4 +1,3 @@
-/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_tex.c,v 1.14 2002/11/05 17:46:08 tsi Exp $ */
 /**************************************************************************
 
 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
@@ -36,20 +35,20 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "r128_context.h"
 #include "r128_state.h"
 #include "r128_ioctl.h"
-#include "r128_vb.h"
 #include "r128_tris.h"
 #include "r128_tex.h"
 #include "r128_texobj.h"
 
-#include "context.h"
-#include "macros.h"
-#include "simple_list.h"
-#include "enums.h"
-#include "texstore.h"
-#include "texformat.h"
-#include "teximage.h"
-#include "imports.h"
-#include "colormac.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/simple_list.h"
+#include "main/enums.h"
+#include "main/texstore.h"
+#include "main/teximage.h"
+#include "main/texobj.h"
+#include "main/imports.h"
+#include "main/colormac.h"
+#include "main/texobj.h"
 
 #include "xmlpool.h"
 
@@ -57,6 +56,14 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define TEX_1  2
 
 
+/**
+ * Set the texture wrap modes.  Currently \c GL_REPEAT, \c GL_CLAMP,
+ * \c GL_CLAMP_TO_EDGE, and \c GL_MIRRORED_REPEAT are supported.
+ * 
+ * \param t Texture object whose wrap modes are to be set
+ * \param swrap Wrap mode for the \a s texture coordinate
+ * \param twrap Wrap mode for the \a t texture coordinate
+ */
 static void r128SetTexWrap( r128TexObjPtr t, GLenum swrap, GLenum twrap )
 {
    t->setup.tex_cntl &= ~(R128_TEX_CLAMP_S_MASK | R128_TEX_CLAMP_T_MASK);
@@ -71,9 +78,6 @@ static void r128SetTexWrap( r128TexObjPtr t, GLenum swrap, GLenum twrap )
    case GL_REPEAT:
       t->setup.tex_cntl |= R128_TEX_CLAMP_S_WRAP;
       break;
-   case GL_CLAMP_TO_BORDER:
-      t->setup.tex_cntl |= R128_TEX_CLAMP_S_BORDER_COLOR;
-      break;
    case GL_MIRRORED_REPEAT:
       t->setup.tex_cntl |= R128_TEX_CLAMP_S_MIRROR;
       break;
@@ -89,9 +93,6 @@ static void r128SetTexWrap( r128TexObjPtr t, GLenum swrap, GLenum twrap )
    case GL_REPEAT:
       t->setup.tex_cntl |= R128_TEX_CLAMP_T_WRAP;
       break;
-   case GL_CLAMP_TO_BORDER:
-      t->setup.tex_cntl |= R128_TEX_CLAMP_T_BORDER_COLOR;
-      break;
    case GL_MIRRORED_REPEAT:
       t->setup.tex_cntl |= R128_TEX_CLAMP_T_MIRROR;
       break;
@@ -133,8 +134,13 @@ static void r128SetTexFilter( r128TexObjPtr t, GLenum minf, GLenum magf )
    }
 }
 
-static void r128SetTexBorderColor( r128TexObjPtr t, GLubyte c[4] )
+static void r128SetTexBorderColor( r128TexObjPtr t, const GLfloat color[4] )
 {
+   GLubyte c[4];
+   CLAMPED_FLOAT_TO_UBYTE(c[0], color[0]);
+   CLAMPED_FLOAT_TO_UBYTE(c[1], color[1]);
+   CLAMPED_FLOAT_TO_UBYTE(c[2], color[2]);
+   CLAMPED_FLOAT_TO_UBYTE(c[3], color[3]);
    t->setup.tex_border_color = r128PackColor( 4, c[0], c[1], c[2], c[3] );
 }
 
@@ -144,7 +150,7 @@ static r128TexObjPtr r128AllocTexObj( struct gl_texture_object *texObj )
    r128TexObjPtr t;
 
    if ( R128_DEBUG & DEBUG_VERBOSE_API ) {
-      fprintf( stderr, "%s( %p )\n", __FUNCTION__, texObj );
+      fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *) texObj );
    }
 
    t = (r128TexObjPtr) CALLOC_STRUCT( r128_tex_obj );
@@ -163,7 +169,7 @@ static r128TexObjPtr r128AllocTexObj( struct gl_texture_object *texObj )
 
       r128SetTexWrap( t, texObj->WrapS, texObj->WrapT );
       r128SetTexFilter( t, texObj->MinFilter, texObj->MagFilter );
-      r128SetTexBorderColor( t, texObj->_BorderChan );
+      r128SetTexBorderColor( t, texObj->BorderColor );
    }
 
    return t;
@@ -171,7 +177,7 @@ static r128TexObjPtr r128AllocTexObj( struct gl_texture_object *texObj )
 
 
 /* Called by the _mesa_store_teximage[123]d() functions. */
-static const struct gl_texture_format *
+static gl_format
 r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
                          GLenum format, GLenum type )
 {
@@ -196,9 +202,9 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_RGBA:
    case GL_COMPRESSED_RGBA:
       if (do32bpt)
-         return &_mesa_texformat_argb8888;
+         return _dri_texformat_argb8888;
       else
-         return &_mesa_texformat_argb4444;
+         return _dri_texformat_argb4444;
 
    /* 16-bit formats with alpha */
    case GL_INTENSITY4:
@@ -206,7 +212,7 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_LUMINANCE4_ALPHA4:
    case GL_RGBA2:
    case GL_RGBA4:
-      return &_mesa_texformat_argb4444;
+      return _dri_texformat_argb4444;
 
    /* 32-bit formats with alpha */
    case GL_INTENSITY8:
@@ -226,9 +232,9 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_RGBA12:
    case GL_RGBA16:
       if (!force16bpt)
-         return &_mesa_texformat_argb8888;
+         return _dri_texformat_argb8888;
       else
-         return &_mesa_texformat_argb4444;
+         return _dri_texformat_argb4444;
 
    /* non-sized formats without alpha */
    case 1:
@@ -238,16 +244,16 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_RGB:
    case GL_COMPRESSED_RGB:
       if (do32bpt)
-         return &_mesa_texformat_argb8888;
+         return _dri_texformat_argb8888;
       else
-         return &_mesa_texformat_rgb565;
+         return _dri_texformat_rgb565;
 
    /* 16-bit formats without alpha */
    case GL_LUMINANCE4:
    case GL_R3_G3_B2:
    case GL_RGB4:
    case GL_RGB5:
-      return &_mesa_texformat_rgb565;
+      return _dri_texformat_rgb565;
 
    /* 32-bit formats without alpha */
    case GL_LUMINANCE8:
@@ -258,9 +264,9 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_RGB12:
    case GL_RGB16:
       if (!force16bpt)
-         return &_mesa_texformat_argb8888;
+         return _dri_texformat_argb8888;
       else
-         return &_mesa_texformat_rgb565;
+         return _dri_texformat_rgb565;
 
    /* color-indexed formats */
    case GL_COLOR_INDEX:
@@ -270,18 +276,18 @@ r128ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_COLOR_INDEX8_EXT:
    case GL_COLOR_INDEX12_EXT:
    case GL_COLOR_INDEX16_EXT:
-      return &_mesa_texformat_ci8;
+      return _dri_texformat_ci8;
 
    case GL_YCBCR_MESA:
       if (type == GL_UNSIGNED_SHORT_8_8_APPLE ||
           type == GL_UNSIGNED_BYTE)
-         return &_mesa_texformat_ycbcr;
+         return MESA_FORMAT_YCBCR;
       else
-         return &_mesa_texformat_ycbcr_rev;
+         return MESA_FORMAT_YCBCR_REV;
 
    default:
       _mesa_problem( ctx, "unexpected format in %s", __FUNCTION__ );
-      return NULL;
+      return MESA_FORMAT_NONE;
    }
 }
 
@@ -411,7 +417,7 @@ static void r128TexSubImage2D( GLcontext *ctx,
 }
 
 
-static void r128DDTexEnv( GLcontext *ctx, GLenum target,
+static void r128TexEnv( GLcontext *ctx, GLenum target,
                          GLenum pname, const GLfloat *param )
 {
    r128ContextPtr rmesa = R128_CONTEXT(ctx);
@@ -457,11 +463,11 @@ static void r128DDTexEnv( GLcontext *ctx, GLenum target,
       }
       break;
 
-   case GL_TEXTURE_LOD_BIAS_EXT:
-      do {
-        CARD32 t = rmesa->setup.tex_cntl_c;
+   case GL_TEXTURE_LOD_BIAS:
+      {
+        uint32_t t = rmesa->setup.tex_cntl_c;
         GLint bias;
-        CARD32 b;
+        uint32_t b;
 
         /* GTH: This isn't exactly correct, but gives good results up to a
          * certain point.  It is better than completely ignoring the LOD
@@ -481,7 +487,7 @@ static void r128DDTexEnv( GLcontext *ctx, GLenum target,
            bias = 127;
         }
 
-        b = (CARD32)bias & 0xff;
+        b = (uint32_t)bias & 0xff;
         t &= ~R128_LOD_BIAS_MASK;
         t |= (b << R128_LOD_BIAS_SHIFT);
 
@@ -490,7 +496,7 @@ static void r128DDTexEnv( GLcontext *ctx, GLenum target,
            rmesa->setup.tex_cntl_c = t;
            rmesa->dirty |= R128_UPLOAD_CONTEXT;
         }
-      } while (0);
+      }
       break;
 
    default:
@@ -499,9 +505,9 @@ static void r128DDTexEnv( GLcontext *ctx, GLenum target,
 }
 
 
-static void r128DDTexParameter( GLcontext *ctx, GLenum target,
-                               struct gl_texture_object *tObj,
-                               GLenum pname, const GLfloat *params )
+static void r128TexParameter( GLcontext *ctx, GLenum target,
+                              struct gl_texture_object *tObj,
+                              GLenum pname, const GLfloat *params )
 {
    r128ContextPtr rmesa = R128_CONTEXT(ctx);
    r128TexObjPtr t = (r128TexObjPtr)tObj->DriverData;
@@ -529,7 +535,7 @@ static void r128DDTexParameter( GLcontext *ctx, GLenum target,
 
    case GL_TEXTURE_BORDER_COLOR:
       if ( t->base.bound ) FLUSH_BATCH( rmesa );
-      r128SetTexBorderColor( t, tObj->_BorderChan );
+      r128SetTexBorderColor( t, tObj->BorderColor );
       break;
 
    case GL_TEXTURE_BASE_LEVEL:
@@ -550,22 +556,20 @@ static void r128DDTexParameter( GLcontext *ctx, GLenum target,
    }
 }
 
-static void r128DDBindTexture( GLcontext *ctx, GLenum target,
+static void r128BindTexture( GLcontext *ctx, GLenum target,
                               struct gl_texture_object *tObj )
 {
    if ( R128_DEBUG & DEBUG_VERBOSE_API ) {
-      fprintf( stderr, "%s( %p ) unit=%d\n", __FUNCTION__, tObj,
+      fprintf( stderr, "%s( %p ) unit=%d\n", __FUNCTION__, (void *) tObj,
               ctx->Texture.CurrentUnit );
    }
 
-   if ( target == GL_TEXTURE_2D || target == GL_TEXTURE_1D ) {
-      if ( tObj->DriverData == NULL ) {
-        r128AllocTexObj( tObj );
-      }
-   }
+   assert( (target != GL_TEXTURE_2D && target != GL_TEXTURE_1D) ||
+           (tObj->DriverData != NULL) );
 }
 
-static void r128DDDeleteTexture( GLcontext *ctx,
+
+static void r128DeleteTexture( GLcontext *ctx,
                                 struct gl_texture_object *tObj )
 {
    r128ContextPtr rmesa = R128_CONTEXT(ctx);
@@ -578,36 +582,39 @@ static void r128DDDeleteTexture( GLcontext *ctx,
 
       driDestroyTextureObject( t );
    }
+   /* Free mipmap images and the texture object itself */
+   _mesa_delete_texture_object(ctx, tObj);
 }
 
-void r128DDInitTextureFuncs( GLcontext *ctx )
+/**
+ * Allocate a new texture object.
+ * Called via ctx->Driver.NewTextureObject.
+ * Note: we could use containment here to 'derive' the driver-specific
+ * texture object from the core mesa gl_texture_object.  Not done at this time.
+ */
+static struct gl_texture_object *
+r128NewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
 {
-   r128ContextPtr rmesa = R128_CONTEXT(ctx);
-
+   struct gl_texture_object *obj;
+   obj = _mesa_new_texture_object(ctx, name, target);
+   r128AllocTexObj( obj );
+   return obj;
+}
 
-   ctx->Driver.TexEnv                  = r128DDTexEnv;
-   ctx->Driver.ChooseTextureFormat     = r128ChooseTextureFormat;
-   ctx->Driver.TexImage1D              = r128TexImage1D;
-   ctx->Driver.TexSubImage1D           = r128TexSubImage1D;
-   ctx->Driver.TexImage2D              = r128TexImage2D;
-   ctx->Driver.TexSubImage2D           = r128TexSubImage2D;
-   ctx->Driver.TexImage3D               = _mesa_store_teximage3d;
-   ctx->Driver.TexSubImage3D            = _mesa_store_texsubimage3d;
-   ctx->Driver.CopyTexImage1D           = _swrast_copy_teximage1d;
-   ctx->Driver.CopyTexImage2D           = _swrast_copy_teximage2d;
-   ctx->Driver.CopyTexSubImage1D        = _swrast_copy_texsubimage1d;
-   ctx->Driver.CopyTexSubImage2D        = _swrast_copy_texsubimage2d;
-   ctx->Driver.CopyTexSubImage3D        = _swrast_copy_texsubimage3d;
-   ctx->Driver.TestProxyTexImage        = _mesa_test_proxy_teximage;
-   ctx->Driver.TexParameter            = r128DDTexParameter;
-   ctx->Driver.BindTexture             = r128DDBindTexture;
-   ctx->Driver.DeleteTexture           = r128DDDeleteTexture;
-   ctx->Driver.UpdateTexturePalette    = NULL;
-   ctx->Driver.ActiveTexture           = NULL;
-   ctx->Driver.IsTextureResident       = driIsTextureResident;
-   ctx->Driver.PrioritizeTexture       = NULL;
-
-   driInitTextureObjects( ctx, & rmesa->swapped,
-                         DRI_TEXMGR_DO_TEXTURE_1D
-                         | DRI_TEXMGR_DO_TEXTURE_2D );
+void r128InitTextureFuncs( struct dd_function_table *functions )
+{
+   functions->TexEnv                   = r128TexEnv;
+   functions->ChooseTextureFormat      = r128ChooseTextureFormat;
+   functions->TexImage1D               = r128TexImage1D;
+   functions->TexSubImage1D            = r128TexSubImage1D;
+   functions->TexImage2D               = r128TexImage2D;
+   functions->TexSubImage2D            = r128TexSubImage2D;
+   functions->TexParameter             = r128TexParameter;
+   functions->BindTexture              = r128BindTexture;
+   functions->NewTextureObject         = r128NewTextureObject;
+   functions->DeleteTexture            = r128DeleteTexture;
+   functions->IsTextureResident                = driIsTextureResident;
+
+   driInitTextureFormats();
 }
+