Graphics/ForwardFramePipeline: Fix unregister + register the same renderable pointer not invalidating rendering

This can happen with ECS components which are mostly stable in memory, when destroying a graphics entity and recreating it (even with a different mesh) its pointer may not change due to memory recycling, especially on simple scenes.

A UInt8 generation counter helps prevents this
This commit is contained in:
SirLynix 2023-05-30 13:34:41 +02:00
parent f2f90e2ca3
commit cff918f6a3
2 changed files with 5 additions and 1 deletions

View File

@ -108,6 +108,7 @@ namespace Nz
const InstancedRenderable* renderable;
Recti scissorBox;
UInt32 renderMask = 0;
UInt8 generation;
NazaraSlot(InstancedRenderable, OnElementInvalidated, onElementInvalidated);
NazaraSlot(InstancedRenderable, OnMaterialInvalidated, onMaterialInvalidated);
@ -169,6 +170,7 @@ namespace Nz
MemoryPool<ViewerData> m_viewerPool;
MemoryPool<WorldInstanceData> m_worldInstances;
RenderFrame* m_currentRenderFrame;
UInt8 m_generationCounter;
bool m_rebuildFrameGraph;
};
}

View File

@ -34,6 +34,7 @@ namespace Nz
m_skeletonInstances(1024),
m_viewerPool(8),
m_worldInstances(2048),
m_generationCounter(0),
m_rebuildFrameGraph(true)
{
}
@ -76,7 +77,7 @@ namespace Nz
else
visibleRenderable.skeletonInstance = nullptr;
visibilityHash = CombineHash(visibilityHash, std::hash<const void*>()(&renderableData));
visibilityHash = CombineHash(visibilityHash, std::hash<const void*>()(&renderableData) + renderableData.generation);
}
return m_visibleRenderables;
@ -148,6 +149,7 @@ namespace Nz
{
std::size_t renderableIndex;
RenderableData* renderableData = m_renderablePool.Allocate(renderableIndex);
renderableData->generation = m_generationCounter++;
renderableData->renderable = instancedRenderable;
renderableData->renderMask = renderMask;
renderableData->scissorBox = scissorBox;