Added offset for updating dynamic buffers.

This commit is contained in:
Branimir Karadžić 2015-06-23 16:40:38 -07:00
parent 3eb0659898
commit f36bfe2e4f
5 changed files with 27 additions and 20 deletions

View file

@ -793,10 +793,12 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
vbh.idx = bc.vertexBufferHandleIdx;
bgfx::updateDynamicIndexBuffer(ibh
, 0
, bgfx::copy(bc.textBuffer->getIndexBuffer(), indexSize)
);
bgfx::updateDynamicVertexBuffer(vbh
, 0
, bgfx::copy(bc.textBuffer->getVertexBuffer(), vertexSize)
);
}

View file

@ -482,7 +482,7 @@ BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(u
BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags);
/**/
BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, const bgfx_memory_t* _mem);
BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem);
/**/
BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle);
@ -494,7 +494,7 @@ BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer
BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags);
/**/
BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, const bgfx_memory_t* _mem);
BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem);
/**/
BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle);

View file

@ -776,11 +776,12 @@ namespace bgfx
/// Update dynamic index buffer.
///
/// @param _handle Dynamic index buffer handle.
/// @param _startIndex Start index.
/// @param _mem Index buffer data.
///
/// @attention C99 equivalent is `bgfx_update_dynamic_index_buffer`.
///
void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem);
void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _startIndex, const Memory* _mem);
/// Destroy dynamic index buffer.
///
@ -834,9 +835,13 @@ namespace bgfx
/// Update dynamic vertex buffer.
///
/// @param _handle Dynamic vertex buffer handle.
/// @param _startVertex Start vertex.
/// @param _mem Vertex buffer data.
///
/// @attention C99 equivalent is `bgfx_update_dynamic_vertex_buffer`.
///
void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem);
void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, const Memory* _mem);
/// Destroy dynamic vertex buffer.
///

View file

@ -2220,11 +2220,11 @@ again:
return s_ctx->createDynamicIndexBuffer(_mem, _flags);
}
void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem)
void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _startIndex, const Memory* _mem)
{
BGFX_CHECK_MAIN_THREAD();
BX_CHECK(NULL != _mem, "_mem can't be NULL");
s_ctx->updateDynamicIndexBuffer(_handle, _mem);
s_ctx->updateDynamicIndexBuffer(_handle, _startIndex, _mem);
}
void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle)
@ -2248,11 +2248,11 @@ again:
return s_ctx->createDynamicVertexBuffer(_mem, _decl, _flags);
}
void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem)
void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, const Memory* _mem)
{
BGFX_CHECK_MAIN_THREAD();
BX_CHECK(NULL != _mem, "_mem can't be NULL");
s_ctx->updateDynamicVertexBuffer(_handle, _mem);
s_ctx->updateDynamicVertexBuffer(_handle, _startVertex, _mem);
}
void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle)
@ -3342,10 +3342,10 @@ BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_m
return handle.c;
}
BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, const bgfx_memory_t* _mem)
BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem)
{
union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle };
bgfx::updateDynamicIndexBuffer(handle.cpp, (const bgfx::Memory*)_mem);
bgfx::updateDynamicIndexBuffer(handle.cpp, _startIndex, (const bgfx::Memory*)_mem);
}
BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle)
@ -3370,10 +3370,10 @@ BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer
return handle.c;
}
BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, const bgfx_memory_t* _mem)
BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem)
{
union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle };
bgfx::updateDynamicVertexBuffer(handle.cpp, (const bgfx::Memory*)_mem);
bgfx::updateDynamicVertexBuffer(handle.cpp, _startVertex, (const bgfx::Memory*)_mem);
}
BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle)

View file

@ -2159,12 +2159,12 @@ namespace bgfx
DynamicIndexBufferHandle handle = createDynamicIndexBuffer(_mem->size/indexSize, _flags);
if (isValid(handle) )
{
updateDynamicIndexBuffer(handle, _mem);
updateDynamicIndexBuffer(handle, 0, _mem);
}
return handle;
}
BGFX_API_FUNC(void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem) )
BGFX_API_FUNC(void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _startIndex, const Memory* _mem) )
{
BGFX_CHECK_HANDLE("updateDynamicIndexBuffer", m_dynamicIndexBufferHandle, _handle);
@ -2185,8 +2185,8 @@ namespace bgfx
dib.m_startIndex = bx::strideAlign(dib.m_offset, indexSize)/indexSize;
}
uint32_t offset = dib.m_startIndex*indexSize;
uint32_t size = bx::uint32_min(dib.m_size, _mem->size);
uint32_t offset = (dib.m_startIndex + _startIndex)*indexSize;
uint32_t size = bx::uint32_min(bx::uint32_satsub(dib.m_size, _startIndex*indexSize), _mem->size);
BX_CHECK(_mem->size <= size, "Truncating dynamic index buffer update (size %d, mem size %d)."
, size
, _mem->size
@ -2308,12 +2308,12 @@ namespace bgfx
DynamicVertexBufferHandle handle = createDynamicVertexBuffer(uint16_t(numVertices), _decl, _flags);
if (isValid(handle) )
{
updateDynamicVertexBuffer(handle, _mem);
updateDynamicVertexBuffer(handle, 0, _mem);
}
return handle;
}
BGFX_API_FUNC(void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem) )
BGFX_API_FUNC(void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, const Memory* _mem) )
{
BGFX_CHECK_HANDLE("updateDynamicVertexBuffer", m_dynamicVertexBufferHandle, _handle);
@ -2333,8 +2333,8 @@ namespace bgfx
dvb.m_startVertex = bx::strideAlign(dvb.m_offset, dvb.m_stride)/dvb.m_stride;
}
uint32_t offset = dvb.m_startVertex*dvb.m_stride;
uint32_t size = bx::uint32_min(dvb.m_size, _mem->size);
uint32_t offset = (dvb.m_startVertex + _startVertex)*dvb.m_stride;
uint32_t size = bx::uint32_min(bx::uint32_satsub(dvb.m_size, _startVertex*dvb.m_stride), _mem->size);
BX_CHECK(_mem->size <= size, "Truncating dynamic vertex buffer update (size %d, mem size %d)."
, dvb.m_size
, _mem->size