Header file clean-up:
[mesa.git] / src / mesa / tnl / t_vb_render.c
index a71ed8d4493bd8c7d66d69e2ef65f7e6bdc5b855..976d3fc3d75dd0f956bc8c72a31a4e0e0811de24 100644 (file)
@@ -1,8 +1,8 @@
-/* $Id: t_vb_render.c,v 1.18 2001/04/26 14:53:48 keithw Exp $ */
+/* $Id: t_vb_render.c,v 1.32 2002/10/24 23:57:25 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  4.0.1
  *
  * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
  *
  * This file makes calls to project vertices and to the point, line
  * and triangle rasterizers via the function pointers:
  *
- *    context->Driver.BuildProjectedVertices()
+ *    context->Driver.Render.*
  *
- *    context->Driver.PointsFunc()
- *    context->Driver.LineFunc()
- *    context->Driver.TriangleFunc()
- *    context->Driver.QuadFunc()
- *
- *    context->Driver.RenderTabVerts[]
- *    context->Driver.RenderTabElts[]
- *
- * None of these may be null.
  */
 
 
 #include "glheader.h"
 #include "context.h"
+#include "enums.h"
 #include "macros.h"
-#include "mem.h"
+#include "imports.h"
 #include "mtypes.h"
 #include "mmath.h"
 
@@ -69,8 +61,8 @@
 
 
 #if defined(USE_IEEE)
-#define NEGATIVE(x) ((*(GLuint *)&x) & (1<<31))
-#define DIFFERENT_SIGNS(x,y) (((*(GLuint *)&x)^(*(GLuint *)&y)) & (1<<31))
+#define NEGATIVE(x) (GET_FLOAT_BITS(x) & (1<<31))
+#define DIFFERENT_SIGNS(x,y) ((GET_FLOAT_BITS(x) ^ GET_FLOAT_BITS(y)) & (1<<31))
 #else
 #define NEGATIVE(x) (x < 0)
 #define DIFFERENT_SIGNS(x,y) (x * y <= 0 && x - y != 0)
  */
 #endif
 
-#define LINTERP_SZ( t, vec, to, a, b, sz )                     \
-do {                                                           \
-   switch (sz) {                                               \
-   case 2: vec[to][2] = 0.0;                                   \
-   case 3: vec[to][3] = 1.0;                                   \
-   }                                                           \
-   switch (sz) {                                               \
-   case 4: vec[to][3] = LINTERP( t, vec[a][3], vec[b][3] );    \
-   case 3: vec[to][2] = LINTERP( t, vec[a][2], vec[b][2] );    \
-   case 2: vec[to][1] = LINTERP( t, vec[a][1], vec[b][1] );    \
-           vec[to][0] = LINTERP( t, vec[a][0], vec[b][0] );    \
-   }                                                           \
-} while(0)
-
-#define LINTERP_4F( t, vec, to, a, b, sz )             \
-do {                                                   \
-   vec[to][3] = LINTERP( t, vec[a][3], vec[b][3] );    \
-   vec[to][2] = LINTERP( t, vec[a][2], vec[b][2] );    \
-   vec[to][1] = LINTERP( t, vec[a][1], vec[b][1] );    \
-   vec[to][0] = LINTERP( t, vec[a][0], vec[b][0] );    \
-} while (0)
 
 #define W(i) coord[i][3]
 #define Z(i) coord[i][2]
