@@ -19,17 +19,32 @@ core::smart_refctd_ptr<DrawAABB> DrawAABB::create(SCreationParameters&& params)
19
19
{
20
20
auto * const logger = params.utilities ->getLogger ();
21
21
22
- auto singlePipeline = createPipeline (params, params.singlePipelineLayout .get (), " single.vertex.hlsl" , " aabb_instances.fragment.hlsl" );
23
- if (!singlePipeline)
22
+ if (!validateCreationParameters (params))
24
23
{
25
- logger->log (" Failed to create pipeline !" , ILogger::ELL_ERROR);
24
+ logger->log (" Failed creation parameters validation !" , ILogger::ELL_ERROR);
26
25
return nullptr ;
27
26
}
28
- auto batchPipeline = createPipeline (params, params.batchPipelineLayout .get (), " aabb_instances.vertex.hlsl" , " aabb_instances.fragment.hlsl" );
29
- if (!batchPipeline)
27
+
28
+ smart_refctd_ptr<IGPUGraphicsPipeline> singlePipeline = nullptr ;
29
+ if (params.drawMode & ADM_DRAW_SINGLE)
30
30
{
31
- logger->log (" Failed to create pipeline!" , ILogger::ELL_ERROR);
32
- return nullptr ;
31
+ singlePipeline = createPipeline (params, params.singlePipelineLayout .get (), " single.vertex.hlsl" , " aabb_instances.fragment.hlsl" );
32
+ if (!singlePipeline)
33
+ {
34
+ logger->log (" Failed to create pipeline!" , ILogger::ELL_ERROR);
35
+ return nullptr ;
36
+ }
37
+ }
38
+
39
+ smart_refctd_ptr<IGPUGraphicsPipeline> batchPipeline = nullptr ;
40
+ if (params.drawMode & ADM_DRAW_BATCH)
41
+ {
42
+ batchPipeline = createPipeline (params, params.batchPipelineLayout .get (), " aabb_instances.vertex.hlsl" , " aabb_instances.fragment.hlsl" );
43
+ if (!batchPipeline)
44
+ {
45
+ logger->log (" Failed to create pipeline!" , ILogger::ELL_ERROR);
46
+ return nullptr ;
47
+ }
33
48
}
34
49
35
50
if (!createStreamingBuffer (params))
@@ -83,6 +98,29 @@ const smart_refctd_ptr<IFileArchive> DrawAABB::mount(smart_refctd_ptr<ILogger> l
83
98
return smart_refctd_ptr (archive);
84
99
}
85
100
101
+ bool DrawAABB::validateCreationParameters (SCreationParameters& creationParams)
102
+ {
103
+ const auto validation = std::to_array
104
+ ({
105
+ std::make_pair (bool (creationParams.assetManager ), " Invalid `creationParams.assetManager` is nullptr!" ),
106
+ std::make_pair (bool (creationParams.assetManager ->getSystem ()), " Invalid `creationParams.assetManager->getSystem()` is nullptr!" ),
107
+ std::make_pair (bool (creationParams.utilities ), " Invalid `creationParams.utilities` is nullptr!" ),
108
+ std::make_pair (bool (creationParams.transfer ), " Invalid `creationParams.transfer` is nullptr!" ),
109
+ std::make_pair (bool (creationParams.renderpass ), " Invalid `creationParams.renderpass` is nullptr!" ),
110
+ (creationParams.assetManager && creationParams.utilities && creationParams.transfer && creationParams.renderpass ) ? std::make_pair (bool (creationParams.utilities ->getLogicalDevice ()->getPhysicalDevice ()->getQueueFamilyProperties ()[creationParams.transfer ->getFamilyIndex ()].queueFlags .hasFlags (IQueue::FAMILY_FLAGS::TRANSFER_BIT)), " Invalid `creationParams.transfer` is not capable of transfer operations!" ) : std::make_pair (false , " Pass valid required DrawAABB::S_CREATION_PARAMETERS!" )
111
+ });
112
+
113
+ system::logger_opt_ptr logger = creationParams.utilities ->getLogger ();
114
+ for (const auto & [ok, error] : validation)
115
+ if (!ok)
116
+ {
117
+ logger.log (error, ILogger::ELL_ERROR);
118
+ return false ;
119
+ }
120
+
121
+ return true ;
122
+ }
123
+
86
124
smart_refctd_ptr<IGPUGraphicsPipeline> DrawAABB::createPipeline (SCreationParameters& params, const IGPUPipelineLayout* pipelineLayout, const std::string& vsPath, const std::string& fsPath)
87
125
{
88
126
auto system = smart_refctd_ptr<ISystem>(params.assetManager ->getSystem ());
@@ -281,6 +319,12 @@ core::smart_refctd_ptr<video::IGPUPipelineLayout> DrawAABB::createDefaultPipelin
281
319
282
320
bool DrawAABB::renderSingle (IGPUCommandBuffer* commandBuffer, const hlsl::shapes::AABB<3 , float >& aabb, const hlsl::float32_t4& color, const hlsl::float32_t4x4& cameraMat)
283
321
{
322
+ if (!(m_cachedCreationParams.drawMode & ADM_DRAW_SINGLE))
323
+ {
324
+ m_cachedCreationParams.utilities ->getLogger ()->log (" DrawAABB has not been enabled for draw single!" , ILogger::ELL_ERROR);
325
+ return false ;
326
+ }
327
+
284
328
commandBuffer->bindGraphicsPipeline (m_singlePipeline.get ());
285
329
commandBuffer->setLineWidth (1 .f );
286
330
asset::SBufferBinding<video::IGPUBuffer> indexBinding = { .offset = 0 , .buffer = m_indicesBuffer };
@@ -300,6 +344,12 @@ bool DrawAABB::renderSingle(IGPUCommandBuffer* commandBuffer, const hlsl::shapes
300
344
301
345
bool DrawAABB::render (IGPUCommandBuffer* commandBuffer, ISemaphore::SWaitInfo waitInfo, std::span<const InstanceData> aabbInstances, const hlsl::float32_t4x4& cameraMat)
302
346
{
347
+ if (!(m_cachedCreationParams.drawMode & ADM_DRAW_BATCH))
348
+ {
349
+ m_cachedCreationParams.utilities ->getLogger ()->log (" DrawAABB has not been enabled for draw batches!" , ILogger::ELL_ERROR);
350
+ return false ;
351
+ }
352
+
303
353
using offset_t = SCachedCreationParameters::streaming_buffer_t ::size_type;
304
354
constexpr auto MdiSizes = std::to_array<offset_t >({ sizeof (float32_t3), sizeof (InstanceData) });
305
355
// shared nPoT alignment needs to be divisible by all smaller ones to satisfy an allocation from all
0 commit comments