5
5
#ifndef __NBL_ASSET_I_MESH_PACKER_H_INCLUDED__
6
6
#define __NBL_ASSET_I_MESH_PACKER_H_INCLUDED__
7
7
8
+ #include " nbl/asset/utils/IMeshManipulator.h"
9
+
8
10
namespace nbl
9
11
{
10
12
namespace asset
@@ -45,6 +47,7 @@ class IMeshPackerBase
45
47
46
48
struct AllocationParamsCommon
47
49
{
50
+ // TODO: review all names and documnetation!
48
51
size_t indexBuffSupportedCnt = 1073741824ull ; /* 2GB*/
49
52
size_t vertexBuffSupportedSize = 1ull << 31ull ; /* 2GB*/
50
53
size_t MDIDataBuffSupportedCnt = 16777216ull ; /* 16MB assuming MDIStructType is DrawElementsIndirectCommand_t*/
@@ -125,7 +128,12 @@ class IMeshPacker : public IMeshPackerBase
125
128
return size;
126
129
}
127
130
128
- inline constexpr uint32_t calcBatchCount (uint32_t triCnt)
131
+ inline constexpr uint32_t calcVertexCountBoundWithBatchDuplication (uint32_t triCnt)
132
+ {
133
+ return triCnt*3u ;
134
+ }
135
+
136
+ inline constexpr uint32_t calcBatchCountBound (uint32_t triCnt)
129
137
{
130
138
if (triCnt!=0u )
131
139
return (triCnt-1u )/m_minTriangleCountPerMDIData+1u ;
@@ -144,13 +152,40 @@ class IMeshPacker : public IMeshPackerBase
144
152
145
153
core::vector<TriangleBatch> constructTriangleBatches (MeshBufferType* meshBuffer)
146
154
{
147
- const size_t idxCnt = meshBuffer->getIndexCount ();
148
- const uint32_t triCnt = idxCnt / 3 ;
149
- assert (idxCnt % 3 == 0 );
155
+ uint32_t triCnt;
156
+ const bool success = IMeshManipulator::getPolyCount (meshBuffer);
157
+ assert (success);
158
+
159
+ const uint32_t batchCount = calcBatchCountBound (triCnt);
160
+ /*
161
+ TODO:
162
+
163
+ //struct TriangleMortonCodePair
164
+ //{
165
+ // Triangle triangle;
166
+ // //uint64_t mortonCode; TODO after benchmarks
167
+ //};
168
+
169
+ core::vector<TriangleMortonCodePair> triangles(triCnt);
170
+ uint32_t ix=0u;
171
+ for (auto it=triangles.begin(); it!=triangles.end(); it++)
172
+ {
173
+ *it = IMeshManipulator::getTriangleIndices(meshbuffer,ix++);
174
+ }
175
+
176
+ std::sort(triangles.begin(),triangles.end(),[]()->bool{return lhs.mortonCode<rhs.mortonCode;}); // maybe use our new core::radix_sort?
150
177
151
- const uint32_t batchCount = calcBatchCount (triCnt);
178
+ // do batch splitting
179
+ core::vector<const TriangleMortonCodePair*> batches;
180
+ batches.reserve(calcBatchCountBound(triCnt)+1u); // actual batch count will be different
181
+ {
182
+ // use batches.push_back();
183
+ }
184
+ batches.push_back(triangles.data()+triangles.size());
152
185
153
- core::vector<TriangleBatch> output (batchCount);
186
+ return {std::move(triangles),std::move(batches)};
187
+ */
188
+ core::vector<TriangleBatch> output (batchCount); // nested vectors are evil
154
189
155
190
for (uint32_t i = 0u ; i < batchCount; i++)
156
191
{
@@ -166,12 +201,6 @@ class IMeshPacker : public IMeshPackerBase
166
201
output[i].triangles = core::vector<Triangle>(m_maxTriangleCountPerMDIData);
167
202
}
168
203
169
- // struct TriangleMortonCodePair
170
- // {
171
- // Triangle triangle;
172
- // //uint64_t mortonCode; TODO after benchmarks
173
- // };
174
-
175
204
// TODO: triangle reordering
176
205
177
206
const auto & srcIdxBuffer = meshBuffer->getIndexBufferBinding ();
0 commit comments