From 83ce6c51d7189094cf2a13fdcc0882a051a3bd41 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 29 Oct 2007 11:23:02 -0600 Subject: Refactor _mesa_UpdateTexEnvProgram() Will be replaced by _mesa_get_fixed_func_fragment_program(). --- src/mesa/main/texenvprogram.c | 68 +++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'src/mesa/main/texenvprogram.c') diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index 21a290402f..d8f3314c70 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -1234,6 +1234,39 @@ static GLuint hash_key( const struct state_key *key ) } +/** + * Return a fragment program which implements the current + * fixed-function texture, fog and color-sum operations. + */ +struct gl_fragment_program * +_mesa_get_fixed_func_fragment_program(GLcontext *ctx) +{ + struct gl_fragment_program *prog; + struct state_key key; + GLuint hash; + + make_state_key(ctx, &key); + hash = hash_key(&key); + + prog = search_cache(&ctx->Texture.env_fp_cache, hash, &key, sizeof(key)); + + if (!prog) { + if (0) + _mesa_printf("Building new texenv proggy for key %x\n", hash); + + prog = (struct gl_fragment_program *) + ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); + + create_new_program(ctx, &key, prog); + + cache_item(&ctx->Texture.env_fp_cache, hash, &key, prog); + } + + return prog; +} + + + /** * If _MaintainTexEnvProgram is set we'll generate a fragment program that * implements the current texture env/combine mode. @@ -1242,8 +1275,6 @@ static GLuint hash_key( const struct state_key *key ) void _mesa_UpdateTexEnvProgram( GLcontext *ctx ) { - struct state_key key; - GLuint hash; const struct gl_fragment_program *prev = ctx->FragmentProgram._Current; ASSERT(ctx->FragmentProgram._MaintainTexEnvProgram); @@ -1252,38 +1283,11 @@ _mesa_UpdateTexEnvProgram( GLcontext *ctx ) if (!ctx->FragmentProgram._Enabled && (!ctx->Shader.CurrentProgram || !ctx->Shader.CurrentProgram->FragmentProgram) ) { - make_state_key(ctx, &key); - hash = hash_key(&key); - - ctx->FragmentProgram._Current = - ctx->FragmentProgram._TexEnvProgram = - search_cache(&ctx->Texture.env_fp_cache, hash, &key, sizeof(key)); - - if (!ctx->FragmentProgram._TexEnvProgram) { - if (0) - _mesa_printf("Building new texenv proggy for key %x\n", hash); - /* create new tex env program */ - ctx->FragmentProgram._Current = - ctx->FragmentProgram._TexEnvProgram = - (struct gl_fragment_program *) - ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); - - create_new_program(ctx, &key, ctx->FragmentProgram._TexEnvProgram); - - cache_item(&ctx->Texture.env_fp_cache, hash, &key, - ctx->FragmentProgram._TexEnvProgram); - } - else { - if (0) - _mesa_printf("Found existing texenv program for key %x\n", hash); - } + ctx->FragmentProgram._Current + = ctx->FragmentProgram._TexEnvProgram + = _mesa_get_fixed_func_fragment_program(ctx); } -#if 0 - else { - ctx->FragmentProgram._Current = ctx->FragmentProgram.Current; - } -#endif /* Tell the driver about the change. Could define a new target for * this? -- cgit v1.2.3