Added topology flip for tristrip.

This commit is contained in:
Branimir Karadžić 2018-06-08 16:52:37 -07:00
parent a167dcda12
commit bc456cdbc9
4 changed files with 42 additions and 1 deletions

View File

@ -327,6 +327,7 @@ namespace bgfx
enum Enum
{
TriListFlipWinding, //!< Flip winding order of triangle list.
TriStripFlipWinding, //!< Flip winding order of trinagle strip.
TriListToLineList, //!< Convert triangle list to line list.
TriStripToTriList, //!< Convert triangle strip to triangle list.
LineStripToLineList, //!< Convert line strip to line list.

View File

@ -248,6 +248,7 @@ typedef enum bgfx_topology
typedef enum bgfx_topology_convert
{
BGFX_TOPOLOGY_CONVERT_TRI_LIST_FLIP_WINDING,
BGFX_TOPOLOGY_CONVERT_TRI_STRIP_FLIP_WINDING,
BGFX_TOPOLOGY_CONVERT_TRI_LIST_TO_LINE_LIST,
BGFX_TOPOLOGY_CONVERT_TRI_STRIP_TO_TRI_LIST,
BGFX_TOPOLOGY_CONVERT_LINE_STRIP_TO_LINE_LIST,

View File

@ -6,7 +6,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(69)
#define BGFX_API_VERSION UINT32_C(70)
/// Color RGB/alpha/depth write. When it's not specified write will be disabled.
#define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write.

View File

@ -37,6 +37,37 @@ namespace bgfx
return _numIndices;
}
inline bool isEven(uint32_t _num)
{
return 0 == (_num & 1);
}
template<typename IndexT>
static uint32_t topologyConvertTriStripFlipWinding(void* _dst, uint32_t _dstSize, const IndexT* _indices, uint32_t _numIndices)
{
const uint32_t numIndices = isEven(_numIndices) ? _numIndices + 1 : _numIndices;
if (NULL != _dst)
{
return numIndices;
}
IndexT* dst = (IndexT*)_dst;
IndexT* end = &dst[_dstSize/sizeof(IndexT)];
if (isEven(_numIndices) )
{
*dst++ = _indices[_numIndices-1];
}
for (uint32_t ii = 1; ii <= _numIndices && dst < end; ++ii)
{
*dst++ = _indices[_numIndices - ii];
}
return numIndices;
}
template<typename IndexT, typename SortT>
static uint32_t topologyConvertTriListToLineList(void* _dst, uint32_t _dstSize, const IndexT* _indices, uint32_t _numIndices, IndexT* _temp, SortT* _tempSort)
{
@ -195,6 +226,14 @@ namespace bgfx
return topologyConvertTriListFlipWinding(_dst, _dstSize, (const uint16_t*)_indices, _numIndices);
case TopologyConvert::TriStripFlipWinding:
if (_index32)
{
return topologyConvertTriStripFlipWinding(_dst, _dstSize, (const uint32_t*)_indices, _numIndices);
}
return topologyConvertTriStripFlipWinding(_dst, _dstSize, (const uint16_t*)_indices, _numIndices);
case TopologyConvert::TriListToLineList:
if (NULL == _allocator)
{