diff options
Diffstat (limited to 'source/blender/gpu/opengl/gl_drawlist.cc')
-rw-r--r-- | source/blender/gpu/opengl/gl_drawlist.cc | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/source/blender/gpu/opengl/gl_drawlist.cc b/source/blender/gpu/opengl/gl_drawlist.cc index 35fecc859b8..9670e580819 100644 --- a/source/blender/gpu/opengl/gl_drawlist.cc +++ b/source/blender/gpu/opengl/gl_drawlist.cc @@ -42,15 +42,6 @@ #define USE_MULTI_DRAW_INDIRECT 1 -/* TODO remove. */ -#if GPU_TRACK_INDEX_RANGE -# define BASE_INDEX(el) ((el)->base_index) -# define INDEX_TYPE(el) ((el)->gl_index_type) -#else -# define BASE_INDEX(el) 0 -# define INDEX_TYPE(el) GL_UNSIGNED_INT -#endif - using namespace blender::gpu; typedef struct GLDrawCommand { @@ -129,11 +120,11 @@ void GLDrawList::init(void) command_offset_ = 0; } -void GLDrawList::append(GPUBatch *batch, int i_first, int i_count) +void GLDrawList::append(GPUBatch *gpu_batch, int i_first, int i_count) { /* Fallback when MultiDrawIndirect is not supported/enabled. */ if (MDI_DISABLED) { - GPU_batch_draw_advanced(batch, 0, 0, i_first, i_count); + GPU_batch_draw_advanced(gpu_batch, 0, 0, i_first, i_count); return; } @@ -141,14 +132,16 @@ void GLDrawList::append(GPUBatch *batch, int i_first, int i_count) this->init(); } + GLBatch *batch = static_cast<GLBatch *>(gpu_batch); if (batch != batch_) { // BLI_assert(batch->flag | GPU_BATCH_INIT); this->submit(); batch_ = batch; /* Cached for faster access. */ - base_index_ = batch->elem ? BASE_INDEX(batch->elem) : UINT_MAX; - v_first_ = batch->elem ? batch->elem->index_start : 0; - v_count_ = batch->elem ? batch->elem->index_len : batch->verts[0]->vertex_len; + GLIndexBuf *el = batch_->gl_elem(); + base_index_ = el ? el->index_base_ : UINT_MAX; + v_first_ = el ? el->index_start_ : 0; + v_count_ = el ? el->index_len_ : batch->verts[0]->vertex_len; } if (v_count_ == 0) { @@ -191,12 +184,9 @@ void GLDrawList::submit(void) BLI_assert(data_); BLI_assert(GPU_context_active_get()->shader != NULL); - GLBatch *batch = static_cast<GLBatch *>(batch_); - /* Only do multi-draw indirect if doing more than 2 drawcall. This avoids the overhead of * buffer mapping if scene is not very instance friendly. BUT we also need to take into - * account the - * case where only a few instances are needed to finish filling a call buffer. */ + * account the case where only a few instances are needed to finish filling a call buffer. */ const bool is_finishing_a_buffer = (command_offset_ >= data_size_); if (command_len_ > 2 || is_finishing_a_buffer) { GLenum prim = to_gl(batch_->prim_type); @@ -208,10 +198,11 @@ void GLDrawList::submit(void) data_ = NULL; /* Unmapped */ data_offset_ += command_offset_; - batch->bind(0); + batch_->bind(0); if (MDI_INDEXED) { - glMultiDrawElementsIndirect(prim, INDEX_TYPE(batch_->elem), offset, command_len_, 0); + GLenum gl_type = to_gl(batch_->gl_elem()->index_type_); + glMultiDrawElementsIndirect(prim, gl_type, offset, command_len_, 0); } else { glMultiDrawArraysIndirect(prim, offset, command_len_, 0); @@ -223,8 +214,8 @@ void GLDrawList::submit(void) GLDrawCommandIndexed *cmd = (GLDrawCommandIndexed *)data_; for (int i = 0; i < command_len_; i++, cmd++) { /* Index start was already added. Avoid counting it twice. */ - cmd->v_first -= batch->elem->index_start; - batch->draw(cmd->v_first, cmd->v_count, cmd->i_first, cmd->i_count); + cmd->v_first -= v_first_; + batch_->draw(cmd->v_first, cmd->v_count, cmd->i_first, cmd->i_count); } /* Reuse the same data. */ command_offset_ -= command_len_ * sizeof(GLDrawCommandIndexed); @@ -232,7 +223,7 @@ void GLDrawList::submit(void) else { GLDrawCommand *cmd = (GLDrawCommand *)data_; for (int i = 0; i < command_len_; i++, cmd++) { - batch->draw(cmd->v_first, cmd->v_count, cmd->i_first, cmd->i_count); + batch_->draw(cmd->v_first, cmd->v_count, cmd->i_first, cmd->i_count); } /* Reuse the same data. */ command_offset_ -= command_len_ * sizeof(GLDrawCommand); |