Skip to content

Commit 60b6275

Browse files
What's the point of IAssetLoader::initialize if its not decoupled from construction?
1 parent 78858cd commit 60b6275

File tree

9 files changed

+42
-19
lines changed

9 files changed

+42
-19
lines changed

examples_tests/18.MitsubaLoader/main.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,12 @@ int main()
210210
asset::IAssetManager* am = device->getAssetManager();
211211
asset::CQuantNormalCache* qnc = am->getMeshManipulator()->getQuantNormalCache();
212212

213-
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CSerializedLoader>(am));
214-
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am,fs));
213+
auto serializedLoader = core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CSerializedLoader>(am);
214+
auto mitsubaLoader = core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am,fs);
215+
serializedLoader->initialize();
216+
mitsubaLoader->initialize();
217+
am->addAssetLoader(std::move(serializedLoader));
218+
am->addAssetLoader(std::move(mitsubaLoader));
215219

216220
std::string filePath = "../../media/mitsuba/staircase2.zip";
217221
//#define MITSUBA_LOADER_TESTS

examples_tests/22.RaytracedAO/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ int main()
4141
{
4242
io::IFileSystem* fs = device->getFileSystem();
4343
asset::IAssetManager* am = device->getAssetManager();
44-
45-
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CSerializedLoader>(am));
46-
am->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am, fs));
44+
45+
auto serializedLoader = core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CSerializedLoader>(am);
46+
auto mitsubaLoader = core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am,fs);
47+
serializedLoader->initialize();
48+
mitsubaLoader->initialize();
49+
am->addAssetLoader(std::move(serializedLoader));
50+
am->addAssetLoader(std::move(mitsubaLoader));
4751

4852
//std::string filePath = "../../media/mitsuba/daily_pt.xml";
4953
std::string filePath = "../../media/mitsuba/staircase2.zip";

examples_tests/39.DenoiserTonemapper/CommandLineHandler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ CommandLineHandler::CommandLineHandler(core::vector<std::string> argv, IAssetMan
2424
os::Printer::log(requiredArgumentsMessage.data(), ELL_INFORMATION);
2525
return;
2626
}
27-
28-
assetManager->addAssetLoader(core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(assetManager));
27+
28+
auto mitsubaLoader = core::make_smart_refctd_ptr<nbl::ext::MitsubaLoader::CMitsubaLoader>(am,fs);
29+
mitsubaLoader->initialize();
30+
am->addAssetLoader(std::move(mitsubaLoader));
2931
core::vector<std::array<std::string, PROPER_CMD_ARGUMENTS_AMOUNT>> argvMappedList;
3032

3133
auto pushArgvList = [&](auto argvStream, auto variableCount)

include/nbl/asset/IAssetManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,6 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin
574574
//! @returns 0xdeadbeefu on failure or 0-based index on success.
575575
uint32_t addAssetLoader(core::smart_refctd_ptr<IAssetLoader>&& _loader)
576576
{
577-
_loader->initialize();
578-
579577
// there's no way it ever fails, so no 0xdeadbeef return
580578
const char** exts = _loader->getAssociatedFileExtensions();
581579
size_t extIx = 0u;

include/nbl/asset/interchange/IAssetLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class IAssetLoader : public virtual core::IReferenceCounted
279279
virtual uint64_t getSupportedAssetTypesBitfield() const { return 0; }
280280

281281
//! Loads an asset from an opened file, returns nullptr in case of failure.
282-
virtual SAssetBundle loadAsset(io::IReadFile* _file, const SAssetLoadParams& _params, IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) = 0;
282+
virtual SAssetBundle loadAsset(io::IReadFile* _file, const SAssetLoadParams& _params, IAssetLoaderOverride* _override, uint32_t _hierarchyLevel = 0u) = 0;
283283

284284
virtual void initialize() {}
285285

src/nbl/asset/IAssetManager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ void IAssetManager::addLoadersAndWriters()
134134
#ifdef _NBL_COMPILE_WITH_PLY_LOADER_
135135
addAssetLoader(core::make_smart_refctd_ptr<asset::CPLYMeshFileLoader>(this));
136136
#endif
137+
#ifdef _NBL_COMPILE_WITH_MTL_LOADER_
138+
addAssetLoader(core::make_smart_refctd_ptr<asset::CGraphicsPipelineLoaderMTL>(this));
139+
#endif
137140
#ifdef _NBL_COMPILE_WITH_OBJ_LOADER_
138141
addAssetLoader(core::make_smart_refctd_ptr<asset::COBJMeshFileLoader>(this));
139142
#endif
@@ -176,15 +179,15 @@ void IAssetManager::addLoadersAndWriters()
176179
#ifdef _NBL_COMPILE_WITH_PNG_WRITER_
177180
addAssetWriter(core::make_smart_refctd_ptr<asset::CImageWriterPNG>());
178181
#endif
179-
#ifdef _NBL_COMPILE_WITH_MTL_LOADER_
180-
addAssetLoader(core::make_smart_refctd_ptr<asset::CGraphicsPipelineLoaderMTL>(this));
181-
#endif
182182
#ifdef _NBL_COMPILE_WITH_OPENEXR_WRITER_
183183
addAssetWriter(core::make_smart_refctd_ptr<asset::CImageWriterOpenEXR>());
184184
#endif
185185
#ifdef _NBL_COMPILE_WITH_GLI_WRITER_
186186
addAssetWriter(core::make_smart_refctd_ptr<asset::CGLIWriter>());
187187
#endif
188+
189+
for (auto& loader : m_loaders.vector)
190+
loader->initialize();
188191
}
189192

