Fixed issue #239.

This commit is contained in:
Branimir Karadžić 2015-01-23 22:18:07 -08:00
parent 938c1a0e92
commit 2764d9d2aa

View file

@ -1179,6 +1179,7 @@ namespace bgfx
IndexBufferHandle m_handle; IndexBufferHandle m_handle;
uint32_t m_offset; uint32_t m_offset;
uint32_t m_size; uint32_t m_size;
uint32_t m_startIndex;
}; };
struct DynamicVertexBuffer struct DynamicVertexBuffer
@ -1331,6 +1332,13 @@ namespace bgfx
m_draw.m_indexBuffer = _handle; m_draw.m_indexBuffer = _handle;
} }
void setIndexBuffer(const DynamicIndexBuffer& _dib, uint32_t _firstIndex, uint32_t _numIndices)
{
m_draw.m_startIndex = _dib.m_startIndex + _firstIndex;
m_draw.m_numIndices = bx::uint32_min(_numIndices, _dib.m_size/2);
m_draw.m_indexBuffer = _dib.m_handle;
}
void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices)
{ {
m_draw.m_indexBuffer = _tib->handle; m_draw.m_indexBuffer = _tib->handle;
@ -2006,7 +2014,7 @@ namespace bgfx
m_vertexBufferHandle.free(_handle.idx); m_vertexBufferHandle.free(_handle.idx);
} }
BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint8_t _flags)) BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint8_t _flags) )
{ {
DynamicIndexBufferHandle handle = BGFX_INVALID_HANDLE; DynamicIndexBufferHandle handle = BGFX_INVALID_HANDLE;
uint32_t size = BX_ALIGN_16(_num*2); uint32_t size = BX_ALIGN_16(_num*2);
@ -2060,6 +2068,7 @@ namespace bgfx
dib.m_handle.idx = uint16_t(ptr>>32); dib.m_handle.idx = uint16_t(ptr>>32);
dib.m_offset = uint32_t(ptr); dib.m_offset = uint32_t(ptr);
dib.m_size = size; dib.m_size = size;
dib.m_startIndex = strideAlign(dib.m_offset, 2)/2;
return handle; return handle;
} }
@ -2099,7 +2108,7 @@ namespace bgfx
BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint16_t _num, const VertexDecl& _decl, uint8_t _flags) ) BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint16_t _num, const VertexDecl& _decl, uint8_t _flags) )
{ {
DynamicVertexBufferHandle handle = BGFX_INVALID_HANDLE; DynamicVertexBufferHandle handle = BGFX_INVALID_HANDLE;
uint32_t size = strideAlign16(_num*_decl.m_stride, _decl.m_stride); uint32_t size = strideAlign16( (_num+1)*_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) )
@ -2147,7 +2156,7 @@ namespace bgfx
dvb.m_handle.idx = uint16_t(ptr>>32); dvb.m_handle.idx = uint16_t(ptr>>32);
dvb.m_offset = uint32_t(ptr); dvb.m_offset = uint32_t(ptr);
dvb.m_size = size; dvb.m_size = size;
dvb.m_startVertex = dvb.m_offset/_decl.m_stride; dvb.m_startVertex = strideAlign(dvb.m_offset, _decl.m_stride)/_decl.m_stride;
dvb.m_numVertices = dvb.m_size/_decl.m_stride; dvb.m_numVertices = dvb.m_size/_decl.m_stride;
dvb.m_stride = _decl.m_stride; dvb.m_stride = _decl.m_stride;
dvb.m_decl = declHandle; dvb.m_decl = declHandle;
@ -2990,11 +2999,7 @@ namespace bgfx
BGFX_API_FUNC(void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) ) BGFX_API_FUNC(void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) )
{ {
const DynamicIndexBuffer& dib = m_dynamicIndexBuffers[_handle.idx]; m_submit->setIndexBuffer(m_dynamicIndexBuffers[_handle.idx], _firstIndex, _numIndices);
m_submit->setIndexBuffer(dib.m_handle
, dib.m_offset / 2 + _firstIndex * 2
, _numIndices
);
} }
BGFX_API_FUNC(void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) ) BGFX_API_FUNC(void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) )
@ -3002,9 +3007,9 @@ namespace bgfx
m_submit->setIndexBuffer(_tib, _firstIndex, _numIndices); m_submit->setIndexBuffer(_tib, _firstIndex, _numIndices);
} }
BGFX_API_FUNC(void setVertexBuffer(VertexBufferHandle _handle, uint32_t _numVertices, uint32_t _startVertex) ) BGFX_API_FUNC(void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) )
{ {
m_submit->setVertexBuffer(_handle, _numVertices, _startVertex); m_submit->setVertexBuffer(_handle, _startVertex, _numVertices);
} }
BGFX_API_FUNC(void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices) ) BGFX_API_FUNC(void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices) )