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:
Diffstat (limited to 'source/blender/gpu/opengl/gl_vertex_buffer.cc')
-rw-r--r--source/blender/gpu/opengl/gl_vertex_buffer.cc45
1 files changed, 43 insertions, 2 deletions
diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.cc b/source/blender/gpu/opengl/gl_vertex_buffer.cc
index a56d5269fde..ce16a491528 100644
--- a/source/blender/gpu/opengl/gl_vertex_buffer.cc
+++ b/source/blender/gpu/opengl/gl_vertex_buffer.cc
@@ -29,6 +29,10 @@ namespace blender::gpu {
void GLVertBuf::acquire_data()
{
+ if (usage_ == GPU_USAGE_DEVICE_ONLY) {
+ return;
+ }
+
/* Discard previous data if any. */
MEM_SAFE_FREE(data);
data = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__);
@@ -36,6 +40,10 @@ void GLVertBuf::acquire_data()
void GLVertBuf::resize_data()
{
+ if (usage_ == GPU_USAGE_DEVICE_ONLY) {
+ return;
+ }
+
data = (uchar *)MEM_reallocN(data, sizeof(uchar) * this->size_alloc_get());
}
@@ -94,8 +102,10 @@ void GLVertBuf::bind()
vbo_size_ = this->size_used_get();
/* Orphan the vbo to avoid sync then upload data. */
glBufferData(GL_ARRAY_BUFFER, vbo_size_, nullptr, to_gl(usage_));
- glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_size_, data);
-
+ /* Do not transfer data from host to device when buffer is device only. */
+ if (usage_ != GPU_USAGE_DEVICE_ONLY) {
+ glBufferSubData(GL_ARRAY_BUFFER, 0, vbo_size_, data);
+ }
memory_usage += vbo_size_;
if (usage_ == GPU_USAGE_STATIC) {
@@ -106,6 +116,37 @@ void GLVertBuf::bind()
}
}
+void GLVertBuf::bind_as_ssbo(uint binding)
+{
+ bind();
+ BLI_assert(vbo_id_ != 0);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding, vbo_id_);
+}
+
+const void *GLVertBuf::read() const
+{
+ BLI_assert(is_active());
+ void *result = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
+ return result;
+}
+
+void *GLVertBuf::unmap(const void *mapped_data) const
+{
+ void *result = MEM_mallocN(vbo_size_, __func__);
+ memcpy(result, mapped_data, vbo_size_);
+ return result;
+}
+
+bool GLVertBuf::is_active() const
+{
+ if (!vbo_id_) {
+ return false;
+ }
+ int active_vbo_id = 0;
+ glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &active_vbo_id);
+ return vbo_id_ == active_vbo_id;
+}
+
void GLVertBuf::update_sub(uint start, uint len, void *data)
{
glBufferSubData(GL_ARRAY_BUFFER, start, len, data);