fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / r200 / r200_vtxfmt_c.c
index dcd7daf7631795a236b6ec6ece333587537b1526..1db5950c8ffea980e877bb5ca7ef562a11f77a46 100644 (file)
@@ -42,6 +42,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "vtxfmt.h"
 
 #include "r200_vtxfmt.h"
+#include "r200_tcl.h"
+
+#include "dispatch.h"
 
 /* Fallback versions of all the entrypoints for situations where
  * codegen isn't available.  This is still a lot faster than the
@@ -122,6 +125,7 @@ static void r200_Vertex2fv( const GLfloat *v )
 
 /* Color for ubyte (packed) color formats:
  */
+#if 0
 static void r200_Color3ub_ub( GLubyte r, GLubyte g, GLubyte b )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -161,7 +165,7 @@ static void r200_Color4ubv_ub( const GLubyte *v )
    r200ContextPtr rmesa = R200_CONTEXT(ctx);
    *(GLuint *)rmesa->vb.colorptr = LE32_TO_CPU(*(GLuint *)v);
 }
-
+#endif /* 0 */
 
 static void r200_Color3f_ub( GLfloat r, GLfloat g, GLfloat b )
 {
@@ -210,6 +214,7 @@ static void r200_Color4fv_ub( const GLfloat *v )
 
 /* Color for float color+alpha formats:
  */
+#if 0
 static void r200_Color3ub_4f( GLubyte r, GLubyte g, GLubyte b )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -253,6 +258,7 @@ static void r200_Color4ubv_4f( const GLubyte *v )
    dest[2] = UBYTE_TO_FLOAT(v[2]);
    dest[3] = UBYTE_TO_FLOAT(v[3]);
 }
+#endif /* 0 */
 
 
 static void r200_Color3f_4f( GLfloat r, GLfloat g, GLfloat b )
@@ -302,6 +308,7 @@ static void r200_Color4fv_4f( const GLfloat *v )
 
 /* Color for float color formats:
  */
+#if 0
 static void r200_Color3ub_3f( GLubyte r, GLubyte g, GLubyte b )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -343,6 +350,7 @@ static void r200_Color4ubv_3f( const GLubyte *v )
    dest[2] = UBYTE_TO_FLOAT(v[2]);
    ctx->Current.Attrib[VERT_ATTRIB_COLOR0][3] = UBYTE_TO_FLOAT(v[3]);
 }
+#endif /* 0 */
 
 
 static void r200_Color3f_3f( GLfloat r, GLfloat g, GLfloat b )
@@ -390,6 +398,7 @@ static void r200_Color4fv_3f( const GLfloat *v )
 
 /* Secondary Color:
  */
+#if 0
 static void r200_SecondaryColor3ubEXT_ub( GLubyte r, GLubyte g, GLubyte b )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -411,6 +420,7 @@ static void r200_SecondaryColor3ubvEXT_ub( const GLubyte *v )
    dest->blue  = v[2];
    dest->alpha = 0xff;
 }
+#endif /* 0 */
 
 static void r200_SecondaryColor3fEXT_ub( GLfloat r, GLfloat g, GLfloat b )
 {
@@ -434,6 +444,7 @@ static void r200_SecondaryColor3fvEXT_ub( const GLfloat *v )
    dest->alpha = 255;
 }
 
+#if 0
 static void r200_SecondaryColor3ubEXT_3f( GLubyte r, GLubyte g, GLubyte b )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -455,6 +466,7 @@ static void r200_SecondaryColor3ubvEXT_3f( const GLubyte *v )
    dest[2] = UBYTE_TO_FLOAT(v[2]);
    dest[3] = 1.0;
 }
+#endif /* 0 */
 
 static void r200_SecondaryColor3fEXT_3f( GLfloat r, GLfloat g, GLfloat b )
 {
@@ -503,69 +515,142 @@ static void r200_Normal3fv( const GLfloat *v )
 }
 
 
