Skip to content

Commit 4a3145c

Browse files
Merge pull request #530 from Hazardu/no-pipeline-fix
No pipeline fix
2 parents bcb7419 + 8a5150c commit 4a3145c

File tree

10 files changed

+178
-86
lines changed

10 files changed

+178
-86
lines changed

examples_tests/44.LevelCurveExtraction/InputEventReciever.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
class ChgSpacingEventReciever : public irr::IEventReceiver
88
{
99
public:
10-
ChgSpacingEventReciever() : spacing(10), running(true)
11-
{
10+
ChgSpacingEventReciever() : spacing(10), running(true), speed(1), resetCam(false) {
1211
}
1312

1413
bool OnEvent(const irr::SEvent& event)
@@ -31,11 +30,29 @@ class ChgSpacingEventReciever : public irr::IEventReceiver
3130
case irr::KEY_KEY_S:
3231
saveBuffer = true;
3332
return true;
33+
case irr::KEY_KEY_R:
34+
resetCam = true;
35+
return true;
36+
case irr::KEY_MINUS:
37+
speed = std::clamp<float>(speed - 0.1f, 0.2f, 5.0f);
38+
std::cout << "Camera speed: " << speed << std::endl;
39+
return true;
40+
case irr::KEY_PLUS:
41+
speed = std::clamp<float>(speed + 0.1f, 0.2f, 5.0f);
42+
std::cout << "Camera speed: " << speed << std::endl;
43+
return true;
3444
default:
3545
break;
3646
}
3747
}
48+
else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT && event.MouseInput.Wheel != 0.0f)
49+
{
50+
speed = std::clamp<float>(speed + event.MouseInput.Wheel / 10.0f, 0.2f, 5.0f);
51+
std::cout << "Camera speed: " << speed << std::endl;
52+
53+
return true;
3854

55+
}
3956
return false;
4057
}
4158
inline bool keepOpen() const { return running; }
@@ -49,10 +66,21 @@ class ChgSpacingEventReciever : public irr::IEventReceiver
4966
}
5067
return false;
5168
}
52-
69+
inline int resetCameraPosition()
70+
{
71+
if (resetCam)
72+
{
73+
resetCam = false;
74+
return true;
75+
}
76+
return false;
77+
}
78+
inline float getCameraSpeed() const { return speed; }
5379
private:
80+
float speed;
5481
int spacing;
5582
bool running;
5683
bool saveBuffer;
84+
bool resetCam;
5785
};
5886
#endif

examples_tests/44.LevelCurveExtraction/main.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,12 @@ int main()
491491
// finally get our GPU mesh
492492
auto gpumesh = driver->getGPUObjectsFromAssets(&mesh_raw, &mesh_raw+1)->front();
493493

494+
auto startingCameraSpeed = gpumesh->getBoundingBox().getExtent().getLength() * 0.0005f;
495+
float cameraSpeed = 1;
494496

497+
auto boundingBoxSize = gpumesh->getBoundingBox().getExtent().getLength();
495498
//! we want to move around the scene and view it from different angles
496-
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,0.5f);
499+
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, startingCameraSpeed);
497500

498501
camera->setPosition(core::vector3df(-4,0,0));
499502
camera->setTarget(core::vector3df(0,0,0));
@@ -502,10 +505,29 @@ int main()
502505

503506
smgr->setActiveCamera(camera);
504507
uint64_t lastFPSTime = 0;
505-
506508
GlobalUniforms globalUniforms = { 0u,10.f };
507509
while(device->run() && receiver.keepOpen())
508510
{
511+
if (receiver.resetCameraPosition())
512+
{
513+
camera->setPosition(core::vector3df(-4, 0, 0));
514+
camera->setTarget(core::vector3df(0, 0, 0));
515+
}
516+
if (cameraSpeed != receiver.getCameraSpeed())
517+
{
518+
cameraSpeed = receiver.getCameraSpeed();
519+
auto pos = camera->getPosition();
520+
auto rot = camera->getRotation();
521+
smgr->addToDeletionQueue(camera);
522+
camera = smgr->addCameraSceneNodeFPS(0, 100.0f, startingCameraSpeed * cameraSpeed);
523+
smgr->setActiveCamera(camera);
524+
camera->setPosition(pos);
525+
camera->setRotation(rot);
526+
camera->setNearValue(1.f);
527+
camera->setFarValue(5000.0f);
528+
}
529+
530+
509531
driver->beginScene(true, true, video::SColor(255,128,128,128) );
510532

511533
// always update cause of mdiIndex

include/irr/asset/IAssetLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ class IAssetLoader : public virtual core::IReferenceCounted
244244
//! Loads an asset from an opened file, returns nullptr in case of failure.
245245
virtual SAssetBundle loadAsset(io::IReadFile* _file, const SAssetLoadParams& _params, IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) = 0;
246246

247+
virtual void initialize() {}
248+
247249
protected:
248250
// accessors for loaders
249251
SAssetBundle interm_getAssetInHierarchy(IAssetManager* _mgr, io::IReadFile* _file, const std::string& _supposedFilename, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override);

include/irr/asset/IAssetManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin
142142
for (size_t i = 0u; i < m_cpuGpuCache.size(); ++i)
143143
m_cpuGpuCache[i] = new CpuGpuCacheType();
144144

145-
addLoadersAndWriters();
146145
insertBuiltinAssets();
146+
addLoadersAndWriters();
147147
}
148148

149149
inline io::IFileSystem* getFileSystem() const { return m_fileSystem.get(); }

