Add stride to set instance buffer

This commit is contained in:
falia18 2024-03-03 15:08:52 +01:00
parent 35000c56a5
commit 6bec22adb2
2 changed files with 39 additions and 11 deletions

View File

@ -1452,13 +1452,15 @@ namespace bgfx
/// @param[in] _handle Vertex buffer.
/// @param[in] _offset Offset of first instance data.
/// @param[in] _num Number of data instances.
/// @param[in] _stride Instance stride. Must be multiple of 16.
///
/// @attention C99's equivalent binding is `TODO`.
/// @attention C99's equivalent binding is `bgfx_encoder_set_instance_data_with_offset_from_vertex_buffer`.
///
void setInstanceDataBufferWithOffset(
VertexBufferHandle _handle
, uint32_t _offset
, uint32_t _num
, uint16_t _stride
);
@ -1481,13 +1483,15 @@ namespace bgfx
/// @param[in] _handle Vertex buffer.
/// @param[in] _offset Offset of first instance data.
/// @param[in] _num Number of data instances.
/// @param[in] _stride Instance stride. Must be multiple of 16.
///
/// @attention C99's equivalent binding is `TODO`.
/// @attention C99's equivalent binding is `bgfx_encoder_set_instance_data_with_offset_from_dynamic_vertex_buffer`.
///
void setInstanceDataBufferWithOffset(
DynamicVertexBufferHandle _handle
, uint32_t _offset
, uint32_t _num
, uint16_t _stride
);
/// Set number of instances for auto generated instances use in conjunction
@ -2636,6 +2640,19 @@ namespace bgfx
, uint16_t _stride
);
/// Returns number of requested or maximum available instance buffer bytes.
///
/// @param[in] _size Size of required instance buffer.
/// @param[in] _stride Stride per instance.
///
/// @attention C99's equivalent binding is `bgfx_get_avail_instance_data_buffer_size`.
///
uint32_t getAvailInstanceDataBufferSize(
uint32_t _size
, uint16_t _stride
);
/// Allocate transient index buffer.
///
/// @param[out] _tib TransientIndexBuffer structure will be filled, and will be valid
@ -4053,6 +4070,7 @@ namespace bgfx
/// @param[in] _handle Vertex buffer.
/// @param[in] _offset Offset of first instance data.
/// @param[in] _num Number of data instances.
/// @param[in] _stride Instance stride. Must be multiple of 16.
///
/// @attention C99's equivalent binding is `bgfx_set_instance_data_from_vertex_buffer`.
///
@ -4060,6 +4078,7 @@ namespace bgfx
VertexBufferHandle _handle
, uint32_t _offset
, uint32_t _num
, uint16_t _stride
);
/// Set instance data buffer for draw primitive.
@ -4081,6 +4100,7 @@ namespace bgfx
/// @param[in] _handle Vertex buffer.
/// @param[in] _offset Offset of first instance data.
/// @param[in] _num Number of data instances.
/// @param[in] _stride Instance stride. Must be multiple of 16.
///
/// @attention C99's equivalent binding is `bgfx_set_instance_data_from_dynamic_vertex_buffer`.
///
@ -4088,6 +4108,7 @@ namespace bgfx
DynamicVertexBufferHandle _handle
, uint32_t _offset
, uint32_t _num
, uint16_t _stride
);
/// Set number of instances for auto generated instances use in conjunction

View File

@ -3861,11 +3861,11 @@ namespace bgfx
BGFX_ENCODER(setInstanceDataBuffer(_handle, _startVertex * vb.m_stride, _num, vb.m_stride) );
}
void Encoder::setInstanceDataBufferWithOffset(VertexBufferHandle _handle, uint32_t _offset, uint32_t _num)
void Encoder::setInstanceDataBufferWithOffset(VertexBufferHandle _handle, uint32_t _offset, uint32_t _num, uint16_t _stride)
{
BGFX_CHECK_HANDLE("setInstanceDataBuffer", s_ctx->m_vertexBufferHandle, _handle);
const VertexBuffer& vb = s_ctx->m_vertexBuffers[_handle.idx];
BGFX_ENCODER(setInstanceDataBuffer(_handle, _offset, _num, vb.m_stride));
BX_ASSERT(bx::isAligned(_stride, 16), "Stride must be multiple of 16.");
BGFX_ENCODER(setInstanceDataBuffer(_handle, _offset, _num, _stride));
}
void Encoder::setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num)
@ -3879,14 +3879,15 @@ namespace bgfx
) );
}
void Encoder::setInstanceDataBufferWithOffset(DynamicVertexBufferHandle _handle, uint32_t _offset, uint32_t _num)
void Encoder::setInstanceDataBufferWithOffset(DynamicVertexBufferHandle _handle, uint32_t _offset, uint32_t _num, uint16_t _stride)
{
BGFX_CHECK_HANDLE("setInstanceDataBuffer", s_ctx->m_dynamicVertexBufferHandle, _handle);
BX_ASSERT(bx::isAligned(_stride, 16), "Stride must be multiple of 16.");
const DynamicVertexBuffer& dvb = s_ctx->m_dynamicVertexBuffers[_handle.idx];
BGFX_ENCODER(setInstanceDataBuffer(dvb.m_handle
, dvb.m_startOffset + _offset
, _num
, dvb.m_stride
, _stride
));
}
@ -4345,6 +4346,12 @@ namespace bgfx
return s_ctx->getAvailTransientVertexBuffer(_num * _stride, _stride) / _stride;
}
uint32_t getAvailInstanceDataBufferSize(uint32_t _size, uint16_t _stride)
{
BX_ASSERT(0 < _size, "Requesting 0 bytes.");
return s_ctx->getAvailTransientVertexBuffer(_size, _stride);
}
void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num, bool _index32)
{
BX_ASSERT(NULL != _tib, "_tib can't be NULL");
@ -5561,10 +5568,10 @@ namespace bgfx
s_ctx->m_encoder0->setInstanceDataBuffer(_handle, _startVertex, _num);
}
void setInstanceDataBufferWithOffset(VertexBufferHandle _handle, uint32_t _offset, uint32_t _num)
void setInstanceDataBufferWithOffset(VertexBufferHandle _handle, uint32_t _offset, uint32_t _num, uint16_t _stride)
{
BGFX_CHECK_ENCODER0();
s_ctx->m_encoder0->setInstanceDataBufferWithOffset(_handle, _offset, _num);
s_ctx->m_encoder0->setInstanceDataBufferWithOffset(_handle, _offset, _num, _stride);
}
void setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num)
@ -5573,10 +5580,10 @@ namespace bgfx
s_ctx->m_encoder0->setInstanceDataBuffer(_handle, _startVertex, _num);
}
void setInstanceDataBufferWithOffset(DynamicVertexBufferHandle _handle, uint32_t _offset, uint32_t _num)
void setInstanceDataBufferWithOffset(DynamicVertexBufferHandle _handle, uint32_t _offset, uint32_t _num, uint16_t _stride)
{
BGFX_CHECK_ENCODER0();
s_ctx->m_encoder0->setInstanceDataBufferWithOffset(_handle, _offset, _num);
s_ctx->m_encoder0->setInstanceDataBufferWithOffset(_handle, _offset, _num, _stride);
}
void setInstanceCount(uint32_t _numInstances)