+/* FogCoord
+ */
+static void r200_FogCoordfEXT( GLfloat f )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   GLfloat *dest = rmesa->vb.fogptr;
+   dest[0] = r200ComputeFogBlendFactor( ctx, f );
+/*   ctx->Current.Attrib[VERT_ATTRIB_FOG][0] = f;*/
+}
+
+static void r200_FogCoordfvEXT( const GLfloat *v )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   GLfloat *dest = rmesa->vb.fogptr;
+   dest[0] = r200ComputeFogBlendFactor( ctx, v[0] );
+/*   ctx->Current.Attrib[VERT_ATTRIB_FOG][0] = v[0];*/
+}
+
+
 /* TexCoord
  */
 
-#define TEX_to_nF(N, P, S, T, R)                                       \
-   static void r200_TexCoord ## N P                                    \
-   {                                                                   \
-      GET_CURRENT_CONTEXT(ctx); r200ContextPtr rmesa = R200_CONTEXT(ctx); \
-      GLfloat * const dest = rmesa->vb.texcoordptr[0];                 \
-      switch( ctx->Texture.Unit[0]._ReallyEnabled ) {                  \
-      case TEXTURE_CUBE_BIT:                                           \
-      case TEXTURE_3D_BIT:                                             \
-        dest[2] = R;                                                   \
-      case TEXTURE_2D_BIT:                                             \
-      case TEXTURE_RECT_BIT:                                           \
-        dest[1] = T;                                                   \
-      case TEXTURE_1D_BIT:                                             \
-        dest[0] = S;                                                   \
-      }                                                                        \
+/* \todo maybe (target & 4 ? target & 5 : target & 3) is more save than (target & 7) */
+static void r200_MultiTexCoord1fARB(GLenum target, GLfloat s)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   GLint unit = (target & 7);
+   GLfloat * const dest = rmesa->vb.texcoordptr[unit];
+
+   switch( ctx->Texture.Unit[unit]._ReallyEnabled ) {
+   case TEXTURE_CUBE_BIT:
+   case TEXTURE_3D_BIT:
+      dest[2] = 0.0;
+      /* FALLTHROUGH */
+   case TEXTURE_2D_BIT:
+   case TEXTURE_RECT_BIT:
+      dest[1] = 0.0;
+      /* FALLTHROUGH */
+   case TEXTURE_1D_BIT:
+      dest[0] = s;
    }
+}
 
-TEX_to_nF( 1f,  (GLfloat s),                       s,    0.0,  0.0 )
-TEX_to_nF( 2f,  (GLfloat s, GLfloat t),            s,    t,    0.0 )
-TEX_to_nF( 3f,  (GLfloat s, GLfloat t, GLfloat r), s,    t,    r )
-TEX_to_nF( 1fv, (const GLfloat * v),               v[0], 0.0,  0.0 )
-TEX_to_nF( 2fv, (const GLfloat * v),               v[0], v[1], 0.0 )
-TEX_to_nF( 3fv, (const GLfloat * v),               v[0], v[1], v[2] )
-
-
-/* MultiTexcoord
- * 
- * Technically speaking, these functions should subtract GL_TEXTURE0 from
- * \c target before masking and using it.  The value of GL_TEXTURE0 is 0x84C0,
- * which has the low-order 5 bits 0.  For all possible valid values of 
- * \c target.  Subtracting GL_TEXTURE0 has the net effect of masking \c target
- * with 0x1F.  Masking with 0x1F and then masking with 0x07 is redundant, so
- * the subtraction has been omitted.
- */
+static void r200_MultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   GLint unit = (target & 7);
+   GLfloat * const dest = rmesa->vb.texcoordptr[unit];
 
