From 74fb466e92a76d8cc1c813bbf74efe02ad401f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 14 Apr 2015 17:01:35 -0700 Subject: [PATCH] Fixed issue #308. --- examples/05-instancing/instancing.cpp | 8 ++++---- src/bgfx_p.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/05-instancing/instancing.cpp b/examples/05-instancing/instancing.cpp index 40b180ea..bac9b685 100644 --- a/examples/05-instancing/instancing.cpp +++ b/examples/05-instancing/instancing.cpp @@ -132,7 +132,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) { float at[3] = { 0.0f, 0.0f, 0.0f }; float eye[3] = { 0.0f, 0.0f, -35.0f }; - + // Set view and projection matrix for view 0. const bgfx::HMD* hmd = bgfx::getHMD(); if (NULL != hmd) @@ -171,9 +171,9 @@ int _main_(int /*_argc*/, char** /*_argv*/) uint8_t* data = idb->data; // Write instance data for 11x11 cubes. - for (uint32_t yy = 0; yy < 11; ++yy) + for (uint32_t yy = 0, numInstances = 0; yy < 11 && numInstances < idb->num; ++yy) { - for (uint32_t xx = 0; xx < 11; ++xx) + for (uint32_t xx = 0; xx < 11 && numInstances < idb->num; ++xx, ++numInstances) { float* mtx = (float*)data; bx::mtxRotateXY(mtx, time + xx*0.21f, time + yy*0.37f); @@ -209,7 +209,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) } } - // Advance to next frame. Rendering thread will be kicked to + // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. bgfx::frame(); } diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 56fe538d..67524d0c 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1478,8 +1478,8 @@ namespace bgfx uint32_t allocTransientIndexBuffer(uint32_t& _num) { - uint32_t offset = m_iboffset; - m_iboffset = offset + (_num+1)*sizeof(uint16_t); + uint32_t offset = bx::strideAlign(m_iboffset, sizeof(uint16_t) ); + m_iboffset = offset + _num*sizeof(uint16_t); m_iboffset = bx::uint32_min(m_iboffset, BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); _num = (m_iboffset-offset)/sizeof(uint16_t); return offset; @@ -1497,7 +1497,7 @@ namespace bgfx uint32_t allocTransientVertexBuffer(uint32_t& _num, uint16_t _stride) { uint32_t offset = bx::strideAlign(m_vboffset, _stride); - m_vboffset = offset + (_num+1) * _stride; + m_vboffset = offset + _num * _stride; m_vboffset = bx::uint32_min(m_vboffset, BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE); _num = (m_vboffset-offset)/_stride; return offset; @@ -2087,7 +2087,7 @@ namespace bgfx { DynamicIndexBufferHandle handle = BGFX_INVALID_HANDLE; const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; - uint32_t size = BX_ALIGN_16( (_num+1)*indexSize); + uint32_t size = BX_ALIGN_16(_num*indexSize); uint64_t ptr = 0; if (0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE) ) @@ -2236,7 +2236,7 @@ namespace bgfx BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint8_t _flags) ) { DynamicVertexBufferHandle handle = BGFX_INVALID_HANDLE; - uint32_t size = bx::strideAlign16( (_num+1)*_decl.m_stride, _decl.m_stride); + uint32_t size = bx::strideAlign16(_num*_decl.m_stride, _decl.m_stride); uint64_t ptr = 0; if (0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE) )