void _tnl_UpdateFixedFunctionProgram( GLcontext *ctx )
{
   TNLcontext *tnl = TNL_CONTEXT(ctx);
   struct state_key *key;
   GLuint hash;
   const struct gl_vertex_program *prev = ctx->VertexProgram._Current;

   if (!ctx->VertexProgram._Current ||
       ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram) {
      struct gl_vertex_program *newProg;

      /* Grab all the relevent state and put it in a single structure:
       */
      key = make_state_key(ctx);
      hash = hash_key(key);

      /* Look for an already-prepared program for this state:
       */
      newProg = search_cache( tnl->vp_cache, hash, key, sizeof(*key));
   
      /* OK, we'll have to build a new one:
       */
      if (!newProg) {

	 if (0)
	    _mesa_printf("Build new TNL program\n");
	 
	 newProg = (struct gl_vertex_program *)
	    ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); 

	 create_new_program( key, newProg, ctx->Const.VertexProgram.MaxTemps );

	 if (ctx->Driver.ProgramStringNotify)
	    ctx->Driver.ProgramStringNotify( ctx, GL_VERTEX_PROGRAM_ARB, 
                                             &newProg->Base );

         /* Our ownership of newProg is transferred to the cache */
	 cache_item(ctx, tnl->vp_cache, hash, key, newProg);
      }
      else {
	 FREE(key);
      }

      _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, newProg);
      _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, newProg);
   }

   /* Tell the driver about the change.  Could define a new target for
    * this?
    */
   if (ctx->VertexProgram._Current != prev && ctx->Driver.BindProgram) {
      ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB,
                            (struct gl_program *) ctx->VertexProgram._Current);
   }
}
Ejemplo n.º 2
0
static void update_tnl_program( struct brw_context *brw )
{
   GLcontext *ctx = &brw->intel.ctx;
   struct state_key key;
   GLuint hash;
   struct gl_vertex_program *old = brw->tnl_program;

   /* _NEW_PROGRAM */
   if (brw->attribs.VertexProgram->_Enabled) 
      return;
      
   /* Grab all the relevent state and put it in a single structure:
    */
   make_state_key(ctx, &key);
   hash = hash_key(&key);

   /* Look for an already-prepared program for this state:
    */
   brw->tnl_program = (struct gl_vertex_program *)
      search_cache( &brw->tnl_program_cache, hash, &key, sizeof(key) );
   
   /* OK, we'll have to build a new one:
    */
   if (!brw->tnl_program) {
      brw->tnl_program = (struct gl_vertex_program *)
	 ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); 

      build_new_tnl_program( &key, brw->tnl_program, 
/* 			     ctx->Const.MaxVertexProgramTemps  */
			     32
	 );

      if (ctx->Driver.ProgramStringNotify)
	 ctx->Driver.ProgramStringNotify( ctx, GL_VERTEX_PROGRAM_ARB, 
					  &brw->tnl_program->Base );

      cache_item( &brw->tnl_program_cache, 
		  hash, &key, brw->tnl_program );
   }

   if (old != brw->tnl_program)
      brw->state.dirty.brw |= BRW_NEW_TNL_PROGRAM;
}