Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / drivers / dri / mga / mgarender.c
index 5fb7af908c4c27e869d4db73efcd932c1e3a9849..f10a91adcec25306b94d6d763071b84a41b3c936 100644 (file)
@@ -1,4 +1,3 @@
-/* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgarender.c,v 1.4 2002/10/30 12:51:36 alanh Exp $ */
 /**************************************************************************
 
 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
@@ -39,17 +38,18 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
  * dma buffers.  Use strip/fan hardware primitives where possible.
  * Simulate missing primitives with indexed vertices.
  */
-#include "glheader.h"
-#include "context.h"
-#include "macros.h"
-#include "imports.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
+
+#include "math/m_xform.h"
 
 #include "tnl/t_context.h"
 
 #include "mgacontext.h"
 #include "mgatris.h"
-#include "mgastate.h"
 #include "mgaioctl.h"
 #include "mgavb.h"
 
@@ -66,7 +66,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #define HAVE_ELTS        0     /* for now */
 
-static void mgaDmaPrimitive( GLcontext *ctx, GLenum prim )
+static void mgaDmaPrimitive( struct gl_context *ctx, GLenum prim )
 {
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);
    GLuint hwprim;
@@ -94,15 +94,6 @@ static void mgaDmaPrimitive( GLcontext *ctx, GLenum prim )
    mgaRasterPrimitive( ctx, GL_TRIANGLES, hwprim );
 }
 
-static void VERT_FALLBACK( GLcontext *ctx, GLuint start, GLuint count, 
-                          GLuint flags )
-{
-   TNLcontext *tnl = TNL_CONTEXT(ctx);
-   tnl->Driver.Render.PrimitiveNotify( ctx, flags & PRIM_MODE_MASK );
-   tnl->Driver.Render.BuildVertices( ctx, start, count, ~0 );
-   tnl->Driver.Render.PrimTabVerts[flags&PRIM_MODE_MASK]( ctx, start, count, flags );
-   MGA_CONTEXT(ctx)->SetupNewInputs |= VERT_BIT_POS;
-}
 
 #define LOCAL_VARS mgaContextPtr mmesa = MGA_CONTEXT(ctx) 
 #define INIT( prim ) do {                      \
@@ -110,14 +101,17 @@ static void VERT_FALLBACK( GLcontext *ctx, GLuint start, GLuint count,
    FLUSH_BATCH(mmesa);                         \
    mgaDmaPrimitive( ctx, prim );               \
 } while (0)
-#define NEW_PRIMITIVE()  FLUSH_BATCH( mmesa )
-#define NEW_BUFFER()  FLUSH_BATCH( mmesa )
+#define FLUSH()  FLUSH_BATCH( mmesa )
 #define GET_CURRENT_VB_MAX_VERTS() \
    0 /* fix me */
 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
    MGA_BUFFER_SIZE / (mmesa->vertex_size * 4)
-#define EMIT_VERTS( ctx, j, nr ) \
-   mga_emit_contiguous_verts(ctx, j, (j)+(nr))
+
+
+#define ALLOC_VERTS( nr ) \
+  mgaAllocDmaLow( mmesa, (nr) * mmesa->vertex_size * 4)
+#define EMIT_VERTS( ctx, j, nr, buf ) \
+   mga_emit_contiguous_verts(ctx, j, (j)+(nr), buf)
 
  
 #define TAG(x) mga_##x
@@ -130,7 +124,7 @@ static void VERT_FALLBACK( GLcontext *ctx, GLuint start, GLuint count,
 /**********************************************************************/
 
 
-static GLboolean mga_run_render( GLcontext *ctx,
+static GLboolean mga_run_render( struct gl_context *ctx,
                                  struct tnl_pipeline_stage *stage )
 {
    mgaContextPtr mmesa = MGA_CONTEXT(ctx);
@@ -140,7 +134,8 @@ static GLboolean mga_run_render( GLcontext *ctx,
 
    /* Don't handle clipping or indexed vertices or vertex manipulations.
     */
-   if (VB->ClipOrMask || mmesa->RenderIndex != 0 || VB->Elts) {
+   if (mmesa->RenderIndex != 0 || 
+       !mga_validate_render( ctx, VB )) {
       return GL_TRUE;
    }
    
@@ -149,7 +144,7 @@ static GLboolean mga_run_render( GLcontext *ctx,
 
    for (i = 0 ; i < VB->PrimitiveCount ; i++)
    {
-      GLuint prim = VB->Primitive[i].mode;
+      GLuint prim = _tnl_translate_prim(&VB->Primitive[i]);
       GLuint start = VB->Primitive[i].start;
       GLuint length = VB->Primitive[i].count;
 
@@ -166,46 +161,12 @@ static GLboolean mga_run_render( GLcontext *ctx,
 }
 
 
-static void mga_check_render( GLcontext *ctx, struct tnl_pipeline_stage *stage )
-{
-   GLuint inputs = VERT_BIT_POS | VERT_BIT_COLOR0;
-
-   if (ctx->RenderMode == GL_RENDER) {
-      if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) 
-        inputs |= VERT_BIT_COLOR1;
-
-      if (ctx->Texture.Unit[0]._ReallyEnabled)
-        inputs |= VERT_BIT_TEX0;
-
-      if (ctx->Texture.Unit[1]._ReallyEnabled)
-        inputs |= VERT_BIT_TEX1;
-
-      if (ctx->Fog.Enabled) 
-        inputs |= VERT_BIT_FOG;
-   }
-
-   stage->inputs = inputs;
-}
-
-
-static void dtr( struct tnl_pipeline_stage *stage )
-{
-   (void)stage;
-}
-
-
 const struct tnl_pipeline_stage _mga_render_stage = 
 { 
    "mga render",
-   (_DD_NEW_SEPARATE_SPECULAR |
-    _NEW_TEXTURE|
-    _NEW_FOG|
-    _NEW_RENDERMODE),          /* re-check (new inputs) */
-   0,                          /* re-run (always runs) */
-   GL_TRUE,                    /* active */
-   0, 0,                       /* inputs (set in check_render), outputs */
-   0, 0,                       /* changed_inputs, private */
-   dtr,                                /* destructor */
-   mga_check_render,           /* check - initially set to alloc data */
+   NULL, 
+   NULL,
+   NULL,
+   NULL,
    mga_run_render              /* run */
 };