Merge branch 'dri2'
[mesa.git] / src / mesa / shader / program.c
index c1606acb1a72581a7d05f1e3a8639bfaaa289070..2097c395918d2c7a2c9a2e241987563193805793 100644 (file)
@@ -118,6 +118,49 @@ _mesa_free_program_data(GLcontext *ctx)
 }
 
 
+/**
+ * Update the default program objects in the given context to reference those
+ * specified in the shared state and release those referencing the old 
+ * shared state.
+ */
+void
+_mesa_update_default_objects_program(GLcontext *ctx)
+{
+#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
+   if (ctx->VertexProgram.Current) {
+      ctx->VertexProgram.Current->Base.RefCount--;
+      if (ctx->VertexProgram.Current->Base.RefCount <= 0)
+         ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
+   }
+   ctx->VertexProgram.Current = (struct gl_vertex_program *) ctx->Shared->DefaultVertexProgram;
+   assert(ctx->VertexProgram.Current);
+   ctx->VertexProgram.Current->Base.RefCount++;
+#endif
+
+#if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
+   if (ctx->FragmentProgram.Current) {
+      ctx->FragmentProgram.Current->Base.RefCount--;
+      if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
+         ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
+   }
+   ctx->FragmentProgram.Current = (struct gl_fragment_program *) ctx->Shared->DefaultFragmentProgram;
+   assert(ctx->FragmentProgram.Current);
+   ctx->FragmentProgram.Current->Base.RefCount++;
+#endif
+
+   /* XXX probably move this stuff */
+#if FEATURE_ATI_fragment_shader
+   if (ctx->ATIFragmentShader.Current) {
+      ctx->ATIFragmentShader.Current->RefCount--;
+      if (ctx->ATIFragmentShader.Current->RefCount <= 0) {
+         _mesa_free(ctx->ATIFragmentShader.Current);
+      }
+   }
+   ctx->ATIFragmentShader.Current = (struct ati_fragment_shader *) ctx->Shared->DefaultFragmentShader;
+   assert(ctx->ATIFragmentShader.Current);
+   ctx->ATIFragmentShader.Current->RefCount++;
+#endif
+}
 
 
 /**
@@ -281,6 +324,8 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog)
       for (i = 0; i < prog->NumInstructions; i++) {
          if (prog->Instructions[i].Data)
             _mesa_free(prog->Instructions[i].Data);
+         if (prog->Instructions[i].Comment)
+            _mesa_free((char *) prog->Instructions[i].Comment);
       }
       _mesa_free(prog->Instructions);
    }
@@ -288,10 +333,12 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog)
    if (prog->Parameters) {
       _mesa_free_parameter_list(prog->Parameters);
    }
-
    if (prog->Varying) {
       _mesa_free_parameter_list(prog->Varying);
    }
+   if (prog->Attributes) {
+      _mesa_free_parameter_list(prog->Attributes);
+   }
 
    /* XXX this is a little ugly */
    if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
@@ -329,7 +376,7 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog)
 {
    struct gl_program *clone;
 
-   clone = _mesa_new_program(ctx, prog->Target, prog->Id);
+   clone = ctx->Driver.NewProgram(ctx, prog->Target, prog->Id);
    if (!clone)
       return NULL;