Hi everybody,

this patch fixes some problems in texturing in the mga driver.

1) It fixes a texture corruption problem, as the mga driver did not use 
the right texture format in some case
      ( I've seen that when an application wants to store a texture in 
RGB5_A1, but it is actually stored in ARGB8 by Mesa).

2) I've enabled again the hardware acceleration for GL_DECAL texture 
function, for both single and multi-texturing. Blending in single 
texturing needs to be emulated through multi-texturing, and problems 
with multi-texturing were probably relied to the bug above (as in Tribes2).

That way, anybody who tries to play Tribes2 with a mga board will be 
impressed by the improvment made by this patch. Please, try it!
As this patch is my first one (wouhou!) , I want to ask you too what's 
the procedures to send a patch and get it approved before it can be 
included in the CVS repository. I did this patch too by using fresh 
XFree-4.1.0 sources, since I don't have access to the DRI cvs tree 
through our firewall.

Thank you!

Karl
--- xc/lib/GL/mesa/src/drv/mga/mgatex.c Wed Jun 13 11:47:17 2001
+++ dri_patches/texture_blending_0/src/mgatex.c Tue Jun 12 17:45:32 2001
@@ -24,7 +24,7 @@
  * Authors:
  *    Keith Whitwell <[EMAIL PROTECTED]>
  */
-/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgatex.c,v 1.10.2.1 2001/05/31 08:31:23 alanh 
Exp $ */
+/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgatex.c,v 1.10 2001/04/10 16:07:51 dawes Exp 
+$ */
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -178,7 +178,7 @@
       }                                                                        \
    } while (0)
 
-   switch ( texImage->IntFormat ) {
+   switch ( texImage->Format ) {
       /* GH: Bias towards GL_RGB, GL_RGBA texture formats.  This has
        * got to be better than sticking them way down the end of this
        * huge list.
@@ -426,7 +426,7 @@
       return;
 
    t = (mgaTextureObjectPtr)tObj->DriverData;
-
+   
    t->setup.texctl2 &= ~TMC_decalblend_enable;
 
    switch (ctx->Texture.Unit[0].EnvMode) {
@@ -454,8 +454,18 @@
    GLuint *reg = ((GLuint *)&mmesa->setup.tdualstage0 + unit);
    GLuint source = mmesa->tmu_source[unit];
    struct gl_texture_object *tObj = ctx->Texture.Unit[source].Current;
-   GLenum format;
-
+   GLenum format;   
+   
+   if ( mmesa->multitex == 2 && unit == 1) {
+     
+      /* bypassing unit 1 */
+      *reg = TD1_color_arg2_prevstage | 
+             TD1_color_sel_arg2       |
+             TD1_alpha_arg2_prevstage |
+             TD1_alpha_sel_arg2;
+      return;
+   }
+   
    if ( tObj != ctx->Texture.Unit[source].CurrentD[2] ||
        !tObj ||
        !tObj->Complete ||
@@ -485,18 +495,19 @@
    case GL_MODULATE:
       if (unit == 0) {
         *reg = ( TD0_color_arg2_diffuse |
-                 TD0_color_sel_mul |
+                 TD0_color_sel_mulout |
                  TD0_alpha_arg2_diffuse |
-                 TD0_alpha_sel_mul);
+                 TD0_alpha_sel_mulout);
       }
       else {
         *reg = ( TD0_color_arg2_prevstage |
                  TD0_color_alpha_prevstage |
-                 TD0_color_sel_mul |
+                 TD0_color_sel_mulout |
                  TD0_alpha_arg2_prevstage |
-                 TD0_alpha_sel_mul);
+                 TD0_alpha_sel_mulout);
       }
       break;
