New vbo_set_draw_func() to keep vbo context opaque to state tracker and tnl module.
[mesa.git] / src / mesa / tnl / t_context.c
index 3b2f91acbaf8a86d5e817869b2bc80159ec78ac5..0ace5c2d6f182f9994cf2189d2c10b48cafc1b4f 100644 (file)
  */
 
 
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "macros.h"
-#include "mtypes.h"
-#include "light.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
+#include "main/light.h"
 
 #include "tnl.h"
 #include "t_context.h"
@@ -61,7 +61,6 @@ _tnl_CreateContext( GLcontext *ctx )
    /* Initialize tnl state.
     */
    if (ctx->VertexProgram._MaintainTnlProgram) {
-      _tnl_ProgramCacheInit( ctx );
       _tnl_install_pipeline( ctx, _tnl_vp_pipeline );
    } else {
       _tnl_install_pipeline( ctx, _tnl_default_pipeline );
@@ -79,6 +78,9 @@ _tnl_CreateContext( GLcontext *ctx )
 
    tnl->nr_blocks = 0;
 
+   /* plug in the VBO drawing function */
+   vbo_set_draw_func(ctx, _tnl_draw_prims);
+
    return GL_TRUE;
 }
 
@@ -90,9 +92,6 @@ _tnl_DestroyContext( GLcontext *ctx )
 
    _tnl_destroy_pipeline( ctx );
 
-   if (ctx->VertexProgram._MaintainTnlProgram)
-      _tnl_ProgramCacheDestroy( ctx );
-
    FREE(tnl);
    ctx->swtnl_context = NULL;
 }
@@ -102,6 +101,8 @@ void
 _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
+   const struct gl_vertex_program *vp = ctx->VertexProgram._Current;
+   const struct gl_fragment_program *fp = ctx->FragmentProgram._Current;
 
    if (new_state & (_NEW_HINT)) {
       ASSERT(tnl->AllowVertexFog || tnl->AllowPixelFog);
@@ -118,7 +119,9 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
 
       RENDERINPUTS_ZERO( tnl->render_inputs_bitset );
       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_POS );
-      RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR0 );
+      if (!fp || (fp->Base.InputsRead & FRAG_BIT_COL0)) {
+         RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR0 );
+      }
       for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
          if (ctx->Texture._EnabledCoordUnits & (1 << i)) {
             RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_TEX(i) );
@@ -134,9 +137,9 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
    }
 
    if (ctx->Fog.Enabled ||
-       (ctx->FragmentProgram._Current &&
+       ((ctx->FragmentProgram._Active || ctx->FragmentProgram._Current) &&
         (ctx->FragmentProgram._Current->FogOption != GL_NONE ||
-         ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_FOGC)))
+         (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_FOGC))))
       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_FOG );
 
    if (ctx->Polygon.FrontMode != GL_FILL || 
@@ -150,13 +153,16 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
        (ctx->VertexProgram._Enabled && ctx->VertexProgram.PointSizeEnabled))
       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_POINTSIZE );
 
-#if 1 /* XXX NEW_SLANG */
-   RENDERINPUTS_SET_RANGE( tnl->render_inputs_bitset,
-                           _TNL_FIRST_GENERIC, _TNL_LAST_GENERIC );
-#else
-   if (ctx->ShaderObjects._VertexShaderPresent || ctx->ShaderObjects._FragmentShaderPresent)
-      RENDERINPUTS_SET_RANGE( tnl->render_inputs_bitset, _TNL_FIRST_GENERIC, _TNL_LAST_GENERIC );
-#endif
+   /* check for varying vars which are written by the vertex program */
+   if (vp) {
+      GLuint i;
+      for (i = 0; i < MAX_VARYING; i++) {
+         if (vp->Base.OutputsWritten & (1 << (VERT_RESULT_VAR0 + i))) {
+            RENDERINPUTS_SET(tnl->render_inputs_bitset,
+                             _TNL_ATTRIB_GENERIC(i));
+         }
+      }
+   }
 }