diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 299f8cf6c..a3d426e0b 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -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. diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index d0d223c4e..3fd065bf7 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -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, diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 13333973b..bfc7df5e3 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -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. diff --git a/src/topology.cpp b/src/topology.cpp index ba7683c73..52dd572ec 100644 --- a/src/topology.cpp +++ b/src/topology.cpp @@ -37,6 +37,37 @@ namespace bgfx return _numIndices; } + inline bool isEven(uint32_t _num) + { + return 0 == (_num & 1); + } + + template + 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 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) {