@@ -81,6 +81,68 @@ class NBL_API2 CPolygonGeometryManipulator
81
81
const_cast <IGeometryBase::SAABBStorage&>(geo->getAABBStorage ()) = computeAABB (geo);
82
82
}
83
83
84
+ static inline void reindexToTriangleList (ICPUPolygonGeometry* geo)
85
+ {
86
+ const auto * indexing = geo->getIndexingCallback ();
87
+ if (indexing && indexing->knownTopology () == EPT_TRIANGLE_LIST)
88
+ return ;
89
+ if (!indexing) return ;
90
+ if (indexing->degree () != 3 ) return ;
91
+
92
+ const auto primCount = geo->getPrimitiveCount ();
93
+ const auto maxIndex = geo->getPositionView ().getElementCount () - 1 ;
94
+ const uint8_t indexSize = maxIndex <= std::numeric_limits<uint16_t >::max () ? sizeof (uint16_t ) : sizeof (uint32_t );
95
+ auto indexBuffer = ICPUBuffer::create ({ primCount * 3 * indexSize, IBuffer::EUF_INDEX_BUFFER_BIT });
96
+ auto indexBufferPtr = indexBuffer->getPointer ();
97
+ auto indexView = ICPUPolygonGeometry::SDataView{
98
+ .composed = {
99
+ .stride = indexSize,
100
+ },
101
+ .src = {
102
+ .offset = 0 ,
103
+ .size = indexBuffer->getSize (),
104
+ .buffer = std::move (indexBuffer)
105
+ }
106
+ };
107
+
108
+ if (indexSize == 2 )
109
+ {
110
+ IPolygonGeometryBase::IIndexingCallback::SContext<uint16_t > context{
111
+ .indexBuffer = geo->getIndexView ().getPointer (),
112
+ .indexSize = indexSize,
113
+ .beginPrimitive = 0 ,
114
+ .endPrimitive = primCount,
115
+ .out = indexBufferPtr,
116
+ };
117
+ indexing->operator ()(context);
118
+
119
+ indexView.composed .encodedDataRange .u16 .minVx [0 ] = 0 ;
120
+ indexView.composed .encodedDataRange .u16 .maxVx [0 ] = maxIndex;
121
+ indexView.composed .format = EF_R16_UINT;
122
+ indexView.composed .rangeFormat = IGeometryBase::EAABBFormat::U16;
123
+
124
+ } else
125
+ {
126
+ IPolygonGeometryBase::IIndexingCallback::SContext<uint32_t > context{
127
+ .indexBuffer = geo->getIndexView ().getPointer (),
128
+ .indexSize = indexSize,
129
+ .beginPrimitive = 0 ,
130
+ .endPrimitive = primCount,
131
+ .out = indexBufferPtr,
132
+ };
133
+ indexing->operator ()(context);
134
+
135
+ indexView.composed .encodedDataRange .u32 .minVx [0 ] = 0 ;
136
+ indexView.composed .encodedDataRange .u32 .maxVx [0 ] = maxIndex;
137
+ indexView.composed .format = EF_R32_UINT;
138
+ indexView.composed .rangeFormat = IGeometryBase::EAABBFormat::U32;
139
+ }
140
+
141
+ geo->setIndexing (IPolygonGeometryBase::TriangleList ());
142
+ geo->setIndexView (std::move (indexView));
143
+ recomputeContentHashes (geo);
144
+ }
145
+
84
146
// ! Comparison methods
85
147
enum E_ERROR_METRIC
86
148
{
0 commit comments