All elements of pre-DRI_NEW_INTERFACE_ONLY are removed. This allows
[mesa.git] / src / mesa / drivers / dri / mga / mgatex.c
index 166bdfc22f380fcb703f5f72907309fd2481f086..8caa1f8580f2f801e7924537b5a97835df9b2f3a 100644 (file)
 #include "texformat.h"
 #include "texstore.h"
 #include "teximage.h"
+#include "texobj.h"
 
 #include "swrast/swrast.h"
 
+#include "xmlpool.h"
+
 /**
  * Set the texture wrap modes.
  * Currently \c GL_REPEAT, \c GL_CLAMP and \c GL_CLAMP_TO_EDGE are supported.
@@ -134,9 +137,9 @@ mgaSetTexFilter( mgaTextureObjectPtr t, GLenum minf, GLenum magf )
    /* See OpenGL 1.2 specification */
    if (magf == GL_LINEAR && (minf == GL_NEAREST_MIPMAP_NEAREST ||
                             minf == GL_NEAREST_MIPMAP_LINEAR)) {
-      val |= (0x20 << TF_fthres_SHIFT); /* c = 0.5 */
+      val |= MGA_FIELD( TF_fthres, 0x20 ); /* c = 0.5 */
    } else {
-      val |= (0x10 << TF_fthres_SHIFT); /* c = 0 */
+      val |= MGA_FIELD( TF_fthres, 0x10 ); /* c = 0 */
    }
 
 
