From 940c55d6658b5f362f652d3c5ad88de43cae469f Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 3 Feb 2023 23:33:23 +0800 Subject: [PATCH] Fixed Renderables not being removed from a batch if their modifiable material was retrieved --- .gitignore | 1 + Assets/Editor/Layouts/UserLayout.ini | 167 ------------------ .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 32 ++-- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- .../MiddleEnd/Interface/SHRenderable.cpp | 2 + 5 files changed, 20 insertions(+), 184 deletions(-) delete mode 100644 Assets/Editor/Layouts/UserLayout.ini diff --git a/.gitignore b/.gitignore index 1771ebb0..51709e10 100644 --- a/.gitignore +++ b/.gitignore @@ -366,3 +366,4 @@ MigrationBackup/ JSON/Schemas/Catalog/ Assets/Editor/Editor.SHConfig +Assets/Editor/Layouts/UserLayout.ini diff --git a/Assets/Editor/Layouts/UserLayout.ini b/Assets/Editor/Layouts/UserLayout.ini deleted file mode 100644 index c9b890bd..00000000 --- a/Assets/Editor/Layouts/UserLayout.ini +++ /dev/null @@ -1,167 +0,0 @@ -[Window][MainStatusBar] -Pos=0,981 -Size=1920,20 -Collapsed=0 - -[Window][SHEditorMenuBar] -Pos=0,48 -Size=1920,933 -Collapsed=0 - -[Window][Hierarchy Panel] -Pos=0,186 -Size=300,795 -Collapsed=0 -DockId=0x00000004,0 - -[Window][Debug##Default] -Pos=60,60 -Size=400,400 -Collapsed=0 - -[Window][Inspector] -Pos=1434,48 -Size=486,933 -Collapsed=0 -DockId=0x00000006,0 - -[Window][Profiler] -Pos=0,48 -Size=300,136 -Collapsed=0 -DockId=0x00000003,0 - -[Window][Viewport] -Pos=227,48 -Size=1457,1012 -Collapsed=0 -DockId=0x0000000B,0 - -[Window][面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面o] -Pos=60,60 -Size=32,64 -Collapsed=0 - -[Window][面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面面] -Pos=60,60 -Size=999,581 -Collapsed=0 - -[Window][o] -Pos=60,60 -Size=32,64 -Collapsed=0 - -[Window][面面] -Pos=60,60 -Size=553,422 -Collapsed=0 - -[Window][] -Pos=60,60 -Size=770,394 -Collapsed=0 - -[Window][ Viewport] -Pos=227,48 -Size=1457,1012 -Collapsed=0 -DockId=0x0000000B,0 - -[Window][ Viewport] -Pos=227,48 -Size=1457,1012 -Collapsed=0 -DockId=0x0000000B,0 - -[Window][ Viewport] -Pos=302,48 -Size=1130,697 -Collapsed=0 -DockId=0x0000000B,0 - -[Window][V] -Pos=310,722 -Size=1501,338 -Collapsed=0 -DockId=0x00000008,0 - -[Window][p] -Pos=310,750 -Size=1501,310 -Collapsed=0 -DockId=0x0000000A,0 - -[Window][ Asset Browser] -Pos=302,747 -Size=1130,234 -Collapsed=0 -DockId=0x0000000C,0 - -[Window][Material Inspector] -Pos=1434,48 -Size=486,933 -Collapsed=0 -DockId=0x00000006,1 - -[Window][Save scene as...] -Pos=1197,693 -Size=165,120 -Collapsed=0 - -[Window][Create New Asset] -Pos=896,472 -Size=464,144 -Collapsed=0 - -[Window][Collider Tag Panel] -Pos=302,48 -Size=1130,697 -Collapsed=0 -DockId=0x0000000B,1 - -[Window][Input Bindings Panel] -Pos=1434,48 -Size=486,933 -Collapsed=0 -DockId=0x00000006,2 - -[Window][Save Scene As] -Pos=877,444 -Size=165,120 -Collapsed=0 - -[Table][0x9D40AE32,17] -Column 0 Weight=0.9945 -Column 1 Weight=0.9945 -Column 2 Weight=0.9945 -Column 3 Weight=0.9945 -Column 4 Weight=0.9945 -Column 5 Weight=0.9945 -Column 6 Weight=0.9945 -Column 7 Weight=0.9945 -Column 8 Weight=0.9945 -Column 9 Weight=0.9945 -Column 10 Weight=0.9945 -Column 11 Weight=0.9945 -Column 12 Weight=1.0132 -Column 13 Weight=0.8444 -Column 14 Weight=0.9945 -Column 15 Weight=1.2009 -Column 16 Weight=1.0132 - -[Docking][Data] -DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,77 Size=1920,933 Split=X - DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1432,1036 Split=X - DockNode ID=0x00000001 Parent=0x00000005 SizeRef=300,1036 Split=Y Selected=0x1E6EB881 - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,147 Selected=0x1E6EB881 - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,863 Selected=0xE096E5AE - DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1130,1036 Split=Y Selected=0xB41284E7 - DockNode ID=0x00000007 Parent=0x00000002 SizeRef=1501,672 Split=Y Selected=0xB41284E7 - DockNode ID=0x00000009 Parent=0x00000007 SizeRef=1501,700 Split=Y Selected=0xB41284E7 - DockNode ID=0x0000000B Parent=0x00000009 SizeRef=1501,705 CentralNode=1 Selected=0xB41284E7 - DockNode ID=0x0000000C Parent=0x00000009 SizeRef=1501,234 Selected=0xB128252A - DockNode ID=0x0000000A Parent=0x00000007 SizeRef=1501,310 Selected=0xD446F7B6 - DockNode ID=0x00000008 Parent=0x00000002 SizeRef=1501,338 Selected=0xD9F31532 - DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=486,1036 Selected=0xE7039252 - diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 1ac6e2d8..31cd0dfc 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -210,7 +210,7 @@ namespace SHADE } else { - SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!"); + SHLOG_WARNING("[SHBatch] Entity #{} with a missing SHRenderable found!", rendId); } } } @@ -290,20 +290,20 @@ namespace SHADE // Build CPU Buffer char* propsCurrPtr = matPropsData.get(); for (auto& subBatch : subBatches) - for (auto rendId : subBatch.Renderables) + for (auto rendId : subBatch.Renderables) + { + const SHRenderable* renderable = SHComponentManager::GetComponent_s(rendId); + if (renderable) { - const SHRenderable* renderable = SHComponentManager::GetComponent(rendId); - if (renderable) - { - renderable->GetMaterial()->ExportProperties(propsCurrPtr); - } - else - { - SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!"); - } - //propsCurrPtr += singleMatPropAlignedSize; - propsCurrPtr += singleMatPropSize; + renderable->GetMaterial()->ExportProperties(propsCurrPtr); } + else + { + SHLOG_WARNING("[SHBatch] Entity #{} with a missing SHRenderable found!", rendId); + } + //propsCurrPtr += singleMatPropAlignedSize; + propsCurrPtr += singleMatPropSize; + } // Transfer to GPU rebuildDescriptorSetBuffers(frameIndex, descPool); @@ -357,7 +357,7 @@ namespace SHADE } else { - SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!"); + SHLOG_WARNING("[SHBatch] Entity #{} containing a SHRenderable with no SHTransformComponent found!", rendId); transformData.emplace_back(); } } @@ -578,7 +578,7 @@ namespace SHADE } else { - SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!"); + SHLOG_WARNING("[SHBatch] Entity #{} contianing a SHRenderable with no SHTransformComponent found!", rendId); transformData.emplace_back(); } @@ -603,7 +603,7 @@ namespace SHADE } else { - SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!"); + SHLOG_WARNING("[SHBatch] Entity #{} with a missing SHRenderable found!", rendId); } propsCurrPtr += singleMatPropSize; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6734a77e..c79b8899 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -1055,7 +1055,7 @@ namespace SHADE for (auto& renderable : renderables) { // Check if the material instance is now unused - renderable.CleanUpMaterials(); + renderable.CleanUpMaterials(); if (!renderable.HasChanged()) continue; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index d3518e67..8d02a84a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -99,6 +99,8 @@ namespace SHADE { SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem(); material = gfxSystem->AddMaterialInstanceCopy(sharedMaterial); + oldMaterial = sharedMaterial; + oldMatIsShared = true; matChanged = true; }