[Bf-blender-cvs] [16fd236e144] eevee-motionblur-object: GPUVertBuf: Add duplication function

Clément Foucault noreply at git.blender.org
Tue Apr 14 19:09:13 CEST 2020


Commit: 16fd236e144448ea27e40eb5bba58b6f8f409cc1
Author: Clément Foucault
Date:   Mon Apr 6 15:02:40 2020 +0200
Branches: eevee-motionblur-object
https://developer.blender.org/rB16fd236e144448ea27e40eb5bba58b6f8f409cc1

GPUVertBuf: Add duplication function

===================================================================

M	source/blender/gpu/GPU_vertex_buffer.h
M	source/blender/gpu/intern/gpu_vertex_buffer.c

===================================================================

diff --git a/source/blender/gpu/GPU_vertex_buffer.h b/source/blender/gpu/GPU_vertex_buffer.h
index fe45ec7b78b..f9bdf726930 100644
--- a/source/blender/gpu/GPU_vertex_buffer.h
+++ b/source/blender/gpu/GPU_vertex_buffer.h
@@ -80,6 +80,8 @@ void GPU_vertbuf_init_with_format_ex(GPUVertBuf *, const GPUVertFormat *, GPUUsa
 #define GPU_vertbuf_init_with_format(verts, format) \
   GPU_vertbuf_init_with_format_ex(verts, format, GPU_USAGE_STATIC)
 
+GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts);
+
 uint GPU_vertbuf_size_get(const GPUVertBuf *);
 void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len);
 void GPU_vertbuf_data_resize(GPUVertBuf *, uint v_len);
diff --git a/source/blender/gpu/intern/gpu_vertex_buffer.c b/source/blender/gpu/intern/gpu_vertex_buffer.c
index 1df7e68e08b..edceefc3dc0 100644
--- a/source/blender/gpu/intern/gpu_vertex_buffer.c
+++ b/source/blender/gpu/intern/gpu_vertex_buffer.c
@@ -85,6 +85,35 @@ void GPU_vertbuf_init_with_format_ex(GPUVertBuf *verts,
   }
 }
 
+GPUVertBuf *GPU_vertbuf_duplicate(GPUVertBuf *verts)
+{
+  GPUVertBuf *verts_dst = GPU_vertbuf_create(GPU_USAGE_STATIC);
+  /* Full copy. */
+  *verts_dst = *verts;
+  GPU_vertformat_copy(&verts_dst->format, &verts->format);
+
+  if (verts->vbo_id) {
+    uint buffer_sz = GPU_vertbuf_size_get(verts);
+
+    verts_dst->vbo_id = GPU_buf_alloc();
+
+    glBindBuffer(GL_COPY_READ_BUFFER, verts->vbo_id);
+    glBindBuffer(GL_COPY_WRITE_BUFFER, verts_dst->vbo_id);
+
+    glBufferData(GL_COPY_WRITE_BUFFER, buffer_sz, NULL, convert_usage_type_to_gl(verts->usage));
+
+    glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, buffer_sz);
+#if VRAM_USAGE
+    vbo_memory_usage += GPU_vertbuf_size_get(verts);
+#endif
+  }
+
+  if (verts->data) {
+    verts_dst->data = MEM_dupallocN(verts->data);
+  }
+  return verts_dst;
+}
+
 /** Same as discard but does not free. */
 void GPU_vertbuf_clear(GPUVertBuf *verts)
 {



More information about the Bf-blender-cvs mailing list