+      
    case GL_DECAL:
       if (format == GL_RGB) {
          if (unit == 0) {
@@ -511,40 +522,38 @@
          }
       }
       else if ( format == GL_RGBA ) {
-#if 0
+         
          if (unit == 0) {
-            /* this doesn't work */
-            *reg = (TD0_color_arg2_diffuse |
-                    TD0_color_alpha_currtex |
-                    TD0_color_alpha2inv_enable |
-                    TD0_color_arg2mul_alpha2 |
-                    TD0_color_arg1mul_alpha1 |
-                    TD0_color_blend_enable |
-                    TD0_color_arg1add_mulout |
-                    TD0_color_arg2add_mulout |
-                    TD0_color_add_add |
-                    TD0_color_sel_mul |
-                    TD0_alpha_arg2_diffuse |
-                    TD0_alpha_sel_arg2 );
+            *reg = ( TD0_color_arg2_diffuse                     |
+                     TD0_color_alpha_currtex                    |
+                     TD0_color_alpha1inv_enable                 |
+                     TD1_color_blend_enable                     |
+                     TD0_color_arg1mul_alpha1                   |
+                     TD0_color_arg2mul_arg2                     |
+                     TD0_color_add_add                          |
+                     TD0_color_arg1add_mulout                   |
+                     TD0_color_arg2add_mulout                   |
+                     TD1_color_sel_addout                       |
+
+                     TD0_alpha_arg2_prevstage                   |
+                     TD0_alpha_sel_arg2                         );
          }
          else {
-            *reg = (TD0_color_arg2_prevstage |
-                    TD0_color_alpha_currtex |
-                    TD0_color_alpha2inv_enable |
-                    TD0_color_arg2mul_alpha2 |
-                    TD0_color_arg1mul_alpha1 |
-                    TD0_color_add_add |
-                    TD0_color_sel_add |
-                    TD0_alpha_arg2_prevstage |
-                    TD0_alpha_sel_arg2 );
+            *reg = ( TD1_color_arg2_prevstage                   |
+                     TD1_color_alpha_currtex                    |
+                     TD1_color_alpha1inv_enable                 |
+                     TD1_color_blend_enable                     |
+                     TD1_color_arg1mul_alpha1                   |
+                     TD1_color_arg2mul_arg2                     |
+                     TD1_color_add_add                          |
+                     TD1_color_arg1add_mulout                   |
+                     TD1_color_arg2add_mulout                   |
+                     TD1_color_sel_addout                       |
+
+                     TD1_alpha_arg2_prevstage                   |
+                     TD1_alpha_sel_arg2                         );
+
          }
-#else
-         /* s/w fallback, pretty sure we can't do in h/w */
-        mmesa->Fallback |= MGA_FALLBACK_TEXTURE;
-        if ( MGA_DEBUG & DEBUG_VERBOSE_FALLBACK )
-           fprintf( stderr, "FALLBACK: GL_DECAL RGBA texture, unit=%d\n",
-                    unit );
-#endif
       }
       else {
         if (unit == 0) {
@@ -567,44 +576,44 @@
          if (format == GL_INTENSITY)
             *reg = ( TD0_color_arg2_diffuse |
                      TD0_color_add_add |
-                     TD0_color_sel_add |
+                     TD0_color_sel_addout |
                      TD0_alpha_arg2_diffuse |
                      TD0_alpha_add_enable |
-                     TD0_alpha_sel_add);
+                     TD0_alpha_sel_addout);
          else if (format == GL_ALPHA)
             *reg = ( TD0_color_arg2_diffuse |
-                     TD0_color_sel_mul |
+                     TD0_color_sel_mulout |
                      TD0_alpha_arg2_diffuse |
-                     TD0_alpha_sel_mul);
+                     TD0_alpha_sel_mulout);
          else
             *reg = ( TD0_color_arg2_diffuse |
                      TD0_color_add_add |
-                     TD0_color_sel_add |
+                     TD0_color_sel_addout |
                      TD0_alpha_arg2_diffuse |
-                     TD0_alpha_sel_mul);
+                     TD0_alpha_sel_mulout);
       }
       else {
          if (format == GL_INTENSITY) {
             *reg = ( TD0_color_arg2_prevstage |
                      TD0_color_add_add |
-                     TD0_color_sel_add |
+                     TD0_color_sel_addout |
                      TD0_alpha_arg2_prevstage |
                      TD0_alpha_add_enable |
-                     TD0_alpha_sel_add);
+                     TD0_alpha_sel_addout);
          }
          else if (format == GL_ALPHA) {
             *reg = ( TD0_color_arg2_prevstage |
-                     TD0_color_sel_mul |
+                     TD0_color_sel_mulout |
                      TD0_alpha_arg2_prevstage |
-                     TD0_alpha_sel_mul);
+                     TD0_alpha_sel_mulout);
          }
          else {
             *reg = ( TD0_color_arg2_prevstage |
                      TD0_color_alpha_prevstage |
                      TD0_color_add_add |
-                     TD0_color_sel_add |
+                     TD0_color_sel_addout |
                      TD0_alpha_arg2_prevstage |
-                     TD0_alpha_sel_mul);
+                     TD0_alpha_sel_mulout);
          }
       }
       break;
