fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / r200 / r200_maos_arrays.c
index 6c6013054abcc9a758a371de4423baeb8d07fb3b..12ea462a400abea13205df635bf151ff7dcf5c04 100644 (file)
@@ -49,7 +49,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "r200_state.h"
 #include "r200_swtcl.h"
 #include "r200_maos.h"
+#include "r200_tcl.h"
 
+
+#if 0
 /* Usage:
  *   - from r200_tcl_render
  *   - call r200EmitArrays to ensure uptodate arrays in dma
@@ -81,29 +84,6 @@ static void emit_ubyte_rgba3( GLcontext *ctx,
    }
 }
 
-
-#if defined(USE_X86_ASM)
-#define COPY_DWORDS( dst, src, nr )                                    \
-do {                                                                   \
-       int __tmp;                                                      \
-       __asm__ __volatile__( "rep ; movsl"                             \
-                             : "=%c" (__tmp), "=D" (dst), "=S" (__tmp) \
-                             : "0" (nr),                               \
-                               "D" ((long)dst),                        \
-                               "S" ((long)src) );                      \
-} while (0)
-#else
-#define COPY_DWORDS( dst, src, nr )            \
-do {                                           \
-   int j;                                      \
-   for ( j = 0 ; j < nr ; j++ )                        \
-      dst[j] = ((int *)src)[j];                        \
-   dst += nr;                                  \
-} while (0)
-#endif
-
-
-
 static void emit_ubyte_rgba4( GLcontext *ctx,
                              struct r200_dma_region *rvb,
                              char *data,
@@ -129,7 +109,6 @@ static void emit_ubyte_rgba4( GLcontext *ctx,
 }
 
 
-#if 0
 static void emit_ubyte_rgba( GLcontext *ctx,
                             struct r200_dma_region *rvb,
                             char *data,
@@ -176,6 +155,70 @@ static void emit_ubyte_rgba( GLcontext *ctx,
 #endif
 
 
+#if defined(USE_X86_ASM)
+#define COPY_DWORDS( dst, src, nr )                                    \
+do {                                                                   \
+       int __tmp;                                                      \
+       __asm__ __volatile__( "rep ; movsl"                             \
+                             : "=%c" (__tmp), "=D" (dst), "=S" (__tmp) \
+                             : "0" (nr),                               \
+                               "D" ((long)dst),                        \
+                               "S" ((long)src) );                      \
+} while (0)
+#else
+#define COPY_DWORDS( dst, src, nr )            \
+do {                                           \
+   int j;                                      \
+   for ( j = 0 ; j < nr ; j++ )                        \
+      dst[j] = ((int *)src)[j];                        \
+   dst += nr;                                  \
+} while (0)
+#endif
+
+
+static void emit_vecfog( GLcontext *ctx,
+                        struct r200_dma_region *rvb,
+                        char *data,
+                        int stride,
+                        int count )
+{
+   int i;
+   GLfloat *out;
+
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   
+   if (R200_DEBUG & DEBUG_VERTS)
+      fprintf(stderr, "%s count %d stride %d\n",
+             __FUNCTION__, count, stride);
+
+   assert (!rvb->buf);
+
+   if (stride == 0) {
+      r200AllocDmaRegion( rmesa, rvb, 4, 4 );
+      count = 1;
+      rvb->aos_start = GET_START(rvb);
+      rvb->aos_stride = 0;
+      rvb->aos_size = 1;
+   }
+   else {
+      r200AllocDmaRegion( rmesa, rvb, count * 4, 4 );  /* alignment? */
+      rvb->aos_start = GET_START(rvb);
+      rvb->aos_stride = 1;
+      rvb->aos_size = 1;
+   }
+
+   /* Emit the data
+    */
+   out = (GLfloat *)(rvb->address + rvb->start);
+   for (i = 0; i < count; i++) {
+      out[0] = r200ComputeFogBlendFactor( ctx, *(GLfloat *)data );
+      out++;
+      data += stride;
+   }
+
+}
+
+
 static void emit_vec4( GLcontext *ctx,
                       struct r200_dma_region *rvb,
                       char *data,
@@ -235,7 +278,7 @@ static void emit_vec12( GLcontext *ctx,
 
    if (R200_DEBUG & DEBUG_VERTS)
       fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-             __FUNCTION__, count, stride, out, (void *)data);
+             __FUNCTION__, count, stride, (void *)out, (void *)data);
 
    if (stride == 12)
       COPY_DWORDS( out, data, count*3 );
@@ -341,6 +384,7 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
    GLuint nr = 0;
    GLuint vfmt0 = 0, vfmt1 = 0;
    GLuint count = VB->Count;
+   GLuint i;
    
    if (1) {
       if (!rmesa->tcl.obj.buf) 
@@ -375,6 +419,18 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
       component[nr++] = &rmesa->tcl.norm;
    }
 
