diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-05-18 22:49:08 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-05-19 00:01:08 +0300 |
commit | 33c5adba627b60d8a7504704bc5e9c80d7bd5ff0 (patch) | |
tree | eb29537c72db2e8164cbee21de7f852bc031fc39 /source/blender/gpu/opengl | |
parent | 9631bb1e17425d9dd9acdf06b251dd98e1838441 (diff) |
GPUStorageBuf: Add `GPU_storagebuf_copy_sub_from_vertbuf()`
This allows using the Graphic API to copy buffer data.
The GPU module do not expose untyped buffers even if that's what most API
do, so the copy function need to be strongly typed.
Contains GL backend implementation.
Diffstat (limited to 'source/blender/gpu/opengl')
-rw-r--r-- | source/blender/gpu/opengl/gl_storage_buffer.cc | 24 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_storage_buffer.hh | 1 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_vertex_buffer.hh | 5 |
3 files changed, 28 insertions, 2 deletions
diff --git a/source/blender/gpu/opengl/gl_storage_buffer.cc b/source/blender/gpu/opengl/gl_storage_buffer.cc index 109bb65fcb7..b30674fe5fa 100644 --- a/source/blender/gpu/opengl/gl_storage_buffer.cc +++ b/source/blender/gpu/opengl/gl_storage_buffer.cc @@ -144,6 +144,30 @@ void GLStorageBuf::clear(eGPUTextureFormat internal_format, eGPUDataFormat data_ } } +void GLStorageBuf::copy_sub(VertBuf *src_, uint dst_offset, uint src_offset, uint copy_size) +{ + GLVertBuf *src = static_cast<GLVertBuf *>(src_); + GLStorageBuf *dst = this; + + if (dst->ssbo_id_ == 0) { + dst->init(); + } + if (src->vbo_id_ == 0) { + src->bind(); + } + + if (GLContext::direct_state_access_support) { + glCopyNamedBufferSubData(src->vbo_id_, dst->ssbo_id_, src_offset, dst_offset, copy_size); + } + else { + /* This binds the buffer to GL_ARRAY_BUFFER and upload the data if any. */ + src->bind(); + glBindBuffer(GL_COPY_WRITE_BUFFER, dst->ssbo_id_); + glCopyBufferSubData(GL_ARRAY_BUFFER, GL_COPY_WRITE_BUFFER, src_offset, dst_offset, copy_size); + glBindBuffer(GL_COPY_WRITE_BUFFER, 0); + } +} + /** \} */ } // namespace blender::gpu diff --git a/source/blender/gpu/opengl/gl_storage_buffer.hh b/source/blender/gpu/opengl/gl_storage_buffer.hh index c808a0bdda1..96052fe0065 100644 --- a/source/blender/gpu/opengl/gl_storage_buffer.hh +++ b/source/blender/gpu/opengl/gl_storage_buffer.hh @@ -36,6 +36,7 @@ class GLStorageBuf : public StorageBuf { void bind(int slot) override; void unbind() override; void clear(eGPUTextureFormat internal_format, eGPUDataFormat data_format, void *data) override; + void copy_sub(VertBuf *src, uint dst_offset, uint src_offset, uint copy_size) override; /* Special internal function to bind SSBOs to indirect argument targets. */ void bind_as(GLenum target); diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.hh b/source/blender/gpu/opengl/gl_vertex_buffer.hh index 88d2a455778..e0a21587b60 100644 --- a/source/blender/gpu/opengl/gl_vertex_buffer.hh +++ b/source/blender/gpu/opengl/gl_vertex_buffer.hh @@ -19,8 +19,9 @@ namespace blender { namespace gpu { class GLVertBuf : public VertBuf { - friend class GLTexture; /* For buffer texture. */ - friend class GLShader; /* For transform feedback. */ + friend class GLTexture; /* For buffer texture. */ + friend class GLShader; /* For transform feedback. */ + friend class GLStorageBuf; /* For sub copy. */ private: /** OpenGL buffer handle. Init on first upload. Immutable after that. */ |