Jelajahi Sumber

Added topology flip for tristrip.

Branimir Karadžić 7 tahun lalu
induk
melakukan
bc456cdbc9
4 mengubah file dengan 42 tambahan dan 1 penghapusan
  1. 1 0
      include/bgfx/bgfx.h
  2. 1 0
      include/bgfx/c99/bgfx.h
  3. 1 1
      include/bgfx/defines.h
  4. 39 0
      src/topology.cpp

+ 1 - 0
include/bgfx/bgfx.h

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

+ 1 - 0
include/bgfx/c99/bgfx.h

@@ -248,6 +248,7 @@ typedef enum bgfx_topology
 typedef enum bgfx_topology_convert
 typedef enum bgfx_topology_convert
 {
 {
     BGFX_TOPOLOGY_CONVERT_TRI_LIST_FLIP_WINDING,
     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_LIST_TO_LINE_LIST,
     BGFX_TOPOLOGY_CONVERT_TRI_STRIP_TO_TRI_LIST,
     BGFX_TOPOLOGY_CONVERT_TRI_STRIP_TO_TRI_LIST,
     BGFX_TOPOLOGY_CONVERT_LINE_STRIP_TO_LINE_LIST,
     BGFX_TOPOLOGY_CONVERT_LINE_STRIP_TO_LINE_LIST,

+ 1 - 1
include/bgfx/defines.h

@@ -6,7 +6,7 @@
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #define 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.
 /// 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.
 #define BGFX_STATE_WRITE_R                 UINT64_C(0x0000000000000001) //!< Enable R write.

+ 39 - 0
src/topology.cpp

@@ -37,6 +37,37 @@ namespace bgfx
 		return _numIndices;
 		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>
 	template<typename IndexT, typename SortT>
 	static uint32_t topologyConvertTriListToLineList(void* _dst, uint32_t _dstSize, const IndexT* _indices, uint32_t _numIndices, IndexT* _temp, SortT* _tempSort)
 	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);
 			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:
 		case TopologyConvert::TriListToLineList:
 			if (NULL == _allocator)
 			if (NULL == _allocator)
 			{
 			{