[Bf-blender-cvs] [9f35495] blender2.8: Gawain: batch mode uses buffer ID funcs
Mike Erwin
noreply at git.blender.org
Tue Nov 29 06:27:33 CET 2016
Commit: 9f35495a26552ba4b18ead8c1bc486207ddbc171
Author: Mike Erwin
Date: Tue Nov 29 00:12:50 2016 -0500
Branches: blender2.8
https://developer.blender.org/rB9f35495a26552ba4b18ead8c1bc486207ddbc171
Gawain: batch mode uses buffer ID funcs
The _discard functions now free their resources! These were waiting on thread-safe ID management, which we now have.
===================================================================
M source/blender/gpu/gawain/batch.c
M source/blender/gpu/gawain/element.c
M source/blender/gpu/gawain/vertex_buffer.c
===================================================================
diff --git a/source/blender/gpu/gawain/batch.c b/source/blender/gpu/gawain/batch.c
index f1c07d4..a60865d 100644
--- a/source/blender/gpu/gawain/batch.c
+++ b/source/blender/gpu/gawain/batch.c
@@ -10,6 +10,7 @@
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "batch.h"
+#include "buffer_id.h"
#include <stdlib.h>
// necessary functions from matrix API
@@ -36,7 +37,10 @@ Batch* Batch_create(PrimitiveType prim_type, VertexBuffer* verts, ElementList* e
void Batch_discard(Batch* batch)
{
- // TODO: clean up
+ if (batch->vao_id)
+ vao_id_free(batch->vao_id);
+
+ free(batch);
}
void Batch_discard_all(Batch* batch)
@@ -194,7 +198,7 @@ void Batch_Uniform4fv(Batch* batch, const char* name, const float data[4])
static void Batch_prime(Batch* batch)
{
- glGenVertexArrays(1, &batch->vao_id);
+ batch->vao_id = vao_id_alloc();
glBindVertexArray(batch->vao_id);
VertexBuffer_use(batch->verts);
diff --git a/source/blender/gpu/gawain/element.c b/source/blender/gpu/gawain/element.c
index 30d7548..3c3ca1c 100644
--- a/source/blender/gpu/gawain/element.c
+++ b/source/blender/gpu/gawain/element.c
@@ -10,6 +10,7 @@
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "element.h"
+#include "buffer_id.h"
#include <stdlib.h>
#define KEEP_SINGLE_COPY 1
@@ -36,7 +37,7 @@ unsigned ElementList_size(const ElementList* elem)
static void ElementList_prime(ElementList* elem)
{
- glGenBuffers(1, &elem->vbo_id);
+ elem->vbo_id = buffer_id_alloc();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elem->vbo_id);
// fill with delicious data & send to GPU the first time only
glBufferData(GL_ELEMENT_ARRAY_BUFFER, ElementList_size(elem), elem->data, GL_STATIC_DRAW);
@@ -270,5 +271,13 @@ void ElementList_build_in_place(ElementListBuilder* builder, ElementList* elem)
void ElementList_discard(ElementList* elem)
{
- // TODO: clean up
+ if (elem->vbo_id)
+ buffer_id_free(elem->vbo_id);
+#if KEEP_SINGLE_COPY
+ else
+#endif
+ if (elem->data)
+ free(elem->data);
+
+ free(elem);
}
diff --git a/source/blender/gpu/gawain/vertex_buffer.c b/source/blender/gpu/gawain/vertex_buffer.c
index 403df3c..5f2da60 100644
--- a/source/blender/gpu/gawain/vertex_buffer.c
+++ b/source/blender/gpu/gawain/vertex_buffer.c
@@ -10,6 +10,7 @@
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "vertex_buffer.h"
+#include "buffer_id.h"
#include <stdlib.h>
#include <string.h>
@@ -49,7 +50,15 @@ void VertexBuffer_init_with_format(VertexBuffer* verts, const VertexFormat* form
void VertexBuffer_discard(VertexBuffer* verts)
{
- // TODO: clean up
+ if (verts->vbo_id)
+ buffer_id_free(verts->vbo_id);
+#if KEEP_SINGLE_COPY
+ else
+#endif
+ if (verts->data)
+ free(verts->data);
+
+ free(verts);
}
unsigned VertexBuffer_size(const VertexBuffer* verts)
@@ -140,7 +149,7 @@ static void VertexBuffer_prime(VertexBuffer* verts)
{
const VertexFormat* format = &verts->format;
- glGenBuffers(1, &verts->vbo_id);
+ verts->vbo_id = buffer_id_alloc();
glBindBuffer(GL_ARRAY_BUFFER, verts->vbo_id);
// fill with delicious data & send to GPU the first time only
glBufferData(GL_ARRAY_BUFFER, vertex_buffer_size(format, verts->vertex_ct), verts->data, GL_STATIC_DRAW);
More information about the Bf-blender-cvs
mailing list