Remove CVS keywords.
[mesa.git] / src / mesa / drivers / dri / i810 / i810tex.c
index f2ebd35c9acb59e3fd837ac1509a38cd015b4c09..ba4e6b5b0b12c46e6b7e5919a0e6a15dcdd9da92 100644 (file)
  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  */
-/* $XFree86: xc/lib/GL/mesa/src/drv/i810/i810tex.c,v 1.9 2002/10/30 12:51:33 alanh Exp $ */
-
-#include "glheader.h"
-#include "mtypes.h"
-#include "imports.h"
-#include "simple_list.h"
-#include "enums.h"
-#include "texstore.h"
-#include "texformat.h"
-#include "teximage.h"
-#include "texmem.h"
+
+#include "main/glheader.h"
+#include "main/mtypes.h"
+#include "main/imports.h"
+#include "main/simple_list.h"
+#include "main/enums.h"
+#include "main/texstore.h"
+#include "main/texformat.h"
+#include "main/teximage.h"
+#include "main/texobj.h"
+#include "main/colormac.h"
+#include "main/texobj.h"
+#include "main/mm.h"
 #include "swrast/swrast.h"
-#include "colormac.h"
 
-#include "mm.h"
+#include "texmem.h"
 
 #include "i810screen.h"
 #include "i810_dri.h"
@@ -160,13 +161,16 @@ static void i810SetTexFilter(i810ContextPtr imesa,
 }
 
 
-static void i810SetTexBorderColor(i810TextureObjectPtr t, 
-                                 GLubyte color[4])
+static void
+i810SetTexBorderColor( i810TextureObjectPtr t, GLubyte color[4] )
 {
    /* Need a fallback.
     */
 }