include/irr/builtin/shaders/loaders/mtl/fragment_impl.glsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,11 @@ vec3 irr_computeLighting(out irr_glsl_IsotropicViewSurfaceInteraction out_intera
209209

210210
void main()
211211
{
212+
#ifndef _NO_UV
212213
mat2 dUV = mat2(dFdx(UV), dFdy(UV));
213-
214+
#else
215+
mat2 dUV = mat2(vec2(0,0),vec2(0,0));
216+
#endif
214217
irr_glsl_IsotropicViewSurfaceInteraction interaction;
215218
vec3 color = irr_computeLighting(interaction, dUV);
216219

src/irr/asset/CGraphicsPipelineLoaderMTL.cpp

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "irr/asset/CGraphicsPipelineLoaderMTL.h"
1111
#include "irr/asset/IGLSLEmbeddedIncludeLoader.h"
12+
#include "irr/builtin/MTLdefaults.h"
1213

1314

1415
namespace
@@ -116,13 +117,33 @@ void main()
116117
using namespace irr;
117118
using namespace asset;
118119

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+
}
119126
static void insertShaderIntoCache(core::smart_refctd_ptr<ICPUSpecializedShader>& asset, const char* path, IAssetManager* _assetMgr)
120127
{
121128
asset::SAssetBundle bundle({ asset });
122129
_assetMgr->changeAssetKey(bundle, path);
123130
_assetMgr->insertAssetIntoCache(bundle);
124131
}
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);
125144

145+
return core::smart_refctd_ptr_static_cast<AssetType>(assets.begin()[0]);
146+
}
126147
#define VERT_SHADER_NO_UV_CACHE_KEY "irr/builtin/shaders/loaders/mtl/vertex_no_uv.vert"
127148
#define VERT_SHADER_UV_CACHE_KEY "irr/builtin/shaders/loaders/mtl/vertex_uv.vert"
128149
#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
148169
registerShader(IRR_CORE_UNIQUE_STRING_LITERAL_TYPE(VERT_SHADER_UV_CACHE_KEY) {}, ICPUSpecializedShader::ESS_VERTEX);
149170
registerShader(IRR_CORE_UNIQUE_STRING_LITERAL_TYPE(FRAG_SHADER_NO_UV_CACHE_KEY){},ICPUSpecializedShader::ESS_FRAGMENT);
150171
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);
151192
}
152193

153194
bool CGraphicsPipelineLoaderMTL::isALoadableFileFormat(io::IReadFile* _file) const
@@ -167,21 +208,6 @@ bool CGraphicsPipelineLoaderMTL::isALoadableFileFormat(io::IReadFile* _file) con
167208
return mtl.find("newmtl") != std::string::npos;
168209
}
169210

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-
}
185211

186212
core::smart_refctd_ptr<ICPUPipelineLayout> CGraphicsPipelineLoaderMTL::makePipelineLayoutFromMtl(const SMtl& _mtl, bool _noDS3)
187213
{
@@ -324,19 +350,34 @@ SAssetBundle CGraphicsPipelineLoaderMTL::loadAsset(io::IReadFile* _file, const I
324350

325351
core::smart_refctd_ptr<ICPUDescriptorSet> ds3;
326352
{
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
333372
{
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())
337376
{
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));
340381
}
341382
}
342383
}
@@ -581,16 +622,27 @@ std::pair<core::smart_refctd_ptr<ICPUSpecializedShader>, core::smart_refctd_ptr<
581622
auto CGraphicsPipelineLoaderMTL::loadImages(const char* _relDir, const SMtl& _mtl, SContext& _ctx) -> image_views_set_t
582623
{
583624
images_set_t images;
625+
image_views_set_t views;
584626

585627
std::string relDir = _relDir;
586628
for (uint32_t i = 0u; i < images.size(); ++i)
587629
{
588630
SAssetLoadParams lp;
589-
if (_mtl.maps[i].size())
631+
if (_mtl.maps[i].size() )
590632
{
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+
{
591642
auto bundle = interm_getAssetInHierarchy(m_assetMgr, relDir+_mtl.maps[i], lp, _ctx.topHierarchyLevel+ICPURenderpassIndependentPipeline::IMAGE_HIERARCHYLEVELS_BELOW, _ctx.loaderOverride);
592643
if (!bundle.isEmpty())
593644
images[i] = core::smart_refctd_ptr_static_cast<ICPUImage>(bundle.getContents().begin()[0]);
645+
}
594646
}
595647
}
596648

@@ -662,7 +714,6 @@ auto CGraphicsPipelineLoaderMTL::loadImages(const char* _relDir, const SMtl& _mt
662714
ICPUImage::SCreationParams cubemapParams = images[CMTLPipelineMetadata::EMP_REFL_POSX]->getCreationParameters();
663715
cubemapParams.arrayLayers = 6u;
664716
cubemapParams.type = IImage::ET_2D;
665-
666717
auto cubemap = ICPUImage::create(std::move(cubemapParams));
667718
auto regions = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<ICPUImage::SBufferCopy>>(regions_);
668719
cubemap->setBufferAndRegions(std::move(imgDataBuf), regions);
@@ -674,7 +725,6 @@ auto CGraphicsPipelineLoaderMTL::loadImages(const char* _relDir, const SMtl& _mt
674725
}
675726
}
676727

677-
image_views_set_t views;
678728
for (uint32_t i = 0u; i < views.size(); ++i)
679729
{
680730
if (!images[i])

src/irr/asset/CGraphicsPipelineLoaderMTL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace asset
3535
public:
3636
CGraphicsPipelineLoaderMTL(IAssetManager* _am);
3737

38+
void initialize();
39+
3840
bool isALoadableFileFormat(io::IReadFile* _file) const override;
3941

4042
const char** getAssociatedFileExtensions() const override

0 commit comments

Comments
 (0)