Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/opengl/gl_drawlist.cc
| Show All 21 Lines | |||||
| * | * | ||||
| * Implementation of Multi Draw Indirect using OpenGL. | * Implementation of Multi Draw Indirect using OpenGL. | ||||
| * Fallback if the needed extensions are not supported. | * Fallback if the needed extensions are not supported. | ||||
| */ | */ | ||||
| #include "BLI_assert.h" | #include "BLI_assert.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_extensions.h" | #include "GPU_capabilities.h" | ||||
| #include "glew-mx.h" | #include "glew-mx.h" | ||||
| #include "gpu_context_private.hh" | #include "gpu_context_private.hh" | ||||
| #include "gpu_drawlist_private.hh" | #include "gpu_drawlist_private.hh" | ||||
| #include "gpu_vertex_buffer_private.hh" | #include "gpu_vertex_buffer_private.hh" | ||||
| #include "gl_backend.hh" | #include "gl_backend.hh" | ||||
| Show All 32 Lines | GLDrawList::GLDrawList(int length) | ||||
| buffer_id_ = 0; | buffer_id_ = 0; | ||||
| command_len_ = 0; | command_len_ = 0; | ||||
| command_offset_ = 0; | command_offset_ = 0; | ||||
| data_offset_ = 0; | data_offset_ = 0; | ||||
| data_size_ = 0; | data_size_ = 0; | ||||
| data_ = NULL; | data_ = NULL; | ||||
| if (USE_MULTI_DRAW_INDIRECT && GLEW_ARB_multi_draw_indirect && | if (USE_MULTI_DRAW_INDIRECT && GLEW_ARB_multi_draw_indirect && | ||||
| GPU_arb_base_instance_is_supported()) { | GLContext::base_instance_support) { | ||||
| /* Alloc the biggest possible command list, which is indexed. */ | /* Alloc the biggest possible command list, which is indexed. */ | ||||
| buffer_size_ = sizeof(GLDrawCommandIndexed) * length; | buffer_size_ = sizeof(GLDrawCommandIndexed) * length; | ||||
| } | } | ||||
| else { | else { | ||||
| /* Indicates MDI is not supported. */ | /* Indicates MDI is not supported. */ | ||||
| buffer_size_ = 0; | buffer_size_ = 0; | ||||
| } | } | ||||
| } | } | ||||
| GLDrawList::~GLDrawList() | GLDrawList::~GLDrawList() | ||||
| { | { | ||||
| /* TODO This ... */ | GLContext::buf_free(buffer_id_); | ||||
| static_cast<GLBackend *>(GPUBackend::get())->buf_free(buffer_id_); | |||||
| /* ... should be this. */ | |||||
| // context_->buf_free(buffer_id_) | |||||
| } | } | ||||
| void GLDrawList::init(void) | void GLDrawList::init(void) | ||||
| { | { | ||||
| BLI_assert(GPU_context_active_get()); | BLI_assert(GPU_context_active_get()); | ||||
| BLI_assert(MDI_ENABLED); | BLI_assert(MDI_ENABLED); | ||||
| BLI_assert(data_ == NULL); | BLI_assert(data_ == NULL); | ||||
| batch_ = NULL; | batch_ = NULL; | ||||
| Show All 31 Lines | void GLDrawList::append(GPUBatch *gpu_batch, int i_first, int i_count) | ||||
| } | } | ||||
| GLBatch *batch = static_cast<GLBatch *>(gpu_batch); | GLBatch *batch = static_cast<GLBatch *>(gpu_batch); | ||||
| if (batch != batch_) { | if (batch != batch_) { | ||||
| // BLI_assert(batch->flag | GPU_BATCH_INIT); | // BLI_assert(batch->flag | GPU_BATCH_INIT); | ||||
| this->submit(); | this->submit(); | ||||
| batch_ = batch; | batch_ = batch; | ||||
| /* Cached for faster access. */ | /* Cached for faster access. */ | ||||
| GLIndexBuf *el = batch_->gl_elem(); | GLIndexBuf *el = batch_->elem_(); | ||||
| base_index_ = el ? el->index_base_ : UINT_MAX; | base_index_ = el ? el->index_base_ : UINT_MAX; | ||||
| v_first_ = el ? el->index_start_ : 0; | v_first_ = el ? el->index_start_ : 0; | ||||
| v_count_ = el ? el->index_len_ : batch->verts[0]->vertex_len; | v_count_ = el ? el->index_len_ : batch->verts_(0)->vertex_len; | ||||
| } | } | ||||
| if (v_count_ == 0) { | if (v_count_ == 0) { | ||||
| /* Nothing to draw. */ | /* Nothing to draw. */ | ||||
| return; | return; | ||||
| } | } | ||||
| if (MDI_INDEXED) { | if (MDI_INDEXED) { | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (command_len_ > 2 || is_finishing_a_buffer) { | ||||
| glFlushMappedBufferRange(GL_DRAW_INDIRECT_BUFFER, 0, command_offset_); | glFlushMappedBufferRange(GL_DRAW_INDIRECT_BUFFER, 0, command_offset_); | ||||
| glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER); | glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER); | ||||
| data_ = NULL; /* Unmapped */ | data_ = NULL; /* Unmapped */ | ||||
| data_offset_ += command_offset_; | data_offset_ += command_offset_; | ||||
| batch_->bind(0); | batch_->bind(0); | ||||
| if (MDI_INDEXED) { | if (MDI_INDEXED) { | ||||
| GLenum gl_type = to_gl(batch_->gl_elem()->index_type_); | GLenum gl_type = to_gl(batch_->elem_()->index_type_); | ||||
| glMultiDrawElementsIndirect(prim, gl_type, offset, command_len_, 0); | glMultiDrawElementsIndirect(prim, gl_type, offset, command_len_, 0); | ||||
| } | } | ||||
| else { | else { | ||||
| glMultiDrawArraysIndirect(prim, offset, command_len_, 0); | glMultiDrawArraysIndirect(prim, offset, command_len_, 0); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Fallback do simple drawcalls, and don't unmap the buffer. */ | /* Fallback do simple drawcalls, and don't unmap the buffer. */ | ||||
| Show All 26 Lines | |||||