@@ -32,14 +32,31 @@ core::smart_refctd_ptr<DrawAABB> DrawAABB::create(SCreationParameters&& params)
32
32
return nullptr ;
33
33
}
34
34
35
- return core::smart_refctd_ptr<DrawAABB>(new DrawAABB (std::move (params), pipeline));
35
+ auto indicesBuffer = createIndicesBuffer (params);
36
+ if (!indicesBuffer)
37
+ {
38
+ logger->log (" Failed to create indices buffer!" , ILogger::ELL_ERROR);
39
+ return nullptr ;
40
+ }
41
+
42
+ return core::smart_refctd_ptr<DrawAABB>(new DrawAABB (std::move (params), pipeline, indicesBuffer));
36
43
}
37
44
38
- DrawAABB::DrawAABB (SCreationParameters&& params, smart_refctd_ptr<IGPUGraphicsPipeline> pipeline)
39
- : m_cachedCreationParams(std::move(params)), m_pipeline(pipeline)
45
+ DrawAABB::DrawAABB (SCreationParameters&& params, smart_refctd_ptr<IGPUGraphicsPipeline> pipeline, smart_refctd_ptr<IGPUBuffer> indicesBuffer )
46
+ : m_cachedCreationParams(std::move(params)), m_pipeline(std::move( pipeline)), m_indicesBuffer(std::move(indicesBuffer) )
40
47
{
41
48
const auto unitAABB = core::aabbox3d<float >({ 0 , 0 , 0 }, { 1 , 1 , 1 });
42
- m_unitAABBVertices = getVerticesFromAABB (unitAABB);
49
+ float32_t3 pMin = { 0 , 0 , 0 };
50
+ float32_t3 pMax = { 1 , 1 , 1 };
51
+
52
+ m_unitAABBVertices[0 ] = float32_t3 (pMin.x , pMin.y , pMin.z );
53
+ m_unitAABBVertices[1 ] = float32_t3 (pMax.x , pMin.y , pMin.z );
54
+ m_unitAABBVertices[2 ] = float32_t3 (pMin.x , pMin.y , pMax.z );
55
+ m_unitAABBVertices[3 ] = float32_t3 (pMax.x , pMin.y , pMax.z );
56
+ m_unitAABBVertices[4 ] = float32_t3 (pMin.x , pMax.y , pMin.z );
57
+ m_unitAABBVertices[5 ] = float32_t3 (pMax.x , pMax.y , pMin.z );
58
+ m_unitAABBVertices[6 ] = float32_t3 (pMin.x , pMax.y , pMax.z );
59
+ m_unitAABBVertices[7 ] = float32_t3 (pMax.x , pMax.y , pMax.z );
43
60
}
44
61
45
62
DrawAABB::~DrawAABB ()
@@ -205,6 +222,53 @@ bool DrawAABB::createStreamingBuffer(SCreationParameters& params)
205
222
return true ;
206
223
}
207
224
225
+ smart_refctd_ptr<IGPUBuffer> DrawAABB::createIndicesBuffer (SCreationParameters& params)
226
+ {
227
+ std::array<uint32_t , IndicesCount> unitAABBIndices;
228
+ unitAABBIndices[0 ] = 0 ;
229
+ unitAABBIndices[1 ] = 1 ;
230
+ unitAABBIndices[2 ] = 0 ;
231
+ unitAABBIndices[3 ] = 2 ;
232
+
233
+ unitAABBIndices[4 ] = 3 ;
234
+ unitAABBIndices[5 ] = 1 ;
235
+ unitAABBIndices[6 ] = 3 ;
236
+ unitAABBIndices[7 ] = 2 ;
237
+
238
+ unitAABBIndices[8 ] = 4 ;
239
+ unitAABBIndices[9 ] = 5 ;
240
+ unitAABBIndices[10 ] = 4 ;
241
+ unitAABBIndices[11 ] = 6 ;
242
+
243
+ unitAABBIndices[12 ] = 7 ;
244
+ unitAABBIndices[13 ] = 5 ;
245
+ unitAABBIndices[14 ] = 7 ;
246
+ unitAABBIndices[15 ] = 6 ;
247
+
248
+ unitAABBIndices[16 ] = 0 ;
249
+ unitAABBIndices[17 ] = 4 ;
250
+ unitAABBIndices[18 ] = 1 ;
251
+ unitAABBIndices[19 ] = 5 ;
252
+
253
+ unitAABBIndices[20 ] = 2 ;
254
+ unitAABBIndices[21 ] = 6 ;
255
+ unitAABBIndices[22 ] = 3 ;
256
+ unitAABBIndices[23 ] = 7 ;
257
+
258
+ IGPUBuffer::SCreationParams bufparams;
259
+ bufparams.size = sizeof (uint32_t ) * unitAABBIndices.size ();
260
+ bufparams.usage = IGPUBuffer::EUF_INDEX_BUFFER_BIT | IGPUBuffer::EUF_TRANSFER_DST_BIT;
261
+
262
+ smart_refctd_ptr<IGPUBuffer> indicesBuffer;
263
+ params.utilities ->createFilledDeviceLocalBufferOnDedMem (
264
+ SIntendedSubmitInfo{ .queue = params.transfer },
265
+ std::move (bufparams),
266
+ unitAABBIndices.data ()
267
+ ).move_into (indicesBuffer);
268
+
269
+ return indicesBuffer;
270
+ }
271
+
208
272
core::smart_refctd_ptr<video::IGPUPipelineLayout> DrawAABB::createDefaultPipelineLayout (video::ILogicalDevice* device, const asset::SPushConstantRange& pcRange)
209
273
{
210
274
return device->createPipelineLayout ({ &pcRange , 1 }, nullptr , nullptr , nullptr , nullptr );
@@ -264,6 +328,8 @@ bool DrawAABB::render(IGPUCommandBuffer* commandBuffer, ISemaphore::SWaitInfo wa
264
328
265
329
commandBuffer->bindGraphicsPipeline (m_pipeline.get ());
266
330
commandBuffer->setLineWidth (1 .f );
331
+ asset::SBufferBinding<video::IGPUBuffer> indexBinding = { .offset = 0 , .buffer = m_indicesBuffer };
332
+ commandBuffer->bindIndexBuffer (indexBinding, asset::EIT_32BIT);
267
333
268
334
auto instances = m_instances;
269
335
for (auto & inst : instances)
@@ -301,52 +367,52 @@ bool DrawAABB::render(IGPUCommandBuffer* commandBuffer, ISemaphore::SWaitInfo wa
301
367
pc.pInstanceBuffer = m_cachedCreationParams.streamingBuffer ->getBuffer ()->getDeviceAddress () + instancesByteOffset;
302
368
303
369
commandBuffer->pushConstants (m_pipeline->getLayout (), ESS_VERTEX, 0 , sizeof (SPushConstants), &pc);
304
- commandBuffer->draw (m_unitAABBVertices. size () , instanceCount, 0 , 0 );
370
+ commandBuffer->drawIndexed (IndicesCount , instanceCount, 0 , 0 , 0 );
305
371
306
372
streaming->multi_deallocate (1 , &inputOffset, &totalSize, waitInfo);
307
373
}
308
374
309
375
return true ;
310
376
}
311
377
312
- std::array<float32_t3, 24 > DrawAABB::getVerticesFromAABB (const core::aabbox3d<float >& aabb)
313
- {
314
- const auto & pMin = aabb.MinEdge ;
315
- const auto & pMax = aabb.MaxEdge ;
316
-
317
- std::array<float32_t3, 24 > vertices;
318
- vertices[0 ] = float32_t3 (pMin.X , pMin.Y , pMin.Z );
319
- vertices[1 ] = float32_t3 (pMax.X , pMin.Y , pMin.Z );
320
- vertices[2 ] = float32_t3 (pMin.X , pMin.Y , pMin.Z );
321
- vertices[3 ] = float32_t3 (pMin.X , pMin.Y , pMax.Z );
322
-
323
- vertices[4 ] = float32_t3 (pMax.X , pMin.Y , pMax.Z );
324
- vertices[5 ] = float32_t3 (pMax.X , pMin.Y , pMin.Z );
325
- vertices[6 ] = float32_t3 (pMax.X , pMin.Y , pMax.Z );
326
- vertices[7 ] = float32_t3 (pMin.X , pMin.Y , pMax.Z );
327
-
328
- vertices[8 ] = float32_t3 (pMin.X , pMax.Y , pMin.Z );
329
- vertices[9 ] = float32_t3 (pMax.X , pMax.Y , pMin.Z );
330
- vertices[10 ] = float32_t3 (pMin.X , pMax.Y , pMin.Z );
331
- vertices[11 ] = float32_t3 (pMin.X , pMax.Y , pMax.Z );
332
-
333
- vertices[12 ] = float32_t3 (pMax.X , pMax.Y , pMax.Z );
334
- vertices[13 ] = float32_t3 (pMax.X , pMax.Y , pMin.Z );
335
- vertices[14 ] = float32_t3 (pMax.X , pMax.Y , pMax.Z );
336
- vertices[15 ] = float32_t3 (pMin.X , pMax.Y , pMax.Z );
337
-
338
- vertices[16 ] = float32_t3 (pMin.X , pMin.Y , pMin.Z );
339
- vertices[17 ] = float32_t3 (pMin.X , pMax.Y , pMin.Z );
340
- vertices[18 ] = float32_t3 (pMax.X , pMin.Y , pMin.Z );
341
- vertices[19 ] = float32_t3 (pMax.X , pMax.Y , pMin.Z );
342
-
343
- vertices[20 ] = float32_t3 (pMin.X , pMin.Y , pMax.Z );
344
- vertices[21 ] = float32_t3 (pMin.X , pMax.Y , pMax.Z );
345
- vertices[22 ] = float32_t3 (pMax.X , pMin.Y , pMax.Z );
346
- vertices[23 ] = float32_t3 (pMax.X , pMax.Y , pMax.Z );
347
-
348
- return vertices;
349
- }
378
+ // std::array<float32_t3, 24> DrawAABB::getVerticesFromAABB(const core::aabbox3d<float>& aabb)
379
+ // {
380
+ // const auto& pMin = aabb.MinEdge;
381
+ // const auto& pMax = aabb.MaxEdge;
382
+ //
383
+ // std::array<float32_t3, 24> vertices;
384
+ // vertices[0] = float32_t3(pMin.X, pMin.Y, pMin.Z); // 0
385
+ // vertices[1] = float32_t3(pMax.X, pMin.Y, pMin.Z); // 1
386
+ // vertices[2] = float32_t3(pMin.X, pMin.Y, pMin.Z); // 0
387
+ // vertices[3] = float32_t3(pMin.X, pMin.Y, pMax.Z); // 2
388
+ //
389
+ // vertices[4] = float32_t3(pMax.X, pMin.Y, pMax.Z); // 3
390
+ // vertices[5] = float32_t3(pMax.X, pMin.Y, pMin.Z); // 1
391
+ // vertices[6] = float32_t3(pMax.X, pMin.Y, pMax.Z); // 3
392
+ // vertices[7] = float32_t3(pMin.X, pMin.Y, pMax.Z); // 2
393
+ //
394
+ // vertices[8] = float32_t3(pMin.X, pMax.Y, pMin.Z); // 4
395
+ // vertices[9] = float32_t3(pMax.X, pMax.Y, pMin.Z); // 5
396
+ // vertices[10] = float32_t3(pMin.X, pMax.Y, pMin.Z); // 4
397
+ // vertices[11] = float32_t3(pMin.X, pMax.Y, pMax.Z); // 6
398
+ //
399
+ // vertices[12] = float32_t3(pMax.X, pMax.Y, pMax.Z); // 7
400
+ // vertices[13] = float32_t3(pMax.X, pMax.Y, pMin.Z); // 5
401
+ // vertices[14] = float32_t3(pMax.X, pMax.Y, pMax.Z); // 7
402
+ // vertices[15] = float32_t3(pMin.X, pMax.Y, pMax.Z); // 6
403
+ //
404
+ // vertices[16] = float32_t3(pMin.X, pMin.Y, pMin.Z); // 0
405
+ // vertices[17] = float32_t3(pMin.X, pMax.Y, pMin.Z); // 4
406
+ // vertices[18] = float32_t3(pMax.X, pMin.Y, pMin.Z); // 1
407
+ // vertices[19] = float32_t3(pMax.X, pMax.Y, pMin.Z); // 5
408
+ //
409
+ // vertices[20] = float32_t3(pMin.X, pMin.Y, pMax.Z); // 2
410
+ // vertices[21] = float32_t3(pMin.X, pMax.Y, pMax.Z); // 6
411
+ // vertices[22] = float32_t3(pMax.X, pMin.Y, pMax.Z); // 3
412
+ // vertices[23] = float32_t3(pMax.X, pMax.Y, pMax.Z); // 7
413
+ //
414
+ // return vertices;
415
+ // }
350
416
351
417
void DrawAABB::addAABB (const hlsl::shapes::AABB<3 ,float >& aabb, const hlsl::float32_t4& color)
352
418
{
0 commit comments