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>2022-07-30 14:28:05 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-08-02 22:53:17 +0300
commit1e5ab041d79224a634268e0b80f114b5566387c4 (patch)
tree59e6622029b7c03b469ee193d50acb464ba1a80e /source/blender/gpu/opengl/gl_batch.cc
parent72206195542369a231a40cf4428cef2508321404 (diff)
GPUBatch: Add GPU_batch_draw_indirect
This allows rendering a batch with parameters computed by the GPU. Contains GL backend implementation.
Diffstat (limited to 'source/blender/gpu/opengl/gl_batch.cc')
-rw-r--r--source/blender/gpu/opengl/gl_batch.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc
index fde2a53bb0f..4ec86b98cbe 100644
--- a/source/blender/gpu/opengl/gl_batch.cc
+++ b/source/blender/gpu/opengl/gl_batch.cc
@@ -18,6 +18,7 @@
#include "gl_debug.hh"
#include "gl_index_buffer.hh"
#include "gl_primitive.hh"
+#include "gl_storage_buffer.hh"
#include "gl_vertex_array.hh"
#include "gl_batch.hh"
@@ -326,4 +327,27 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count)
}
}
+void GLBatch::draw_indirect(GPUStorageBuf *indirect_buf)
+{
+ GL_CHECK_RESOURCES("Batch");
+
+ this->bind(0);
+
+ dynamic_cast<GLStorageBuf *>(unwrap(indirect_buf))->bind_as(GL_DRAW_INDIRECT_BUFFER);
+ /* This barrier needs to be here as it only work on the currently bound indirect buffer. */
+ glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
+
+ GLenum gl_type = to_gl(prim_type);
+ if (elem) {
+ const GLIndexBuf *el = this->elem_();
+ GLenum index_type = to_gl(el->index_type_);
+ glDrawElementsIndirect(gl_type, index_type, (GLvoid *)nullptr);
+ }
+ else {
+ glDrawArraysIndirect(gl_type, (GLvoid *)nullptr);
+ }
+ /* Unbind. */
+ glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
+}
+
/** \} */