Replace _mesa_malloc, _mesa_calloc and _mesa_free with plain libc versions
[mesa.git] / src / mesa / tnl / t_vb_render.c
index 28dd1412167f4b7325ca96bf25133a3027a0be0b..c1bebc99423589651e0e1dcd15d7124e89d4bc13 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.5
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  */
 
 
-#include "glheader.h"
-#include "context.h"
-#include "enums.h"
-#include "macros.h"
-#include "imports.h"
-#include "mtypes.h"
-
-#include "math/m_matrix.h"
-#include "math/m_xform.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/enums.h"
+#include "main/macros.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
 
 #include "t_pipeline.h"
 
 /*              Clip and render whole begin/end objects               */
 /**********************************************************************/
 
-#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
 
 
+/* This does NOT include the CLIP_USER_BIT! */
+#define CLIPMASK (CLIP_FRUSTUM_BITS | CLIP_CULL_BIT)
+
+
 /* Vertices, with the possibility of clipping.
  */
 #define RENDER_POINTS( start, count ) \
@@ -88,7 +88,7 @@ do {                                          \
    GLubyte ormask = c1|c2;                     \
    if (!ormask)                                        \
       LineFunc( ctx, v1, v2 );                 \
-   else if (!(c1 & c2 & 0x3f))                 \
+   else if (!(c1 & c2 & CLIPMASK))                     \
       clip_line_4( ctx, v1, v2, ormask );      \
 } while (0)
 
@@ -98,7 +98,7 @@ do {                                                  \
    GLubyte ormask = c1|c2|c3;                          \
    if (!ormask)                                                \
       TriangleFunc( ctx, v1, v2, v3 );                 \
-   else if (!(c1 & c2 & c3 & 0x3f))                    \
+   else if (!(c1 & c2 & c3 & CLIPMASK))                        \
       clip_tri_4( ctx, v1, v2, v3, ormask );           \
 } while (0)
 
@@ -109,7 +109,7 @@ do {                                                        \
    GLubyte ormask = c1|c2|c3|c4;                       \
    if (!ormask)                                                \
       QuadFunc( ctx, v1, v2, v3, v4 );                 \
-   else if (!(c1 & c2 & c3 & c4 & 0x3f))               \
+   else if (!(c1 & c2 & c3 & c4 & CLIPMASK))           \
       clip_quad_4( ctx, v1, v2, v3, v4, ormask );      \
 } while (0)
 
