From 3a7e9ff7cd7bb370d667b27abaa8d61421a40354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 23 Jan 2015 22:40:04 -0800 Subject: [PATCH] Fixed transient buffer alignment. --- include/bgfx.h | 2 +- src/bgfx.cpp | 2 +- src/bgfx_p.h | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/bgfx.h b/include/bgfx.h index 1a8059cb0..8a01ff615 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 3f2a64387..9435ead64 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 4e6725585..f81403411 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;