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);
   }
}
Example #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;
}
Example #3
0
/**
 * Return a vertex program which implements the current fixed-function
 * transform/lighting/texgen operations.
 * XXX move this into core mesa (main/)
 */
struct gl_vertex_program *
_mesa_get_fixed_func_vertex_program(GLcontext *ctx)
{
   struct gl_vertex_program *prog;
   struct state_key key;

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

   /* Look for an already-prepared program for this state:
    */
   prog = (struct gl_vertex_program *)
      _mesa_search_program_cache(ctx->VertexProgram.Cache, &key, sizeof(key));

   if (!prog) {
      /* OK, we'll have to build a new one */
      if (0)
         _mesa_printf("Build new TNL program\n");

      prog = (struct gl_vertex_program *)
         ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
      if (!prog)
         return NULL;

      create_new_program( &key, prog,
                          ctx->mvp_with_dp4,
                          ctx->Const.VertexProgram.MaxTemps );

#if 0
      if (ctx->Driver.ProgramStringNotify)
         ctx->Driver.ProgramStringNotify( ctx, GL_VERTEX_PROGRAM_ARB,
                                          &prog->Base );
#endif
      _mesa_program_cache_insert(ctx, ctx->VertexProgram.Cache,
                                 &key, sizeof(key), &prog->Base);
   }

   return prog;
}
Example #4
0
/**
 * Return a vertex program which implements the current fixed-function
 * transform/lighting/texgen operations.
 */
struct gl_program *
_mesa_get_fixed_func_vertex_program(struct gl_context *ctx)
{
   struct gl_program *prog;
   struct state_key key;

   /* Grab all the relevant state and put it in a single structure:
    */
   make_state_key(ctx, &key);

   /* Look for an already-prepared program for this state:
    */
   prog = _mesa_search_program_cache(ctx->VertexProgram.Cache, &key,
                                     sizeof(key));

   if (!prog) {
      /* OK, we'll have to build a new one */
      if (0)
         printf("Build new TNL program\n");

      prog = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
      if (!prog)
         return NULL;

      create_new_program( &key, prog,
                          ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS,
                          ctx->Const.Program[MESA_SHADER_VERTEX].MaxTemps );

      if (ctx->Driver.ProgramStringNotify)
         ctx->Driver.ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB, prog);

      _mesa_program_cache_insert(ctx, ctx->VertexProgram.Cache, &key,
                                 sizeof(key), prog);
   }

   return prog;
}
/**
 * Update st->pixel_xfer.program in response to new pixel-transfer state.
 */
static void
update_pixel_transfer(struct st_context *st)
{
   GLcontext *ctx = st->ctx;
   struct state_key key;
   struct gl_fragment_program *fp;

   make_state_key(st->ctx, &key);

   fp = (struct gl_fragment_program *)
      _mesa_search_program_cache(st->pixel_xfer.cache, &key, sizeof(key));
   if (!fp) {
      fp = get_pixel_transfer_program(st->ctx, &key);
      _mesa_program_cache_insert(st->ctx, st->pixel_xfer.cache,
                                 &key, sizeof(key), &fp->Base);
   }

   if (ctx->Pixel.MapColorFlag) {
      load_color_map_texture(ctx, st->pixel_xfer.pixelmap_texture);
   }
   st->pixel_xfer.pixelmap_enabled = ctx->Pixel.MapColorFlag;

   st->pixel_xfer.program = (struct st_fragment_program *) fp;
}