@@ -163,38 +166,53 @@ mgaChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
                        GLenum format, GLenum type )
 {
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);
-   const GLboolean do32bpt = mmesa->default32BitTextures;
+   const GLboolean do32bpt =
+       ( mmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_32 );
+   const GLboolean force16bpt =
+       ( mmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FORCE_16 );
+   (void) format;
 
    switch ( internalFormat ) {
    case 4:
    case GL_RGBA:
    case GL_COMPRESSED_RGBA:
-      if ( format == GL_BGRA ) {
-        if ( type == GL_UNSIGNED_INT_8_8_8_8_REV ) {
-           return &_mesa_texformat_argb8888;
-        }
-         else if ( type == GL_UNSIGNED_SHORT_4_4_4_4_REV ) {
-            return &_mesa_texformat_argb4444;
-        }
-         else if ( type == GL_UNSIGNED_SHORT_1_5_5_5_REV ) {
-           return &_mesa_texformat_argb1555;
-        }
+      switch ( type ) {
+      case GL_UNSIGNED_INT_10_10_10_2:
+      case GL_UNSIGNED_INT_2_10_10_10_REV:
+        return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555;
+      case GL_UNSIGNED_SHORT_4_4_4_4:
+      case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+        return &_mesa_texformat_argb4444;
+      case GL_UNSIGNED_SHORT_5_5_5_1:
+      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+        return &_mesa_texformat_argb1555;
+      default:
+         return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
       }
-      return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
 
    case 3:
    case GL_RGB:
    case GL_COMPRESSED_RGB:
-      if ( format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 ) {
+      switch ( type ) {
+      case GL_UNSIGNED_SHORT_4_4_4_4:
+      case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+        return &_mesa_texformat_argb4444;
+      case GL_UNSIGNED_SHORT_5_5_5_1:
+      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+        return &_mesa_texformat_argb1555;
+      case GL_UNSIGNED_SHORT_5_6_5:
+      case GL_UNSIGNED_SHORT_5_6_5_REV:
         return &_mesa_texformat_rgb565;
+      default:
+         return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
       }
-      return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
 
    case GL_RGBA8:
    case GL_RGB10_A2:
    case GL_RGBA12:
    case GL_RGBA16:
-      return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
+      return !force16bpt ?
+         &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
 
    case GL_RGBA4:
    case GL_RGBA2:
@@ -207,7 +225,7 @@ mgaChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
    case GL_RGB10:
    case GL_RGB12:
    case GL_RGB16:
-      return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
+      return !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
 
    case GL_RGB5:
    case GL_RGB4:
@@ -303,10 +321,7 @@ mgaAllocTexObj( struct gl_texture_object *tObj )
 
       t->setup.texctl = TMC_takey_1 | TMC_tamask_0;
       t->setup.texctl2 = TMC_ckstransdis_enable;
-      t->setup.texfilter = (TF_minfilter_nrst 
-                           | TF_magfilter_nrst
-                           | TF_filteralpha_enable
-                           | TF_uvoffset_OGL);
+      t->setup.texfilter = TF_filteralpha_enable | TF_uvoffset_OGL;
 
       t->border_fallback = GL_FALSE;
       t->texenv_fallback = GL_FALSE;
@@ -322,7 +337,7 @@ mgaAllocTexObj( struct gl_texture_object *tObj )
 }
 
 
-static void mgaDDTexEnv( GLcontext *ctx, GLenum target,
+static void mgaTexEnv( GLcontext *ctx, GLenum target,
                         GLenum pname, const GLfloat *param )
 {
    GLuint unit = ctx->Texture.CurrentUnit;
@@ -334,27 +349,7 @@ static void mgaDDTexEnv( GLcontext *ctx, GLenum target,
       GLubyte c[4];
 
       UNCLAMPED_FLOAT_TO_RGBA_CHAN( c, texUnit->EnvColor );
-      mmesa->envcolor = PACK_COLOR_8888( c[3], c[0], c[1], c[2] );
-
-      if (mmesa->setup.fcol != mmesa->envcolor) {
-        FLUSH_BATCH(mmesa);
-        mmesa->setup.fcol = mmesa->envcolor;
-        mmesa->dirty |= MGA_UPLOAD_CONTEXT;
-
-        mmesa->blend_flags = 0;
-
-         if ((mmesa->envcolor & 0xffffff) == 0x0) {
-            mmesa->blend_flags |= MGA_BLEND_RGB_ZERO;
-         } else if ((mmesa->envcolor & 0xffffff) == 0xffffff) {
-            mmesa->blend_flags |= MGA_BLEND_RGB_ONE;
-         }
-
-        if ((mmesa->envcolor >> 24) == 0x0) {
-            mmesa->blend_flags |= MGA_BLEND_ALPHA_ZERO;
-         } else if ((mmesa->envcolor >> 24) == 0xff) {
-            mmesa->blend_flags |= MGA_BLEND_ALPHA_ONE;
-         }
-      }
+      mmesa->envcolor[unit] = PACK_COLOR_8888( c[3], c[0], c[1], c[2] );
       break;
    }
    }
@@ -371,7 +366,6 @@ static void mgaTexImage2D( GLcontext *ctx, GLenum target, GLint level,
 {
    driTextureObject * t = (driTextureObject *) texObj->DriverData;
 
-
    if ( t != NULL ) {
       driSwapOutTextureObject( t );
    } 
@@ -404,8 +398,7 @@ static void mgaTexSubImage2D( GLcontext *ctx,
 {
    driTextureObject * t = (driTextureObject *) texObj->DriverData;
 
-
-   assert( t != NULL ); /* this _should_ be true */
+   assert( t ); /* this _should_ be true */
    if ( t != NULL ) {
       driSwapOutTextureObject( t );
    } 
@@ -432,20 +425,17 @@ static void mgaTexSubImage2D( GLcontext *ctx,
  */
 
 static void
-mgaDDTexParameter( GLcontext *ctx, GLenum target,
+mgaTexParameter( GLcontext *ctx, GLenum target,
                   struct gl_texture_object *tObj,
                   GLenum pname, const GLfloat *params )
 {
-   mgaContextPtr       mmesa = MGA_CONTEXT( ctx );
-   mgaTextureObjectPtr t;
-
-   t = (mgaTextureObjectPtr) tObj->DriverData;
+   mgaContextPtr mmesa = MGA_CONTEXT( ctx );
+   mgaTextureObjectPtr t = (mgaTextureObjectPtr) tObj->DriverData;
 
    /* If we don't have a hardware texture, it will be automatically
     * created with current state before it is used, so we don't have
     * to do anything now 
     */
-
    if ( (t == NULL) ||
         (target != GL_TEXTURE_2D &&
          target != GL_TEXTURE_RECTANGLE_NV) ) {
@@ -491,20 +481,16 @@ mgaDDTexParameter( GLcontext *ctx, GLenum target,
 
 
 static void
-mgaDDBindTexture( GLcontext *ctx, GLenum target,
+mgaBindTexture( GLcontext *ctx, GLenum target,
                  struct gl_texture_object *tObj )
 {
-   if ( target == GL_TEXTURE_2D ||
-        target == GL_TEXTURE_RECTANGLE_NV ) {
-      if ( tObj->DriverData == NULL ) {
-        mgaAllocTexObj( tObj );
-      }
-   }
+   assert( (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE_NV) ||
+           (tObj->DriverData != NULL) );
 }
 
 
 static void
-mgaDDDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj )
+mgaDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj )
 {
    mgaContextPtr mmesa = MGA_CONTEXT( ctx );
    driTextureObject * t = (driTextureObject *) tObj->DriverData;
@@ -519,38 +505,34 @@ mgaDDDeleteTexture( GLcontext *ctx, struct gl_texture_object *tObj )
 }
 
 
-void
-mgaDDInitTextureFuncs( 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 *
+mgaNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
 {
-   mgaContextPtr mmesa = MGA_CONTEXT(ctx);
+   struct gl_texture_object *obj;
+   obj = _mesa_new_texture_object(ctx, name, target);
+   mgaAllocTexObj( obj );
+   return obj;
+}
 
 
-   ctx->Driver.ChooseTextureFormat     = mgaChooseTextureFormat;
-   ctx->Driver.TexImage1D              = _mesa_store_teximage1d;
-   ctx->Driver.TexImage2D              = mgaTexImage2D;
-   ctx->Driver.TexImage3D              = _mesa_store_teximage3d;
-   ctx->Driver.TexSubImage1D           = _mesa_store_texsubimage1d;
-   ctx->Driver.TexSubImage2D           = mgaTexSubImage2D;
-   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.BindTexture             = mgaDDBindTexture;
-   ctx->Driver.CreateTexture           = NULL; /* FIXME: Is this used??? */
-   ctx->Driver.DeleteTexture           = mgaDDDeleteTexture;
-   ctx->Driver.IsTextureResident       = driIsTextureResident;
-   ctx->Driver.PrioritizeTexture       = NULL;
-   ctx->Driver.ActiveTexture           = NULL;
-   ctx->Driver.UpdateTexturePalette    = NULL;
-
-   ctx->Driver.TexEnv                  = mgaDDTexEnv;
-   ctx->Driver.TexParameter            = mgaDDTexParameter;
-
-   driInitTextureObjects( ctx, & mmesa->swapped,
-                          (DRI_TEXMGR_DO_TEXTURE_2D |
-                           DRI_TEXMGR_DO_TEXTURE_RECT) );
+void
+mgaInitTextureFuncs( struct dd_function_table *functions )
+{
+   functions->ChooseTextureFormat      = mgaChooseTextureFormat;
+   functions->TexImage2D               = mgaTexImage2D;
+   functions->TexSubImage2D            = mgaTexSubImage2D;
+   functions->BindTexture              = mgaBindTexture;
+   functions->NewTextureObject         = mgaNewTextureObject;
+   functions->DeleteTexture            = mgaDeleteTexture;
+   functions->IsTextureResident                = driIsTextureResident;
+   functions->TexEnv                   = mgaTexEnv;
+   functions->TexParameter             = mgaTexParameter;
 }