-#define MTEX_to_nF(N, P, U, S, T, R)                                   \
-   static void r200_MultiTexCoord ## N ## ARB P                                \
-   {                                                                   \
-      GET_CURRENT_CONTEXT(ctx); r200ContextPtr rmesa = R200_CONTEXT(ctx); \
-      GLfloat * const dest = rmesa->vb.texcoordptr[U];                 \
-      switch( ctx->Texture.Unit[U]._ReallyEnabled ) {                  \
-      case TEXTURE_CUBE_BIT:                                           \
-      case TEXTURE_3D_BIT:                                             \
-        dest[2] = R;                                                   \
-      case TEXTURE_2D_BIT:                                             \
-      case TEXTURE_RECT_BIT:                                           \
-        dest[1] = T;                                                   \
-      case TEXTURE_1D_BIT:                                             \
-        dest[0] = S;                                                   \
-      }                                                                        \
+   switch( ctx->Texture.Unit[unit]._ReallyEnabled ) {
+   case TEXTURE_CUBE_BIT:
+   case TEXTURE_3D_BIT:
+      dest[2] = 0.0;
+      /* FALLTHROUGH */
+   case TEXTURE_2D_BIT:
+   case TEXTURE_RECT_BIT:
+      dest[1] = t;
+      dest[0] = s;
+      break;
+   default:
+      VFMT_FALLBACK(__FUNCTION__);
+      CALL_MultiTexCoord2fARB(GET_DISPATCH(), (target, s, t));
+      return;  
    }
+}
 
-/* \todo maybe (target & 4 ? target & 5 : target & 3) is more save than (target & 7) */
-MTEX_to_nF( 1f, (GLenum target, GLfloat s), (target & 7), s, 0.0, 0.0 )
-MTEX_to_nF( 2f, (GLenum target, GLfloat s, GLfloat t), (target & 7), s, t, 0.0 )
-MTEX_to_nF( 3f, (GLenum target, GLfloat s, GLfloat t, GLfloat r), (target & 7), s, t, r )
+static void r200_MultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   GLint unit = (target & 7);
+   GLfloat * const dest = rmesa->vb.texcoordptr[unit];
+
+   switch( ctx->Texture.Unit[unit]._ReallyEnabled ) {
+   case TEXTURE_CUBE_BIT:
+   case TEXTURE_3D_BIT:
+      dest[2] = r;
+      dest[1] = t;
+      dest[0] = s;
+      break;
+   default:
+      VFMT_FALLBACK(__FUNCTION__);
+      CALL_MultiTexCoord3fARB(GET_DISPATCH(), (target, s, t, r));
+      return;  
+   }
+}
+
+static void r200_TexCoord1f(GLfloat s)
+{
+   r200_MultiTexCoord1fARB(GL_TEXTURE0, s);
+}
+
+static void r200_TexCoord2f(GLfloat s, GLfloat t)
+{
+   r200_MultiTexCoord2fARB(GL_TEXTURE0, s, t);
+}
+
+static void r200_TexCoord3f(GLfloat s, GLfloat t, GLfloat r)
+{
+   r200_MultiTexCoord3fARB(GL_TEXTURE0, s, t, r);
+}
+
+static void r200_TexCoord1fv(const GLfloat *v)
+{
+   r200_MultiTexCoord1fARB(GL_TEXTURE0, v[0]);
+}
+
+static void r200_TexCoord2fv(const GLfloat *v)
+{
+   r200_MultiTexCoord2fARB(GL_TEXTURE0, v[0], v[1]);
+}
+
+static void r200_TexCoord3fv(const GLfloat *v)
+{
+   r200_MultiTexCoord3fARB(GL_TEXTURE0, v[0], v[1], v[2]);
+}
+
+static void r200_MultiTexCoord1fvARB(GLenum target, const GLfloat *v)
+{
+   r200_MultiTexCoord1fARB(target, v[0]);
+}
+
+static void r200_MultiTexCoord2fvARB(GLenum target, const GLfloat *v)
+{
+   r200_MultiTexCoord2fARB(target, v[0], v[1]);
+}
+
+static void r200_MultiTexCoord3fvARB(GLenum target, const GLfloat *v)
+{
+   r200_MultiTexCoord3fARB(target, v[0], v[1], v[2]);
+}
 