@@ -123,7 +94,7 @@ do {                                                 \
 /* Vertices, with the possibility of clipping.
  */
 #define RENDER_POINTS( start, count ) \
-   tnl->Driver.PointsFunc( ctx, start, count )
+   tnl->Driver.Render.Points( ctx, start, count )
 
 #define RENDER_LINE( v1, v2 )                  \
 do {                                           \
@@ -163,16 +134,16 @@ do {                                                      \
    const GLuint * const elt = VB->Elts;                                \
    const GLubyte *mask = VB->ClipMask;                         \
    const GLuint sz = VB->ClipPtr->size;                                \
-   const line_func LineFunc = tnl->Driver.LineFunc;            \
-   const triangle_func TriangleFunc = tnl->Driver.TriangleFunc;        \
-   const quad_func QuadFunc = tnl->Driver.QuadFunc;            \
+   const line_func LineFunc = tnl->Driver.Render.Line;         \
+   const triangle_func TriangleFunc = tnl->Driver.Render.Triangle;     \
+   const quad_func QuadFunc = tnl->Driver.Render.Quad;         \
    const GLboolean stipple = ctx->Line.StippleFlag;            \
    (void) (LineFunc && TriangleFunc && QuadFunc);              \
    (void) elt; (void) mask; (void) sz; (void) stipple;
 
 #define TAG(x) clip_##x##_verts
-#define INIT(x) tnl->Driver.RenderPrimitive( ctx, x )
-#define RESET_STIPPLE if (stipple) tnl->Driver.ResetLineStipple( ctx )
+#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x )
+#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx )
 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
 #define PRESERVE_VB_DEFS
 #include "t_vb_rendertmp.h"
@@ -195,7 +166,7 @@ static void clip_elt_triangles( GLcontext *ctx,
                                GLuint flags )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
-   render_func render_tris = tnl->Driver.RenderTabElts[GL_TRIANGLES];
+   render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES];
    struct vertex_buffer *VB = &tnl->vb;
    const GLuint * const elt = VB->Elts;
    GLubyte *mask = VB->ClipMask;
@@ -203,7 +174,7 @@ static void clip_elt_triangles( GLcontext *ctx,
    GLuint j;
    (void) flags;
 
-   tnl->Driver.RenderPrimitive( ctx, GL_TRIANGLES );
+   tnl->Driver.Render.PrimitiveNotify( ctx, GL_TRIANGLES );
 
    for (j=start; j < last; j+=3 ) {
       GLubyte c1 = mask[elt[j]];
@@ -235,7 +206,7 @@ static void clip_elt_triangles( GLcontext *ctx,
 /* Vertices, no clipping.
  */
 #define RENDER_POINTS( start, count ) \
-   tnl->Driver.PointsFunc( ctx, start, count )
+   tnl->Driver.Render.Points( ctx, start, count )
 
 #define RENDER_LINE( v1, v2 ) \
    LineFunc( ctx, v1, v2 )
@@ -252,15 +223,16 @@ static void clip_elt_triangles( GLcontext *ctx,
    TNLcontext *tnl = TNL_CONTEXT(ctx);                         \
    struct vertex_buffer *VB = &tnl->vb;                                \
    const GLuint * const elt = VB->Elts;                                \
-   const line_func LineFunc = tnl->Driver.LineFunc;            \
-   const triangle_func TriangleFunc = tnl->Driver.TriangleFunc;        \
-   const quad_func QuadFunc = tnl->Driver.QuadFunc;            \
+   const line_func LineFunc = tnl->Driver.Render.Line;         \
+   const triangle_func TriangleFunc = tnl->Driver.Render.Triangle;     \
+   const quad_func QuadFunc = tnl->Driver.Render.Quad;         \
+   const GLboolean stipple = ctx->Line.StippleFlag;            \
    (void) (LineFunc && TriangleFunc && QuadFunc);              \
-   (void) elt;
+   (void) elt; (void) stipple
 
-#define RESET_STIPPLE tnl->Driver.ResetLineStipple( ctx )
+#define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx )
 #define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
-#define INIT(x) tnl->Driver.RenderPrimitive( ctx, x )
+#define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x )
 #define RENDER_TAB_QUALIFIER
 #define PRESERVE_VB_DEFS
 #include "t_vb_rendertmp.h"
@@ -274,6 +246,27 @@ static void clip_elt_triangles( GLcontext *ctx,
 #include "t_vb_rendertmp.h"
 
 
+/**********************************************************************/
+/*              Helper functions for drivers                  */
+/**********************************************************************/
+
+void _tnl_RenderClippedPolygon( GLcontext *ctx, const GLuint *elts, GLuint n )
+{
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+   struct vertex_buffer *VB = &tnl->vb;
+   GLuint *tmp = VB->Elts;
+
+   VB->Elts = (GLuint *)elts;
+   tnl->Driver.Render.PrimTabElts[GL_POLYGON]( ctx, 0, n, PRIM_BEGIN|PRIM_END );
+   VB->Elts = tmp;
+}
+
+void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
+{
+   TNLcontext *tnl = TNL_CONTEXT(ctx);
+   tnl->Driver.Render.Line( ctx, ii, jj );
+}
+
 
 
 /**********************************************************************/
@@ -290,56 +283,64 @@ static GLboolean run_render( GLcontext *ctx,
    render_func *tab;
    GLint pass = 0;
 
-
    /* Allow the drivers to lock before projected verts are built so
     * that window coordinates are guarenteed not to change before
     * rendering.
     */
-   ASSERT(tnl->Driver.RenderStart);
+   ASSERT(tnl->Driver.Render.Start);
 
-   tnl->Driver.RenderStart( ctx );
+   tnl->Driver.Render.Start( ctx );
 
-   ASSERT(tnl->Driver.BuildProjectedVertices);
-   ASSERT(tnl->Driver.RenderPrimitive);
-   ASSERT(tnl->Driver.PointsFunc);
-   ASSERT(tnl->Driver.LineFunc);
-   ASSERT(tnl->Driver.TriangleFunc);
-   ASSERT(tnl->Driver.QuadFunc);
-   ASSERT(tnl->Driver.ResetLineStipple);
-   ASSERT(tnl->Driver.RenderInterp);
-   ASSERT(tnl->Driver.RenderCopyPV);
-   ASSERT(tnl->Driver.RenderClippedLine);
-   ASSERT(tnl->Driver.RenderClippedPolygon);
-   ASSERT(tnl->Driver.RenderFinish);
+   ASSERT(tnl->Driver.Render.BuildVertices);
+   ASSERT(tnl->Driver.Render.PrimitiveNotify);
+   ASSERT(tnl->Driver.Render.Points);
+   ASSERT(tnl->Driver.Render.Line);
+   ASSERT(tnl->Driver.Render.Triangle);
+   ASSERT(tnl->Driver.Render.Quad);
+   ASSERT(tnl->Driver.Render.ResetLineStipple);
+   ASSERT(tnl->Driver.Render.Interp);
+   ASSERT(tnl->Driver.Render.CopyPV);
+   ASSERT(tnl->Driver.Render.ClippedLine);
+   ASSERT(tnl->Driver.Render.ClippedPolygon);
+   ASSERT(tnl->Driver.Render.Finish);
 
-   tnl->Driver.BuildProjectedVertices( ctx, 0, VB->Count, new_inputs );
+   tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, new_inputs );
 
    if (VB->ClipOrMask) {
       tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts;
       clip_render_tab_elts[GL_TRIANGLES] = clip_elt_triangles;
    }
    else {
-      tab = VB->Elts ? tnl->Driver.RenderTabElts : tnl->Driver.RenderTabVerts;
+      tab = (VB->Elts ? 
+            tnl->Driver.Render.PrimTabElts : 
+            tnl->Driver.Render.PrimTabVerts);
    }
 
    do
    {
       GLuint i, length, flags = 0;
-      for (i = 0 ; !(flags & PRIM_LAST) ; i += length)
+      for (i = VB->FirstPrimitive ; !(flags & PRIM_LAST) ; i += length)
       {
         flags = VB->Primitive[i];
         length= VB->PrimitiveLength[i];
         ASSERT(length || (flags & PRIM_LAST));
         ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1);
+
+        if (MESA_VERBOSE & VERBOSE_PRIMS)
+           _mesa_debug(NULL, "MESA prim %s %d..%d\n", 
+                   _mesa_lookup_enum_by_nr(flags & PRIM_MODE_MASK), 
+                   i, i+length);
+
         if (length)
            tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags );
       }
-   } while (tnl->Driver.MultipassFunc &&
-           tnl->Driver.MultipassFunc( ctx, ++pass ));
+   } while (tnl->Driver.Render.Multipass &&
+           tnl->Driver.Render.Multipass( ctx, ++pass ));
 
 
-   tnl->Driver.RenderFinish( ctx );
-/*     usleep(100000); */
+   tnl->Driver.Render.Finish( ctx );
+/*     _swrast_flush(ctx); */
+/*     usleep(1000000); */
    return GL_FALSE;            /* finished the pipe */
 }
 
@@ -355,39 +356,39 @@ static GLboolean run_render( GLcontext *ctx,
  */
 static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage )
 {
-   GLuint inputs = VERT_CLIP;
+   GLuint inputs = VERT_BIT_CLIP;
    GLuint i;
 
    if (ctx->Visual.rgbMode) {
-      inputs |= VERT_RGBA;
+      inputs |= VERT_BIT_COLOR0;
 
       if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
-        inputs |= VERT_SPEC_RGB;
+        inputs |= VERT_BIT_COLOR1;
 
-      if (ctx->Texture._ReallyEnabled) {
+      if (ctx->Texture._EnabledUnits) {
         for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
            if (ctx->Texture.Unit[i]._ReallyEnabled)
-              inputs |= VERT_TEX(i);
+              inputs |= VERT_BIT_TEX(i);
         }
       }
    }
    else {
-      inputs |= VERT_INDEX;
+      inputs |= VERT_BIT_INDEX;
    }
 
    if (ctx->Point._Attenuated)
-      inputs |= VERT_POINT_SIZE;
+      inputs |= VERT_BIT_POINT_SIZE;
 
    /* How do drivers turn this off?
     */
    if (ctx->Fog.Enabled)
-      inputs |= VERT_FOG_COORD;
+      inputs |= VERT_BIT_FOG;
 
    if (ctx->_TriangleCaps & DD_TRI_UNFILLED)
-      inputs |= VERT_EDGE;
+      inputs |= VERT_BIT_EDGEFLAG;
 
    if (ctx->RenderMode==GL_FEEDBACK)
-      inputs |= VERT_TEX_ANY;
+      inputs |= VERT_BITS_TEX_ANY;
 
    stage->inputs = inputs;
 }
@@ -402,7 +403,7 @@ static void dtr( struct gl_pipeline_stage *stage )
 
 const struct gl_pipeline_stage _tnl_render_stage =
 {
-   "render",
+   "render",                   /* name */
    (_NEW_BUFFERS |
     _DD_NEW_SEPARATE_SPECULAR |
     _DD_NEW_FLATSHADE |
@@ -413,9 +414,11 @@ const struct gl_pipeline_stage _tnl_render_stage =
     _DD_NEW_TRI_UNFILLED |
     _NEW_RENDERMODE),          /* re-check (new inputs, interp function) */
    0,                          /* re-run (always runs) */
-   GL_TRUE,                    /* active */
-   0, 0,                       /* inputs (set in check_render), outputs */
-   0, 0,                       /* changed_inputs, private */
+   GL_TRUE,                    /* active? */
+   0,                          /* inputs (set in check_render) */
+   0,                          /* outputs */
+   0,                          /* changed_inputs */
+   NULL,                       /* private data */
    dtr,                                /* destructor */
    check_render,               /* check */
    run_render                  /* run */