[Bf-blender-cvs] [f0caa0b] GPU_data_request: Merge remote-tracking branch 'origin/GPU_data_request' into GPU_data_request
Mike Erwin
noreply at git.blender.org
Tue Apr 21 08:29:39 CEST 2015
Commit: f0caa0bbad4e56feb4732c6e265494d3690c7c96
Author: Mike Erwin
Date: Tue Apr 21 02:27:52 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rBf0caa0bbad4e56feb4732c6e265494d3690c7c96
Merge remote-tracking branch 'origin/GPU_data_request' into GPU_data_request
Conflicts (resolved):
source/blender/gpu/intern/gpux_draw.c
source/blender/gpu/intern/gpux_element.c
source/blender/gpu/intern/gpux_vbo.c
===================================================================
===================================================================
diff --cc source/blender/gpu/intern/gpux_draw.c
index 2cccdb4,a1de374..6ae3e8e
--- a/source/blender/gpu/intern/gpux_draw.c
+++ b/source/blender/gpu/intern/gpux_draw.c
@@@ -1,11 -1,12 +1,10 @@@
#include "GPUx_draw.h"
#include "gpux_element_private.h"
-
- #include <stdlib.h>
+ #include "MEM_guardedalloc.h"
-//#include <stdio.h> /* TODO: remove */
-
#ifdef TRUST_NO_ONE
- #include <assert.h>
+ #include "BLI_utildefines.h"
#endif /* TRUST_NO_ONE */
#define REALLY_DRAW
@@@ -141,7 -142,8 +140,7 @@@ void GPUx_draw_primitives(const VertexB
GPUxBatch *GPUx_batch_create()
{
- GPUxBatch *batch = calloc(1, sizeof(GPUxBatch));
-// puts(__FUNCTION__);
+ GPUxBatch *batch = MEM_callocN(sizeof(GPUxBatch), "GPUxBatch");
batch->prim_type = GL_NONE;
batch->state = default_state;
return batch;
@@@ -152,17 -154,10 +151,17 @@@ void GPUx_batch_discard(GPUxBatch *batc
GPUx_vertex_buffer_discard(batch->buff);
if (batch->elem)
GPUx_element_list_discard(batch->elem);
- free(batch);
+ MEM_freeN(batch);
}
+unsigned GPUx_batch_size(const GPUxBatch *batch)
+{
+ unsigned sz = GPUx_vertex_buffer_size(batch->buff);
+ if (batch->elem)
+ sz += GPUx_element_list_size(batch->elem);
+ return sz;
+}
+
void GPUx_draw_batch(const GPUxBatch *batch)
{
int vert_per_prim = 0;
diff --cc source/blender/gpu/intern/gpux_element.c
index 41dda57,cff4e97..74c6e7b
--- a/source/blender/gpu/intern/gpux_element.c
+++ b/source/blender/gpu/intern/gpux_element.c
@@@ -1,7 -1,6 +1,7 @@@
#include "gpux_element_private.h"
+#include "gpux_buffer_id.h"
- #include <stdlib.h>
+ #include "MEM_guardedalloc.h"
/* private functions */
@@@ -50,12 -49,22 +50,12 @@@ const void *index_ptr(const ElementLis
ElementList *GPUx_element_list_create(GLenum prim_type, unsigned prim_ct, unsigned max_index)
{
ElementList *el;
- unsigned index_size, prim_vertex_ct;
- if (prim_type == GL_POINTS)
- prim_vertex_ct = 1;
- else if (prim_type == GL_LINES)
- prim_vertex_ct = 2;
- else if (prim_type == GL_TRIANGLES)
- prim_vertex_ct = 3;
- else {
#ifdef TRUST_NO_ONE
- assert(prim_type == GL_POINTS || prim_type == GL_LINES || prim_type == GL_TRIANGLES);
- BLI_assert(false);
++ BLI_assert(prim_type == GL_POINTS || prim_type == GL_LINES || prim_type == GL_TRIANGLES);
#endif /* TRUST_NO_ONE */
- return NULL;
- }
- el = calloc(1, sizeof(ElementList));
+ el = MEM_callocN(sizeof(ElementList), "ElementList");
el->prim_type = prim_type;
el->prim_ct = prim_ct;
@@@ -73,7 -88,7 +73,7 @@@
el->max_observed_index = 0;
#endif /* TRACK_INDEX_RANGE */
- el->indices = calloc(1, GPUx_element_list_size(el));
- el->indices = MEM_callocN(prim_ct * prim_vertex_ct * index_size, "ElementList.indices");
++ el->indices = MEM_callocN(GPUx_element_list_size(el), "ElementList.indices");
/* TODO: use only one calloc, not two */
return el;
@@@ -83,34 -98,13 +83,34 @@@ void GPUx_element_list_discard(ElementL
{
#ifdef USE_ELEM_VBO
if (el->vbo_id)
- glDeleteBuffers(1, &el->vbo_id);
+ buffer_id_free(el->vbo_id);
#endif /* USE_ELEM_VBO */
- free(el->indices);
- free(el);
+ MEM_freeN(el->indices);
+ MEM_freeN(el);
}
+unsigned GPUx_element_list_size(const ElementList *el)
+{
+ unsigned prim_vertex_ct = 0, index_size = 0;
+
+ if (el->prim_type == GL_POINTS)
+ prim_vertex_ct = 1;
+ else if (el->prim_type == GL_LINES)
+ prim_vertex_ct = 2;
+ else if (el->prim_type == GL_TRIANGLES)
+ prim_vertex_ct = 3;
+
+ if (el->index_type == GL_UNSIGNED_BYTE)
+ index_size = sizeof(GLubyte);
+ else if (el->index_type == GL_UNSIGNED_SHORT)
+ index_size = sizeof(GLushort);
+ else if (el->index_type == GL_UNSIGNED_INT)
+ index_size = sizeof(GLuint);
+
+ return prim_vertex_ct * el->prim_ct * index_size;
+}
+
void GPUx_set_point_vertex(ElementList *el, unsigned prim_idx, unsigned v1)
{
const unsigned offset = prim_idx;
@@@ -245,13 -239,32 +245,13 @@@ void GPUx_optimize(ElementList *el
void GPUx_element_list_prime(ElementList *el)
{
#ifdef USE_ELEM_VBO
- int prim_vertex_ct = 0, index_size = 0, total_size;
-
-#ifdef TRUST_NO_ONE
+ #ifdef TRUST_NO_ONE
- assert(el->vbo_id == 0);
+ BLI_assert(el->vbo_id == 0);
#endif /* TRUST_NO_ONE */
-
- if (el->prim_type == GL_POINTS)
- prim_vertex_ct = 1;
- else if (el->prim_type == GL_LINES)
- prim_vertex_ct = 2;
- else if (el->prim_type == GL_TRIANGLES)
- prim_vertex_ct = 3;
-
- if (el->index_type == GL_UNSIGNED_BYTE)
- index_size = sizeof(GLubyte);
- else if (el->index_type == GL_UNSIGNED_SHORT)
- index_size = sizeof(GLushort);
- else if (el->index_type == GL_UNSIGNED_INT)
- index_size = sizeof(GLuint);
-
- total_size = prim_vertex_ct * el->prim_ct * index_size;
-
- glGenBuffers(1, &el->vbo_id);
+ el->vbo_id = buffer_id_alloc();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, el->vbo_id);
/* fill with delicious data & send to GPU the first time only */
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, total_size, el->indices, GL_STATIC_DRAW);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, GPUx_element_list_size(el), el->indices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#else
(void)el;
diff --cc source/blender/gpu/intern/gpux_vbo.c
index 42521d9,12cc082..cce55b5
--- a/source/blender/gpu/intern/gpux_vbo.c
+++ b/source/blender/gpu/intern/gpux_vbo.c
@@@ -1,7 -1,6 +1,7 @@@
#include "GPUx_vbo.h"
+#include "gpux_buffer_id.h"
- #include <stdlib.h>
+ #include "MEM_guardedalloc.h"
#include <string.h>
/* VBOs are guaranteed for any GL >= 1.5
@@@ -163,19 -162,19 +163,19 @@@ void GPUx_vertex_buffer_discard(VertexB
Attrib *a = buff->attribs + a_idx;
#ifdef USE_VBO
if (a->vbo_id)
- glDeleteBuffers(1, &a->vbo_id);
+ buffer_id_free(a->vbo_id);
#endif /* USE_VBO */
#ifdef GENERIC_ATTRIB
- free(a->name);
+ MEM_freeN(a->name);
#endif /* GENERIC_ATTRIB */
- free(a->data);
+ MEM_freeN(a->data);
}
#ifdef USE_VAO
if (buff->vao_id)
- glDeleteVertexArrays(1, &buff->vao_id);
+ vao_id_free(buff->vao_id);
#endif /* USE_VAO */
- free(buff->attribs);
- free(buff);
+ MEM_freeN(buff->attribs);
+ MEM_freeN(buff);
}
static unsigned attrib_total_size(const VertexBuffer *buff, unsigned attrib_num)
@@@ -435,10 -425,10 +435,10 @@@ void GPUx_vertex_buffer_prime(VertexBuf
unsigned a_idx;
#ifdef USE_VAO
#ifdef TRUST_NO_ONE
- assert(buff->vao_id == 0);
+ BLI_assert(buff->vao_id == 0);
#endif /* TRUST_NO_ONE */
- glGenVertexArrays(1, &buff->vao_id);
+ buff->vao_id = vao_id_alloc();
glBindVertexArray(buff->vao_id);
#endif /* USE_VAO */
@@@ -458,10 -448,10 +458,10 @@@
#endif /* USE_VAO */
#ifdef TRUST_NO_ONE
- assert(a->vbo_id == 0);
+ BLI_assert(a->vbo_id == 0);
#endif /* TRUST_NO_ONE */
- glGenBuffers(1, &a->vbo_id);
+ a->vbo_id = buffer_id_alloc();
glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
/* fill with delicious data & send to GPU the first time only */
glBufferData(GL_ARRAY_BUFFER, attrib_total_size(buff, a_idx), a->data, GL_STATIC_DRAW);
More information about the Bf-blender-cvs
mailing list