Fixed issue #308.

This commit is contained in:
Branimir Karadžić 2015-04-14 17:01:35 -07:00
parent bff3ae937c
commit 74fb466e92
2 changed files with 9 additions and 9 deletions

View file

@ -132,7 +132,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
{ {
float at[3] = { 0.0f, 0.0f, 0.0f }; float at[3] = { 0.0f, 0.0f, 0.0f };
float eye[3] = { 0.0f, 0.0f, -35.0f }; float eye[3] = { 0.0f, 0.0f, -35.0f };
// Set view and projection matrix for view 0. // Set view and projection matrix for view 0.
const bgfx::HMD* hmd = bgfx::getHMD(); const bgfx::HMD* hmd = bgfx::getHMD();
if (NULL != hmd) if (NULL != hmd)
@ -171,9 +171,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
uint8_t* data = idb->data; uint8_t* data = idb->data;
// Write instance data for 11x11 cubes. // 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; float* mtx = (float*)data;
bx::mtxRotateXY(mtx, time + xx*0.21f, time + yy*0.37f); 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. // process submitted rendering primitives.
bgfx::frame(); bgfx::frame();
} }

View file

@ -1478,8 +1478,8 @@ namespace bgfx
uint32_t allocTransientIndexBuffer(uint32_t& _num) uint32_t allocTransientIndexBuffer(uint32_t& _num)
{ {
uint32_t offset = m_iboffset; uint32_t offset = bx::strideAlign(m_iboffset, sizeof(uint16_t) );
m_iboffset = offset + (_num+1)*sizeof(uint16_t); m_iboffset = offset + _num*sizeof(uint16_t);
m_iboffset = bx::uint32_min(m_iboffset, BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE); m_iboffset = bx::uint32_min(m_iboffset, BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE);
_num = (m_iboffset-offset)/sizeof(uint16_t); _num = (m_iboffset-offset)/sizeof(uint16_t);
return offset; return offset;
@ -1497,7 +1497,7 @@ namespace bgfx
uint32_t allocTransientVertexBuffer(uint32_t& _num, uint16_t _stride) uint32_t allocTransientVertexBuffer(uint32_t& _num, uint16_t _stride)
{ {
uint32_t offset = bx::strideAlign(m_vboffset, _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); m_vboffset = bx::uint32_min(m_vboffset, BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE);
_num = (m_vboffset-offset)/_stride; _num = (m_vboffset-offset)/_stride;
return offset; return offset;
@ -2087,7 +2087,7 @@ namespace bgfx
{ {
DynamicIndexBufferHandle handle = BGFX_INVALID_HANDLE; DynamicIndexBufferHandle handle = BGFX_INVALID_HANDLE;
const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; 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; uint64_t ptr = 0;
if (0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE) ) 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) ) BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint8_t _flags) )
{ {
DynamicVertexBufferHandle handle = BGFX_INVALID_HANDLE; 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; uint64_t ptr = 0;
if (0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE) ) if (0 != (_flags & BGFX_BUFFER_COMPUTE_WRITE) )