Merge branch 'mesa_7_6_branch'
[mesa.git] / src / mesa / state_tracker / st_cb_program.c
index b23e000a0b079b3bd670f9f80242b8e7559d8ee2..b2d5c39a3a0d139676432de96616e482d7308e57 100644 (file)
@@ -45,6 +45,7 @@
 #include "st_context.h"
 #include "st_program.h"
 #include "st_atom_shader.h"
+#include "st_mesa_to_tgsi.h"
 #include "st_cb_program.h"
 
 
@@ -89,13 +90,17 @@ static void st_use_program( GLcontext *ctx,
 
 
 
+/**
+ * Called via ctx->Driver.NewProgram() to allocate a new vertex or
+ * fragment program.
+ */
 static struct gl_program *st_new_program( GLcontext *ctx,
-                                         GLenum target, 
+                                         GLenum target,
                                          GLuint id )
 {
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB: {
-      struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program);
+      struct st_vertex_program *prog = ST_CALLOC_STRUCT(st_vertex_program);
 
       prog->serialNo = SerialNo++;
 
@@ -107,7 +112,7 @@ static struct gl_program *st_new_program( GLcontext *ctx,
 
    case GL_FRAGMENT_PROGRAM_ARB:
    case GL_FRAGMENT_PROGRAM_NV: {
-      struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program);
+      struct st_fragment_program *prog = ST_CALLOC_STRUCT(st_fragment_program);
 
       prog->serialNo = SerialNo++;
 
@@ -118,7 +123,8 @@ static struct gl_program *st_new_program( GLcontext *ctx,
    }
 
    default:
-      return _mesa_new_program(ctx, target, id);
+      assert(0);
+      return NULL;
    }
 }
 
@@ -138,8 +144,16 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog)
             stvp->driver_shader = NULL;
          }
 
+         if (stvp->draw_shader) {
+#if FEATURE_feedback || FEATURE_drawpix
+            /* this would only have been allocated for the RasterPos path */
+            draw_delete_vertex_shader(st->draw, stvp->draw_shader);
+            stvp->draw_shader = NULL;
+#endif
+         }
+
          if (stvp->state.tokens) {
-            FREE((void *) stvp->state.tokens);
+            st_free_tokens(stvp->state.tokens);
             stvp->state.tokens = NULL;
          }
       }
@@ -154,7 +168,7 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog)
          }
          
          if (stfp->state.tokens) {
-            FREE((void *) stfp->state.tokens);
+            st_free_tokens(stfp->state.tokens);
             stfp->state.tokens = NULL;
          }
 
@@ -171,6 +185,7 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog)
       assert(0); /* problem */
    }
 
+   /* delete base class */
    _mesa_delete_program( ctx, prog );
 }
 
@@ -200,7 +215,7 @@ static void st_program_string_notify( GLcontext *ctx,
       }
 
       if (stfp->state.tokens) {
-         FREE((void *) stfp->state.tokens);
+         st_free_tokens(stfp->state.tokens);
          stfp->state.tokens = NULL;
       }
 
@@ -220,12 +235,15 @@ static void st_program_string_notify( GLcontext *ctx,
       }
 
       if (stvp->draw_shader) {
+#if FEATURE_feedback || FEATURE_drawpix
+         /* this would only have been allocated for the RasterPos path */
          draw_delete_vertex_shader(st->draw, stvp->draw_shader);
          stvp->draw_shader = NULL;
+#endif
       }
 
       if (stvp->state.tokens) {
-         FREE((void *) stvp->state.tokens);
+         st_free_tokens(stvp->state.tokens);
          stvp->state.tokens = NULL;
       }