From f7060b66eece0f35c41706f532992b7abe63d004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 3 Aug 2016 21:57:56 -0700 Subject: [PATCH] Cleanup. --- include/bgfx/bgfx.h | 39 +++++++++++++++++++++++++++++++++ include/bgfx/bgfxdefines.h | 2 +- include/bgfx/c99/bgfx.h | 25 +++++++++++++++++++++ include/bgfx/c99/bgfxplatform.h | 1 + src/bgfx.cpp | 11 ++++++++++ src/topology.cpp | 28 +++++++++++------------ src/topology.h | 34 +++++----------------------- 7 files changed, 97 insertions(+), 43 deletions(-) diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 35094b102..77005638a 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -312,6 +312,28 @@ namespace bgfx }; }; + /// + struct TopologySort + { + enum Enum + { + DirectionFrontToBackMin, + DirectionFrontToBackAvg, + DirectionFrontToBackMax, + DirectionBackToFrontMin, + DirectionBackToFrontAvg, + DirectionBackToFrontMax, + DistanceFrontToBackMin, + DistanceFrontToBackAvg, + DistanceFrontToBackMax, + DistanceBackToFrontMin, + DistanceBackToFrontAvg, + DistanceBackToFrontMax, + + Count + }; + }; + static const uint16_t invalidHandle = UINT16_MAX; BGFX_HANDLE(DynamicIndexBufferHandle); @@ -830,6 +852,23 @@ namespace bgfx , bool _index32 ); + /// Sort indices. + /// + /// @attention C99 equivalent is `bgfx_topology_sort_tri_list`. + /// + void topologySortTriList( + TopologySort::Enum _sort + , void* _dst + , uint32_t _dstSize + , const float _dir[3] + , const float _pos[3] + , const void* _vertices + , uint32_t _stride + , const void* _indices + , uint32_t _numIndices + , bool _index32 + ); + /// Swizzle RGBA8 image to BGRA8. /// /// @param[in] _width Width of input image (pixels). diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index 1ae0c4332..36e308507 100644 --- a/include/bgfx/bgfxdefines.h +++ b/include/bgfx/bgfxdefines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(16) +#define BGFX_API_VERSION UINT32_C(17) /// #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 222f202f2..c91c5e7ee 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -235,6 +235,25 @@ typedef enum bgfx_topology_convert } bgfx_topology_convert_t; +typedef enum bgfx_topology_sort +{ + BGFX_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_MIN, + BGFX_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_AVG, + BGFX_TOPOLOGY_SORT_DIRECTION_FRONT_TO_BACK_MAX, + BGFX_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_MIN, + BGFX_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_AVG, + BGFX_TOPOLOGY_SORT_DIRECTION_BACK_TO_FRONT_MAX, + BGFX_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_MIN, + BGFX_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_AVG, + BGFX_TOPOLOGY_SORT_DISTANCE_FRONT_TO_BACK_MAX, + BGFX_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_MIN, + BGFX_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_AVG, + BGFX_TOPOLOGY_SORT_DISTANCE_BACK_TO_FRONT_MAX, + + BGFX_TOPOLOGY_SORT_COUNT + +} bgfx_topology_sort_t; + #define BGFX_HANDLE_T(_name) \ typedef struct _name { uint16_t idx; } _name##_t @@ -483,6 +502,12 @@ BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_decl_t* _destDecl, void* _ /**/ BGFX_C_API uint16_t bgfx_weld_vertices(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon); +/**/ +BGFX_C_API uint32_t bgfx_topology_convert(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32); + +/**/ +BGFX_C_API void bgfx_topology_sort_tri_list(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32); + /**/ BGFX_C_API void bgfx_image_swizzle_bgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst); diff --git a/include/bgfx/c99/bgfxplatform.h b/include/bgfx/c99/bgfxplatform.h index f7d5b76b5..cfde48342 100644 --- a/include/bgfx/c99/bgfxplatform.h +++ b/include/bgfx/c99/bgfxplatform.h @@ -78,6 +78,7 @@ typedef struct bgfx_interface_vtbl void (*vertex_convert)(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num); uint16_t (*weld_vertices)(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon); uint32_t (*topology_convert)(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32); + void (*topology_sort_tri_list)(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32); void (*image_swizzle_bgra8)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst); void (*image_rgba8_downsample_2x2)(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst); uint8_t (*get_supported_renderers)(bgfx_renderer_type_t _enum[BGFX_RENDERER_TYPE_COUNT]); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 83dacf5e6..90c6cee61 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2379,6 +2379,11 @@ namespace bgfx return topologyConvert(_conversion, _dst, _dstSize, _indices, _numIndices, _index32, g_allocator); } + void topologySortTriList(TopologySort::Enum _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32) + { + topologySortTriList(_sort, _dst, _dstSize, _dir, _pos, _vertices, _stride, _indices, _numIndices, _index32, g_allocator); + } + uint8_t getSupportedRenderers(RendererType::Enum _enum[RendererType::Count]) { uint8_t num = 0; @@ -3852,6 +3857,11 @@ uint32_t bgfx_topology_convert(bgfx_topology_convert_t _conversion, void* _dst, return bgfx::topologyConvert(bgfx::TopologyConvert::Enum(_conversion), _dst, _dstSize, _indices, _numIndices, _index32); } +void bgfx_topology_sort_tri_list(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32) +{ + bgfx::topologySortTriList(bgfx::TopologySort::Enum(_sort), _dst, _dstSize, _dir, _pos, _vertices, _stride, _indices, _numIndices, _index32); +} + BGFX_C_API void bgfx_image_swizzle_bgra8(uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _src, void* _dst) { bgfx::imageSwizzleBgra8(_width, _height, _pitch, _src, _dst); @@ -4625,6 +4635,7 @@ BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) BGFX_IMPORT_FUNC(vertex_convert) \ BGFX_IMPORT_FUNC(weld_vertices) \ BGFX_IMPORT_FUNC(topology_convert) \ + BGFX_IMPORT_FUNC(topology_sort_tri_list) \ BGFX_IMPORT_FUNC(image_swizzle_bgra8) \ BGFX_IMPORT_FUNC(image_rgba8_downsample_2x2) \ BGFX_IMPORT_FUNC(get_supported_renderers) \ diff --git a/src/topology.cpp b/src/topology.cpp index 076284d37..da4609711 100644 --- a/src/topology.cpp +++ b/src/topology.cpp @@ -291,7 +291,7 @@ namespace bgfx template void topologySortTriList( - Sort::Enum _sort + TopologySort::Enum _sort , IndexT* _dst , uint32_t* _keys , uint32_t* _values @@ -310,18 +310,18 @@ namespace bgfx switch (_sort) { default: - case Sort::DirectionFrontToBackMin: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; - case Sort::DirectionFrontToBackAvg: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; - case Sort::DirectionFrontToBackMax: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; - case Sort::DirectionBackToFrontMin: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; - case Sort::DirectionBackToFrontAvg: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; - case Sort::DirectionBackToFrontMax: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; - case Sort::DistanceFrontToBackMin: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; - case Sort::DistanceFrontToBackAvg: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; - case Sort::DistanceFrontToBackMax: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; - case Sort::DistanceBackToFrontMin: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; - case Sort::DistanceBackToFrontAvg: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; - case Sort::DistanceBackToFrontMax: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; + case TopologySort::DirectionFrontToBackMin: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; + case TopologySort::DirectionFrontToBackAvg: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; + case TopologySort::DirectionFrontToBackMax: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; + case TopologySort::DirectionBackToFrontMin: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; + case TopologySort::DirectionBackToFrontAvg: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; + case TopologySort::DirectionBackToFrontMax: calcSortKeys(_keys, _values, _dir, _vertices, _stride, _indices, _num); break; + case TopologySort::DistanceFrontToBackMin: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; + case TopologySort::DistanceFrontToBackAvg: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; + case TopologySort::DistanceFrontToBackMax: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; + case TopologySort::DistanceBackToFrontMin: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; + case TopologySort::DistanceBackToFrontAvg: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; + case TopologySort::DistanceBackToFrontMax: calcSortKeys(_keys, _values, _pos, _vertices, _stride, _indices, _num); break; } radixSort(_keys, _tempKeys, _values, _tempValues, _num); @@ -343,7 +343,7 @@ namespace bgfx } void topologySortTriList( - Sort::Enum _sort + TopologySort::Enum _sort , void* _dst , uint32_t _dstSize , const float _dir[3] diff --git a/src/topology.h b/src/topology.h index 689dfaa60..a0a1be588 100644 --- a/src/topology.h +++ b/src/topology.h @@ -36,40 +36,18 @@ namespace bgfx , bx::AllocatorI* _allocator ); - /// - struct Sort - { - enum Enum - { - DirectionFrontToBackMin, - DirectionFrontToBackAvg, - DirectionFrontToBackMax, - DirectionBackToFrontMin, - DirectionBackToFrontAvg, - DirectionBackToFrontMax, - DistanceFrontToBackMin, - DistanceFrontToBackAvg, - DistanceFrontToBackMax, - DistanceBackToFrontMin, - DistanceBackToFrontAvg, - DistanceBackToFrontMax, - - Count - }; - }; - /// void topologySortTriList( - Sort::Enum _sort - , void* _dst - , uint32_t _dstSize + TopologySort::Enum _sort + , void* _dst + , uint32_t _dstSize , const float _dir[3] , const float _pos[3] , const void* _vertices - , uint32_t _stride + , uint32_t _stride , const void* _indices - , uint32_t _numIndices - , bool _index32 + , uint32_t _numIndices + , bool _index32 , bx::AllocatorI* _allocator );