From: Brian Date: Mon, 29 Oct 2007 17:30:09 +0000 (-0600) Subject: Refactor _tnl_UpdateFixedFunctionProgram(). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=27153bf02dab57d11565fa7730de4767618ce62d;p=mesa.git Refactor _tnl_UpdateFixedFunctionProgram(). New _mesa_get_fixed_func_vertex_program() function... --- diff --git a/src/mesa/tnl/t_vp_build.c b/src/mesa/tnl/t_vp_build.c index dc2d5e0065a..86c6ccc1c0e 100644 --- a/src/mesa/tnl/t_vp_build.c +++ b/src/mesa/tnl/t_vp_build.c @@ -1534,49 +1534,66 @@ static GLuint hash_key( struct state_key *key ) return hash; } -void _tnl_UpdateFixedFunctionProgram( GLcontext *ctx ) + +/** + * 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) { TNLcontext *tnl = TNL_CONTEXT(ctx); + struct gl_vertex_program *prog; 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) { - /* Grab all the relevent state and put it in a single structure: - */ - key = make_state_key(ctx); - hash = hash_key(key); + /* 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: - */ - ctx->VertexProgram._TnlProgram = (struct gl_vertex_program *) - search_cache( tnl->vp_cache, hash, key, sizeof(*key) ); + /* Look for an already-prepared program for this state: + */ + prog = (struct gl_vertex_program *) + search_cache( tnl->vp_cache, hash, key, sizeof(*key) ); - /* OK, we'll have to build a new one: - */ - if (!ctx->VertexProgram._TnlProgram) { - if (0) - _mesa_printf("Build new TNL program\n"); + if (!prog) { + /* OK, we'll have to build a new one */ + if (0) + _mesa_printf("Build new TNL program\n"); - ctx->VertexProgram._TnlProgram = (struct gl_vertex_program *) - ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); + prog = (struct gl_vertex_program *) + ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); - create_new_program( key, ctx->VertexProgram._TnlProgram, - ctx->Const.VertexProgram.MaxTemps ); + create_new_program( key, prog, + ctx->Const.VertexProgram.MaxTemps ); - if (ctx->Driver.ProgramStringNotify) - ctx->Driver.ProgramStringNotify( ctx, GL_VERTEX_PROGRAM_ARB, - &ctx->VertexProgram._TnlProgram->Base ); +#if 0 + if (ctx->Driver.ProgramStringNotify) + ctx->Driver.ProgramStringNotify( ctx, GL_VERTEX_PROGRAM_ARB, + &prog->Base ); +#endif + cache_item(tnl->vp_cache, hash, key, prog); + } + else { + /* use cached program */ + _mesa_free(key); + } - cache_item(tnl->vp_cache, hash, key, ctx->VertexProgram._TnlProgram ); - } - else { - FREE(key); - if (0) - _mesa_printf("Found existing TNL program for key %x\n", hash); - } - ctx->VertexProgram._Current = ctx->VertexProgram._TnlProgram; + return prog; +} + + +void _tnl_UpdateFixedFunctionProgram( GLcontext *ctx ) +{ + const struct gl_vertex_program *prev = ctx->VertexProgram._Current; + + if (!ctx->VertexProgram._Current || + ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram) { + ctx->VertexProgram._Current + = ctx->VertexProgram._TnlProgram + = _mesa_get_fixed_func_vertex_program(ctx); } /* Tell the driver about the change. Could define a new target for diff --git a/src/mesa/tnl/t_vp_build.h b/src/mesa/tnl/t_vp_build.h index 5e22fcf8c40..034701d8c46 100644 --- a/src/mesa/tnl/t_vp_build.h +++ b/src/mesa/tnl/t_vp_build.h @@ -17,24 +17,29 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * TUNGSTEN GRAPHICS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * TUNGSTEN GRAPHICS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef _T_ARB_BUILD_H -#define _T_ARB_BUILD_H +#ifndef T_VP_BUILD_H +#define T_VP_BUILD_H #include "mtypes.h" #define TNL_FIXED_FUNCTION_STATE_FLAGS (_NEW_PROGRAM | \ _NEW_LIGHT | \ _NEW_TEXTURE | \ + _NEW_TEXTURE_MATRIX | \ _NEW_TRANSFORM | \ _NEW_FOG | \ _NEW_POINT) +extern struct gl_vertex_program * +_mesa_get_fixed_func_vertex_program(GLcontext *ctx); + extern void _tnl_UpdateFixedFunctionProgram( GLcontext *ctx ); extern void _tnl_ProgramCacheInit( GLcontext *ctx );