@@ -120,9 +120,9 @@ do {                                                        \
    const GLuint * const elt = VB->Elts;                                \
    const GLubyte *mask = VB->ClipMask;                         \
    const GLuint sz = VB->ClipPtr->size;                                \
-   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 tnl_line_func LineFunc = tnl->Driver.Render.Line;             \
+   const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \
+   const tnl_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;
@@ -130,7 +130,6 @@ do {                                                        \
 #define TAG(x) clip_##x##_verts
 #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"
 
@@ -152,7 +151,7 @@ static void clip_elt_triangles( GLcontext *ctx,
                                GLuint flags )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
-   render_func render_tris = tnl->Driver.Render.PrimTabElts[GL_TRIANGLES];
+   tnl_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;
@@ -170,7 +169,7 @@ static void clip_elt_triangles( GLcontext *ctx,
       if (ormask) {
         if (start < j)
            render_tris( ctx, start, j, 0 );
-        if (!(c1&c2&c3&0x3f))
+        if (!(c1&c2&c3&CLIPMASK))
            clip_tri_4( ctx, elt[j], elt[j+1], elt[j+2], ormask );
         start = j+3;
       }
@@ -184,7 +183,7 @@ static void clip_elt_triangles( GLcontext *ctx,
 /*                  Render whole begin/end objects                    */
 /**********************************************************************/
 
-#define NEED_EDGEFLAG_SETUP (ctx->_TriangleCaps & DD_TRI_UNFILLED)
+#define NEED_EDGEFLAG_SETUP (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)
 #define EDGEFLAG_GET(idx) VB->EdgeFlag[idx]
 #define EDGEFLAG_SET(idx, val) VB->EdgeFlag[idx] = val
 
@@ -209,15 +208,14 @@ 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.Render.Line;         \
-   const triangle_func TriangleFunc = tnl->Driver.Render.Triangle;     \
-   const quad_func QuadFunc = tnl->Driver.Render.Quad;         \
+   const tnl_line_func LineFunc = tnl->Driver.Render.Line;             \
+   const tnl_triangle_func TriangleFunc = tnl->Driver.Render.Triangle; \
+   const tnl_quad_func QuadFunc = tnl->Driver.Render.Quad;             \
    const GLboolean stipple = ctx->Line.StippleFlag;            \
    (void) (LineFunc && TriangleFunc && QuadFunc);              \
    (void) elt; (void) stipple
 
 #define RESET_STIPPLE if (stipple) tnl->Driver.Render.ResetLineStipple( ctx )
-#define RESET_OCCLUSION ctx->OcclusionResult = GL_TRUE
 #define INIT(x) tnl->Driver.Render.PrimitiveNotify( ctx, x )
 #define RENDER_TAB_QUALIFIER
 #define PRESERVE_VB_DEFS
@@ -261,12 +259,11 @@ void _tnl_RenderClippedLine( GLcontext *ctx, GLuint ii, GLuint jj )
 
 
 static GLboolean run_render( GLcontext *ctx,
-                            struct gl_pipeline_stage *stage )
+                            struct tnl_pipeline_stage *stage )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
-   GLuint new_inputs = stage->changed_inputs;
-   render_func *tab;
+   tnl_render_func *tab;
    GLint pass = 0;
 
    /* Allow the drivers to lock before projected verts are built so
@@ -290,7 +287,7 @@ static GLboolean run_render( GLcontext *ctx,
    ASSERT(tnl->Driver.Render.ClippedPolygon);
    ASSERT(tnl->Driver.Render.Finish);
 
-   tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, new_inputs );
+   tnl->Driver.Render.BuildVertices( ctx, 0, VB->Count, ~0 );
 
    if (VB->ClipOrMask) {
       tab = VB->Elts ? clip_render_tab_elts : clip_render_tab_verts;
@@ -304,29 +301,29 @@ static GLboolean run_render( GLcontext *ctx,
 
    do
    {
-      GLuint i, length, flags = 0;
-      for (i = VB->FirstPrimitive ; !(flags & PRIM_LAST) ; i += length)
+      GLuint i;
+
+      for (i = 0 ; i < VB->PrimitiveCount ; i++)
       {
-        flags = VB->Primitive[i];
-        length= VB->PrimitiveLength[i];
-        ASSERT(length || (flags & PRIM_LAST));
-        ASSERT((flags & PRIM_MODE_MASK) <= GL_POLYGON+1);
+        GLuint prim = _tnl_translate_prim(&VB->Primitive[i]);
+        GLuint start = VB->Primitive[i].start;
+        GLuint length = VB->Primitive[i].count;
+
+        assert((prim & PRIM_MODE_MASK) <= GL_POLYGON);
 
-        if (MESA_VERBOSE & VERBOSE_PRIMS)
+        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);
+                       _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK), 
+                       start, start+length);
 
         if (length)
-           tab[flags & PRIM_MODE_MASK]( ctx, i, i + length, flags );
+           tab[prim & PRIM_MODE_MASK]( ctx, start, start + length, prim );
       }
    } while (tnl->Driver.Render.Multipass &&
            tnl->Driver.Render.Multipass( ctx, ++pass ));
 
-
    tnl->Driver.Render.Finish( ctx );
-/*     _swrast_flush(ctx); */
-/*     usleep(1000000); */
+
    return GL_FALSE;            /* finished the pipe */
 }
 
@@ -337,75 +334,14 @@ static GLboolean run_render( GLcontext *ctx,
 
 
 
-/* Quite a bit of work involved in finding out the inputs for the
- * render stage.
- */
-static void check_render( GLcontext *ctx, struct gl_pipeline_stage *stage )
-{
-   GLuint inputs = VERT_BIT_CLIP;
-   GLuint i;
-
-   if (ctx->Visual.rgbMode) {
-      inputs |= VERT_BIT_COLOR0;
-
-      if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
-        inputs |= VERT_BIT_COLOR1;
-
-      if (ctx->Texture._EnabledCoordUnits) {
-        for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
-           if (ctx->Texture._EnabledCoordUnits & (1 << i))
-              inputs |= VERT_BIT_TEX(i);
-        }
-      }
-   }
-   else {
-      inputs |= VERT_BIT_INDEX;
-   }
-
-   if (ctx->Point._Attenuated)
-      inputs |= VERT_BIT_POINT_SIZE;
-
-   /* How do drivers turn this off?
-    */
-   if (ctx->Fog.Enabled)
-      inputs |= VERT_BIT_FOG;
-
-   if (ctx->_TriangleCaps & DD_TRI_UNFILLED)
-      inputs |= VERT_BIT_EDGEFLAG;
-
-   if (ctx->RenderMode==GL_FEEDBACK)
-      inputs |= VERT_BITS_TEX_ANY;
-
-   stage->inputs = inputs;
-}
-
-
-
-
-static void dtr( struct gl_pipeline_stage *stage )
-{
-}
 
 
-const struct gl_pipeline_stage _tnl_render_stage =
+const struct tnl_pipeline_stage _tnl_render_stage =
 {
    "render",                   /* name */
-   (_NEW_BUFFERS |
-    _DD_NEW_SEPARATE_SPECULAR |
-    _DD_NEW_FLATSHADE |
-    _NEW_TEXTURE|
-    _NEW_LIGHT|
-    _NEW_POINT|
-    _NEW_FOG|
-    _DD_NEW_TRI_UNFILLED |
-    _NEW_RENDERMODE),          /* re-check (new inputs, interp function) */
-   0,                          /* re-run (always runs) */
-   GL_TRUE,                    /* active? */
-   0,                          /* inputs (set in check_render) */
-   0,                          /* outputs */
-   0,                          /* changed_inputs */
    NULL,                       /* private data */
-   dtr,                                /* destructor */
-   check_render,               /* check */
+   NULL,                       /* creator */
+   NULL,                       /* destructor */
+   NULL,                       /* validate */
    run_render                  /* run */
 };