diff --git a/include/bgfx.h b/include/bgfx.h index 1a8059cb..8a01ff61 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -324,8 +324,8 @@ namespace bgfx { uint8_t* data; uint32_t size; - IndexBufferHandle handle; uint32_t startIndex; + IndexBufferHandle handle; }; /// diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 3f2a6438..9435ead6 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2746,7 +2746,7 @@ again: { BGFX_CHECK_MAIN_THREAD(); BX_CHECK(NULL != _tvb, "_tvb can't be NULL"); - s_ctx->setVertexBuffer(_tvb, _tvb->startVertex + _startVertex, _numVertices); + s_ctx->setVertexBuffer(_tvb, _startVertex, _numVertices); } void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _num) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 4e672558..f8140341 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1365,7 +1365,7 @@ namespace bgfx void setVertexBuffer(const TransientVertexBuffer* _tvb, uint32_t _startVertex, uint32_t _numVertices) { - m_draw.m_startVertex = _startVertex; + m_draw.m_startVertex = _tvb->startVertex + _startVertex; m_draw.m_numVertices = bx::uint32_min(_tvb->size/_tvb->stride, _numVertices); m_draw.m_vertexBuffer = _tvb->handle; m_draw.m_vertexDecl = _tvb->decl; @@ -2017,7 +2017,7 @@ namespace bgfx BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint8_t _flags) ) { DynamicIndexBufferHandle handle = BGFX_INVALID_HANDLE; - uint32_t size = BX_ALIGN_16(_num*2); + uint32_t size = BX_ALIGN_16( (_num+1)*2); uint64_t ptr = 0; if (0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE)) @@ -2334,8 +2334,8 @@ namespace bgfx uint32_t offset = m_submit->allocTransientVertexBuffer(_num, _decl.m_stride); _tvb->data = &dvb.data[offset]; - _tvb->size = _num * _decl.m_stride; - _tvb->startVertex = offset/_decl.m_stride; + _tvb->size = (_num+1) * _decl.m_stride; + _tvb->startVertex = strideAlign(offset, _decl.m_stride)/_decl.m_stride; _tvb->stride = _decl.m_stride; _tvb->handle = dvb.handle; _tvb->decl = declHandle;