+   if (inputs & VERT_BIT_FOG) {
+      if (!rmesa->tcl.fog.buf)
+        emit_vecfog( ctx, 
+                     &(rmesa->tcl.fog), 
+                     (char *)VB->FogCoordPtr->data,
+                     VB->FogCoordPtr->stride,
+                     count);
+
+      vfmt0 |= R200_VTX_DISCRETE_FOG;
+      component[nr++] = &rmesa->tcl.fog;
+   }
    if (inputs & VERT_BIT_COLOR0) {
       int emitsize;
 
@@ -416,34 +472,20 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
       vfmt0 |= R200_VTX_FP_RGB << R200_VTX_COLOR_1_SHIFT; 
       component[nr++] = &rmesa->tcl.spec;
    }
-
-/*    vtx = (rmesa->hw.tcl.cmd[TCL_OUTPUT_VTXFMT] & */
-/*       ~(R200_TCL_VTX_Q0|R200_TCL_VTX_Q1)); */
       
-   if (inputs & VERT_BIT_TEX0) {
-      if (!rmesa->tcl.tex[0].buf)
-        emit_vector( ctx, 
-                     &(rmesa->tcl.tex[0]), 
-                     (char *)VB->TexCoordPtr[0]->data,
-                     VB->TexCoordPtr[0]->size,
-                     VB->TexCoordPtr[0]->stride,
-                     count );
-
-      vfmt1 |= VB->TexCoordPtr[0]->size << R200_VTX_TEX0_COMP_CNT_SHIFT;
-      component[nr++] = &rmesa->tcl.tex[0];
-   }
-
-   if (inputs & VERT_BIT_TEX1) {
-      if (!rmesa->tcl.tex[1].buf)
-        emit_vector( ctx, 
-                     &(rmesa->tcl.tex[1]), 
-                     (char *)VB->TexCoordPtr[1]->data,
-                     VB->TexCoordPtr[1]->size,
-                     VB->TexCoordPtr[1]->stride,
-                     count );
-        
-      vfmt1 |= VB->TexCoordPtr[1]->size << R200_VTX_TEX1_COMP_CNT_SHIFT;
-      component[nr++] = &rmesa->tcl.tex[1];
+   for ( i = 0 ; i < ctx->Const.MaxTextureUnits ; i++ ) {
+      if (inputs & (VERT_BIT_TEX0 << i)) {
+        if (!rmesa->tcl.tex[i].buf)
+            emit_vector( ctx, 
+                         &(rmesa->tcl.tex[i]),
+                         (char *)VB->TexCoordPtr[i]->data,
+                         VB->TexCoordPtr[i]->size,
+                         VB->TexCoordPtr[i]->stride,
+                         count );
+
+        vfmt1 |= VB->TexCoordPtr[i]->size << (i * 3);
+        component[nr++] = &rmesa->tcl.tex[i];
+      }
    }
 
    if (vfmt0 != rmesa->hw.vtx.cmd[VTX_VTXFMT_0] ||
@@ -460,6 +502,7 @@ void r200EmitArrays( GLcontext *ctx, GLuint inputs )
 
 void r200ReleaseArrays( GLcontext *ctx, GLuint newinputs )
 {
+   GLuint unit;
    r200ContextPtr rmesa = R200_CONTEXT( ctx );
 
 /*    if (R200_DEBUG & DEBUG_VERTS)  */
@@ -470,6 +513,9 @@ void r200ReleaseArrays( GLcontext *ctx, GLuint newinputs )
 
    if (newinputs & VERT_BIT_NORMAL) 
       r200ReleaseDmaRegion( rmesa, &rmesa->tcl.norm, __FUNCTION__ );
+      
+   if (newinputs & VERT_BIT_FOG) 
+      r200ReleaseDmaRegion( rmesa, &rmesa->tcl.fog, __FUNCTION__ );
 
    if (newinputs & VERT_BIT_COLOR0) 
       r200ReleaseDmaRegion( rmesa, &rmesa->tcl.rgba, __FUNCTION__ );
@@ -477,9 +523,8 @@ void r200ReleaseArrays( GLcontext *ctx, GLuint newinputs )
    if (newinputs & VERT_BIT_COLOR1) 
       r200ReleaseDmaRegion( rmesa, &rmesa->tcl.spec, __FUNCTION__ );
 
-   if (newinputs & VERT_BIT_TEX0)
-      r200ReleaseDmaRegion( rmesa, &rmesa->tcl.tex[0], __FUNCTION__ );
-
-   if (newinputs & VERT_BIT_TEX1)
-      r200ReleaseDmaRegion( rmesa, &rmesa->tcl.tex[1], __FUNCTION__ );
+   for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++) {
+      if (newinputs & VERT_BIT_TEX(unit))
+        r200ReleaseDmaRegion( rmesa, &rmesa->tcl.tex[unit], __FUNCTION__ );
+   }
 }