@@ -612,9 +621,9 @@
    case GL_BLEND:
       if (format == GL_ALPHA) {
         *reg = ( TD0_color_arg2_diffuse |
-                 TD0_color_sel_mul |
+                 TD0_color_sel_mulout |
                  TD0_alpha_arg2_diffuse |
-                 TD0_alpha_sel_mul);
+                 TD0_alpha_sel_mulout);
       }
       else {
         mmesa->Fallback |= MGA_FALLBACK_TEXTURE;
@@ -632,7 +641,7 @@
              */
             *reg = ( TD0_color_arg2_diffuse |
                      TD0_color_arg1_inv_enable |
-                     TD0_color_sel_mul |
+                     TD0_color_sel_mulout |
                      TD0_alpha_arg2_diffuse |
                      TD0_alpha_sel_arg1);
          } else {
@@ -641,7 +650,7 @@
              */
             *reg = ( TD0_color_arg2_prevstage |
                      TD0_color_add_add |
-                     TD0_color_sel_add |
+                     TD0_color_sel_addout |
                      TD0_alpha_arg2_prevstage |
                      TD0_alpha_sel_arg2);
          }
@@ -864,10 +873,8 @@
 
    t = (mgaTextureObjectPtr) tObj->DriverData;
 
-
    /* just free the mga texture if it exists, it will be recreated at
       mgaUpdateTextureState time. */
