Skip to content

Commit 9d07cc9

Browse files
first example of proper CFileView usage
1 parent 079334a commit 9d07cc9

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

include/nbl/system/CFileView.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ class CFileView : public IFileView
4646

4747
public:
4848
// constructor for making a file with memory already allocated by the allocator
49-
CFileView(path&& _name, const core::bitflag<E_CREATE_FLAGS> _flags, void* buffer, const size_t fileSize, allocator_t&& _allocator) :
50-
IFileView(std::move(sys),std::move(_name),_flags,buffer,fileSize), allocator(std::move(_allocator)) {}
49+
CFileView(path&& _name, const core::bitflag<E_CREATE_FLAGS> _flags, void* buffer, const size_t fileSize, allocator_t&& _allocator={}) :
50+
IFileView(std::move(_name),_flags,buffer,fileSize), allocator(std::move(_allocator)) {}
5151

5252
//
5353
static inline core::smart_refctd_ptr<CFileView<allocator_t>> create(path&& _name, const core::bitflag<E_CREATE_FLAGS> _flags, size_t fileSize, allocator_t&& _allocator={})
5454
{
5555
auto mem = reintepret_cast<std::byte*>(_allocator.alloc(fileSize));
5656
if (!mem)
5757
return nullptr;
58-
auto retval = new CFileView(std::move(sys),_name,_flags,mem,fileSize,std::move(_allocator));
58+
auto retval = new CFileView(std::move(_name),_flags,mem,fileSize,std::move(_allocator));
5959
return core::smart_refctd_ptr(retval,core::dont_grab);
6060
}
6161

src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

55
#include "nbl/asset/asset.h"
6+
#include "nbl/asset/interchange/CGraphicsPipelineLoaderMTL.h"
7+
#include "nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h"
8+
#include "nbl/asset/utils/CDerivativeMapCreator.h"
69

710
#include <utility>
811
#include <regex>
912
#include <filesystem>
1013

11-
#include "nbl/asset/asset.h"
12-
#include "nbl/asset/interchange/CGraphicsPipelineLoaderMTL.h"
13-
#include "nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h"
14-
#include "nbl/asset/utils/CDerivativeMapCreator.h"
15-
#include "nbl/system/IFileViewAllocator.h"
14+
#include "nbl/system/CFileView.h"
1615

1716
#include "nbl/builtin/MTLdefaults.h"
1817

@@ -84,13 +83,12 @@ void CGraphicsPipelineLoaderMTL::initialize()
8483
}
8584

8685
// default pipelines
87-
constexpr std::string_view filename = "Nabla default MTL material";
88-
89-
auto default_mtl_file = core::make_smart_refctd_ptr<system::CFileView<system::CPlainHeapAllocator>>(core::smart_refctd_ptr(m_system), filename, system::IFile::ECF_READ_WRITE, strlen(DUMMY_MTL_CONTENT));
90-
91-
system::future<size_t> future;
92-
default_mtl_file->write(future, DUMMY_MTL_CONTENT, 0, strlen(DUMMY_MTL_CONTENT));
93-
future.get();
86+
auto default_mtl_file = core::make_smart_refctd_ptr<system::CFileView<system::CNullAllocator>>(
87+
system::path("Nabla default MTL material"),
88+
system::IFile::ECF_READ,
89+
const_cast<char*>(DUMMY_MTL_CONTENT),
90+
strlen(DUMMY_MTL_CONTENT)
91+
);
9492

9593
SAssetLoadParams assetLoadParams;
9694
auto bundle = loadAsset(default_mtl_file.get(), assetLoadParams, &dfltOver);
@@ -105,11 +103,9 @@ bool CGraphicsPipelineLoaderMTL::isALoadableFileFormat(system::IFile* _file, con
105103

106104
std::string mtl;
107105
mtl.resize(_file->getSize());
108-
system::future<size_t> future;
109-
_file->read(future, mtl.data(), 0, _file->getSize());
110-
future.get();
111-
112-
return mtl.find("newmtl") != std::string::npos;
106+
system::IFile::success_t success;
107+
_file->read(success, mtl.data(), 0, _file->getSize());
108+
return success && mtl.find("newmtl")!=std::string::npos;
113109
}
114110

115111
SAssetBundle CGraphicsPipelineLoaderMTL::loadAsset(system::IFile* _file, const IAssetLoader::SAssetLoadParams& _params, IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel)
@@ -726,10 +722,11 @@ auto CGraphicsPipelineLoaderMTL::readMaterials(system::IFile* _file, const syste
726722
std::string mtl;
727723
size_t fileSize = _file->getSize();
728724
mtl.resize(fileSize);
729-
system::future<size_t> fut;
730-
731-
_file->read(fut, mtl.data(), 0, fileSize);
732-
fut.get();
725+
726+
system::IFile::success_t success;
727+
_file->read(success, mtl.data(), 0, fileSize);
728+
if (!success)
729+
return {};
733730

734731
const char* bufPtr = mtl.c_str();
735732
const char* const bufEnd = mtl.c_str()+mtl.size();
@@ -868,7 +865,7 @@ auto CGraphicsPipelineLoaderMTL::readMaterials(system::IFile* _file, const syste
868865
{
869866
case 'f': // Tf - Transmitivity
870867
currMaterial->params.transmissionFilter = readRGB();
871-
sprintf(tmpbuf, "%s, %s: Detected Tf parameter, it won't be used in generated shader - fallback to alpha=0.5 instead", _file->getFileName().c_str(), currMaterial->name.c_str());
868+
sprintf(tmpbuf, "%s, %s: Detected Tf parameter, it won't be used in generated shader - fallback to alpha=0.5 instead", _file->getFileName().string().c_str(), currMaterial->name.c_str());
872869
logger.log(tmpbuf, system::ILogger::ELL_WARNING);
873870
break;
874871
case 'r': // Tr, transparency = 1.0-d

0 commit comments

Comments
 (0)