Gawain: add GWN_vertbuf_clear
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jul 2017 14:28:18 +0000 (00:28 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jul 2017 15:48:52 +0000 (01:48 +1000)
Needed to clear the buffer without freeing.

intern/gawain/gawain/vertex_buffer.h
intern/gawain/src/vertex_buffer.c

index a66154d06e34b9e634beb6533593e46eadfa3cd1..9aee8e05877686ea2ff49b0216495d080bdc6c3f 100644 (file)
@@ -31,6 +31,7 @@ typedef struct {
 Gwn_VertBuf* GWN_vertbuf_create(void);
 Gwn_VertBuf* GWN_vertbuf_create_with_format(const Gwn_VertFormat*);
 
+void GWN_vertbuf_clear(Gwn_VertBuf* verts);
 void GWN_vertbuf_discard(Gwn_VertBuf*);
 
 void GWN_vertbuf_init(Gwn_VertBuf*);
index a9b481261f39b1da30bd59320e45e29e2a4233df..364e16a1a68c4e31e324da94e39b4156e4498970 100644 (file)
@@ -51,6 +51,25 @@ void GWN_vertbuf_init_with_format(Gwn_VertBuf* verts, const Gwn_VertFormat* form
                VertexFormat_pack(&verts->format);
        }
 
+/**
+ * Like #GWN_vertbuf_discard but doesn't free.
+ */
+void GWN_vertbuf_clear(Gwn_VertBuf* verts)
+       {
+       if (verts->vbo_id) {
+               GWN_buf_id_free(verts->vbo_id);
+               vbo_memory_usage -= GWN_vertbuf_size_get(verts);
+       }
+#if KEEP_SINGLE_COPY
+       else
+#endif
+       if (verts->data)
+               {
+               free(verts->data);
+               verts->data = NULL;
+               }
+       }
+
 void GWN_vertbuf_discard(Gwn_VertBuf* verts)
        {
        if (verts->vbo_id) {