9
9
10
10
#include " irr/asset/CGraphicsPipelineLoaderMTL.h"
11
11
#include " irr/asset/IGLSLEmbeddedIncludeLoader.h"
12
+ #include " irr/builtin/MTLdefaults.h"
12
13
13
14
14
15
namespace
@@ -116,13 +117,33 @@ void main()
116
117
using namespace irr ;
117
118
using namespace asset ;
118
119
120
+ static void insertPipelineIntoCache (core::smart_refctd_ptr<ICPURenderpassIndependentPipeline>&& asset, const char * path, IAssetManager* _assetMgr)
121
+ {
122
+ asset::SAssetBundle bundle ({ std::move (asset) });
123
+ _assetMgr->changeAssetKey (bundle, path);
124
+ _assetMgr->insertAssetIntoCache (bundle);
125
+ }
119
126
static void insertShaderIntoCache (core::smart_refctd_ptr<ICPUSpecializedShader>& asset, const char * path, IAssetManager* _assetMgr)
120
127
{
121
128
asset::SAssetBundle bundle ({ asset });
122
129
_assetMgr->changeAssetKey (bundle, path);
123
130
_assetMgr->insertAssetIntoCache (bundle);
124
131
}
132
+ template <typename AssetType, IAsset::E_TYPE assetType>
133
+ static core::smart_refctd_ptr<AssetType> getDefaultAsset (const char * _key, IAssetManager* _assetMgr)
134
+ {
135
+ size_t storageSz = 1ull ;
136
+ asset::SAssetBundle bundle;
137
+ const IAsset::E_TYPE types[]{ assetType, static_cast <IAsset::E_TYPE>(0u ) };
138
+
139
+ _assetMgr->findAssets (storageSz, &bundle, _key, types);
140
+ if (bundle.isEmpty ())
141
+ return nullptr ;
142
+ auto assets = bundle.getContents ();
143
+ // assert(assets.first != assets.second);
125
144
145
+ return core::smart_refctd_ptr_static_cast<AssetType>(assets.begin ()[0 ]);
146
+ }
126
147
#define VERT_SHADER_NO_UV_CACHE_KEY " irr/builtin/shaders/loaders/mtl/vertex_no_uv.vert"
127
148
#define VERT_SHADER_UV_CACHE_KEY " irr/builtin/shaders/loaders/mtl/vertex_uv.vert"
128
149
#define FRAG_SHADER_NO_UV_CACHE_KEY " irr/builtin/shaders/loaders/mtl/fragment_no_uv.frag"
@@ -148,6 +169,26 @@ CGraphicsPipelineLoaderMTL::CGraphicsPipelineLoaderMTL(IAssetManager* _am) : m_a
148
169
registerShader (IRR_CORE_UNIQUE_STRING_LITERAL_TYPE (VERT_SHADER_UV_CACHE_KEY) {}, ICPUSpecializedShader::ESS_VERTEX);
149
170
registerShader (IRR_CORE_UNIQUE_STRING_LITERAL_TYPE (FRAG_SHADER_NO_UV_CACHE_KEY){},ICPUSpecializedShader::ESS_FRAGMENT);
150
171
registerShader (IRR_CORE_UNIQUE_STRING_LITERAL_TYPE (FRAG_SHADER_UV_CACHE_KEY){},ICPUSpecializedShader::ESS_FRAGMENT);
172
+
173
+
174
+
175
+ }
176
+
177
+ void CGraphicsPipelineLoaderMTL::initialize ()
178
+ {
179
+ constexpr const char * MISSING_MTL_PIPELINE_NO_UV_CACHE_KEY = " irr/builtin/graphics_pipeline/loaders/mtl/missing_material_pipeline_no_uv" ;
180
+ constexpr const char * MISSING_MTL_PIPELINE_UV_CACHE_KEY = " irr/builtin/graphics_pipeline/loaders/mtl/missing_material_pipeline_uv" ;
181
+ SAssetLoadParams assetLoadParams;
182
+
183
+ auto default_mtl_file = m_assetMgr->getFileSystem ()->createMemoryReadFile (DUMMY_MTL_CONTENT, strlen (DUMMY_MTL_CONTENT), " default IrrlichtBAW material" );
184
+ auto bundle = loadAsset (default_mtl_file, assetLoadParams);
185
+ auto pipelineAssets = bundle.getContents ().begin ();
186
+ default_mtl_file->drop ();
187
+ auto pNoUV = core::smart_refctd_ptr_dynamic_cast<ICPURenderpassIndependentPipeline>(pipelineAssets[0 ]);
188
+ auto pUV = core::smart_refctd_ptr_dynamic_cast<ICPURenderpassIndependentPipeline>(pipelineAssets[1 ]);
189
+
190
+ insertPipelineIntoCache (std::move (pNoUV), MISSING_MTL_PIPELINE_NO_UV_CACHE_KEY, m_assetMgr);
191
+ insertPipelineIntoCache (std::move (pUV), MISSING_MTL_PIPELINE_UV_CACHE_KEY, m_assetMgr);
151
192
}
152
193
153
194
bool CGraphicsPipelineLoaderMTL::isALoadableFileFormat (io::IReadFile* _file) const
@@ -167,21 +208,6 @@ bool CGraphicsPipelineLoaderMTL::isALoadableFileFormat(io::IReadFile* _file) con
167
208
return mtl.find (" newmtl" ) != std::string::npos;
168
209
}
169
210
170
- template <typename AssetType, IAsset::E_TYPE assetType>
171
- static core::smart_refctd_ptr<AssetType> getDefaultAsset (const char * _key, IAssetManager* _assetMgr)
172
- {
173
- size_t storageSz = 1ull ;
174
- asset::SAssetBundle bundle;
175
- const IAsset::E_TYPE types[]{ assetType, static_cast <IAsset::E_TYPE>(0u ) };
176
-
177
- _assetMgr->findAssets (storageSz, &bundle, _key, types);
178
- if (bundle.isEmpty ())
179
- return nullptr ;
180
- auto assets = bundle.getContents ();
181
- // assert(assets.first != assets.second);
182
-
183
- return core::smart_refctd_ptr_static_cast<AssetType>(assets.begin ()[0 ]);
184
- }
185
211
186
212
core::smart_refctd_ptr<ICPUPipelineLayout> CGraphicsPipelineLoaderMTL::makePipelineLayoutFromMtl (const SMtl& _mtl, bool _noDS3)
187
213
{
@@ -324,19 +350,34 @@ SAssetBundle CGraphicsPipelineLoaderMTL::loadAsset(io::IReadFile* _file, const I
324
350
325
351
core::smart_refctd_ptr<ICPUDescriptorSet> ds3;
326
352
{
327
- const std::string dsCacheKey = std::string (fullName.c_str ())+" ?" +materials[i].name +" ?_ds" ;
328
- const asset::IAsset::E_TYPE types[]{ asset::IAsset::ET_DESCRIPTOR_SET, (asset::IAsset::E_TYPE)0u };
329
- auto ds_bundle = _override->findCachedAsset (dsCacheKey, types, ctx.inner , _hierarchyLevel + ICPUMesh::DESC_SET_HIERARCHYLEVELS_BELOW);
330
- if (!ds_bundle.isEmpty ())
331
- ds3 = core::smart_refctd_ptr_static_cast<ICPUDescriptorSet>(ds_bundle.getContents ().begin ()[0 ]);
332
- else
353
+ const std::string dsCacheKey = std::string (fullName.c_str ()) + " ?" + materials[i].name + " ?_ds" ;
354
+ if (_override)
355
+ {
356
+ const asset::IAsset::E_TYPE types[]{ asset::IAsset::ET_DESCRIPTOR_SET, (asset::IAsset::E_TYPE)0u };
357
+ auto ds_bundle = _override->findCachedAsset (dsCacheKey, types, ctx.inner , _hierarchyLevel + ICPUMesh::DESC_SET_HIERARCHYLEVELS_BELOW);
358
+ if (!ds_bundle.isEmpty ())
359
+ ds3 = core::smart_refctd_ptr_static_cast<ICPUDescriptorSet>(ds_bundle.getContents ().begin ()[0 ]);
360
+ else
361
+ {
362
+ auto views = loadImages (relPath.c_str (), materials[i], ctx);
363
+ ds3 = makeDescSet (std::move (views), layout->getDescriptorSetLayout (3u ));
364
+ if (ds3)
365
+ {
366
+ SAssetBundle bundle{ ds3 };
367
+ _override->insertAssetIntoCache (bundle, dsCacheKey, ctx.inner , _hierarchyLevel + ICPURenderpassIndependentPipeline::DESC_SET_HIERARCHYLEVELS_BELOW);
368
+ }
369
+ }
370
+ }
371
+ else
333
372
{
334
- auto views = loadImages (relPath. c_str (), materials[i], ctx) ;
335
- ds3 = makeDescSet ( std::move (views), layout-> getDescriptorSetLayout ( 3u ) );
336
- if (ds3 )
373
+ SAssetLoadParams assetloadparams ;
374
+ auto default_imageview_bundle = m_assetMgr-> getAsset ( " irr/builtin/image_views/dummy2d " , assetloadparams );
375
+ if (!default_imageview_bundle. isEmpty () )
337
376
{
338
- SAssetBundle bundle{ds3};
339
- _override->insertAssetIntoCache (bundle, dsCacheKey, ctx.inner , _hierarchyLevel + ICPURenderpassIndependentPipeline::DESC_SET_HIERARCHYLEVELS_BELOW);
377
+ auto assetptr = core::smart_refctd_ptr_static_cast<ICPUImageView>(default_imageview_bundle.getContents ().begin ()[0 ]);
378
+ image_views_set_t views;
379
+ views[0 ] = assetptr;
380
+ ds3 = makeDescSet (std::move (views), layout->getDescriptorSetLayout (3u ));
340
381
}
341
382
}
342
383
}
@@ -581,16 +622,27 @@ std::pair<core::smart_refctd_ptr<ICPUSpecializedShader>, core::smart_refctd_ptr<
581
622
auto CGraphicsPipelineLoaderMTL::loadImages (const char * _relDir, const SMtl& _mtl, SContext& _ctx) -> image_views_set_t
582
623
{
583
624
images_set_t images;
625
+ image_views_set_t views;
584
626
585
627
std::string relDir = _relDir;
586
628
for (uint32_t i = 0u ; i < images.size (); ++i)
587
629
{
588
630
SAssetLoadParams lp;
589
- if (_mtl.maps [i].size ())
631
+ if (_mtl.maps [i].size () )
590
632
{
633
+ io::path output;
634
+ core::getFileNameExtension (output,_mtl.maps [i].c_str ());
635
+ if (output == " .dds" )
636
+ {
637
+ auto bundle = interm_getAssetInHierarchy (m_assetMgr, relDir + _mtl.maps [i], lp, _ctx.topHierarchyLevel + ICPURenderpassIndependentPipeline::IMAGE_HIERARCHYLEVELS_BELOW, _ctx.loaderOverride );
638
+ if (!bundle.isEmpty ())
639
+ views[i] = core::smart_refctd_ptr_static_cast<ICPUImageView>(bundle.getContents ().begin ()[0 ]);
640
+ }else
641
+ {
591
642
auto bundle = interm_getAssetInHierarchy (m_assetMgr, relDir+_mtl.maps [i], lp, _ctx.topHierarchyLevel +ICPURenderpassIndependentPipeline::IMAGE_HIERARCHYLEVELS_BELOW, _ctx.loaderOverride );
592
643
if (!bundle.isEmpty ())
593
644
images[i] = core::smart_refctd_ptr_static_cast<ICPUImage>(bundle.getContents ().begin ()[0 ]);
645
+ }
594
646
}
595
647
}
596
648
@@ -662,7 +714,6 @@ auto CGraphicsPipelineLoaderMTL::loadImages(const char* _relDir, const SMtl& _mt
662
714
ICPUImage::SCreationParams cubemapParams = images[CMTLPipelineMetadata::EMP_REFL_POSX]->getCreationParameters ();
663
715
cubemapParams.arrayLayers = 6u ;
664
716
cubemapParams.type = IImage::ET_2D;
665
-
666
717
auto cubemap = ICPUImage::create (std::move (cubemapParams));
667
718
auto regions = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUImage::SBufferCopy>>(regions_);
668
719
cubemap->setBufferAndRegions (std::move (imgDataBuf), regions);
@@ -674,7 +725,6 @@ auto CGraphicsPipelineLoaderMTL::loadImages(const char* _relDir, const SMtl& _mt
674
725
}
675
726
}
676
727
677
- image_views_set_t views;
678
728
for (uint32_t i = 0u ; i < views.size (); ++i)
679
729
{
680
730
if (!images[i])
0 commit comments