Skip to content

Commit

Permalink
Replacements must be processed strictly with and after static
Browse files Browse the repository at this point in the history
  • Loading branch information
sultim-t committed Sep 30, 2023
1 parent 947d111 commit 028482d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
7 changes: 2 additions & 5 deletions Source/ASManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ RTGL1::StaticGeometryToken RTGL1::ASManager::BeginStaticGeometry()

// destroy previous static
builtStaticInstances.clear();
// and replacements, because they depend on allocator / vertex collector of static
builtReplacements.clear();
allocStaticGeom->Reset();

erase_if( curFrame_objects, []( const Object& o ) { return o.isStatic; } );
Expand Down Expand Up @@ -653,11 +655,6 @@ void RTGL1::ASManager::SubmitStaticGeometry( StaticGeometryToken& token )
Utils::WaitAndResetFence( device, staticCopyFence );
}

void RTGL1::ASManager::ClearReplacements()
{
builtReplacements.clear();
}

RTGL1::DynamicGeometryToken RTGL1::ASManager::BeginDynamicGeometry( VkCommandBuffer cmd,
uint32_t frameIndex )
{
Expand Down
3 changes: 0 additions & 3 deletions Source/ASManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class ASManager
void SubmitStaticGeometry( StaticGeometryToken& token );


void ClearReplacements();


[[nodiscard]] DynamicGeometryToken BeginDynamicGeometry( VkCommandBuffer cmd,
uint32_t frameIndex );
void SubmitDynamicGeometry( DynamicGeometryToken& token,
Expand Down
25 changes: 12 additions & 13 deletions Source/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ void RTGL1::Scene::RereadReplacements( VkCommandBuffer cmdForTextur
namespace fs = std::filesystem;

replacements.clear();
asManager->ClearReplacements();

if( !exists( replacementsFolder ) )
{
Expand Down Expand Up @@ -579,16 +578,17 @@ void RTGL1::SceneImportExport::CheckForNewScene( std::string_view mapName,
TextureMetaManager& textureMeta,
LightManager& lightManager )
{
if( currentMap != mapName || reimportRequested )
if( currentMap != mapName || reimportRequested || reimportReplacementsRequested )
{
reimportRequested = false;
debug::Verbose( "Starting new scene..." );

currentMap = mapName;
currentMap = mapName;
reimportRequested = false;
reimportReplacementsRequested = false;

// before importer, as it relies on texture properties
textureMeta.RereadFromFiles( GetImportMapName() );

debug::Verbose( "Starting new scene..." );
{
auto staticScene = GltfImporter{ MakeGltfPath( scenesFolder, GetImportMapName() ),
MakeWorldTransform(),
Expand All @@ -598,16 +598,15 @@ void RTGL1::SceneImportExport::CheckForNewScene( std::string_view mapName,
cmd, frameIndex, staticScene, textureManager, textureMeta, lightManager );
}
debug::Verbose( "New scene is ready" );
}

if( reimportReplacementsRequested )
{
reimportReplacementsRequested = false;
debug::Verbose( "Reading replacements..." );

scene.RereadReplacements(
cmd, frameIndex, replacementsFolder, textureManager, textureMeta );
// NOTE: RereadReplacements must happen with NewScene,
// as replacement AS depend on static AS infrastructure

debug::Verbose( "Reading replacements..." );
{
scene.RereadReplacements(
cmd, frameIndex, replacementsFolder, textureManager, textureMeta );
}
debug::Verbose( "Replacements are ready" );
}
}
Expand Down

0 comments on commit 028482d

Please sign in to comment.