summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/state.c
diff options
context:
space:
mode:
authorBrian <[email protected]>2008-05-06 22:13:06 -0600
committerBrian <[email protected]>2008-05-06 22:13:06 -0600
commit103ae5d16fd9fef566096570f731bb634a8025d4 (patch)
tree184578514c317c199b6b05bee1f3c57bf3e19877 /src/mesa/main/state.c
parent10f6ae0355937615d137c79c060b9e5a923f0d65 (diff)
gallium: implement full reference counting for vertex/fragment programs
Use _mesa_reference_vert/fragprog() wherever we assign program pointers. Fixes a memory corruption bug found with glean/api2 test. Another memory bug involving shaders yet to be fixed...
Diffstat (limited to 'src/mesa/main/state.c')
-rw-r--r--src/mesa/main/state.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 0b1c56fdd5f..90379a17726 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -982,16 +982,20 @@ update_program(GLcontext *ctx)
#endif
if (shProg && shProg->LinkStatus && shProg->FragmentProgram) {
/* user-defined fragment shader */
- ctx->FragmentProgram._Current = shProg->FragmentProgram;
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
+ shProg->FragmentProgram);
}
else if (ctx->FragmentProgram._Enabled) {
/* use user-defined fragment program */
- ctx->FragmentProgram._Current = ctx->FragmentProgram.Current;
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
+ ctx->FragmentProgram.Current);
}
else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
/* fragment program generated from fixed-function state */
- ctx->FragmentProgram._Current = _mesa_get_fixed_func_fragment_program(ctx);
- ctx->FragmentProgram._TexEnvProgram = ctx->FragmentProgram._Current;
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
+ _mesa_get_fixed_func_fragment_program(ctx));
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram,
+ ctx->FragmentProgram._Current);
/* XXX get rid of this confusing stuff someday? */
ctx->FragmentProgram._Active = ctx->FragmentProgram._Enabled;
@@ -1000,7 +1004,7 @@ update_program(GLcontext *ctx)
}
else {
/* no fragment program */
- ctx->FragmentProgram._Current = NULL;
+ _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
}
if (ctx->FragmentProgram._Current != prevFP && ctx->Driver.BindProgram) {
@@ -1013,29 +1017,33 @@ update_program(GLcontext *ctx)
**/
#if 1
/* XXX get rid of this someday? */
- ctx->VertexProgram._TnlProgram = NULL;
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
#endif
if (shProg && shProg->LinkStatus && shProg->VertexProgram) {
/* user-defined vertex shader */
- ctx->VertexProgram._Current = shProg->VertexProgram;
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
+ shProg->VertexProgram);
}
else if (ctx->VertexProgram._Enabled) {
/* use user-defined vertex program */
- ctx->VertexProgram._Current = ctx->VertexProgram.Current;
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
+ ctx->VertexProgram.Current);
}
else if (ctx->VertexProgram._MaintainTnlProgram) {
/* vertex program generated from fixed-function state */
- ctx->VertexProgram._Current = _mesa_get_fixed_func_vertex_program(ctx);
- ctx->VertexProgram._TnlProgram = ctx->VertexProgram._Current;
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current,
+ _mesa_get_fixed_func_vertex_program(ctx));
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram,
+ ctx->VertexProgram._Current);
}
else {
/* no vertex program / used fixed-function code */
- ctx->VertexProgram._Current = NULL;
+ _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
}
if (ctx->VertexProgram._Current != prevVP && ctx->Driver.BindProgram) {
ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB,
- (struct gl_program *) ctx->VertexProgram._Current);
+ (struct gl_program *) ctx->VertexProgram._Current);
}
}