Cell: generalize the batch buffer code for vertex buffers...
[mesa.git] / src / mesa / vbo / vbo_save.c
index 3a97ea66a4ffe026fe8604708e382c7b456524e2..8dd87141c0c27ec84c813f73d3f27dd8575d0510 100644 (file)
  */
 
 
-#include "mtypes.h"
-#include "dlist.h"
-#include "vtxfmt.h"
-#include "imports.h"
+#include "main/mtypes.h"
+#include "main/dlist.h"
+#include "main/vtxfmt.h"
+#include "main/imports.h"
 
 #include "vbo_context.h"
 
@@ -49,19 +49,41 @@ static void vbo_save_callback_init( GLcontext *ctx )
 
 void vbo_save_init( GLcontext *ctx )
 {
-   struct vbo_save_context *save = &vbo_context(ctx)->save;
+   struct vbo_context *vbo = vbo_context(ctx);
+   struct vbo_save_context *save = &vbo->save;
 
    save->ctx = ctx;
 
    vbo_save_api_init( save );
    vbo_save_callback_init(ctx);
 
+   {
+      struct gl_client_array *arrays = save->arrays;
+      memcpy(arrays,      vbo->legacy_currval,  16 * sizeof(arrays[0]));
+      memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+   }
+
    ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
 }
 
 
 void vbo_save_destroy( GLcontext *ctx )
 {
+   struct vbo_context *vbo = vbo_context(ctx);
+   struct vbo_save_context *save = &vbo->save;
+   if (save->prim_store) {
+      if ( --save->prim_store->refcount == 0 ) {
+         FREE( save->prim_store );
+         save->prim_store = NULL;
+      }
+      if ( --save->vertex_store->refcount == 0 ) {
+         if (save->vertex_store->bufferobj)
+            ctx->Driver.DeleteBuffer( ctx, save->vertex_store->bufferobj );
+
+         FREE( save->vertex_store );
+         save->vertex_store = NULL;
+      }
+   }
 }