-   t = (mgaTextureObjectPtr) tObj->DriverData;
    if ( t ) {
       if (t->bound) FLUSH_BATCH(mmesa);
       /* if this is the current object, it will force an update */
--- xc/lib/GL/mesa/src/drv/mga/mgaregs.h        Wed Jun 13 11:47:18 2001
+++ dri_patches/texture_blending_0/src/mgaregs.h        Tue Jun 12 17:40:44 2001
@@ -834,16 +834,16 @@
     #define TD0_color_alpha2inv_disable 0x0            
     #define TD0_color_alpha2inv_enable         0x400           
     #define TD0_color_arg1mul_MASK     0xfffff7ff      /* bit 11 */
-    #define TD0_color_arg1mul_disable  0x0             /* val 0, shift 11 */
+    #define TD0_color_arg1mul_arg1     0x0             /* val 0, shift 11 */
     #define TD0_color_arg1mul_alpha1   0x800           /* val 1, shift 11 */
     #define TD0_color_arg2mul_MASK     0xffffefff      /* bit 12 */
-    #define TD0_color_arg2mul_disable  0x0             /* val 0, shift 12 */
+    #define TD0_color_arg2mul_arg2     0x0             /* val 0, shift 12 */
     #define TD0_color_arg2mul_alpha2   0x1000          /* val 1, shift 12 */
     #define TD0_color_arg1add_MASK     0xffffdfff      /* bit 13 */
-    #define TD0_color_arg1add_disable  0x0             /* val 0, shift 13 */
+    #define TD0_color_arg1add_arg1     0x0             /* val 0, shift 13 */
     #define TD0_color_arg1add_mulout   0x2000          /* val 1, shift 13 */
     #define TD0_color_arg2add_MASK     0xffffbfff      /* bit 14 */
-    #define TD0_color_arg2add_disable  0x0             /* val 0, shift 14 */
+    #define TD0_color_arg2add_arg2     0x0             /* val 0, shift 14 */
     #define TD0_color_arg2add_mulout   0x4000          /* val 1, shift 14 */
     #define TD0_color_modbright_MASK   0xfffe7fff      /* bits 15-16 */
     #define TD0_color_modbright_disable 0x0            /* val 0, shift 15 */
@@ -864,8 +864,8 @@
     #define TD0_color_sel_MASK                 0xff9fffff      /* bits 21-22 */
     #define TD0_color_sel_arg1                 0x0             /* val 0, shift 21 */
     #define TD0_color_sel_arg2                 0x200000        /* val 1, shift 21 */
-    #define TD0_color_sel_add          0x400000        /* val 2, shift 21 */
-    #define TD0_color_sel_mul          0x600000        /* val 3, shift 21 */
+    #define TD0_color_sel_addout       0x400000        /* val 2, shift 21 */
+    #define TD0_color_sel_mulout       0x600000        /* val 3, shift 21 */
     #define TD0_alpha_arg1_inv_MASK    0xff7fffff      /* bit 23 */
     #define TD0_alpha_arg1_inv_disable         0x0             
     #define TD0_alpha_arg1_inv_enable  0x800000        
@@ -893,11 +893,10 @@
     #define TD0_alpha_sel_MASK                 0x3fffffff      /* bits 30-31 */
     #define TD0_alpha_sel_arg1                 0x0             /* val 0, shift 30 */
     #define TD0_alpha_sel_arg2                 0x40000000      /* val 1, shift 30 */
-    #define TD0_alpha_sel_add          0x80000000      /* val 2, shift 30 */
-    #define TD0_alpha_sel_mul          0xc0000000      /* val 3, shift 30 */
+    #define TD0_alpha_sel_addout       0x80000000      /* val 2, shift 30 */
+    #define TD0_alpha_sel_mulout       0xc0000000      /* val 3, shift 30 */
 
 #define MGAREG_TDUALSTAGE1                     0x2cfc
-
     #define TD1_color_arg2_MASK        0xfffffffc      /* bits 0-1 */
     #define TD1_color_arg2_diffuse     0x0             /* val 0, shift 0 */
     #define TD1_color_arg2_specular    0x1             /* val 1, shift 0 */
@@ -906,7 +905,7 @@
     #define TD1_color_alpha_MASK       0xffffffe3      /* bits 2-4 */
     #define TD1_color_alpha_diffuse    0x0             /* val 0, shift 2 */
     #define TD1_color_alpha_fcol       0x4             /* val 1, shift 2 */
-    #define TD1_color_alpha_tex0       0x8             /* val 2, shift 2 */
+    #define TD1_color_alpha_currtex    0x8             /* val 2, shift 2 */
     #define TD1_color_alpha_prevtex    0xc             /* val 3, shift 2 */
     #define TD1_color_alpha_prevstage  0x10            /* val 4, shift 2 */
     #define TD1_color_arg1_replicatealpha_MASK 0xffffffdf      /* bit 5 */
@@ -928,16 +927,16 @@
     #define TD1_color_alpha2inv_disable 0x0            
     #define TD1_color_alpha2inv_enable         0x400           
     #define TD1_color_arg1mul_MASK     0xfffff7ff      /* bit 11 */
-    #define TD1_color_arg1mul_disable  0x0             /* val 0, shift 11 */
+    #define TD1_color_arg1mul_arg1     0x0             /* val 0, shift 11 */
     #define TD1_color_arg1mul_alpha1   0x800           /* val 1, shift 11 */
     #define TD1_color_arg2mul_MASK     0xffffefff      /* bit 12 */
-    #define TD1_color_arg2mul_disable  0x0             /* val 0, shift 12 */
+    #define TD1_color_arg2mul_arg2     0x0             /* val 0, shift 12 */
     #define TD1_color_arg2mul_alpha2   0x1000          /* val 1, shift 12 */
     #define TD1_color_arg1add_MASK     0xffffdfff      /* bit 13 */
-    #define TD1_color_arg1add_disable  0x0             /* val 0, shift 13 */
+    #define TD1_color_arg1add_arg1     0x0             /* val 0, shift 13 */
     #define TD1_color_arg1add_mulout   0x2000          /* val 1, shift 13 */
     #define TD1_color_arg2add_MASK     0xffffbfff      /* bit 14 */
-    #define TD1_color_arg2add_disable  0x0             /* val 0, shift 14 */
+    #define TD1_color_arg2add_arg2     0x0             /* val 0, shift 14 */
     #define TD1_color_arg2add_mulout   0x4000          /* val 1, shift 14 */
     #define TD1_color_modbright_MASK   0xfffe7fff      /* bits 15-16 */
     #define TD1_color_modbright_disable 0x0            /* val 0, shift 15 */
@@ -958,8 +957,8 @@
     #define TD1_color_sel_MASK                 0xff9fffff      /* bits 21-22 */
     #define TD1_color_sel_arg1                 0x0             /* val 0, shift 21 */
     #define TD1_color_sel_arg2                 0x200000        /* val 1, shift 21 */
-    #define TD1_color_sel_add          0x400000        /* val 2, shift 21 */
-    #define TD1_color_sel_mul          0x600000        /* val 3, shift 21 */
+    #define TD1_color_sel_addout       0x400000        /* val 2, shift 21 */
+    #define TD1_color_sel_mulout       0x600000        /* val 3, shift 21 */
     #define TD1_alpha_arg1_inv_MASK    0xff7fffff      /* bit 23 */
     #define TD1_alpha_arg1_inv_disable         0x0             
     #define TD1_alpha_arg1_inv_enable  0x800000        
@@ -987,8 +986,8 @@
     #define TD1_alpha_sel_MASK                 0x3fffffff      /* bits 30-31 */
     #define TD1_alpha_sel_arg1                 0x0             /* val 0, shift 30 */
     #define TD1_alpha_sel_arg2                 0x40000000      /* val 1, shift 30 */
-    #define TD1_alpha_sel_add          0x80000000      /* val 2, shift 30 */
-    #define TD1_alpha_sel_mul          0xc0000000      /* val 3, shift 30 */
+    #define TD1_alpha_sel_addout       0x80000000      /* val 2, shift 30 */
+    #define TD1_alpha_sel_mulout       0xc0000000      /* val 3, shift 30 */
 
 #define MGAREG_TEST0                           0x1e48
 
--- xc/lib/GL/mesa/src/drv/mga/mgacontext.h     Wed Jun 13 11:47:16 2001
+++ dri_patches/texture_blending_0/src/mgacontext.h     Tue Jun 12 17:23:53 2001
@@ -108,14 +108,14 @@
    struct gl_texture_object *tObj;
    struct mga_context_t *ctx;
    PMemBlock   MemBlock;
-   GLuint              offsets[MGA_TEX_MAXLEVELS];
-   int             lastLevel;
-   GLuint         dirty_images;
-   GLuint              totalSize;
+   GLuint      offsets[MGA_TEX_MAXLEVELS];
+   int          lastLevel;
+   GLuint       dirty_images;
+   GLuint      totalSize;
    int         texelBytes;
    GLuint      age;
-   int             bound;
-   int             heap;       /* agp or card */
+   int          bound;
+   int          heap;  /* agp or card */
 
    mga_texture_regs_t setup;
 } mgaTextureObject_t;