-MTEX_to_nF( 1fv, (GLenum target, const GLfloat *v), (target & 7), v[0], 0.0, 0.0 )
-MTEX_to_nF( 2fv, (GLenum target, const GLfloat *v), (target & 7), v[0], v[1], 0.0 )
-MTEX_to_nF( 3fv, (GLenum target, const GLfloat *v), (target & 7), v[0], v[1], v[2] )
 
 static struct dynfn *lookup( struct dynfn *l, const int *key )
 {
@@ -576,7 +661,7 @@ static struct dynfn *lookup( struct dynfn *l, const int *key )
         return f;
    }
 
-   return 0;
+   return NULL;
 }
 
 /* Can't use the loopback template for this:
@@ -600,15 +685,15 @@ static void choose_##FN ARGS1                                             \
       fprintf(stderr, "%s -- cached codegen\n", __FUNCTION__ );                \
                                                                        \
    if (dfn)                                                            \
-      ctx->Exec->FN = (FNTYPE)(dfn->code);                             \
+      SET_ ## FN (ctx->Exec, (FNTYPE)(dfn->code));                     \
    else {                                                              \
       if (R200_DEBUG & DEBUG_CODEGEN)                                  \
         fprintf(stderr, "%s -- generic version\n", __FUNCTION__ );     \
-      ctx->Exec->FN = r200_##FN;                                       \
+      SET_ ## FN (ctx->Exec, r200_##FN);                               \
    }                                                                   \
                                                                        \
    ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;                      \
-   ctx->Exec->FN ARGS2;                                                        \
+   CALL_ ## FN (ctx->Exec, ARGS2);                                     \
 }
 
 
@@ -632,7 +717,7 @@ static void choose_##FN ARGS1                                               \
    key[1] = rmesa->vb.vtxfmt_1 & MASK1;                                        \
                                                                        \
    if (VTX_COLOR(rmesa->vb.vtxfmt_0,0) == R200_VTX_PK_RGBA) {          \
-      ctx->Exec->FN = r200_##FN##_ub;                                  \
+      SET_ ## FN (ctx->Exec, r200_##FN##_ub);                          \
    }                                                                   \
    else if (VTX_COLOR(rmesa->vb.vtxfmt_0,0) == R200_VTX_FP_RGB) {      \
                                                                        \
@@ -642,15 +727,15 @@ static void choose_##FN ARGS1                                             \
          if (ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) {           \
             r200_copy_to_current( ctx );                               \
             _mesa_install_exec_vtxfmt( ctx, &rmesa->vb.vtxfmt );       \
-            ctx->Exec->FN ARGS2;                                       \
+            CALL_ ## FN (ctx->Exec, ARGS2);                            \
             return;                                                    \
          }                                                             \
       }                                                                        \
                                                                        \
-      ctx->Exec->FN = r200_##FN##_3f;                                  \
+      SET_ ## FN (ctx->Exec, r200_##FN##_3f);                          \
    }                                                                   \
    else {                                                              \
-      ctx->Exec->FN = r200_##FN##_4f;                                  \
+      SET_ ## FN (ctx->Exec, r200_##FN##_4f);                          \
    }                                                                   \
                                                                        \
                                                                        \
@@ -660,13 +745,13 @@ static void choose_##FN ARGS1                                             \
    if (dfn) {                                                          \
       if (R200_DEBUG & DEBUG_CODEGEN)                                  \
          fprintf(stderr, "%s -- codegen version\n", __FUNCTION__ );    \
-      ctx->Exec->FN = (FNTYPE)dfn->code;                               \
+      SET_ ## FN (ctx->Exec, (FNTYPE)dfn->code);                       \
    }                                                                   \
    else if (R200_DEBUG & DEBUG_CODEGEN)                                        \
          fprintf(stderr, "%s -- 'c' version\n", __FUNCTION__ );                \
                                                                        \
    ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;                      \
-   ctx->Exec->FN ARGS2;                                                        \
+   CALL_ ## FN (ctx->Exec, ARGS2);                                     \
 }
 
 
@@ -695,16 +780,16 @@ static void choose_##FN ARGS1                                             \
       fprintf(stderr, "%s -- cached version\n", __FUNCTION__ );                \
                                                                        \
    if (dfn)                                                            \
-      ctx->Exec->FN = (FNTYPE)(dfn->code);                     \
+      SET_ ## FN (ctx->Exec, (FNTYPE)(dfn->code));                     \
    else {                                                              \
       if (R200_DEBUG & DEBUG_CODEGEN)                                  \
          fprintf(stderr, "%s -- generic version\n", __FUNCTION__ );    \
-      ctx->Exec->FN = (VTX_COLOR(rmesa->vb.vtxfmt_0,1) == R200_VTX_PK_RGBA) \
-         ? r200_##FN##_ub : r200_##FN##_3f                           \
+      SET_ ## FN (ctx->Exec, (VTX_COLOR(rmesa->vb.vtxfmt_0,1) == R200_VTX_PK_RGBA) \
+         ? r200_##FN##_ub : r200_##FN##_3f);                           \
    }                                                                   \
                                                                        \
    ctx->Driver.NeedFlush |= FLUSH_UPDATE_CURRENT;              \
-   ctx->Exec->FN ARGS2;                                                \
+   CALL_ ## FN (ctx->Exec, ARGS2);                                     \
 }
 
 
@@ -717,7 +802,8 @@ static void choose_##FN ARGS1                                               \
  */
 #define MASK_XYZW  (R200_VTX_W0|R200_VTX_Z0)
 #define MASK_NORM  (MASK_XYZW|R200_VTX_N0)
