Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2016-01-02 21:55:15 +0300
committerAntony Riakiotakis <kalast@gmail.com>2016-01-02 21:55:15 +0300
commitc2bd260122c5d05d92a843fb5c3a8b60c7425b73 (patch)
treec3f1665c2abec52ebe40ec5a6aeffca8034a607d /source/blender/gpu
parent66bea2d77e0416bee3d3f49ee3d820adfd80f922 (diff)
GPU buffers: Add update functionality for existing buffers.
Only used for color for now, but we need this for any kind of buffer updates actually. This should get rid of some allocation/deallocation, making vertex painting a bit faster.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 3c44811324c..a2a604f0d40 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -483,10 +483,9 @@ static GPUBuffer *gpu_try_realloc(GPUBufferPool *pool, GPUBuffer *buffer, size_t
}
static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
- int type, void *user)
+ int type, void *user, GPUBuffer *buffer)
{
GPUBufferPool *pool;
- GPUBuffer *buffer;
float *varray;
int *mat_orig_to_new;
int i;
@@ -500,9 +499,11 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
BLI_mutex_lock(&buffer_mutex);
/* alloc a GPUBuffer; fall back to legacy mode on failure */
- if (!(buffer = gpu_buffer_alloc_intern(size))) {
- BLI_mutex_unlock(&buffer_mutex);
- return NULL;
+ if (!buffer) {
+ if (!(buffer = gpu_buffer_alloc_intern(size))) {
+ BLI_mutex_unlock(&buffer_mutex);
+ return NULL;
+ }
}
mat_orig_to_new = MEM_mallocN(sizeof(*mat_orig_to_new) * dm->totmat,
@@ -601,10 +602,9 @@ static size_t gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type)
}
/* call gpu_buffer_setup with settings for a particular type of buffer */
-static GPUBuffer *gpu_buffer_setup_type(DerivedMesh *dm, GPUBufferType type)
+static GPUBuffer *gpu_buffer_setup_type(DerivedMesh *dm, GPUBufferType type, GPUBuffer *buf)
{
void *user_data = NULL;
- GPUBuffer *buf;
/* special handling for MCol and UV buffers */
if (type == GPU_BUFFER_COLOR) {
@@ -616,14 +616,14 @@ static GPUBuffer *gpu_buffer_setup_type(DerivedMesh *dm, GPUBufferType type)
return NULL;
}
- buf = gpu_buffer_setup(dm, dm->drawObject, type, user_data);
+ buf = gpu_buffer_setup(dm, dm->drawObject, type, user_data, buf);
return buf;
}
/* get the buffer of `type', initializing the GPUDrawObject and
* buffer if needed */
-static GPUBuffer *gpu_buffer_setup_common(DerivedMesh *dm, GPUBufferType type)
+static GPUBuffer *gpu_buffer_setup_common(DerivedMesh *dm, GPUBufferType type, bool update)
{
GPUBuffer **buf;
@@ -632,14 +632,16 @@ static GPUBuffer *gpu_buffer_setup_common(DerivedMesh *dm, GPUBufferType type)
buf = gpu_drawobject_buffer_from_type(dm->drawObject, type);
if (!(*buf))
- *buf = gpu_buffer_setup_type(dm, type);
+ *buf = gpu_buffer_setup_type(dm, type, NULL);
+ else if (update)
+ *buf = gpu_buffer_setup_type(dm, type, *buf);
return *buf;
}
void GPU_vertex_setup(DerivedMesh *dm)
{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX, false))
return;
glEnableClientState(GL_VERTEX_ARRAY);
@@ -651,7 +653,7 @@ void GPU_vertex_setup(DerivedMesh *dm)
void GPU_normal_setup(DerivedMesh *dm)
{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_NORMAL))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_NORMAL, false))
return;
glEnableClientState(GL_NORMAL_ARRAY);
@@ -663,7 +665,7 @@ void GPU_normal_setup(DerivedMesh *dm)
void GPU_uv_setup(DerivedMesh *dm)
{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UV))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UV, false))
return;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -675,7 +677,7 @@ void GPU_uv_setup(DerivedMesh *dm)
void GPU_texpaint_uv_setup(DerivedMesh *dm)
{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UV_TEXPAINT))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UV_TEXPAINT, false))
return;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -692,6 +694,8 @@ void GPU_texpaint_uv_setup(DerivedMesh *dm)
void GPU_color_setup(DerivedMesh *dm, int colType)
{
+ bool update = false;
+
if (!dm->drawObject) {
/* XXX Not really nice, but we need a valid gpu draw object to set the colType...
* Else we would have to add a new param to gpu_buffer_setup_common. */
@@ -702,17 +706,12 @@ void GPU_color_setup(DerivedMesh *dm, int colType)
/* In paint mode, dm may stay the same during stroke, however we still want to update colors!
* Also check in case we changed color type (i.e. which MCol cdlayer we use). */
else if ((dm->dirty & DM_DIRTY_MCOL_UPDATE_DRAW) || (colType != dm->drawObject->colType)) {
- GPUBuffer **buf = gpu_drawobject_buffer_from_type(dm->drawObject, GPU_BUFFER_COLOR);
- /* XXX Freeing this buffer is a bit stupid, as geometry has not changed, size should remain the same.
- * Not sure though it would be worth defining a sort of gpu_buffer_update func - nor whether
- * it is even possible ! */
- GPU_buffer_free(*buf);
- *buf = NULL;
+ update = true;
dm->dirty &= ~DM_DIRTY_MCOL_UPDATE_DRAW;
dm->drawObject->colType = colType;
}
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_COLOR))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_COLOR, update))
return;
glEnableClientState(GL_COLOR_ARRAY);
@@ -734,10 +733,10 @@ void GPU_buffer_bind_as_color(GPUBuffer *buffer)
void GPU_edge_setup(DerivedMesh *dm)
{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_EDGE))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_EDGE, false))
return;
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX, false))
return;
glEnableClientState(GL_VERTEX_ARRAY);
@@ -751,7 +750,7 @@ void GPU_edge_setup(DerivedMesh *dm)
void GPU_uvedge_setup(DerivedMesh *dm)
{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UVEDGE))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UVEDGE, false))
return;
glEnableClientState(GL_VERTEX_ARRAY);
@@ -763,7 +762,7 @@ void GPU_uvedge_setup(DerivedMesh *dm)
void GPU_triangle_setup(struct DerivedMesh *dm)
{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_TRIANGLES))
+ if (!gpu_buffer_setup_common(dm, GPU_BUFFER_TRIANGLES, false))
return;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->triangles->id);