@@ -140,7 +140,7 @@
 
    /* Map GL texture units onto hardware.
     */
-   GLuint multitex;
+   GLuint multitex; /* 0 = single mode; 1 = multi mode; 2 = emulated single mode */
    GLuint tmu_source[2];
    GLuint tex_dest[2];
 
--- xc/lib/GL/mesa/src/drv/mga/mgavb.c  Wed Jun 13 11:47:17 2001
+++ dri_patches/texture_blending_0/src/mgavb.c  Wed Jun 13 11:46:38 2001
@@ -268,46 +268,76 @@
    mmesa->multitex = 0;
    mmesa->blend_flags &= ~MGA_BLEND_MULTITEX;
 
-   if (ctx->Texture.ReallyEnabled & 0xf) {
-      /* This doesn't work for non-RGBA textures
-      if (ctx->Texture.Unit[0].EnvMode == GL_REPLACE)
-        funcindex &= ~MGA_RGBA_BIT;
-      */
-      if (ctx->Texture.Unit[0].EnvMode == GL_BLEND &&
-         mmesa->envcolor)
-      {
-        mmesa->multitex = 1;
-        mmesa->vertsize = 10;
-        mmesa->tmu_source[1] = 0;
-        funcindex |= MGA_TEX1_BIT;
+   if (ctx->Texture.ReallyEnabled & 0xf) {     
+      if (ctx->Texture.ReallyEnabled & 0xf0) {
+         
+         /*** Texture unit 0 and Texture unit 1 are enabled ***/
+         
+         mmesa->multitex = 1;
+         mmesa->vertsize = 10;
+         mmesa->blend_flags |= MGA_BLEND_MULTITEX;
+         funcindex |= MGA_TEX1_BIT;
+      }
+      else {
+         
+         /*** Only texture unit 0 is enabled ***/
+         
+         switch (ctx->Texture.Unit[0].EnvMode) {
+            
+            /* exceptions */
+            
+            case GL_BLEND:
+               if (mmesa->envcolor) {
+                  mmesa->multitex = 1;
+                  mmesa->vertsize = 10;
+                  mmesa->tmu_source[1] = 0;
+                  funcindex |= MGA_TEX1_BIT;
+               }
+               break;
+
+            case GL_DECAL:
+               mmesa->multitex = 2;
+               break;
+
+            default:
+               break;
+         }
       }
 
       funcindex |= MGA_TEX0_BIT;
    }
+   else if (ctx->Texture.ReallyEnabled & 0xf0) {
+      
+      /*** Texture unit 1 only is enabled ***/
+        
+      /* Just a funny way of doing single texturing :
+       * use the first texture unit with settings of the second.
+       */
+      mmesa->tmu_source[0] = 1;
+      mmesa->tex_dest[1] = MGA_TEX0_BIT;
 
-   if (ctx->Texture.ReallyEnabled & 0xf0) {
-      if (ctx->Texture.ReallyEnabled & 0xf) {
-        mmesa->multitex = 1;
-        mmesa->vertsize = 10;
-        mmesa->blend_flags |= MGA_BLEND_MULTITEX;
-        funcindex |= MGA_TEX1_BIT;
-      } else {
-        /* Just a funny way of doing single texturing
-         */
-        mmesa->tmu_source[0] = 1;
-        mmesa->tex_dest[1] = MGA_TEX0_BIT;
-
-        if (ctx->Texture.Unit[0].EnvMode == GL_BLEND &&
-            mmesa->envcolor)
-        {
-           mmesa->multitex = 1;
-           mmesa->vertsize = 10;
-           mmesa->tmu_source[1] = 1;
-           funcindex |= MGA_TEX1_BIT;
-        }
+      switch (ctx->Texture.Unit[1].EnvMode) {
+           
+         /* exceptions */
+            
+         case GL_BLEND:
+            if (mmesa->envcolor) {
+               mmesa->multitex = 1;
+               mmesa->vertsize = 10;
+               mmesa->tmu_source[1] = 0;
+               funcindex |= MGA_TEX1_BIT;
+            }
+            break;
 
-        funcindex |= MGA_TEX0_BIT;
+         case GL_DECAL:
+            mmesa->multitex = 2;
+            break;
+
+         default:
+            break;
       }
+      
+      funcindex |= MGA_TEX0_BIT;
    }
 
    if (multi != mmesa->multitex)

Reply via email to