-#define MASK_COLOR (MASK_NORM |(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_0_SHIFT))
+#define MASK_FOG   (MASK_NORM |R200_VTX_DISCRETE_FOG)
+#define MASK_COLOR (MASK_FOG |(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_0_SHIFT))
 #define MASK_SPEC  (MASK_COLOR|(R200_VTX_COLOR_MASK<<R200_VTX_COLOR_1_SHIFT))
 
 /* VTXFMT_1
@@ -810,6 +896,10 @@ CHOOSE(Vertex2f, p2f, ~0, ~0,
 CHOOSE(Vertex2fv, pfv, ~0, ~0, 
        (const GLfloat *v), (v))
 
+CHOOSE(FogCoordfEXT, p1f, MASK_FOG, ~0, 
+       (GLfloat f), (f))
+CHOOSE(FogCoordfvEXT, pfv, MASK_FOG, ~0, 
+       (const GLfloat *f), (f))
 
 
 
@@ -840,6 +930,8 @@ void r200VtxfmtInitChoosers( GLvertexformat *vfmt )
    vfmt->Vertex2fv = choose_Vertex2fv;
    vfmt->Vertex3f = choose_Vertex3f;
    vfmt->Vertex3fv = choose_Vertex3fv;
+/*   vfmt->FogCoordfEXT = choose_FogCoordfEXT;
+   vfmt->FogCoordfvEXT = choose_FogCoordfvEXT;*/
 
    /* TODO: restore ubyte colors to vtxfmt.
     */
@@ -857,7 +949,7 @@ void r200VtxfmtInitChoosers( GLvertexformat *vfmt )
 static struct dynfn *codegen_noop( GLcontext *ctx, const int *key )
 {
    (void) ctx; (void) key;
-   return 0;
+   return NULL;
 }
 
 void r200InitCodegen( struct dfn_generators *gen, GLboolean useCodegen )
@@ -882,6 +974,8 @@ void r200InitCodegen( struct dfn_generators *gen, GLboolean useCodegen )
    gen->MultiTexCoord2fvARB = codegen_noop;
    gen->MultiTexCoord1fARB = codegen_noop;
    gen->MultiTexCoord1fvARB = codegen_noop;
+/*   gen->FogCoordfEXT = codegen_noop;
+   gen->FogCoordfvEXT = codegen_noop;*/
 
    gen->Vertex2f = codegen_noop;
    gen->Vertex2fv = codegen_noop;