Revert "st/mesa: Always recalculate invalid index bounds."
[mesa.git] / src / mesa / vbo / vbo_save.c
index e7f46879639c4eea88c92ca07dfb4d14212836b4..fd9a13027050d4c5ad6f156f62d53635358fd302 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  7.2
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  */
 
 
-#include "mtypes.h"
-#include "dlist.h"
-#include "vtxfmt.h"
-#include "imports.h"
+#include "main/mtypes.h"
+#include "main/bufferobj.h"
+#include "main/imports.h"
 
 #include "vbo_context.h"
 
@@ -59,8 +58,19 @@ void vbo_save_init( GLcontext *ctx )
 
    {
       struct gl_client_array *arrays = save->arrays;
+      unsigned i;
+
       memcpy(arrays,      vbo->legacy_currval,  16 * sizeof(arrays[0]));
       memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+
+      for (i = 0; i < 16; ++i) {
+         arrays[i     ].BufferObj = NULL;
+         arrays[i + 16].BufferObj = NULL;
+         _mesa_reference_buffer_object(ctx, &arrays[i     ].BufferObj, 
+                                       vbo->legacy_currval[i].BufferObj);
+         _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj,
+                                       vbo->generic_currval[i].BufferObj);
+      }
    }
 
    ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
@@ -69,6 +79,26 @@ void vbo_save_init( GLcontext *ctx )
 
 void vbo_save_destroy( GLcontext *ctx )
 {
+   struct vbo_context *vbo = vbo_context(ctx);
+   struct vbo_save_context *save = &vbo->save;
+   GLuint i;
+
+   if (save->prim_store) {
+      if ( --save->prim_store->refcount == 0 ) {
+         FREE( save->prim_store );
+         save->prim_store = NULL;
+      }
+      if ( --save->vertex_store->refcount == 0 ) {
+         _mesa_reference_buffer_object(ctx,
+                                       &save->vertex_store->bufferobj, NULL);
+         FREE( save->vertex_store );
+         save->vertex_store = NULL;
+      }
+   }
+
+   for (i = 0; i < VBO_ATTRIB_MAX; i++) {
+      _mesa_reference_buffer_object(ctx, &save->arrays[i].BufferObj, NULL);
+   }
 }