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:
authorClément Foucault <foucault.clem@gmail.com>2020-09-07 02:20:55 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-09-07 14:59:51 +0300
commitc38debd39fac1e3d44b84e8092419da34f0b613d (patch)
treebba08fc983f7e18025f4e09fa346737053ba4ed0 /source/blender/gpu/opengl/gl_vertex_buffer.cc
parentbb2aeb4504907cab1cf8c4afc4dd1d6495c940e4 (diff)
GPUVertBuf: GL Backend Isolation
Part of the Vulkan port T68990 This makes a few changes in how the data is being handled by the backend to allow more flexibility in the future. The overall code logic is left unchanged.
Diffstat (limited to 'source/blender/gpu/opengl/gl_vertex_buffer.cc')
-rw-r--r--source/blender/gpu/opengl/gl_vertex_buffer.cc69
1 files changed, 61 insertions, 8 deletions
diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.cc b/source/blender/gpu/opengl/gl_vertex_buffer.cc
index ee9e0a0b0c9..66ff1f36cef 100644
--- a/source/blender/gpu/opengl/gl_vertex_buffer.cc
+++ b/source/blender/gpu/opengl/gl_vertex_buffer.cc
@@ -27,30 +27,83 @@
namespace blender::gpu {
-void GLVertBuf::bind(void)
+void GLVertBuf::acquire_data(void)
{
+ /* Discard previous data if any. */
+ MEM_SAFE_FREE(data);
+ data = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__);
}
-void GLVertBuf::upload_data(void)
+void GLVertBuf::resize_data(void)
{
+ data = (uchar *)MEM_reallocN(data, sizeof(uchar) * this->size_alloc_get());
}
-uchar *GLVertBuf::acquire_data(void)
+void GLVertBuf::release_data(void)
{
- return nullptr;
+ if (vbo_id_ != 0) {
+ GLBackend::get()->buf_free(vbo_id_);
+ vbo_id_ = 0;
+ memory_usage -= vbo_size_;
+ }
+
+ MEM_SAFE_FREE(data);
}
-uchar *GLVertBuf::resize_data(void)
+void GLVertBuf::duplicate_data(VertBuf *dst_)
{
- return nullptr;
+ BLI_assert(GPU_context_active_get() != NULL);
+ GLVertBuf *src = this;
+ GLVertBuf *dst = static_cast<GLVertBuf *>(dst_);
+
+ if (src->vbo_id_ != 0) {
+ dst->vbo_size_ = src->size_used_get();
+
+ glGenBuffers(1, &dst->vbo_id_);
+ glBindBuffer(GL_COPY_WRITE_BUFFER, dst->vbo_id_);
+ glBufferData(GL_COPY_WRITE_BUFFER, dst->vbo_size_, NULL, to_gl(dst->usage_));
+
+ glBindBuffer(GL_COPY_READ_BUFFER, src->vbo_id_);
+
+ glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, dst->vbo_size_);
+
+ memory_usage += dst->vbo_size_;
+ }
+
+ if (data != nullptr) {
+ dst->data = (uchar *)MEM_dupallocN(src->data);
+ }
}
-void GLVertBuf::release_data(void)
+void GLVertBuf::upload_data(void)
{
+ this->bind();
}
-void GLVertBuf::duplicate_data(VertBuf *)
+void GLVertBuf::bind(void)
{
+ BLI_assert(GPU_context_active_get() != NULL);
+
+ if (vbo_id_ == 0) {
+ glGenBuffers(1, &vbo_id_);
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo_id_);
+
+ if (flag & GPU_VERTBUF_DATA_DIRTY) {
+ vbo_size_ = this->size_used_get();
+ /* Orphan the vbo to avoid sync then upload data. */
+ glBufferData(GL_ARRAY_BUFFER, vbo_size_, NULL, to_gl(usage_));
+ glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_size_, data);
+
+ memory_usage += vbo_size_;
+
+ if (usage_ == GPU_USAGE_STATIC) {
+ MEM_SAFE_FREE(data);
+ }
+ flag &= ~GPU_VERTBUF_DATA_DIRTY;
+ flag |= GPU_VERTBUF_DATA_UPLOADED;
+ }
}
} // namespace blender::gpu \ No newline at end of file