190193

src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ CGraphicsPipelineLoaderMTL::CGraphicsPipelineLoaderMTL(IAssetManager* _am) : m_a
5050

5151
void CGraphicsPipelineLoaderMTL::initialize()
5252
{
53+
auto dfltOver = IAssetLoaderOverride(m_assetMgr);
5354
// need to initialize this first
5455
{
55-
auto dfltOver = IAssetLoaderOverride(m_assetMgr);
5656
const IAssetLoader::SAssetLoadContext fakeCtx(IAssetLoader::SAssetLoadParams{},nullptr);
5757

5858
// find ds1 layout
@@ -67,7 +67,7 @@ void CGraphicsPipelineLoaderMTL::initialize()
6767
//if intellisense shows error here, it's most likely intellisense's fault and it'll build fine anyway
6868
static_assert(sizeof(SMtl::params) <= ICPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE, "It must fit in push constants!");
6969

70-
auto pplnLayout = core::make_smart_refctd_ptr<ICPUPipelineLayout>(&pcRng, &pcRng+1, nullptr, std::move(ds1layout), nullptr, nullptr);
70+
auto pplnLayout = core::make_smart_refctd_ptr<ICPUPipelineLayout>(&pcRng, &pcRng+1, nullptr, core::smart_refctd_ptr(ds1layout), nullptr, nullptr);
7171
insertBuiltinAssetIntoCache(m_assetMgr, SAssetBundle(nullptr,{ core::smart_refctd_ptr_static_cast<IAsset>(std::move(pplnLayout)) }), "nbl/builtin/pipeline_layout/loader/mtl/no_uv");
7272
}
7373

@@ -113,7 +113,7 @@ void CGraphicsPipelineLoaderMTL::initialize()
113113
SAssetLoadParams assetLoadParams;
114114

115115
auto default_mtl_file = m_assetMgr->getFileSystem()->createMemoryReadFile(DUMMY_MTL_CONTENT, strlen(DUMMY_MTL_CONTENT), "default IrrlichtBAW material");
116-
auto bundle = loadAsset(default_mtl_file, assetLoadParams);
116+
auto bundle = loadAsset(default_mtl_file, assetLoadParams, &dfltOver);
117117
default_mtl_file->drop();
118118

119119
insertBuiltinAssetIntoCache(m_assetMgr, std::move(bundle), "nbl/builtin/renderpass_independent_pipeline/loader/mtl/missing_material_pipeline");
@@ -147,7 +147,13 @@ SAssetBundle CGraphicsPipelineLoaderMTL::loadAsset(io::IReadFile* _file, const I
147147
_override
148148
);
149149
const std::string fullName = _file->getFileName().c_str();
150-
const std::string relPath = std::filesystem::path(fullName).parent_path().string()+"/";
150+
const std::string relPath = [&fullName]() -> std::string
151+
{
152+
auto dir = std::filesystem::path(fullName).parent_path().string();
153+
if (dir.empty())
154+
return "";
155+
return dir+"/";
156+
}();
151157

152158
auto materials = readMaterials(_file);
153159

src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CGraphicsPipelineLoaderMTL final : public asset::IAssetLoader
5151

5252
uint64_t getSupportedAssetTypesBitfield() const override { return asset::IAsset::ET_RENDERPASS_INDEPENDENT_PIPELINE; }
5353

54-
asset::SAssetBundle loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override;
54+
asset::SAssetBundle loadAsset(io::IReadFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel = 0u) override;
5555

5656
private:
5757
core::smart_refctd_ptr<ICPURenderpassIndependentPipeline> makePipelineFromMtl(SContext& ctx, const SMtl& _mtl, bool hasUV);

src/nbl/asset/interchange/COBJMeshFileLoader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(io::IReadFile* _file, const as
7676
uint32_t smoothingGroup=0;
7777

7878
const std::string fullName = _file->getFileName().c_str();
79-
const std::string relPath = std::filesystem::path(fullName).parent_path().string()+"/";
79+
const std::string relPath = [&fullName]() -> std::string
80+
{
81+
auto dir = std::filesystem::path(fullName).parent_path().string();
82+
if (dir.empty())
83+
return "";
84+
return dir+"/";
85+
}();
8086

8187
//value_type: directory from which .mtl (pipeline) was loaded and the pipeline
8288
using pipeline_meta_pair_t = std::pair<core::smart_refctd_ptr<ICPURenderpassIndependentPipeline>,const CMTLMetadata::CRenderpassIndependentPipeline*>;

0 commit comments

Comments
 (0)