From 937da03f04b83f6aaf38adc2733b7f788abc305d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 13 Mar 2016 18:13:10 -0700 Subject: [PATCH] GL: Added orphaning buffers to avoid transient buffer stalls. Issue #706. --- src/renderer_gl.cpp | 4 ++-- src/renderer_gl.h | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 82b87e459..cd750514f 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -5383,13 +5383,13 @@ namespace bgfx { namespace gl if (0 < _render->m_iboffset) { TransientIndexBuffer* ib = _render->m_transientIb; - m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data); + m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true); } if (0 < _render->m_vboffset) { TransientVertexBuffer* vb = _render->m_transientVb; - m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data); + m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true); } _render->sort(); diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 884cc614c..511897afa 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -1058,9 +1058,17 @@ namespace bgfx { namespace gl GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) ); } - void update(uint32_t _offset, uint32_t _size, void* _data) + void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false) { BX_CHECK(0 != m_id, "Updating invalid index buffer."); + + if (_discard) + { + // orphan buffer... + destroy(); + create(m_size, NULL, m_flags); + } + GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) ); GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER , _offset @@ -1104,9 +1112,17 @@ namespace bgfx { namespace gl GL_CHECK(glBindBuffer(m_target, 0) ); } - void update(uint32_t _offset, uint32_t _size, void* _data) + void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false) { BX_CHECK(0 != m_id, "Updating invalid vertex buffer."); + + if (_discard) + { + // orphan buffer... + destroy(); + create(m_size, NULL, m_decl, 0); + } + GL_CHECK(glBindBuffer(m_target, m_id) ); GL_CHECK(glBufferSubData(m_target , _offset