-static i810TextureObjectPtr i810AllocTexObj( GLcontext *ctx, struct gl_texture_object *texObj )
+
+
+static i810TextureObjectPtr
+i810AllocTexObj( GLcontext *ctx, struct gl_texture_object *texObj )
 {
    i810TextureObjectPtr t;
    i810ContextPtr imesa = I810_CONTEXT(ctx);
@@ -220,6 +224,7 @@ static void i810TexParameter( GLcontext *ctx, GLenum target,
 {
    i810ContextPtr imesa = I810_CONTEXT(ctx);
    i810TextureObjectPtr t = (i810TextureObjectPtr) tObj->DriverData;
+
    if (!t)
       return;
 
@@ -277,48 +282,52 @@ static void i810TexParameter( GLcontext *ctx, GLenum target,
 }
 
 
+/**
+ * Setup hardware bits for new texture environment settings.
+ * 
+ * \todo
+ * Determine whether or not \c param can be used instead of
+ * \c texUnit->EnvColor in the \c GL_TEXTURE_ENV_COLOR case.
+ */
 static void i810TexEnv( GLcontext *ctx, GLenum target, 
                        GLenum pname, const GLfloat *param )
 {
    i810ContextPtr imesa = I810_CONTEXT( ctx );
-   GLuint unit = ctx->Texture.CurrentUnit;
+   const GLuint unit = ctx->Texture.CurrentUnit;
+   const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
 
    /* Only one env color.  Need a fallback if env colors are different
     * and texture setup references env color in both units.  
     */
    switch (pname) {
    case GL_TEXTURE_ENV_COLOR: {
-      struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
-      GLfloat *fc = texUnit->EnvColor;
-      GLuint r, g, b, a, col;
-      CLAMPED_FLOAT_TO_UBYTE(r, fc[0]);
-      CLAMPED_FLOAT_TO_UBYTE(g, fc[1]);
-      CLAMPED_FLOAT_TO_UBYTE(b, fc[2]);
-      CLAMPED_FLOAT_TO_UBYTE(a, fc[3]);
-
-      col = ((a << 24) | 
-            (r << 16) | 
-            (g <<  8) | 
-            (b <<  0));
-      if (imesa->Setup[I810_CTXREG_CF1] != col) {
-        I810_STATECHANGE(imesa, I810_UPLOAD_CTX);      
-        imesa->Setup[I810_CTXREG_CF1] = col;      
+      GLubyte c[4];
+      GLuint envColor;
+
+      UNCLAMPED_FLOAT_TO_RGBA_CHAN( c, texUnit->EnvColor );
+      envColor = PACK_COLOR_8888( c[3], c[0], c[1], c[2] );
+
+      if (imesa->Setup[I810_CTXREG_CF1] != envColor) {
+        I810_STATECHANGE(imesa, I810_UPLOAD_CTX);
+        imesa->Setup[I810_CTXREG_CF1] = envColor;
       }
       break;
    }
+
    case GL_TEXTURE_ENV_MODE:
       imesa->TexEnvImageFmt[unit] = 0; /* force recalc of env state */
       break;
 
-   case GL_TEXTURE_LOD_BIAS_EXT:
-      {
-         struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current;
-         i810TextureObjectPtr t = (i810TextureObjectPtr) tObj->DriverData;
-         t->Setup[I810_TEXREG_MLC] &= ~(MLC_LOD_BIAS_MASK);
-         t->Setup[I810_TEXREG_MLC] |= i810ComputeLodBias(*param);
+   case GL_TEXTURE_LOD_BIAS: {
+      if ( texUnit->_Current != NULL ) {
+        const struct gl_texture_object *tObj = texUnit->_Current;
+        i810TextureObjectPtr t = (i810TextureObjectPtr) tObj->DriverData;
+
+        t->Setup[I810_TEXREG_MLC] &= ~(MLC_LOD_BIAS_MASK);
+        t->Setup[I810_TEXREG_MLC] |= i810ComputeLodBias(*param);
       }
       break;
+   }
 
    default:
       break;
@@ -381,7 +390,6 @@ static void i810TexImage2D( GLcontext *ctx, GLenum target, GLint level,
    _mesa_store_teximage2d( ctx, target, level, internalFormat,
                           width, height, border, format, type,
                           pixels, packing, texObj, texImage );
-
 }
 
 static void i810TexSubImage2D( GLcontext *ctx, 
@@ -396,7 +404,6 @@ static void i810TexSubImage2D( GLcontext *ctx,
                               struct gl_texture_image *texImage )
 {
    driTextureObject *t = (driTextureObject *)texObj->DriverData;
-
    if (t) {
      I810_FIREVERTICES( I810_CONTEXT(ctx) );
      driSwapOutTextureObject( t );
@@ -404,30 +411,35 @@ static void i810TexSubImage2D( GLcontext *ctx,
    _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width, 
                             height, format, type, pixels, packing, texObj,
                             texImage);
-
 }
 
 
 static void i810BindTexture( GLcontext *ctx, GLenum target,
                             struct gl_texture_object *tObj )
 {
-  if (!tObj->DriverData) {
-      i810AllocTexObj( ctx, tObj );
-  }
+   assert( (target != GL_TEXTURE_2D) || (tObj->DriverData != NULL) );
 }
 
 
 static void i810DeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj )
 {
-  driTextureObject * t = (driTextureObject *) tObj->DriverData;
+   driTextureObject * t = (driTextureObject *) tObj->DriverData;
    if (t) {
       i810ContextPtr imesa = I810_CONTEXT( ctx );
       if (imesa)
          I810_FIREVERTICES( imesa );
       driDestroyTextureObject( t );
    }
+   /* Free mipmap images and the texture object itself */
+   _mesa_delete_texture_object(ctx, tObj);
 }
 
+/**
+ * Choose a Mesa texture format to match the requested format.
+ * 
+ * The i810 only supports 5 texture modes that are useful to Mesa.  That
+ * makes this routine pretty simple.
+ */
 static const struct gl_texture_format *
 i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
                         GLenum format, GLenum type )
@@ -435,11 +447,18 @@ i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    switch ( internalFormat ) {
    case 4:
    case GL_RGBA:
+   case GL_RGBA2:
+   case GL_RGBA4:
+   case GL_RGB5_A1:
+   case GL_RGBA8:
+   case GL_RGB10_A2:
+   case GL_RGBA12:
+   case GL_RGBA16:
    case GL_COMPRESSED_RGBA:
-      if ( format == GL_BGRA ) {
-         if ( type == GL_UNSIGNED_SHORT_1_5_5_5_REV ) {
-           return &_mesa_texformat_argb1555;
-        }
+      if ( ((format == GL_BGRA) && (type == GL_UNSIGNED_SHORT_1_5_5_5_REV))
+          || ((format == GL_RGBA) && (type == GL_UNSIGNED_SHORT_5_5_5_1))
+          || (internalFormat == GL_RGB5_A1) ) {
+        return &_mesa_texformat_argb1555;
       }
       return &_mesa_texformat_argb4444;
 
@@ -453,18 +472,7 @@ i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_RGB10:
    case GL_RGB12:
    case GL_RGB16:
-     return &_mesa_texformat_rgb565;
-
-   case GL_RGBA2:
-   case GL_RGBA4:
-   case GL_RGBA8:
-   case GL_RGB10_A2:
-   case GL_RGBA12:
-   case GL_RGBA16:
-      return &_mesa_texformat_argb4444;
-
-   case GL_RGB5_A1:
-      return &_mesa_texformat_argb1555;
+      return &_mesa_texformat_rgb565;
 
    case GL_ALPHA:
    case GL_ALPHA4:
@@ -472,8 +480,6 @@ i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_ALPHA12:
    case GL_ALPHA16:
    case GL_COMPRESSED_ALPHA:
-      return &_mesa_texformat_al88;
-
    case 1:
    case GL_LUMINANCE:
    case GL_LUMINANCE4:
@@ -481,8 +487,6 @@ i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_LUMINANCE12:
    case GL_LUMINANCE16:
    case GL_COMPRESSED_LUMINANCE:
-      return &_mesa_texformat_rgb565;
-
    case 2:
    case GL_LUMINANCE_ALPHA:
    case GL_LUMINANCE4_ALPHA4:
@@ -498,7 +502,7 @@ i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_INTENSITY12:
    case GL_INTENSITY16:
    case GL_COMPRESSED_INTENSITY:
-      return &_mesa_texformat_argb4444;
+      return &_mesa_texformat_al88;
 
    case GL_YCBCR_MESA:
       if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
@@ -515,30 +519,32 @@ i810ChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    return NULL; /* never get here */
 }
 
-void i810InitTextureFuncs( GLcontext *ctx )
+/**
+ * Allocate a new texture object.
+ * Called via ctx->Driver.NewTextureObject.
+ * Note: this function will be called during context creation to
+ * allocate the default texture objects.
+ * 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 *
+i810NewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
 {
-   i810ContextPtr imesa = I810_CONTEXT(ctx);
-
-   ctx->Driver.TexEnv = i810TexEnv;
-   ctx->Driver.ChooseTextureFormat = i810ChooseTextureFormat;
-   ctx->Driver.TexImage1D = _mesa_store_teximage1d;
-   ctx->Driver.TexImage2D = i810TexImage2D;
-   ctx->Driver.TexImage3D = _mesa_store_teximage3d;
-   ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
-   ctx->Driver.TexSubImage2D = i810TexSubImage2D;
-   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.BindTexture = i810BindTexture;
-   ctx->Driver.DeleteTexture = i810DeleteTexture;
-   ctx->Driver.TexParameter = i810TexParameter;
-   ctx->Driver.UpdateTexturePalette = 0;
-   ctx->Driver.IsTextureResident = driIsTextureResident;
-   ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
-
-   driInitTextureObjects( ctx, &imesa->swapped, DRI_TEXMGR_DO_TEXTURE_2D);
+   struct gl_texture_object *obj;
+   obj = _mesa_new_texture_object(ctx, name, target);
+   i810AllocTexObj( ctx, obj );
+   return obj;
+}
 
+void i810InitTextureFuncs( struct dd_function_table *functions )
+{
+   functions->ChooseTextureFormat = i810ChooseTextureFormat;
+   functions->TexImage2D = i810TexImage2D;
+   functions->TexSubImage2D = i810TexSubImage2D;
+   functions->BindTexture = i810BindTexture;
+   functions->NewTextureObject = i810NewTextureObject;
+   functions->DeleteTexture = i810DeleteTexture;
+   functions->TexParameter = i810TexParameter;
+   functions->TexEnv = i810TexEnv;
+   functions->IsTextureResident = driIsTextureResident;
 }