diff --git a/Editor/Source/Editor.cpp b/Editor/Source/Editor.cpp index 654b27356..fcffb24f1 100644 --- a/Editor/Source/Editor.cpp +++ b/Editor/Source/Editor.cpp @@ -82,6 +82,7 @@ namespace Lumos , m_IniFile("") { Debug::Log::SetLoggerFunction(ConsoleLoggerFunction); + Application::SetInstance(this); } Editor::~Editor() @@ -173,7 +174,7 @@ namespace Lumos guizmoStyle.HatchedAxisLineThickness = -1.0f; #ifdef LUMOS_PLATFORM_IOS - m_TempSceneSaveFilePath = OS::Instance()->GetAssetPath(); + m_TempSceneSaveFilePath = OS::Get().GetAssetPath(); #else #ifdef LUMOS_PLATFORM_LINUX m_TempSceneSaveFilePath = std::filesystem::current_path().string(); @@ -194,8 +195,8 @@ namespace Lumos std::filesystem::create_directory(m_TempSceneSaveFilePath); std::vector iniLocation = { - StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "Editor.ini", - StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../../Editor.ini" + StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "Editor.ini", + StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../../Editor.ini" }; bool fileFound = false; std::string filePath; @@ -226,9 +227,9 @@ namespace Lumos { LINFO("Editor Ini not found"); #ifdef LUMOS_PLATFORM_MACOS - filePath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../../Editor.ini"; + filePath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../../Editor.ini"; #else - filePath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "Editor.ini"; + filePath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "Editor.ini"; #endif LINFO("Creating Editor Ini %s", filePath.c_str()); @@ -312,7 +313,7 @@ namespace Lumos Application::Get().GetSystem()->SetDebugDrawFlags(m_Settings.m_Physics2DDebugFlags); ImGuiUtilities::SetTheme(m_Settings.m_Theme); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); Application::Get().GetWindow()->SetWindowTitle("Lumos Editor"); ImGuizmo::SetGizmoSizeClipSpace(m_Settings.m_ImGuizmoScale); @@ -507,7 +508,7 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); // Set filePath to working directory - auto path = OS::Instance()->GetExecutablePath(); + auto path = OS::Get().GetExecutablePath(); std::filesystem::current_path(path); m_FileBrowserPanel->SetCallback(BIND_FILEBROWSER_FN(Editor::FileOpenCallback)); m_FileBrowserPanel->Open(); @@ -601,73 +602,73 @@ namespace Lumos { m_Settings.m_Theme = ImGuiUtilities::Dark; ImGuiUtilities::SetTheme(ImGuiUtilities::Dark); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Dracula", "", m_Settings.m_Theme == ImGuiUtilities::Dracula)) { m_Settings.m_Theme = ImGuiUtilities::Dracula; ImGuiUtilities::SetTheme(ImGuiUtilities::Dracula); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Black", "", m_Settings.m_Theme == ImGuiUtilities::Black)) { m_Settings.m_Theme = ImGuiUtilities::Black; ImGuiUtilities::SetTheme(ImGuiUtilities::Black); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Grey", "", m_Settings.m_Theme == ImGuiUtilities::Grey)) { m_Settings.m_Theme = ImGuiUtilities::Grey; ImGuiUtilities::SetTheme(ImGuiUtilities::Grey); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Light", "", m_Settings.m_Theme == ImGuiUtilities::Light)) { m_Settings.m_Theme = ImGuiUtilities::Light; ImGuiUtilities::SetTheme(ImGuiUtilities::Light); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Cherry", "", m_Settings.m_Theme == ImGuiUtilities::Cherry)) { m_Settings.m_Theme = ImGuiUtilities::Cherry; ImGuiUtilities::SetTheme(ImGuiUtilities::Cherry); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Blue", "", m_Settings.m_Theme == ImGuiUtilities::Blue)) { m_Settings.m_Theme = ImGuiUtilities::Blue; ImGuiUtilities::SetTheme(ImGuiUtilities::Blue); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Cinder", "", m_Settings.m_Theme == ImGuiUtilities::Cinder)) { m_Settings.m_Theme = ImGuiUtilities::Cinder; ImGuiUtilities::SetTheme(ImGuiUtilities::Cinder); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Classic", "", m_Settings.m_Theme == ImGuiUtilities::Classic)) { m_Settings.m_Theme = ImGuiUtilities::Classic; ImGuiUtilities::SetTheme(ImGuiUtilities::Classic); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("ClassicDark", "", m_Settings.m_Theme == ImGuiUtilities::ClassicDark)) { m_Settings.m_Theme = ImGuiUtilities::ClassicDark; ImGuiUtilities::SetTheme(ImGuiUtilities::ClassicDark); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("ClassicLight", "", m_Settings.m_Theme == ImGuiUtilities::ClassicLight)) { m_Settings.m_Theme = ImGuiUtilities::ClassicLight; ImGuiUtilities::SetTheme(ImGuiUtilities::ClassicLight); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } if(ImGui::MenuItem("Cosy", "", m_Settings.m_Theme == ImGuiUtilities::Cosy)) { m_Settings.m_Theme = ImGuiUtilities::Cosy; ImGuiUtilities::SetTheme(ImGuiUtilities::Cosy); - OS::Instance()->SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); + OS::Get().SetTitleBarColour(ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); } ImGui::EndMenu(); } @@ -832,7 +833,7 @@ namespace Lumos std::string githubMenuText = ICON_MDI_GITHUB_BOX " Github"; if(ImGui::MenuItem(githubMenuText.c_str())) { - Lumos::OS::Instance()->OpenURL("https://www.github.com/jmorton06/Lumos"); + Lumos::OS::Get().OpenURL("https://www.github.com/jmorton06/Lumos"); } ImGui::Separator(); @@ -841,25 +842,25 @@ namespace Lumos ArenaTemp scratch = ScratchBegin(nullptr, 0); if(ImGui::MenuItem((const char*)PushStr8F(scratch.arena, "ImGui - Version : %s, Revision - %i", IMGUI_VERSION, IMGUI_VERSION_NUM).str)) - Lumos::OS::Instance()->OpenURL("https://github.com/ocornut/imgui"); + Lumos::OS::Get().OpenURL("https://github.com/ocornut/imgui"); if(ImGui::MenuItem((const char*)PushStr8F(scratch.arena, "Entt - Version : %s", ENTT_VERSION).str)) - Lumos::OS::Instance()->OpenURL("https://github.com/skypjack/entt"); + Lumos::OS::Get().OpenURL("https://github.com/skypjack/entt"); if(ImGui::MenuItem((const char*)PushStr8F(scratch.arena, "Cereal - Version : %i.%i.%i", CEREAL_VERSION_MAJOR, CEREAL_VERSION_MINOR, CEREAL_VERSION_PATCH).str)) - Lumos::OS::Instance()->OpenURL("https://github.com/USCiLab/cereal"); + Lumos::OS::Get().OpenURL("https://github.com/USCiLab/cereal"); if(ImGui::MenuItem((const char*)PushStr8F(scratch.arena, "Box2D - Version : %i.%i", 3, 0).str)) - Lumos::OS::Instance()->OpenURL("https://github.com/erincatto/box2d"); + Lumos::OS::Get().OpenURL("https://github.com/erincatto/box2d"); ScratchEnd(scratch); if(ImGui::BeginMenu("Contributers")) { if(ImGui::MenuItem("Joe Morton")) - Lumos::OS::Instance()->OpenURL("https://github.com/jmorton06"); + Lumos::OS::Get().OpenURL("https://github.com/jmorton06"); if(ImGui::MenuItem("RuanLucasGD")) - Lumos::OS::Instance()->OpenURL("https://github.com/RuanLucasGD"); + Lumos::OS::Get().OpenURL("https://github.com/RuanLucasGD"); if(ImGui::MenuItem("adriengivry")) - Lumos::OS::Instance()->OpenURL("https://github.com/adriengivry"); + Lumos::OS::Get().OpenURL("https://github.com/adriengivry"); ImGui::EndMenu(); // Contributer Menu } @@ -1226,7 +1227,7 @@ namespace Lumos locationPopupOpened = true; // Set filePath to working directory - const auto& path = OS::Instance()->GetExecutablePath(); + const auto& path = OS::Get().GetExecutablePath(); auto& browserPath = m_FileBrowserPanel->GetPath(); browserPath = std::filesystem::path(path); m_FileBrowserPanel->SetFileTypeFilters({ ".lmproj" }); @@ -1249,7 +1250,7 @@ namespace Lumos locationPopupOpened = true; // Set filePath to working directory - const auto& path = OS::Instance()->GetExecutablePath(); + const auto& path = OS::Get().GetExecutablePath(); auto& browserPath = m_FileBrowserPanel->GetPath(); browserPath = std::filesystem::path(path); m_FileBrowserPanel->ClearFileTypeFilters(); @@ -2659,7 +2660,7 @@ namespace Lumos isProfiling = tracy::GetProfiler().IsConnected(); #endif if(!isProfiling && m_Settings.m_SleepOutofFocus && !Application::Get().GetWindow()->GetWindowFocus() && m_EditorState != EditorState::Play && !firstFrame) - OS::Instance()->Delay(1000000); + OS::Get().Delay(1000000); Application::OnRender(); @@ -2884,10 +2885,10 @@ namespace Lumos #ifdef LUMOS_PLATFORM_MACOS // Assuming working directory in /bin/Debug-macosx-x86_64/LumosEditor.app/Contents/MacOS - m_ProjectSettings.m_ProjectRoot = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../../../../ExampleProject/"; + m_ProjectSettings.m_ProjectRoot = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../../../../ExampleProject/"; if(!Lumos::FileSystem::FolderExists(m_ProjectSettings.m_ProjectRoot)) { - m_ProjectSettings.m_ProjectRoot = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "/ExampleProject/"; + m_ProjectSettings.m_ProjectRoot = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "/ExampleProject/"; if(!Lumos::FileSystem::FolderExists(m_ProjectSettings.m_ProjectRoot)) { m_ProjectSettings.m_ProjectRoot = "../../ExampleProject/"; diff --git a/Editor/Source/Editor.h b/Editor/Source/Editor.h index a80f1fd80..46674f42e 100644 --- a/Editor/Source/Editor.h +++ b/Editor/Source/Editor.h @@ -11,9 +11,7 @@ namespace Lumos { -#define BIND_FILEBROWSER_FN(fn) [this](auto&&... args) -> decltype(auto) { \ - return this->fn(std::forward(args)...); \ -} +#define BIND_FILEBROWSER_FN(fn) [this](auto&&... args) -> decltype(auto) { return this->fn(std::forward(args)...); } class Scene; class Event; diff --git a/Editor/Source/ResourcePanel.cpp b/Editor/Source/ResourcePanel.cpp index 0def2389a..518f88203 100644 --- a/Editor/Source/ResourcePanel.cpp +++ b/Editor/Source/ResourcePanel.cpp @@ -748,7 +748,7 @@ namespace Lumos if(ImGui::Selectable("Open Location")) { - Lumos::OS::Instance()->OpenFileLocation(ToStdString(m_CurrentDir->AssetPath)); + Lumos::OS::Get().OpenFileLocation(ToStdString(m_CurrentDir->AssetPath)); } ImGui::Separator(); @@ -987,7 +987,7 @@ namespace Lumos { ArenaTemp temp = ScratchBegin(&m_Arena, 1); String8 fullPath = StringUtilities::RelativeToAbsolutePath(temp.arena, m_CurrentDir->Children[dirIndex]->AssetPath, Str8Lit("//Assets"), m_BasePath); - Lumos::OS::Instance()->OpenFileLocation(std::string((const char*)fullPath.str, fullPath.size)); + Lumos::OS::Get().OpenFileLocation(std::string((const char*)fullPath.str, fullPath.size)); ScratchEnd(temp); } @@ -995,7 +995,7 @@ namespace Lumos { ArenaTemp temp = ScratchBegin(&m_Arena, 1); String8 fullPath = StringUtilities::RelativeToAbsolutePath(temp.arena, m_CurrentDir->Children[dirIndex]->AssetPath, Str8Lit("//Assets"), m_BasePath); - Lumos::OS::Instance()->OpenFileExternal(std::string((const char*)fullPath.str, fullPath.size)); + Lumos::OS::Get().OpenFileExternal(std::string((const char*)fullPath.str, fullPath.size)); ScratchEnd(temp); } diff --git a/ExampleProject/Assets/Scenes/CollisionPyramidTest.lsn b/ExampleProject/Assets/Scenes/CollisionPyramidTest.lsn index 00d9683f0..b2086764a 100644 --- a/ExampleProject/Assets/Scenes/CollisionPyramidTest.lsn +++ b/ExampleProject/Assets/Scenes/CollisionPyramidTest.lsn @@ -1278,27 +1278,8 @@ "value2": 1.0 } }, - "value192": 0, + "value192": 1, "value193": { - "Position": { - "value0": -62.4451789855957, - "value1": 37.44212341308594, - "value2": 26.386333465576173 - }, - "Rotation": { - "value0": -0.19666795432567597, - "value1": -0.5465598702430725, - "value2": -0.13387542963027955, - "value3": 0.8029143214225769 - }, - "Scale": { - "value0": 1.0000100135803223, - "value1": 1.0000016689300538, - "value2": 1.00001060962677 - } - }, - "value194": 1, - "value195": { "Position": { "value0": -5.864191055297852, "value1": 4.970639705657959, @@ -1316,6 +1297,25 @@ "value2": 1.000001311302185 } }, + "value194": 0, + "value195": { + "Position": { + "value0": -62.4451789855957, + "value1": 37.44212341308594, + "value2": 26.386333465576173 + }, + "Rotation": { + "value0": -0.19666795432567597, + "value1": -0.5465598702430725, + "value2": -0.13387542963027955, + "value3": 0.8029143214225769 + }, + "Scale": { + "value0": 1.0000100135803223, + "value1": 1.0000016689300538, + "value2": 1.00001060962677 + } + }, "value196": 64, "value197": 0, "value198": { @@ -1579,7 +1579,7 @@ "value328": 1, "value329": { "Scale": 1.0, - "Aspect": 0.8345070481300354, + "Aspect": 0.7917808294296265, "FOV": 60.0, "Near": 0.10000000149011612, "Far": 100.0, @@ -1611,9 +1611,9 @@ "value2": 0.0, "value3": 0.0, "value4": { - "value0": -0.8250278830528259, - "value1": 0.46215835213661196, - "value2": 0.32517489790916445, + "value0": -0.8250242471694946, + "value1": 0.46215686202049258, + "value2": 0.325186163187027, "value3": 1.0 }, "value5": 120000.0, @@ -1675,7 +1675,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 12765891224963149148 + "UUID": 179182723597584396 } }, "value340": 15, @@ -1715,7 +1715,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -1732,7 +1732,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 14124620850671517816 + "UUID": 1818045409618000476 } }, "value342": 1048579, @@ -1772,7 +1772,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -1789,7 +1789,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 1380821290874780425 + "UUID": 6045465172091505932 } }, "value344": 5, @@ -1829,7 +1829,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -1846,7 +1846,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 3248324608811708532 + "UUID": 6828137227947396838 } }, "value346": 6, @@ -1886,7 +1886,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -1903,7 +1903,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 6684469800302012934 + "UUID": 2533255684707918324 } }, "value348": 7, @@ -1943,7 +1943,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -1960,7 +1960,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 15073449979222112400 + "UUID": 11930240693188244339 } }, "value350": 8, @@ -2000,7 +2000,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2017,7 +2017,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 9281915264351173579 + "UUID": 5121420269304102350 } }, "value352": 9, @@ -2057,7 +2057,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2074,7 +2074,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 2069776245703872564 + "UUID": 14349243405333937365 } }, "value354": 10, @@ -2114,7 +2114,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2131,7 +2131,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 3916300973233201414 + "UUID": 15194606780167736742 } }, "value356": 11, @@ -2171,7 +2171,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2188,7 +2188,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 9209434808726851781 + "UUID": 7671930669270942881 } }, "value358": 12, @@ -2228,7 +2228,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2245,7 +2245,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 15927763354293157651 + "UUID": 1661530569663573634 } }, "value360": 13, @@ -2285,7 +2285,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2302,7 +2302,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 3549040201012728216 + "UUID": 13077949273136509090 } }, "value362": 14, @@ -2342,7 +2342,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2359,7 +2359,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 6073528338790435857 + "UUID": 15106905067355283703 } }, "value364": 2097156, @@ -2399,7 +2399,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2416,7 +2416,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 12724538206079671668 + "UUID": 15477854326906404058 } }, "value366": 16, @@ -2456,7 +2456,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2473,7 +2473,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 5702730866380331189 + "UUID": 7260753250592374851 } }, "value368": 17, @@ -2513,7 +2513,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2530,7 +2530,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 6879513321339947330 + "UUID": 2189477769059498148 } }, "value370": 18, @@ -2570,7 +2570,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2587,7 +2587,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 10633312526547410 + "UUID": 752573146412109999 } }, "value372": 19, @@ -2627,7 +2627,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2644,7 +2644,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 424568702641793878 + "UUID": 9922643420853088265 } }, "value374": 20, @@ -2684,7 +2684,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2701,7 +2701,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 11699665882880201439 + "UUID": 10869462115132980274 } }, "value376": 21, @@ -2741,7 +2741,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2758,7 +2758,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 12641160362773292545 + "UUID": 12859764492534740704 } }, "value378": 22, @@ -2798,7 +2798,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2815,7 +2815,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 2428159787742849398 + "UUID": 11847191314866566833 } }, "value380": 23, @@ -2855,7 +2855,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2872,7 +2872,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 17778560311173156369 + "UUID": 14700503978037018245 } }, "value382": 24, @@ -2912,7 +2912,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2929,7 +2929,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 9476386836145103300 + "UUID": 8826653037772137916 } }, "value384": 25, @@ -2969,7 +2969,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -2986,7 +2986,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 15989596112139022853 + "UUID": 13405097037343651030 } }, "value386": 26, @@ -3026,7 +3026,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3043,7 +3043,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 994319030523486187 + "UUID": 3183649899231218030 } }, "value388": 27, @@ -3083,7 +3083,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3100,7 +3100,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 12115965623484273656 + "UUID": 1733503446949415728 } }, "value390": 28, @@ -3140,7 +3140,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3157,7 +3157,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 4441128601702071229 + "UUID": 8590402183589778554 } }, "value392": 29, @@ -3197,7 +3197,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3214,7 +3214,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 3011590062345662049 + "UUID": 8498315524525232432 } }, "value394": 30, @@ -3254,7 +3254,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3271,7 +3271,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 7958226201624162227 + "UUID": 14365814025472645403 } }, "value396": 31, @@ -3311,7 +3311,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3328,7 +3328,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 14364822935462599121 + "UUID": 13102685198304323990 } }, "value398": 32, @@ -3368,7 +3368,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3385,7 +3385,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 10116647278128067124 + "UUID": 13254255273246769406 } }, "value400": 33, @@ -3425,7 +3425,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3442,7 +3442,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 4350360944147137390 + "UUID": 13939230201604292627 } }, "value402": 34, @@ -3482,7 +3482,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3499,7 +3499,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 17967561138144687667 + "UUID": 968911713633529105 } }, "value404": 35, @@ -3539,7 +3539,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3556,7 +3556,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 6648076573853182731 + "UUID": 1441578788782020585 } }, "value406": 36, @@ -3596,7 +3596,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3613,7 +3613,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 11346640541330593480 + "UUID": 16718749401438774549 } }, "value408": 37, @@ -3653,7 +3653,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3670,7 +3670,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 2135497860795676741 + "UUID": 16546546366529625979 } }, "value410": 38, @@ -3710,7 +3710,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3727,7 +3727,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 11586390797303232911 + "UUID": 16044696873204338891 } }, "value412": 39, @@ -3767,7 +3767,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3784,7 +3784,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 14212772810234838412 + "UUID": 3093487887556497912 } }, "value414": 40, @@ -3824,7 +3824,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3841,7 +3841,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 11594871595722117326 + "UUID": 14238327317188437753 } }, "value416": 41, @@ -3881,7 +3881,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3898,7 +3898,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 12224865755712903676 + "UUID": 1292644875548548526 } }, "value418": 42, @@ -3938,7 +3938,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -3955,7 +3955,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 4151978595224798290 + "UUID": 7138516496525000751 } }, "value420": 43, @@ -3995,7 +3995,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4012,7 +4012,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 4297293758746473244 + "UUID": 154856918226496095 } }, "value422": 44, @@ -4052,7 +4052,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 1.0, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4069,7 +4069,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 5149694027543575115 + "UUID": 9198268907774561076 } }, "value424": 45, @@ -4109,7 +4109,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4126,7 +4126,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 13288373671117375945 + "UUID": 8232279480038863874 } }, "value426": 46, @@ -4166,7 +4166,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4183,7 +4183,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 18036779982147106073 + "UUID": 12964709596416169346 } }, "value428": 47, @@ -4223,7 +4223,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4240,7 +4240,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 9293254586593893222 + "UUID": 16121816344882625794 } }, "value430": 48, @@ -4280,7 +4280,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4297,7 +4297,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 5175011279538699142 + "UUID": 2442351546540665136 } }, "value432": 49, @@ -4337,7 +4337,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4354,7 +4354,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 5073070895345712869 + "UUID": 6653751586198337986 } }, "value434": 50, @@ -4394,7 +4394,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4411,7 +4411,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 4842248677782477089 + "UUID": 16659543140009721495 } }, "value436": 51, @@ -4451,7 +4451,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4468,7 +4468,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 5503708230626557142 + "UUID": 18096416314940791399 } }, "value438": 52, @@ -4508,7 +4508,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4525,7 +4525,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 7730052640854699457 + "UUID": 11210784465750760210 } }, "value440": 53, @@ -4565,7 +4565,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4582,7 +4582,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 6607013305280990753 + "UUID": 14042148476073189863 } }, "value442": 54, @@ -4622,7 +4622,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4639,7 +4639,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 1281327391123014549 + "UUID": 12552449471398053441 } }, "value444": 55, @@ -4679,7 +4679,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4696,7 +4696,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 9027422283863313191 + "UUID": 6210985305911137279 } }, "value446": 56, @@ -4736,7 +4736,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4753,7 +4753,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 16320441224867957411 + "UUID": 8779276643356106075 } }, "value448": 57, @@ -4793,7 +4793,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4810,7 +4810,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 8039210053221457630 + "UUID": 5651281166425344471 } }, "value450": 58, @@ -4850,7 +4850,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4867,7 +4867,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 2181841838239292726 + "UUID": 1897880355733938132 } }, "value452": 59, @@ -4907,7 +4907,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4924,7 +4924,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 14598477269013623668 + "UUID": 15098385944655115011 } }, "value454": 60, @@ -4964,7 +4964,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -4981,7 +4981,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 6402239013415017164 + "UUID": 13262777166327958682 } }, "value456": 61, @@ -5021,7 +5021,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -5038,7 +5038,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 3209867867122034582 + "UUID": 7845552626040083084 } }, "value458": 1048638, @@ -5078,7 +5078,7 @@ "value2": 0.0 }, "Static": false, - "Friction": 0.5, + "Friction": 0.8999999761581421, "Elasticity": 0.5, "CollisionShape": { "polymorphic_id": 1, @@ -5095,7 +5095,7 @@ }, "Trigger": false, "AngularFactor": 1.0, - "UUID": 17572775997179209122 + "UUID": 12300446513650994490 } }, "value460": 0, @@ -5398,7 +5398,7 @@ "emissiveMapFactor": 0.0, "alphaCutOff": 0.4000000059604645, "workflow": 0.0, - "shader": "/Users/jmorton/Dev/Lumos/Lumos/Assets/Shaders/ForwardPBR.shader", + "shader": "Embedded", "Reflectance": 0.30000001192092898 } } @@ -6024,8 +6024,8 @@ "value2": 1.0, "value3": 1.0 }, - "roughnessValue": 0.2150000035762787, - "metallicValue": 0.953000009059906, + "roughnessValue": 0.5527864098548889, + "metallicValue": 0.699999988079071, "emissiveValue": 0.0, "albedoMapFactor": 1.0, "metallicMapFactor": 0.0, @@ -6035,8 +6035,8 @@ "emissiveMapFactor": 0.0, "alphaCutOff": 0.4000000059604645, "workflow": 0.0, - "shader": "/Users/jmorton/Dev/Lumos/Lumos/Assets/Shaders/ForwardPBR.shader", - "Reflectance": 0.5289999842643738 + "shader": "Embedded", + "Reflectance": 0.30000001192092898 } } } diff --git a/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp b/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp index 15cae614e..d38062052 100644 --- a/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp +++ b/Lumos/External/imgui/backends/imgui_impl_vulkan.cpp @@ -360,15 +360,7 @@ static uint32_t __glsl_shader_frag_spv[] = //----------------------------------------------------------------------------- // FUNCTIONS -//----------------------------------------------------------------------------- - -static std::array, 3>* g_DescriptorSets = nullptr; -static std::unordered_map* g_DescriptorImageInfos = nullptr; - -std::unordered_map& ImGui_ImplVulkan_GetDescriptorImageMap() -{ - return *g_DescriptorImageInfos; -} +//---------------------------------------------------------------------------- // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts. @@ -442,7 +434,7 @@ static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkPipeline { vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); VkDescriptorSet desc_set[1] = { bd->FontDescriptorSet }; - vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, NULL); + //vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, NULL); } // Bind Vertex And Index Buffer: @@ -579,26 +571,26 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm static VkDescriptorSet lastSet = VK_NULL_HANDLE; VkDescriptorSet desc_set[1]; - if (pcmd->TextureId && (*g_DescriptorSets)[bufferIndex].find(pcmd->TextureId) != (*g_DescriptorSets)[bufferIndex].end()) + if (pcmd->TextureId) { uint32_t index = 0; - auto desc = (*g_DescriptorSets)[bufferIndex][pcmd->TextureId]; - //if (lastSet != desc) + auto desc = (VkDescriptorSet)pcmd->TextureId; + if (lastSet != desc) { desc_set[0] = desc; lastSet = desc; vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, NULL); } } - else - { - //if (lastSet != g_DescriptorSet) - { - // desc_set[0] = g_DescriptorSet; - // lastSet = g_DescriptorSet; - vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, NULL); - } - } + //else + //{ + // //if (lastSet != g_DescriptorSet) + // { + // // desc_set[0] = g_DescriptorSet; + // // lastSet = g_DescriptorSet; + // //vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bd->PipelineLayout, 0, 1, desc_set, 0, NULL); + // } + //} // Project scissor/clipping rectangles into framebuffer space ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); @@ -1140,9 +1132,6 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend IM_ASSERT(0 && "Can't use dynamic rendering when neither VK_VERSION_1_3 or VK_KHR_dynamic_rendering is defined."); #endif } - - g_DescriptorSets = new std::array, 3>(); - g_DescriptorImageInfos = new std::unordered_map(); ImGuiIO& io = ImGui::GetIO(); IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); @@ -1184,8 +1173,6 @@ void ImGui_ImplVulkan_Shutdown() IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); ImGuiIO& io = ImGui::GetIO(); - delete g_DescriptorImageInfos; - delete g_DescriptorSets; // First destroy objects in all viewports ImGui_ImplVulkan_DestroyDeviceObjects(); @@ -1871,100 +1858,40 @@ void ImGui_ImplVulkan_ShutdownPlatformInterface() ImGui::DestroyPlatformWindows(); } -void ImGui_ImplVulkan_CreateDescriptorSets(ImDrawData* draw_data, uint32_t frameIndex) -{ - - static std::array, 3> g_DescriptorSetHasUpdated; - g_DescriptorSetHasUpdated[frameIndex].clear(); - - ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; - auto& lDescriptorSets = *g_DescriptorSets; - uint32_t imageInfoCount = 0; - VkDescriptorImageInfo imageInfo[1024]; - - // Create Descriptor Set: - { - VkDescriptorSetAllocateInfo alloc_info = {}; - alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - alloc_info.descriptorPool = v->DescriptorPools[0]; - alloc_info.descriptorSetCount = 1; - alloc_info.pSetLayouts = &bd->DescriptorSetLayout; - vkAllocateDescriptorSets(v->Device, &alloc_info, &bd->FontDescriptorSet); - } - - for (int n = 0; n < draw_data->CmdListsCount; n++) - { - const ImDrawList* cmd_list = draw_data->CmdLists[n]; - for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) - { - const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - - if (pcmd->TextureId) - { - const auto& findResult = lDescriptorSets.at(frameIndex).find(pcmd->TextureId); - if (findResult == lDescriptorSets.at(frameIndex).end()) - { - VkWriteDescriptorSet descriptorWrites[1] = {}; - - VkDescriptorSet set; - VkDescriptorSetAllocateInfo alloc_info = {}; - alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - alloc_info.descriptorPool = v->DescriptorPools[frameIndex]; - alloc_info.descriptorSetCount = 1; - - ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); - alloc_info.pSetLayouts = &bd->DescriptorSetLayout; - alloc_info.pNext = nullptr; - if (vkAllocateDescriptorSets(v->Device, &alloc_info, &set) == VK_SUCCESS) - lDescriptorSets[frameIndex][pcmd->TextureId] = set; - else - LERROR("Failed to allocate descriptor set"); - } - - if(!g_DescriptorSetHasUpdated.at(frameIndex)[pcmd->TextureId]) - { - VkWriteDescriptorSet descriptorWrites[1] = {}; - - const auto& findResult = lDescriptorSets.at(frameIndex).find(pcmd->TextureId); - if (findResult != lDescriptorSets.at(frameIndex).end() && findResult->second) - { - auto set = findResult->second; - - descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - descriptorWrites[0].dstSet = set; - descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - imageInfo[imageInfoCount] = ((VkDescriptorImageInfo)(*g_DescriptorImageInfos)[pcmd->TextureId]); - descriptorWrites[0].pImageInfo = &imageInfo[imageInfoCount]; - descriptorWrites[0].descriptorCount = 1; - descriptorWrites[0].dstBinding = 0; - - imageInfoCount++; - - if (descriptorWrites[0].pImageInfo) - { - g_DescriptorSetHasUpdated.at(frameIndex)[pcmd->TextureId] = true; - vkUpdateDescriptorSets(v->Device, 1, descriptorWrites, 0, nullptr); - } - } - - } - } - } - } -} - -void ImGui_ImplVulkan_ClearDescriptors(uint32_t index) +VkDescriptorSet ImGui_ImplVulkanH_GetFontDescriptor() { - (*g_DescriptorSets)[index].clear(); + return VkDescriptorSet(); } -void ImGui_ImplVulkan_AddTexture(ImTextureID id, VkDescriptorSet sets, uint32_t index) +ImTextureID ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout, VkDescriptorPool pool) { - (*g_DescriptorSets)[index][id] = sets; -} + ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); + if (!bd->DescriptorSetLayout) + return nullptr; -VkDescriptorSet ImGui_ImplVulkanH_GetFontDescriptor() -{ - return VkDescriptorSet(); + ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; + + VkDescriptorSetAllocateInfo alloc_info = {}; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = pool; + alloc_info.descriptorSetCount = 1; + alloc_info.pSetLayouts = &bd->DescriptorSetLayout; + VkDescriptorSet descriptor_set; + VkResult err = vkAllocateDescriptorSets(v->Device, &alloc_info, &descriptor_set); + + VkDescriptorImageInfo desc_image = {}; + desc_image.sampler = sampler; + desc_image.imageView = image_view; + desc_image.imageLayout = image_layout; + + VkWriteDescriptorSet write_desc = {}; + write_desc.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + write_desc.dstSet = descriptor_set; + write_desc.descriptorCount = 1; + write_desc.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + write_desc.pImageInfo = &desc_image; + + vkUpdateDescriptorSets(v->Device, 1, &write_desc, 0, NULL); + + return (ImTextureID)descriptor_set; } diff --git a/Lumos/External/imgui/backends/imgui_impl_vulkan.h b/Lumos/External/imgui/backends/imgui_impl_vulkan.h index d44ab0e17..0a48b44ed 100644 --- a/Lumos/External/imgui/backends/imgui_impl_vulkan.h +++ b/Lumos/External/imgui/backends/imgui_impl_vulkan.h @@ -71,7 +71,6 @@ struct ImGui_ImplVulkan_InitInfo }; // Called by user code -IMGUI_IMPL_API void ImGui_ImplVulkan_CreateDescriptorSets(ImDrawData* draw_data, uint32_t frameIndex); IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass); IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown(); IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame(); @@ -80,15 +79,11 @@ IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects(); IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated) - // Optional: load Vulkan functions with a custom function loader // This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = NULL); -IMGUI_IMPL_API void ImGui_ImplVulkan_AddTexture(ImTextureID id, VkDescriptorSet sets, uint32_t index); -IMGUI_IMPL_API void ImGui_ImplVulkan_ClearDescriptors(uint32_t index); -IMGUI_IMPL_API std::unordered_map& ImGui_ImplVulkan_GetDescriptorImageMap(); -IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data); - +IMGUI_IMPL_API ImTextureID ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout, VkDescriptorPool pool); +IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data); //------------------------------------------------------------------------- // Internal / Miscellaneous Vulkan Helpers // (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.) diff --git a/Lumos/Source/Lumos/AI/AINode.h b/Lumos/Source/Lumos/AI/AINode.h index a93332e42..502281e3c 100644 --- a/Lumos/Source/Lumos/AI/AINode.h +++ b/Lumos/Source/Lumos/AI/AINode.h @@ -8,6 +8,6 @@ namespace Lumos AINode() = default; virtual ~AINode() = default; - void Update(float dt) {}; + void Update(float dt) { }; }; } diff --git a/Lumos/Source/Lumos/Audio/AudioManager.h b/Lumos/Source/Lumos/Audio/AudioManager.h index 0986dc9a9..e6928096f 100644 --- a/Lumos/Source/Lumos/Audio/AudioManager.h +++ b/Lumos/Source/Lumos/Audio/AudioManager.h @@ -21,24 +21,14 @@ namespace Lumos virtual ~AudioManager() = default; virtual bool OnInit() override = 0; virtual void OnUpdate(const TimeStep& dt, Scene* scene) override = 0; - virtual void UpdateListener(Scene* scene) {}; + virtual void UpdateListener(Scene* scene) { }; - void AddSoundNode(SoundNode* node) - { - m_SoundNodes.EmplaceBack(node); - } - void OnDebugDraw() override {}; - - void ClearNodes() - { - m_SoundNodes.Clear(); - } + void OnDebugDraw() override { }; bool GetPaused() const { return m_Paused; } void SetPaused(bool paused); protected: - TDArray m_SoundNodes; bool m_Paused; }; } diff --git a/Lumos/Source/Lumos/Audio/EmptyAudioManager.h b/Lumos/Source/Lumos/Audio/EmptyAudioManager.h index 84a53950c..3ca2755f2 100644 --- a/Lumos/Source/Lumos/Audio/EmptyAudioManager.h +++ b/Lumos/Source/Lumos/Audio/EmptyAudioManager.h @@ -11,7 +11,7 @@ namespace Lumos ~EmptyAudioManager() = default; bool OnInit() override { return true; }; - void OnUpdate(const TimeStep& dt, Scene* scene) override {}; + void OnUpdate(const TimeStep& dt, Scene* scene) override { }; void OnImGui() override { } }; } diff --git a/Lumos/Source/Lumos/Core/Application.cpp b/Lumos/Source/Lumos/Core/Application.cpp index 57d831d22..c42813117 100644 --- a/Lumos/Source/Lumos/Core/Application.cpp +++ b/Lumos/Source/Lumos/Core/Application.cpp @@ -57,18 +57,12 @@ namespace Lumos { - Application* Application::s_Instance = nullptr; - Application::Application() : m_Frames(0) , m_Updates(0) , m_SceneViewWidth(800) , m_SceneViewHeight(600) { - LUMOS_PROFILE_FUNCTION(); - ASSERT(!s_Instance, "Application already exists!"); - - s_Instance = this; } Application::~Application() @@ -132,8 +126,8 @@ namespace Lumos } // Initialise the Window - m_Window = UniquePtr(Window::Create(windowDesc)); - if(!m_Window->HasInitialised()) + m_Window = UniquePtr(Window::Create()); + if(!m_Window->Init(windowDesc)) OnQuit(); m_Window->SetEventCallback(BIND_EVENT_FN(Application::OnEvent)); @@ -249,9 +243,9 @@ namespace Lumos m_AssetManager.reset(); m_SceneManager.reset(); m_SceneRenderer.reset(); - m_SystemManager.reset(); m_ImGuiManager.reset(); LuaManager::Release(); + m_SystemManager.reset(); Graphics::Pipeline::ClearCache(); Graphics::RenderPass::ClearCache(); @@ -317,10 +311,10 @@ namespace Lumos #ifdef LUMOS_PLATFORM_MACOS // This is assuming Application in bin/Release-macos-x86_64/LumosEditor.app - LINFO(StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()).c_str()); - m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../../../../Lumos/Assets/"; + LINFO(StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()).c_str()); + m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../../../../Lumos/Assets/"; #else - m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../Lumos/Assets/"; + m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../Lumos/Assets/"; #endif FileSystem::CreateFolderIfDoesntExist(m_ProjectSettings.m_ProjectRoot + "Assets"); @@ -465,6 +459,11 @@ namespace Lumos } System::JobSystem::Context context; + if(!m_Minimized) + { + Graphics::Renderer::GetRenderer()->Begin(); + } + m_ImGuiManager->OnNewFrame(); { LUMOS_PROFILE_SCOPE("Application::Update"); @@ -498,9 +497,7 @@ namespace Lumos LUMOS_PROFILE_SCOPE("Application::Render"); Engine::Get().ResetStats(); - Graphics::Renderer::GetRenderer()->Begin(); OnRender(); - m_ImGuiManager->OnNewFrame(); m_ImGuiManager->OnRender(m_SceneManager->GetCurrentScene()); // Clears debug line and point lists @@ -846,15 +843,15 @@ namespace Lumos #ifdef LUMOS_PLATFORM_MACOS // This is assuming Application in bin/Release-macos-x86_64/LumosEditor.app - LINFO(StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()).c_str()); - m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../../../../Lumos/Assets/"; + LINFO(StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()).c_str()); + m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../../../../Lumos/Assets/"; if(!FileSystem::FolderExists(m_ProjectSettings.m_EngineAssetPath)) { - m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../Lumos/Assets/"; + m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../Lumos/Assets/"; } #else - m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../Lumos/Assets/"; + m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../Lumos/Assets/"; #endif m_SceneManager->EnqueueScene(new Scene("Empty Scene")); m_SceneManager->SwitchScene(0); @@ -903,9 +900,9 @@ namespace Lumos m_ProjectSettings.Fullscreen = false; #ifdef LUMOS_PLATFORM_MACOS - m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../../../../Lumos/Assets/"; + m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../../../../Lumos/Assets/"; #else - m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Instance()->GetExecutablePath()) + "../../Lumos/Assets/"; + m_ProjectSettings.m_EngineAssetPath = StringUtilities::GetFileLocation(OS::Get().GetExecutablePath()) + "../../Lumos/Assets/"; #endif m_SceneManager->EnqueueScene(new Scene("Empty Scene")); diff --git a/Lumos/Source/Lumos/Core/Application.h b/Lumos/Source/Lumos/Core/Application.h index 5c0a04788..0270a6a7e 100644 --- a/Lumos/Source/Lumos/Core/Application.h +++ b/Lumos/Source/Lumos/Core/Application.h @@ -52,8 +52,9 @@ namespace Lumos Editor }; - class LUMOS_EXPORT Application + class LUMOS_EXPORT Application : public TSingleton { + friend class TSingleton; friend class Editor; friend class Runtime; template @@ -110,15 +111,6 @@ namespace Lumos void SubmitToMainThread(const Function& function); void ExecuteMainThreadQueue(); - static Application& Get() { return *s_Instance; } - - static void Release() - { - if(s_Instance) - delete s_Instance; - s_Instance = nullptr; - } - template T* GetSystem() { @@ -242,8 +234,6 @@ namespace Lumos EditorState m_EditorState = EditorState::Preview; AppType m_AppType = AppType::Editor; - static Application* s_Instance; - std::thread m_UpdateThread; TDArray> m_MainThreadQueue; diff --git a/Lumos/Source/Lumos/Core/Asset/MeshAsset.cpp b/Lumos/Source/Lumos/Core/Asset/MeshAsset.cpp new file mode 100644 index 000000000..a423dd23b --- /dev/null +++ b/Lumos/Source/Lumos/Core/Asset/MeshAsset.cpp @@ -0,0 +1,14 @@ +#include "Precompiled.h" +#include "MeshAsset.h" + +namespace Lumos +{ + void Serialise(const char* path, MeshAsset& asset) + { + } + + Graphics::Mesh* Deserialise(const char* path) + { + return nullptr; + } +} \ No newline at end of file diff --git a/Lumos/Source/Lumos/Core/Asset/MeshAsset.h b/Lumos/Source/Lumos/Core/Asset/MeshAsset.h new file mode 100644 index 000000000..4f298eac9 --- /dev/null +++ b/Lumos/Source/Lumos/Core/Asset/MeshAsset.h @@ -0,0 +1,27 @@ +#pragma once + +namespace Lumos +{ + namespace Graphics + { + class Mesh; + + } + struct MeshAsset + { + const char* name; + u64 ID; + u64 materialID; + + u32* Indices; + u32 IndexCount; + + u8* VertedData; // Can be cast to Vertex or AnimVertex; + u32 VertexDataSize; + + bool Animated; + }; + + void Serialise(const char* path, MeshAsset& asset); + Graphics::Mesh* Deserialise(const char* path); +} \ No newline at end of file diff --git a/Lumos/Source/Lumos/Core/Core.h b/Lumos/Source/Lumos/Core/Core.h index 2f5f24f07..ece3a4a8f 100644 --- a/Lumos/Source/Lumos/Core/Core.h +++ b/Lumos/Source/Lumos/Core/Core.h @@ -145,8 +145,7 @@ #if defined(_MSC_VER) #define DISABLE_WARNING_PUSH __pragma(warning(push)) #define DISABLE_WARNING_POP __pragma(warning(pop)) -#define DISABLE_WARNING(warningNumber) __pragma(warning(disable \ - : warningNumber)) +#define DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber)) #define DISABLE_WARNING_UNREFERENCED_FORMAL_PARAMETER DISABLE_WARNING(4100) #define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(4505) diff --git a/Lumos/Source/Lumos/Core/CoreSystem.cpp b/Lumos/Source/Lumos/Core/CoreSystem.cpp index 1e2567868..cc1ae9b01 100644 --- a/Lumos/Source/Lumos/Core/CoreSystem.cpp +++ b/Lumos/Source/Lumos/Core/CoreSystem.cpp @@ -62,7 +62,7 @@ namespace Lumos ArenaClear(s_Arena); - MemoryManager::OnShutdown(); + MemoryManager::Release(); ThreadContextRelease(GetThreadContext()); } diff --git a/Lumos/Source/Lumos/Core/DataStructures/Map.h b/Lumos/Source/Lumos/Core/DataStructures/Map.h index 2b25d0f63..84118756e 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/Map.h +++ b/Lumos/Source/Lumos/Core/DataStructures/Map.h @@ -55,8 +55,8 @@ namespace Lumos #define HashMapKSize(MAP) sizeof((MAP)->data->key) #define HashMapVSize(MAP) sizeof((MAP)->data->value) #define HashMapElemSize(MAP) sizeof(*(MAP)->data) -#define HashMapKOffset(MAP) (int)((uintptr_t) & (MAP)->data->key - (uintptr_t)(MAP)->data) -#define HashMapVOffset(MAP) (int)((uintptr_t) & (MAP)->data->value - (uintptr_t)(MAP)->data) +#define HashMapKOffset(MAP) (int)((uintptr_t)&(MAP)->data->key - (uintptr_t)(MAP)->data) +#define HashMapVOffset(MAP) (int)((uintptr_t)&(MAP)->data->value - (uintptr_t)(MAP)->data) #define HashMap(K, V) \ struct \ diff --git a/Lumos/Source/Lumos/Core/DataStructures/Set.h b/Lumos/Source/Lumos/Core/DataStructures/Set.h index 95e218914..9e415414d 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/Set.h +++ b/Lumos/Source/Lumos/Core/DataStructures/Set.h @@ -64,8 +64,7 @@ namespace Lumos { \ int i_next; \ K* elem; \ - } \ - IT; \ + } IT; \ if((SET)->length > 0) \ for(IT = { 0 }; \ HashMapIter((HashMapRaw*)(SET), &IT.i_next, (void**)&IT.elem, NULL, HashMapKOffset(SET), 0, HashMapElemSize(SET));) diff --git a/Lumos/Source/Lumos/Core/DataStructures/TDArray.h b/Lumos/Source/Lumos/Core/DataStructures/TDArray.h index 338ef8861..8d95f7865 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/TDArray.h +++ b/Lumos/Source/Lumos/Core/DataStructures/TDArray.h @@ -100,14 +100,14 @@ namespace Lumos ConstIterator begin() const { return ConstIterator(m_Data); } ConstIterator end() const { return ConstIterator(m_Data + m_Size); } - template - struct EqualTo - { - constexpr bool operator()(const U& a, const U& b) { return a == b; } - }; + template + struct EqualTo + { + constexpr bool operator()(const U& a, const U& b) { return a == b; } + }; - template ::type>> - void Unique(CompareFunc compare = CompareFunc()); + template ::type>> + void Unique(CompareFunc compare = CompareFunc()); T*& Data() { return m_Data; } const T* Data() const { return m_Data; } @@ -413,14 +413,14 @@ namespace Lumos template void TDArray::Unique(CompareFunc compare) { - if (m_Size < 2) + if(m_Size < 2) return; size_t writeIndex = 1; // Start writing from the second element - for (size_t readIndex = 1; readIndex < m_Size; ++readIndex) + for(size_t readIndex = 1; readIndex < m_Size; ++readIndex) { // Compare with the last written element - if (!compare(m_Data[readIndex], m_Data[writeIndex - 1])) + if(!compare(m_Data[readIndex], m_Data[writeIndex - 1])) { m_Data[writeIndex] = Move(m_Data[readIndex]); ++writeIndex; diff --git a/Lumos/Source/Lumos/Core/JobSystem.cpp b/Lumos/Source/Lumos/Core/JobSystem.cpp index dbabbcccb..4b5d6c7bb 100644 --- a/Lumos/Source/Lumos/Core/JobSystem.cpp +++ b/Lumos/Source/Lumos/Core/JobSystem.cpp @@ -112,11 +112,11 @@ namespace Lumos ~InternalState() { LUMOS_PROFILE_FUNCTION_LOW(); - + alive.store(false); // indicate that new jobs cannot be started from this point bool bWakeLoop = true; - - #ifdef LUMOS_PLATFORM_LINUX + +#ifdef LUMOS_PLATFORM_LINUX for(auto& thread : threads) { if(thread.joinable()) @@ -124,14 +124,13 @@ namespace Lumos } bWakeLoop = false; wakeCondition.notify_all(); - #else +#else std::thread waker([&] - { + { while (bWakeLoop) { wakeCondition.notify_all(); // wakes up sleeping worker threads - } - }); + } }); for(auto& thread : threads) { @@ -141,8 +140,8 @@ namespace Lumos bWakeLoop = false; if(waker.joinable()) waker.join(); - #endif - +#endif + delete[] jobQueuePerThread; } }; diff --git a/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.h b/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.h index 4ba0a0771..f5d70efc8 100644 --- a/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.h +++ b/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.h @@ -29,7 +29,7 @@ namespace Lumos } private: - BinAllocator(const BinAllocator& other) {}; + BinAllocator(const BinAllocator& other) { }; BinAllocator operator=(const BinAllocator& other) { return *this; diff --git a/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp b/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp index 18e66a6d0..32be01109 100644 --- a/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp +++ b/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp @@ -1,64 +1,64 @@ -#include "Precompiled.h" -#include "DefaultAllocator.h" - -#include "Core/OS/MemoryManager.h" -// #define TRACK_ALLOCATIONS - -#define LUMOS_MEMORY_ALIGNMENT 16 -#define LUMOS_ALLOC(size) _aligned_malloc(size, LUMOS_MEMORY_ALIGNMENT) -#define LUMOS_FREE(block) _aligned_free(block); - -namespace Lumos -{ - void* DefaultAllocator::Malloc(size_t size, const char* file, int line) - { -#ifdef TRACK_ALLOCATIONS - ASSERT(size < 1024 * 1024 * 1024, "Allocation more than max size"); - - Lumos::MemoryManager::Get()->m_MemoryStats.totalAllocated += size; - Lumos::MemoryManager::Get()->m_MemoryStats.currentUsed += size; - Lumos::MemoryManager::Get()->m_MemoryStats.totalAllocations++; - - size_t actualSize = size + sizeof(size_t); - void* mem = malloc(actualSize + sizeof(void*)); - - uint8_t* result = (uint8_t*)mem; - if(result == NULL) - { - LERROR("Aligned malloc failed"); - return NULL; - } - - memset(result, 0, actualSize); - memcpy(result, &size, sizeof(size_t)); - result += sizeof(size_t); - - return result; - -#else - return malloc(size); -#endif - } - - void DefaultAllocator::Free(void* location) - { -#ifdef TRACK_ALLOCATIONS - uint8_t* memory = ((uint8_t*)location) - sizeof(size_t); - if(location && memory) - { - uint8_t* memory = ((uint8_t*)location) - sizeof(size_t); - size_t size = *(size_t*)memory; - free(((void**)memory)); - Lumos::MemoryManager::Get()->m_MemoryStats.totalFreed += size; - Lumos::MemoryManager::Get()->m_MemoryStats.currentUsed -= size; - } - else - { - free(location); - } - -#else - free(location); -#endif - } -} +#include "Precompiled.h" +#include "DefaultAllocator.h" + +#include "Core/OS/MemoryManager.h" +// #define TRACK_ALLOCATIONS + +#define LUMOS_MEMORY_ALIGNMENT 16 +#define LUMOS_ALLOC(size) _aligned_malloc(size, LUMOS_MEMORY_ALIGNMENT) +#define LUMOS_FREE(block) _aligned_free(block); + +namespace Lumos +{ + void* DefaultAllocator::Malloc(size_t size, const char* file, int line) + { +#ifdef TRACK_ALLOCATIONS + ASSERT(size < 1024 * 1024 * 1024, "Allocation more than max size"); + + Lumos::MemoryManager::Get().m_MemoryStats.totalAllocated += size; + Lumos::MemoryManager::Get().m_MemoryStats.currentUsed += size; + Lumos::MemoryManager::Get().m_MemoryStats.totalAllocations++; + + size_t actualSize = size + sizeof(size_t); + void* mem = malloc(actualSize + sizeof(void*)); + + uint8_t* result = (uint8_t*)mem; + if(result == NULL) + { + LERROR("Aligned malloc failed"); + return NULL; + } + + memset(result, 0, actualSize); + memcpy(result, &size, sizeof(size_t)); + result += sizeof(size_t); + + return result; + +#else + return malloc(size); +#endif + } + + void DefaultAllocator::Free(void* location) + { +#ifdef TRACK_ALLOCATIONS + uint8_t* memory = ((uint8_t*)location) - sizeof(size_t); + if(location && memory) + { + uint8_t* memory = ((uint8_t*)location) - sizeof(size_t); + size_t size = *(size_t*)memory; + free(((void**)memory)); + Lumos::MemoryManager::Get().m_MemoryStats.totalFreed += size; + Lumos::MemoryManager::Get().m_MemoryStats.currentUsed -= size; + } + else + { + free(location); + } + +#else + free(location); +#endif + } +} diff --git a/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp b/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp index 87d6c76d8..b0ff6a558 100644 --- a/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp +++ b/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp @@ -1,45 +1,28 @@ -#include "Precompiled.h" -#include "MemoryManager.h" -#include "Utilities/StringUtilities.h" - -namespace Lumos -{ - MemoryManager* MemoryManager::s_Instance = nullptr; - - MemoryManager::MemoryManager() - { - } - - void MemoryManager::OnInit() - { - } - - void MemoryManager::OnShutdown() - { - if(s_Instance) - delete s_Instance; - } - - MemoryManager* MemoryManager::Get() - { - if(s_Instance == nullptr) - { - s_Instance = new MemoryManager(); - } - return s_Instance; - } - - void SystemMemoryInfo::Log() - { - std::string apm, tpm, avm, tvm; - - apm = StringUtilities::BytesToString(availablePhysicalMemory); - tpm = StringUtilities::BytesToString(totalPhysicalMemory); - avm = StringUtilities::BytesToString(availableVirtualMemory); - tvm = StringUtilities::BytesToString(totalVirtualMemory); - - LINFO("Memory Info:"); - LINFO("\tPhysical Memory : %s / %s", apm.c_str(), tpm.c_str()); - LINFO("\tVirtual Memory : %s / %s: ", avm.c_str(), tvm.c_str()); - } -} +#include "Precompiled.h" +#include "MemoryManager.h" +#include "Utilities/StringUtilities.h" + +namespace Lumos +{ + MemoryManager::MemoryManager() + { + } + + void MemoryManager::OnInit() + { + } + + void SystemMemoryInfo::Log() + { + std::string apm, tpm, avm, tvm; + + apm = StringUtilities::BytesToString(availablePhysicalMemory); + tpm = StringUtilities::BytesToString(totalPhysicalMemory); + avm = StringUtilities::BytesToString(availableVirtualMemory); + tvm = StringUtilities::BytesToString(totalVirtualMemory); + + LINFO("Memory Info:"); + LINFO("\tPhysical Memory : %s / %s", apm.c_str(), tpm.c_str()); + LINFO("\tVirtual Memory : %s / %s: ", avm.c_str(), tvm.c_str()); + } +} diff --git a/Lumos/Source/Lumos/Core/OS/MemoryManager.h b/Lumos/Source/Lumos/Core/OS/MemoryManager.h index cc95f93bc..7f3a01c20 100644 --- a/Lumos/Source/Lumos/Core/OS/MemoryManager.h +++ b/Lumos/Source/Lumos/Core/OS/MemoryManager.h @@ -1,58 +1,55 @@ -#pragma once - -namespace Lumos -{ - struct SystemMemoryInfo - { - int64_t availablePhysicalMemory; - int64_t totalPhysicalMemory; - - int64_t availableVirtualMemory; - int64_t totalVirtualMemory; - - void Log(); - }; - - struct MemoryStats - { - int64_t totalAllocated; - int64_t totalFreed; - int64_t currentUsed; - int64_t totalAllocations; - - MemoryStats() - : totalAllocated(0) - , totalFreed(0) - , currentUsed(0) - , totalAllocations(0) - { - } - }; - - class MemoryManager - { - public: - static MemoryManager* s_Instance; - - public: - MemoryStats m_MemoryStats; - - public: - MemoryManager(); - - static void OnInit(); - static void OnShutdown(); - - static MemoryManager* Get(); - inline MemoryStats GetMemoryStats() const - { - return m_MemoryStats; - } - - public: - SystemMemoryInfo GetSystemInfo(); - - public: - static std::string BytesToString(int64_t bytes); - }; -} +#pragma once +#include "Utilities/TSingleton.h" + +namespace Lumos +{ + struct SystemMemoryInfo + { + int64_t availablePhysicalMemory; + int64_t totalPhysicalMemory; + + int64_t availableVirtualMemory; + int64_t totalVirtualMemory; + + void Log(); + }; + + struct MemoryStats + { + int64_t totalAllocated; + int64_t totalFreed; + int64_t currentUsed; + int64_t totalAllocations; + + MemoryStats() + : totalAllocated(0) + , totalFreed(0) + , currentUsed(0) + , totalAllocations(0) + { + } + }; + + class MemoryManager : public TSingleton + { + friend class TSingleton; + + public: + MemoryStats m_MemoryStats; + + public: + MemoryManager(); + + void OnInit(); + inline MemoryStats GetMemoryStats() const + { + return m_MemoryStats; + } + + public: + SystemMemoryInfo GetSystemInfo(); + + public: + static std::string BytesToString(int64_t bytes); + }; +} diff --git a/Lumos/Source/Lumos/Core/OS/OS.cpp b/Lumos/Source/Lumos/Core/OS/OS.cpp index 021279b89..630bc6bc6 100644 --- a/Lumos/Source/Lumos/Core/OS/OS.cpp +++ b/Lumos/Source/Lumos/Core/OS/OS.cpp @@ -13,29 +13,21 @@ namespace Lumos { - OS* OS::s_Instance = nullptr; - void OS::Create() { - ASSERT(!s_Instance, "OS already exists!"); + ASSERT(!m_pInstance, "OS already exists!"); #if defined(LUMOS_PLATFORM_WINDOWS) - s_Instance = new WindowsOS(); + m_pInstance = new WindowsOS(); #elif defined(LUMOS_PLATFORM_MACOS) - s_Instance = new MacOSOS(); + m_pInstance = new MacOSOS(); #elif defined(LUMOS_PLATFORM_IOS) - s_Instance = new iOSOS(); + m_pInstance = new iOSOS(); #else - s_Instance = new UnixOS(); + m_pInstance = new UnixOS(); #endif } - void OS::Release() - { - delete s_Instance; - s_Instance = nullptr; - } - std::string OS::PowerStateToString(PowerState state) { switch(state) diff --git a/Lumos/Source/Lumos/Core/OS/OS.h b/Lumos/Source/Lumos/Core/OS/OS.h index 48ffbc854..e3adb34ef 100644 --- a/Lumos/Source/Lumos/Core/OS/OS.h +++ b/Lumos/Source/Lumos/Core/OS/OS.h @@ -1,59 +1,49 @@ -#pragma once -#include "Core/Core.h" -#include "Maths/MathsFwd.h" - -namespace Lumos -{ - enum PowerState - { - POWERSTATE_UNKNOWN, - POWERSTATE_ON_BATTERY, - POWERSTATE_NO_BATTERY, - POWERSTATE_CHARGING, - POWERSTATE_CHARGED - }; - - class LUMOS_EXPORT OS - { - public: - OS() = default; - virtual ~OS() = default; - - virtual void Run() = 0; - - static void Create(); - static void Release(); - static void SetInstance(OS* instance) - { - s_Instance = instance; - } - - static OS* Instance() - { - return s_Instance; - } - static std::string PowerStateToString(PowerState state); - - virtual std::string GetExecutablePath() = 0; - virtual std::string GetCurrentWorkingDirectory(); - virtual std::string GetAssetPath(); - virtual void Vibrate() const {}; - virtual void SetTitleBarColour(const Vec4& colour, bool dark = true) {}; - - // Mobile only - virtual void ShowKeyboard() {}; - virtual void HideKeyboard() {}; - virtual void Delay(uint32_t usec) {}; - - // Needed for MaxOS - virtual void MaximiseWindow() { } - - virtual void OpenFileLocation(const std::string& path) { } - virtual void OpenFileExternal(const std::string& path) { } - virtual void OpenURL(const std::string& url) { } - static void ConsoleWrite(const char* msg, u8 level); - - protected: - static OS* s_Instance; - }; -} +#pragma once +#include "Core/Core.h" +#include "Maths/MathsFwd.h" +#include "Utilities/TSingleton.h" + +namespace Lumos +{ + enum PowerState + { + POWERSTATE_UNKNOWN, + POWERSTATE_ON_BATTERY, + POWERSTATE_NO_BATTERY, + POWERSTATE_CHARGING, + POWERSTATE_CHARGED + }; + + class LUMOS_EXPORT OS : public TSingletonAbstract + { + friend class TSingletonAbstract; + + public: + OS() = default; + virtual ~OS() = default; + + virtual void Run() = 0; + static void Create(); + + static std::string PowerStateToString(PowerState state); + + virtual std::string GetExecutablePath() = 0; + virtual std::string GetCurrentWorkingDirectory(); + virtual std::string GetAssetPath(); + virtual void Vibrate() const { }; + virtual void SetTitleBarColour(const Vec4& colour, bool dark = true) { }; + + // Mobile only + virtual void ShowKeyboard() { }; + virtual void HideKeyboard() { }; + virtual void Delay(uint32_t usec) { }; + + // Needed for MaxOS + virtual void MaximiseWindow() { } + + virtual void OpenFileLocation(const std::string& path) { } + virtual void OpenFileExternal(const std::string& path) { } + virtual void OpenURL(const std::string& url) { } + static void ConsoleWrite(const char* msg, u8 level); + }; +} diff --git a/Lumos/Source/Lumos/Core/OS/Window.cpp b/Lumos/Source/Lumos/Core/OS/Window.cpp index 69bbdad39..beba55ef3 100644 --- a/Lumos/Source/Lumos/Core/OS/Window.cpp +++ b/Lumos/Source/Lumos/Core/OS/Window.cpp @@ -3,7 +3,7 @@ namespace Lumos { - Window* (*Window::CreateFunc)(const WindowDesc&) = NULL; + Window* (*Window::CreateFunc)() = NULL; Window::~Window() { @@ -11,14 +11,9 @@ namespace Lumos m_GraphicsContext.reset(); } - Window* Window::Create(const WindowDesc& windowDesc) + Window* Window::Create() { ASSERT(CreateFunc, "No Windows Create Function"); - return CreateFunc(windowDesc); - } - - bool Window::Initialise(const WindowDesc& windowDesc) - { - return HasInitialised(); + return CreateFunc(); } } diff --git a/Lumos/Source/Lumos/Core/OS/Window.h b/Lumos/Source/Lumos/Core/OS/Window.h index 62c7cc789..0e604971d 100644 --- a/Lumos/Source/Lumos/Core/OS/Window.h +++ b/Lumos/Source/Lumos/Core/OS/Window.h @@ -41,9 +41,9 @@ namespace Lumos public: using EventCallbackFn = Function; - static Window* Create(const WindowDesc& windowDesc); + static Window* Create(); virtual ~Window(); - bool Initialise(const WindowDesc& windowDesc); + virtual bool Init(const WindowDesc& windowDesc) = 0; bool HasInitialised() const { @@ -66,19 +66,19 @@ namespace Lumos virtual void SetVSync(bool set) = 0; virtual void SetWindowTitle(const std::string& title) = 0; virtual void OnUpdate() = 0; - virtual void ProcessInput() {}; + virtual void ProcessInput() { }; virtual void SetBorderlessWindow(bool borderless) = 0; virtual void* GetHandle() { return nullptr; }; virtual float GetScreenRatio() const = 0; - virtual void HideMouse(bool hide) {}; - virtual void SetMousePosition(const Vec2& pos) {}; + virtual void HideMouse(bool hide) { }; + virtual void SetMousePosition(const Vec2& pos) { }; virtual void SetEventCallback(const EventCallbackFn& callback) = 0; virtual void UpdateCursorImGui() = 0; virtual void SetIcon(const WindowDesc& desc) = 0; - virtual void Maximise() {}; + virtual void Maximise() { }; virtual std::string GetTitle() const = 0; virtual uint32_t GetWidth() const = 0; virtual uint32_t GetHeight() const = 0; @@ -93,7 +93,7 @@ namespace Lumos const SharedPtr& GetGraphicsContext() const { return m_GraphicsContext; } protected: - static Window* (*CreateFunc)(const WindowDesc&); + static Window* (*CreateFunc)(); Window() = default; diff --git a/Lumos/Source/Lumos/Events/Event.h b/Lumos/Source/Lumos/Events/Event.h index 9cd05234e..fe19cf8e4 100644 --- a/Lumos/Source/Lumos/Events/Event.h +++ b/Lumos/Source/Lumos/Events/Event.h @@ -34,9 +34,7 @@ namespace Lumos EventCategoryMouseButton = BIT(4) }; -#define BIND_EVENT_FN(fn) [this](auto&&... args) -> decltype(auto) { \ - return this->fn(std::forward(args)...); \ -} +#define BIND_EVENT_FN(fn) [this](auto&&... args) -> decltype(auto) { return this->fn(std::forward(args)...); } #define EVENT_CLASS_TYPE(type) \ static EventType GetStaticType() \ diff --git a/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp b/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp index 5049b605a..59fba0997 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp +++ b/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp @@ -23,7 +23,7 @@ namespace Lumos , m_Near(Near) , m_Far(Far) , m_Orthographic(false) - , m_Scale(1.0f) {}; + , m_Scale(1.0f) { }; Camera::Camera(float pitch, float yaw, const Vec3& position, float FOV, float Near, float Far, float aspect) : m_AspectRatio(aspect) diff --git a/Lumos/Source/Lumos/Graphics/Camera/CameraController.h b/Lumos/Source/Lumos/Graphics/Camera/CameraController.h index e975fd261..8a7e4aee0 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/CameraController.h +++ b/Lumos/Source/Lumos/Graphics/Camera/CameraController.h @@ -16,11 +16,11 @@ namespace Lumos CameraController() = default; virtual ~CameraController() = default; - virtual void HandleMouse(Maths::Transform& transform, float dt, float xpos, float ypos) {}; - virtual void HandleKeyboard(Maths::Transform& transform, float dt) {}; - virtual void UpdateScroll(Maths::Transform& transform, float offset, float dt) {}; + virtual void HandleMouse(Maths::Transform& transform, float dt, float xpos, float ypos) { }; + virtual void HandleKeyboard(Maths::Transform& transform, float dt) { }; + virtual void UpdateScroll(Maths::Transform& transform, float offset, float dt) { }; - virtual void OnImGui() {}; + virtual void OnImGui() { }; void SetMouseSensitivity(float value) { m_MouseSensitivity = value; } diff --git a/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.h b/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.h index 5e11dcbcd..c15e9aaa2 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.h +++ b/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.h @@ -13,7 +13,7 @@ namespace Lumos virtual void HandleMouse(Maths::Transform& transform, float dt, float xpos, float ypos) override; virtual void HandleKeyboard(Maths::Transform& transform, float dt) override; - void UpdateScroll(Maths::Transform& transform, float offset, float dt) override {}; + void UpdateScroll(Maths::Transform& transform, float offset, float dt) override { }; }; } diff --git a/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h b/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h index 23662b496..958e899b7 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h +++ b/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.h @@ -23,13 +23,13 @@ namespace Lumos virtual void SetUniform(const std::string& bufferName, const std::string& uniformName, void* data, uint32_t size) = 0; virtual void SetUniformBufferData(const std::string& bufferName, void* data) = 0; - virtual void SetTexture(u8 binding, Texture* texture, uint32_t mipIndex = 0, TextureType textureType = TextureType(0)) = 0; + virtual void SetTexture(u8 binding, Texture* texture, uint32_t mipIndex = 0, TextureType textureType = TextureType(0)) = 0; virtual void SetTexture(u8 binding, Texture** texture, uint32_t textureCount, TextureType textureType = TextureType(0)) = 0; - virtual void SetBuffer(u8 binding, UniformBuffer* buffer) = 0; - virtual void SetUniform(u8 binding, const std::string& uniformName, void* data) = 0; - virtual void SetUniform(u8 binding, const std::string& uniformName, void* data, uint32_t size) = 0; - virtual void SetUniformBufferData(u8 binding, void* data) = 0; - virtual void SetUniformBufferData(u8 binding, void* data, float size) = 0; + virtual void SetBuffer(u8 binding, UniformBuffer* buffer) = 0; + virtual void SetUniform(u8 binding, const std::string& uniformName, void* data) = 0; + virtual void SetUniform(u8 binding, const std::string& uniformName, void* data, uint32_t size) = 0; + virtual void SetUniformBufferData(u8 binding, void* data) = 0; + virtual void SetUniformBufferData(u8 binding, void* data, float size) = 0; virtual void TransitionImages(CommandBuffer* commandBuffer = nullptr) { } virtual void SetUniformDynamic(const std::string& bufferName, uint32_t size) { } @@ -38,7 +38,6 @@ namespace Lumos virtual Buffer* GetUniformBufferLocalData(u8 binding) { return nullptr; } virtual Graphics::UniformBuffer* GetUniformBuffer(u8 binding) = 0; - protected: static DescriptorSet* (*CreateFunc)(const DescriptorDesc&); }; diff --git a/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.h b/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.h index 06efe718a..d27fcc44f 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.h +++ b/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.h @@ -16,7 +16,7 @@ namespace Lumos virtual ~Framebuffer(); - virtual void Validate() {}; + virtual void Validate() { }; virtual uint32_t GetWidth() const = 0; virtual uint32_t GetHeight() const = 0; diff --git a/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp b/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp index 4d4dd419b..9c99f3c1c 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp @@ -26,23 +26,12 @@ namespace Lumos return CreateFunc(width, height, clearScreen); } - ImGuiTextureID* IMGUIRenderer::AddTexture(Texture* texture, TextureType type, uint32_t level, uint32_t mip) + ImTextureID IMGUIRenderer::AddTexture(Texture* texture, TextureType type, uint32_t level, uint32_t mip) { if(Graphics::GraphicsContext::GetRenderAPI() == RenderAPI::OPENGL) - return (ImGuiTextureID*)texture->GetHandle(); + return (ImTextureID)texture->GetHandle(); - if(m_CurrentTextureIDIndex >= MAX_IMGUI_TEXTURES) - { - LERROR("Exceeded max imgui textures"); - return &m_TextureIDs[0]; - } - - m_TextureIDs[m_CurrentTextureIDIndex].texture = texture; - m_TextureIDs[m_CurrentTextureIDIndex].type = type; - m_TextureIDs[m_CurrentTextureIDIndex].level = level; - m_TextureIDs[m_CurrentTextureIDIndex].mip = mip; - - return &m_TextureIDs[m_CurrentTextureIDIndex++]; + return nullptr; } } } diff --git a/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.h b/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.h index 8fd61a2e4..263364a0d 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.h +++ b/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.h @@ -1,20 +1,13 @@ #pragma once #include "RHIDefinitions.h" +typedef void* ImTextureID; namespace Lumos { namespace Graphics { class CommandBuffer; - struct ImGuiTextureID - { - Texture* texture; - TextureType type; - uint32_t level; - uint32_t mip; - }; - class LUMOS_EXPORT IMGUIRenderer { public: @@ -28,14 +21,10 @@ namespace Lumos virtual void Clear() { } virtual bool Implemented() const = 0; virtual void RebuildFontTexture() = 0; - virtual ImGuiTextureID* AddTexture(Texture* texture, TextureType type = TextureType::COLOUR, uint32_t level = 0, uint32_t mip = 0); + virtual ImTextureID AddTexture(Texture* texture, TextureType type = TextureType::COLOUR, uint32_t level = 0, uint32_t mip = 0); protected: static IMGUIRenderer* (*CreateFunc)(uint32_t, uint32_t, bool); - -#define MAX_IMGUI_TEXTURES 1024 - ImGuiTextureID m_TextureIDs[MAX_IMGUI_TEXTURES]; - uint32_t m_CurrentTextureIDIndex = 0; }; } } diff --git a/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.h b/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.h index c9fdc0d11..ef886f31b 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.h +++ b/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.h @@ -15,7 +15,7 @@ namespace Lumos virtual uint32_t GetCount() const = 0; virtual uint32_t GetSize() const { return 0; } virtual void SetCount(uint32_t m_index_count) = 0; - virtual void ReleasePointer() {}; + virtual void ReleasePointer() { }; template T* GetPointer() diff --git a/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.cpp b/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.cpp deleted file mode 100644 index c91ec248b..000000000 --- a/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "Precompiled.h" -#include "RenderDevice.h" - -namespace Lumos -{ - namespace Graphics - { - RenderDevice* (*RenderDevice::CreateFunc)() = nullptr; - - RenderDevice* RenderDevice::s_Instance = nullptr; - - void RenderDevice::Create() - { - ASSERT(CreateFunc, "No RenderDevice Create Function"); - - s_Instance = CreateFunc(); - } - - void RenderDevice::Release() - { - delete s_Instance; - }; - } -} diff --git a/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.h b/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.h deleted file mode 100644 index 236ddebf0..000000000 --- a/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -namespace Lumos -{ - namespace Graphics - { - class RenderDevice - { - public: - RenderDevice() = default; - virtual ~RenderDevice() = default; - - virtual void Init() = 0; - - static void Create(); - static void Release(); - - protected: - static RenderDevice* (*CreateFunc)(); - - private: - static RenderDevice* s_Instance; - }; - } -} diff --git a/Lumos/Source/Lumos/Graphics/RHI/Renderer.h b/Lumos/Source/Lumos/Graphics/RHI/Renderer.h index 479b0425b..b543defa3 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Renderer.h +++ b/Lumos/Source/Lumos/Graphics/RHI/Renderer.h @@ -47,14 +47,14 @@ namespace Lumos virtual void PresentInternal(Graphics::CommandBuffer* commandBuffer) = 0; virtual void BindDescriptorSetsInternal(Graphics::Pipeline* pipeline, Graphics::CommandBuffer* commandBuffer, uint32_t dynamicOffset, Graphics::DescriptorSet** descriptorSets, uint32_t descriptorCount) = 0; - virtual const char* GetTitleInternal() const = 0; + virtual const char* GetTitleInternal() const = 0; virtual void DrawIndexedInternal(CommandBuffer* commandBuffer, DrawType type, uint32_t count, uint32_t start) const = 0; virtual void DrawInternal(CommandBuffer* commandBuffer, DrawType type, uint32_t count, DataType datayType, void* indices) const = 0; virtual void Dispatch(CommandBuffer* commandBuffer, uint32_t workGroupSizeX, uint32_t workGroupSizeY, uint32_t workGroupSizeZ) { } virtual void DrawSplashScreen(Texture* texture) { } virtual uint32_t GetGPUCount() const { return 1; } virtual bool SupportsCompute() { return false; } - virtual void SaveScreenshot(const std::string& path, Graphics::Texture* texture = nullptr) {}; + virtual void SaveScreenshot(const std::string& path, Graphics::Texture* texture = nullptr) { }; virtual RHIFormat GetDepthFormat() { return RHIFormat::D32_Float; }; inline static void Present() diff --git a/Lumos/Source/Lumos/Graphics/RHI/Texture.h b/Lumos/Source/Lumos/Graphics/RHI/Texture.h index d365803ad..543b71c50 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Texture.h +++ b/Lumos/Source/Lumos/Graphics/RHI/Texture.h @@ -23,7 +23,7 @@ namespace Lumos virtual TextureType GetType() const = 0; virtual RHIFormat GetFormat() const = 0; virtual void GenerateMipMaps(CommandBuffer* commandBuffer = nullptr) { } - virtual void SetName(const std::string& name) {}; + virtual void SetName(const std::string& name) { }; virtual uint8_t GetSamples() const { return 0; } virtual uint32_t GetSize() const { return 0; } diff --git a/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.h b/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.h index f85d72e92..5f0ed5c97 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.h +++ b/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.h @@ -21,11 +21,11 @@ namespace Lumos void UpdateUniformBuffer(); void Begin() override; - void Submit(const RenderCommand& command) override {}; - void SubmitMesh(Mesh* mesh, Material* material, const Mat4& transform, const Mat4& textureMatrix) override {}; - void EndScene() override {}; + void Submit(const RenderCommand& command) override { }; + void SubmitMesh(Mesh* mesh, Material* material, const Mat4& transform, const Mat4& textureMatrix) override { }; + void EndScene() override { }; void End() override; - void Present() override {}; + void Present() override { }; void RenderScene() override; void PresentToScreen() override { } diff --git a/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.h b/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.h index 71324c46a..80f923355 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.h +++ b/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.h @@ -37,14 +37,14 @@ namespace Lumos virtual void Init() = 0; virtual void Begin() = 0; virtual void BeginScene(Scene* scene, Camera* overrideCamera, Maths::Transform* overrideCameraTransform) = 0; - virtual void Submit(const RenderCommand& command) {}; - virtual void SubmitMesh(Mesh* mesh, Material* material, const Mat4& transform, const Mat4& textureMatrix) {}; + virtual void Submit(const RenderCommand& command) { }; + virtual void SubmitMesh(Mesh* mesh, Material* material, const Mat4& transform, const Mat4& textureMatrix) { }; virtual void EndScene() = 0; virtual void End() = 0; virtual void Present() = 0; virtual void PresentToScreen() = 0; virtual void OnResize(uint32_t width, uint32_t height) = 0; - virtual void OnImGui() {}; + virtual void OnImGui() { }; virtual void SetScreenBufferSize(uint32_t width, uint32_t height) { diff --git a/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp index 769752dde..746039157 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp @@ -55,8 +55,8 @@ static const uint32_t MaxLineIndices = MaxLines * 2; static const uint32_t MAX_LINE_BATCH_DRAW_CALLS = 100; static const uint32_t RENDERER_LINE_SIZE = sizeof(Lumos::Graphics::LineVertexData) * 4; static const uint32_t RENDERER_LINE_BUFFER_SIZE = RENDERER_LINE_SIZE * MaxLineVertices; -static const uint32_t MAX_LIGHTS = 32; -static const uint32_t MAX_SHADOWMAPS = 4; +static const uint32_t MAX_LIGHTS = 32; +static const uint32_t MAX_SHADOWMAPS = 4; namespace Lumos::Graphics { @@ -851,8 +851,6 @@ namespace Lumos::Graphics emitter.Update((float)Engine::GetTimeStep().GetSeconds(), trans.GetWorldPosition()); } - - m_ForwardData.m_CommandQueue.Clear(); struct UniformSceneData @@ -884,29 +882,29 @@ namespace Lumos::Graphics LUMOS_PROFILE_SCOPE("Get Light"); auto group = registry.group(entt::get); - for (auto& lightEntity : group) + for(auto& lightEntity : group) { - if (!Entity(lightEntity, scene).Active()) + if(!Entity(lightEntity, scene).Active()) continue; - if (numLights >= MAX_LIGHTS) + if(numLights >= MAX_LIGHTS) break; const auto& [light, trans] = group.get(lightEntity); - light.Position = Vec4(trans.GetWorldPosition(), 1.0f); - Vec3 forward = Vec3(0.0f, 0.0f, 1.0f); - forward = trans.GetWorldOrientation() * forward; + light.Position = Vec4(trans.GetWorldPosition(), 1.0f); + Vec3 forward = Vec3(0.0f, 0.0f, 1.0f); + forward = trans.GetWorldOrientation() * forward; forward.Normalise(); light.Direction = Vec4(forward, 1.0f); - if (light.Type == (float)Graphics::LightType::DirectionalLight) + if(light.Type == (float)Graphics::LightType::DirectionalLight) directionaLight = &light; - if (light.Type != float(LightType::DirectionalLight)) + if(light.Type != float(LightType::DirectionalLight)) { auto inside = m_ForwardData.m_Frustum.IsInside(Maths::BoundingSphere(Vec3(light.Position), light.Radius * 100)); - if (inside == Maths::Intersection::OUTSIDE) + if(inside == Maths::Intersection::OUTSIDE) continue; } @@ -916,18 +914,18 @@ namespace Lumos::Graphics } } - if (renderSettings.ShadowsEnabled) + if(renderSettings.ShadowsEnabled) { - for (uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) + for(uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) { m_ShadowData.m_CascadeCommandQueue[i].Clear(); } - if (directionaLight) + if(directionaLight) { UpdateCascades(scene, directionaLight); - for (uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) + for(uint32_t i = 0; i < m_ShadowData.m_ShadowMapNum; i++) { m_ShadowData.m_CascadeFrustums[i].Define(m_ShadowData.m_ShadowProjView[i]); } @@ -936,29 +934,29 @@ namespace Lumos::Graphics UniformSceneData uniformSceneData; auto& shadowData = GetShadowData(); - MemoryCopy(uniformSceneData.ShadowTransform, shadowData.m_ShadowProjView, sizeof(Mat4)* shadowData.m_ShadowMapNum); - MemoryCopy(uniformSceneData.SplitDepths, shadowData.m_SplitDepth, sizeof(Vec4)* shadowData.m_ShadowMapNum); - uniformSceneData.LightView = shadowData.m_LightMatrix; - uniformSceneData.InitialBias = shadowData.m_InitialBias; - uniformSceneData.LightSize = shadowData.m_ShadowMapSize; - uniformSceneData.ShadowFade = shadowData.m_ShadowFade; - uniformSceneData.CascadeFade = shadowData.m_CascadeFade; - uniformSceneData.MaxShadowDist = shadowData.m_MaxShadowDistance; - uniformSceneData.Width = (float)m_MainTexture->GetWidth(); - uniformSceneData.Height = (float)m_MainTexture->GetHeight(); - uniformSceneData.shadowEnabled = renderSettings.ShadowsEnabled ? 1 : 0; - uniformSceneData.ShadowCount = shadowData.m_ShadowMapNum; - uniformSceneData.EnvMipCount = m_ForwardData.m_EnvironmentMap ? m_ForwardData.m_EnvironmentMap->GetMipMapLevels() : 0; - uniformSceneData.ViewMatrix = view; - uniformSceneData.BiasMatrix = m_ForwardData.m_BiasMatrix; - uniformSceneData.Mode = m_ForwardData.m_RenderMode; + MemoryCopy(uniformSceneData.ShadowTransform, shadowData.m_ShadowProjView, sizeof(Mat4) * shadowData.m_ShadowMapNum); + MemoryCopy(uniformSceneData.SplitDepths, shadowData.m_SplitDepth, sizeof(Vec4) * shadowData.m_ShadowMapNum); + uniformSceneData.LightView = shadowData.m_LightMatrix; + uniformSceneData.InitialBias = shadowData.m_InitialBias; + uniformSceneData.LightSize = (float)shadowData.m_ShadowMapSize; + uniformSceneData.ShadowFade = shadowData.m_ShadowFade; + uniformSceneData.CascadeFade = shadowData.m_CascadeFade; + uniformSceneData.MaxShadowDist = shadowData.m_MaxShadowDistance; + uniformSceneData.Width = (float)m_MainTexture->GetWidth(); + uniformSceneData.Height = (float)m_MainTexture->GetHeight(); + uniformSceneData.shadowEnabled = renderSettings.ShadowsEnabled ? 1 : 0; + uniformSceneData.ShadowCount = shadowData.m_ShadowMapNum; + uniformSceneData.EnvMipCount = m_ForwardData.m_EnvironmentMap ? m_ForwardData.m_EnvironmentMap->GetMipMapLevels() : 0; + uniformSceneData.ViewMatrix = view; + uniformSceneData.BiasMatrix = m_ForwardData.m_BiasMatrix; + uniformSceneData.Mode = m_ForwardData.m_RenderMode; uniformSceneData.cameraPosition = Vec4(m_CameraTransform->GetWorldPosition(), 1.0f); - - MemoryCopy(uniformSceneData.lights, lights, sizeof(Graphics::Light)* numLights); + + MemoryCopy(uniformSceneData.lights, lights, sizeof(Graphics::Light) * numLights); uniformSceneData.LightCount = numLights; m_ForwardData.m_DescriptorSet[2]->SetUniformBufferData(5, &uniformSceneData); - + m_ForwardData.m_DescriptorSet[2]->SetTexture(0, reinterpret_cast(shadowData.m_ShadowTex), 0, TextureType::DEPTHARRAY); m_ForwardData.m_DescriptorSet[2]->SetTexture(3, m_ForwardData.m_BRDFLUT.get()); m_ForwardData.m_DescriptorSet[2]->SetTexture(4, Application::Get().GetCurrentScene()->GetSettings().RenderSettings.SSAOEnabled ? m_SSAOTexture : Material::GetDefaultTexture().get()); @@ -1193,8 +1191,8 @@ namespace Lumos::Graphics LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Render Passes"); - auto& sceneRenderSettings = Application::Get().GetCurrentScene()->GetSettings().RenderSettings; - + auto& sceneRenderSettings = Application::Get().GetCurrentScene()->GetSettings().RenderSettings; + sceneRenderSettings.SSAOEnabled = false; { LUMOS_PROFILE_GPU("Clear Main Texture Pass"); Renderer::GetRenderer()->ClearRenderTarget(m_MainTexture, Renderer::GetMainSwapChain()->GetCurrentCommandBuffer()); @@ -1306,7 +1304,7 @@ namespace Lumos::Graphics // dispatcher.Dispatch(BIND_EVENT_FN(SceneRenderer::OnwindowResizeEvent)); } - std::string RenderModeToString(int mode) + const char* RenderModeToString(int mode) { switch(mode) { @@ -1341,7 +1339,6 @@ namespace Lumos::Graphics { static int index = 0; - // TODO: Fix - only showing layer 0 ImGui::SliderInt("Texture Array Index", &index, 0, m_ShadowData.m_ShadowTex->GetCount() - 1); bool flipImage = Renderer::GetGraphicsContext()->FlipImGUITexture(); @@ -1384,13 +1381,13 @@ namespace Lumos::Graphics ImGui::TextUnformatted("Render Mode"); ImGui::NextColumn(); ImGui::PushItemWidth(-1); - if(ImGui::BeginMenu(RenderModeToString(m_ForwardData.m_RenderMode).c_str())) + if(ImGui::BeginMenu(RenderModeToString(m_ForwardData.m_RenderMode))) { const int numRenderModes = 8; for(int i = 0; i < numRenderModes; i++) { - if(ImGui::MenuItem(RenderModeToString(i).c_str(), "", m_ForwardData.m_RenderMode == i, true)) + if(ImGui::MenuItem(RenderModeToString(i), "", m_ForwardData.m_RenderMode == i, true)) { m_ForwardData.m_RenderMode = i; } @@ -1639,7 +1636,7 @@ namespace Lumos::Graphics auto& pushConstants = command.pipeline->GetShader()->GetPushConstants(); memcpy(pushConstants[0].data + sizeof(Mat4), &layer, sizeof(uint32_t)); currentDescriptors[0] = alphaBlend ? m_ShadowData.m_DescriptorSet[1].get() : m_ShadowData.m_DescriptorSet[0].get(); - currentDescriptors[2] = m_ForwardData.m_DescriptorSet[2]; + currentDescriptors[2] = m_ForwardData.m_DescriptorSet[2]; if(command.animated) { @@ -1768,21 +1765,21 @@ namespace Lumos::Graphics Vec3 sample(Random32::Rand(-0.9f, 0.9f), Random32::Rand(-0.9f, 0.9f), Random32::Rand(0.0f, 1.0f)); sample.Normalise(); // Snap to surface of hemisphere sample *= Random32::Rand(0.0f, 1.0f); // Space out linearly - float scale = (float)i / (float)64; - scale = Maths::Lerp(0.1f, 1.0f, scale * scale); // Bring distribution of samples closer to origin - data.samples[i] = Vec4(sample * scale, 0.0f); + float scale = (float)i / (float)64; + scale = Maths::Lerp(0.1f, 1.0f, scale * scale); // Bring distribution of samples closer to origin + data.samples[i] = Vec4(sample * scale, 0.0f); } init = true; } Scene::SceneRenderSettings& renderSettings = m_CurrentScene->GetSettings().RenderSettings; - data.invProj = invProj; - data.projection = projection; - data.view = view; - data.ssaoRadius = renderSettings.SSAOSampleRadius; - data.Near = nearC; - data.Far = farC; - data.strength = renderSettings.SSAOStrength; + data.invProj = invProj; + data.projection = projection; + data.view = view; + data.ssaoRadius = renderSettings.SSAOSampleRadius; + data.Near = nearC; + data.Far = farC; + data.strength = renderSettings.SSAOStrength; m_SSAOPassDescriptorSet->SetUniformBufferData(0, &data); m_SSAOPassDescriptorSet->SetTexture(1, m_ForwardData.m_DepthTexture); @@ -1827,7 +1824,7 @@ namespace Lumos::Graphics int pad; }; static SSAOUniformBufferData data; - data.view = view; + data.view = view; data.texelOffset[0] = 2.0f / m_SSAOTexture->GetWidth(); data.texelOffset[1] = 0.0f; @@ -1921,12 +1918,12 @@ namespace Lumos::Graphics struct SkyboxUniformData { float Exposure; - int Mode; //0 env map , 1 custom sky + int Mode; // 0 env map , 1 custom sky float BlurLevel; float p1; }; SkyboxUniformData data; - data.Mode = 0; + data.Mode = 0; data.Exposure = m_Exposure * 120000.0f; data.BlurLevel = m_CurrentScene->GetSettings().RenderSettings.SkyboxMipLevel; m_SkyboxDescriptorSet->SetTexture(1, m_CubeMap, 0, TextureType::CUBE); @@ -1983,7 +1980,7 @@ namespace Lumos::Graphics if(depthLinearizeMul * depthLinearizeAdd < 0) depthLinearizeAdd = -depthLinearizeAdd; - Vec4 UniformData = { renderSettings.DepthOfFieldDistance, renderSettings.DepthOfFieldStrength , depthLinearizeMul, depthLinearizeAdd }; + Vec4 UniformData = { renderSettings.DepthOfFieldDistance, renderSettings.DepthOfFieldStrength, depthLinearizeMul, depthLinearizeAdd }; m_DepthOfFieldPassDescriptorSet->SetUniformBufferData(0, &UniformData); m_DepthOfFieldPassDescriptorSet->SetTexture(1, m_LastRenderTarget); @@ -2005,7 +2002,7 @@ namespace Lumos::Graphics Renderer::BindDescriptorSets(pipeline.get(), commandBuffer, 0, &set, 1); Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); - std::swap(m_LastRenderTarget, m_PostProcessTexture1); + Swap(m_LastRenderTarget, m_PostProcessTexture1); } void SceneRenderer::SharpenPass() @@ -2036,7 +2033,7 @@ namespace Lumos::Graphics Renderer::BindDescriptorSets(pipeline.get(), commandBuffer, 0, &set, 1); Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); } static Vec2 debugUIOffset = Vec2(0.0f, 0.0f); @@ -2456,10 +2453,10 @@ namespace Lumos::Graphics ToneMappingUniformData data; data.BloomIntensity = m_CurrentScene->GetSettings().RenderSettings.BloomEnabled ? m_CurrentScene->GetSettings().RenderSettings.m_BloomIntensity : 0.0f; - data.Saturation = m_CurrentScene->GetSettings().RenderSettings.Saturation; - data.Brightness = m_CurrentScene->GetSettings().RenderSettings.Brightness; - data.Contrast = m_CurrentScene->GetSettings().RenderSettings.Contrast; - data.ToneMapIndex = m_ToneMapIndex; + data.Saturation = m_CurrentScene->GetSettings().RenderSettings.Saturation; + data.Brightness = m_CurrentScene->GetSettings().RenderSettings.Brightness; + data.Contrast = m_CurrentScene->GetSettings().RenderSettings.Contrast; + data.ToneMapIndex = m_ToneMapIndex; m_ToneMappingPassDescriptorSet->SetUniformBufferData(0, &data); m_ToneMappingPassDescriptorSet->SetTexture(1, m_LastRenderTarget); @@ -2480,7 +2477,7 @@ namespace Lumos::Graphics Renderer::BindDescriptorSets(pipeline.get(), commandBuffer, 0, &set, 1); Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); } void SceneRenderer::FinalPass() @@ -2544,7 +2541,7 @@ namespace Lumos::Graphics Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); if(m_LastRenderTarget != m_MainTexture && m_LastRenderTarget != m_ResolveTexture) - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); commandBuffer->UnBindPipeline(); commandBuffer->EndCurrentRenderPass(); @@ -2968,7 +2965,7 @@ namespace Lumos::Graphics Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); } - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); } void SceneRenderer::DebandingPass() @@ -2999,7 +2996,7 @@ namespace Lumos::Graphics Renderer::BindDescriptorSets(pipeline.get(), commandBuffer, 0, &set, 1); Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); } void SceneRenderer::FilmicGrainPass() @@ -3041,7 +3038,7 @@ namespace Lumos::Graphics Renderer::BindDescriptorSets(pipeline.get(), commandBuffer, 0, &set, 1); Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); } void SceneRenderer::OutlinePass() @@ -3072,7 +3069,7 @@ namespace Lumos::Graphics // Renderer::BindDescriptorSets(pipeline.get(), commandBuffer, 0, &set, 1); Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); } void SceneRenderer::ChromaticAberationPass() @@ -3083,7 +3080,7 @@ namespace Lumos::Graphics if(!m_Camera || !m_LastRenderTarget || !m_ChromaticAberationShader->IsCompiled()) return; - auto set = m_ChromaticAberationPassDescriptorSet.get(); + auto set = m_ChromaticAberationPassDescriptorSet.get(); float data[4] = { 100.0f, m_Camera->GetAperture(), 0.0f, 0.0f }; set->SetTexture(1, m_LastRenderTarget); set->SetUniformBufferData(0, data); @@ -3103,7 +3100,7 @@ namespace Lumos::Graphics Renderer::BindDescriptorSets(pipeline.get(), commandBuffer, 0, &set, 1); Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); - std::swap(m_PostProcessTexture1, m_LastRenderTarget); + Swap(m_PostProcessTexture1, m_LastRenderTarget); } void SceneRenderer::EyeAdaptationPass() @@ -3132,6 +3129,10 @@ namespace Lumos::Graphics { Render2DFlush(); Renderer2DBeginBatch(); + + auto projView = m_Camera->GetProjectionMatrix() * m_CameraTransform->GetWorldMatrix().Inverse(); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->Update(); } m_Renderer2DData.m_Textures[m_Renderer2DData.m_TextureCount] = texture; m_Renderer2DData.m_TextureCount++; @@ -3178,6 +3179,10 @@ namespace Lumos::Graphics { Render2DFlush(); Renderer2DBeginBatch(); + + projView = m_Camera->GetProjectionMatrix() * m_CameraTransform->GetWorldMatrix().Inverse(); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->Update(); } auto& renderable = command.renderable; @@ -3254,6 +3259,22 @@ namespace Lumos::Graphics m_Renderer2DData.m_VertexBuffers[currentFrame][m_Renderer2DData.m_BatchDrawCallIndex]->Bind(Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(), m_Renderer2DData.m_Pipeline.get()); m_Renderer2DData.m_Buffer = m_2DBufferBase[currentFrame][m_Renderer2DData.m_BatchDrawCallIndex]; + + // TODO: Pass this matrix as a parameter + auto projView = Mat4::Orthographic(0.0f, (float)m_MainTexture->GetWidth(), 0.0f, (float)m_MainTexture->GetHeight(), -1.0f, 1.0f); // m_Camera->GetProjectionMatrix();// * Mat4::Inverse(m_CameraTransform->GetWorldMatrix()); + float aspectRatio = (float)m_MainTexture->GetWidth() / (float)m_MainTexture->GetHeight(); + // projView = Mat4::Orthographic(-aspectRatio * scale, aspectRatio * scale, 0.0f, scale, -10.0f, 10.0f); + + if(m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0] == nullptr) + { + Graphics::DescriptorDesc descriptorDesc {}; + descriptorDesc.layoutIndex = 0; + descriptorDesc.shader = m_Renderer2DData.m_Shader.get(); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0] = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); + } + + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->Update(); } void SceneRenderer::Render2DFlush() @@ -3603,22 +3624,6 @@ namespace Lumos::Graphics m_Renderer2DData.m_Pipeline = Graphics::Pipeline::Get(pipelineDesc); Renderer2DBeginBatch(); - - auto projView = Mat4::Orthographic(0.0f, (float)m_MainTexture->GetWidth(), 0.0f, (float)m_MainTexture->GetHeight(), -1.0f, 1.0f); // m_Camera->GetProjectionMatrix();// * Mat4::Inverse(m_CameraTransform->GetWorldMatrix()); - float scale = 10.0f; - float aspectRatio = (float)m_MainTexture->GetWidth() / (float)m_MainTexture->GetHeight(); - // projView = Mat4::Orthographic(-aspectRatio * scale, aspectRatio * scale, 0.0f, scale, -10.0f, 10.0f); - - if(m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0] == nullptr) - { - Graphics::DescriptorDesc descriptorDesc {}; - descriptorDesc.layoutIndex = 0; - descriptorDesc.shader = m_Renderer2DData.m_Shader.get(); - m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0] = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); - } - - m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->SetUniformBufferData(0, &projView); - m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->Update(); } void SceneRenderer::BeginTextPass() @@ -3966,7 +3971,7 @@ namespace Lumos::Graphics } Graphics::CommandBuffer* commandBuffer = Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); - commandBuffer->UnBindPipeline(); + commandBuffer->UnBindPipeline(); currentDescriptors[0] = m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][0].get(); currentDescriptors[1] = m_DebugDrawData.m_Renderer2DData.m_DescriptorSet[0][1].get(); @@ -4934,7 +4939,7 @@ namespace Lumos::Graphics { if(m_ParticleData.m_TextureCount >= m_ParticleData.m_Limits.MaxTextures) { - Render2DFlush(); + ParticleFlush(); ParticleBeginBatch(); } m_ParticleData.m_Textures[m_ParticleData.m_TextureCount] = texture; diff --git a/Lumos/Source/Lumos/Maths/MathsBasicTypes.h b/Lumos/Source/Lumos/Maths/MathsBasicTypes.h index 9e13a53b5..79eb31aa6 100644 --- a/Lumos/Source/Lumos/Maths/MathsBasicTypes.h +++ b/Lumos/Source/Lumos/Maths/MathsBasicTypes.h @@ -19,7 +19,7 @@ namespace Lumos Vector3Simple(float x, float y, float z) : x(x) , y(y) - , z(z) {}; + , z(z) { }; float x, y, z; }; diff --git a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.h b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.h index 7aa854226..d8fce9815 100644 --- a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.h +++ b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.h @@ -22,7 +22,7 @@ namespace Lumos struct ContactCallback { - virtual void OnCollision(b2BodyId a, b2BodyId b, float approachSpeed) {}; + virtual void OnCollision(b2BodyId a, b2BodyId b, float approachSpeed) { }; }; class LUMOS_EXPORT B2PhysicsEngine : public ISystem diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp index e675d10f3..ec6adf653 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp @@ -108,7 +108,7 @@ namespace Lumos else continue; - // Slow check for duplicates + // Slow check for duplicates #if DEBUG_CHECK_DUPLICATES bool duplicate = false; for(int i = 0; i < collisionPairs.Size(); i++) diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp index 9c149018c..edf860c48 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp @@ -100,13 +100,13 @@ namespace Lumos Vec3 tangent = dv - normal * Maths::Dot(dv, normal); float tangent_len = Maths::Length(tangent); - if(tangent_len > 0.001f) + if(tangent_len > Maths::M_EPSILON) { tangent = tangent * (1.0f / tangent_len); float frictionalMass = (m_pNodeA->GetInverseMass() + m_pNodeB->GetInverseMass()) + Maths::Dot(tangent, Maths::Cross(m_pNodeA->GetInverseInertia() * Maths::Cross(r1, tangent), r1) + Maths::Cross(m_pNodeB->GetInverseInertia() * Maths::Cross(r2, tangent), r2)); - float frictionCoef = sqrtf(Maths::Max(m_pNodeA->GetFriction(), 0.1f) * Maths::Max(m_pNodeB->GetFriction(), 0.1f)); + float frictionCoef = Maths::Sqrt(Maths::Max(m_pNodeA->GetFriction(), 0.1f) * Maths::Max(m_pNodeB->GetFriction(), 0.1f)); float jt = -1.0f * frictionCoef * Maths::Dot(dv, tangent) / frictionalMass; // Clamp friction to never apply more force than the main collision diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp index eb292dd42..d7a6aa696 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp @@ -202,6 +202,24 @@ namespace Lumos m_AtRest = false; } + void RigidBody3D::SetLinearVelocity(const Vec3& v) + { + if(m_Static) + return; + m_LinearVelocity = v; + + if(Maths::Length2(v) > Maths::M_EPSILON) + m_AtRest = false; + } + void RigidBody3D::SetForce(const Vec3& v) + { + if(m_Static) + return; + m_Force = v; + if(Maths::Length2(v) > Maths::M_EPSILON) + m_AtRest = false; + } + void RigidBody3D::CollisionShapeUpdated() { if(m_CollisionShape) @@ -233,16 +251,16 @@ namespace Lumos RigidBody3DProperties RigidBody3D::GetProperties() { RigidBody3DProperties properties; - properties.Position = m_Position; + properties.Position = m_Position; properties.LinearVelocity = m_LinearVelocity; - properties.Force = m_Force; - properties.Elasticity = m_Elasticity; + properties.Force = m_Force; + properties.Elasticity = m_Elasticity; if(m_InvMass != 0.0f) - properties.Mass = 1.0f / m_InvMass; - else - properties.Mass = 1.0f; - //TODO: Finish rest; + properties.Mass = 1.0f / m_InvMass; + else + properties.Mass = 1.0f; + // TODO: Finish rest; LWARN("WIP Rigidbody GetProperties"); return properties; diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h index 1bf391bbd..ceacd2014 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h @@ -102,29 +102,15 @@ namespace Lumos m_Position = v; m_WSTransformInvalidated = true; m_WSAabbInvalidated = true; - // m_AtRest = false; } - void SetLinearVelocity(const Vec3& v) - { - if(m_Static) - return; - m_LinearVelocity = v; - m_AtRest = false; - } - void SetForce(const Vec3& v) - { - if(m_Static) - return; - m_Force = v; - m_AtRest = false; - } + void SetLinearVelocity(const Vec3& v); + void SetForce(const Vec3& v); void SetOrientation(const Quat& v) { m_Orientation = v; m_WSTransformInvalidated = true; - m_AtRest = false; } void SetAngularVelocity(const Vec3& v); diff --git a/Lumos/Source/Lumos/Platform/Android/AndroidOS.h b/Lumos/Source/Lumos/Platform/Android/AndroidOS.h index 8f1faa164..40bcc6741 100644 --- a/Lumos/Source/Lumos/Platform/Android/AndroidOS.h +++ b/Lumos/Source/Lumos/Platform/Android/AndroidOS.h @@ -46,11 +46,6 @@ namespace Lumos return m_Y; } - static AndroidOS* Get() - { - return (AndroidOS*)s_Instance; - } - private: float m_X, m_Y; }; diff --git a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp index fd82526aa..326a04896 100644 --- a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp +++ b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp @@ -40,28 +40,14 @@ namespace Lumos LERROR("GLFW Error - %i : %s", error, description); } - GLFWWindow::GLFWWindow(const WindowDesc& properties) + GLFWWindow::GLFWWindow() { LUMOS_PROFILE_FUNCTION(); m_Init = false; - m_VSync = properties.VSync; - - LINFO("VSync : %s", m_VSync ? "True" : "False"); - m_HasResized = true; - m_Data.m_RenderAPI = static_cast(properties.RenderAPI); - m_Data.VSync = m_VSync; - m_Init = Init(properties); - - // Setting fullscreen overrides width and heigh in Init - auto propCopy = properties; - propCopy.Width = m_Data.Width; - propCopy.Height = m_Data.Height; - - m_GraphicsContext = SharedPtr(Graphics::GraphicsContext::Create()); - m_GraphicsContext->Init(); + m_VSync = false; - m_SwapChain = SharedPtr(Graphics::SwapChain::Create(m_Data.Width, m_Data.Height)); - m_SwapChain->Init(m_VSync, (Window*)this); + m_HasResized = true; + m_Init = false; } GLFWWindow::~GLFWWindow() @@ -88,6 +74,13 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); LINFO("Creating window - Title : %s, Width : %i, Height : %i", properties.Title.str, properties.Width, properties.Height); + m_VSync = properties.VSync; + + LINFO("VSync : %s", m_VSync ? "True" : "False"); + m_HasResized = true; + m_Data.m_RenderAPI = static_cast(properties.RenderAPI); + m_Data.VSync = m_VSync; + if(!s_GLFWInitialized) { int success = glfwInit(); @@ -201,126 +194,126 @@ namespace Lumos // Set GLFW callbacks glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - - int w, h; - glfwGetFramebufferSize(window, &w, &h); - - data.DPIScale = (float)w / (float)width; - - data.Width = uint32_t(width * data.DPIScale); - data.Height = uint32_t(height * data.DPIScale); - - WindowResizeEvent event(data.Width, data.Height, data.DPIScale); - data.EventCallback(event); }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + + int w, h; + glfwGetFramebufferSize(window, &w, &h); + + data.DPIScale = (float)w / (float)width; + + data.Width = uint32_t(width * data.DPIScale); + data.Height = uint32_t(height * data.DPIScale); + + WindowResizeEvent event(data.Width, data.Height, data.DPIScale); + data.EventCallback(event); }); glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - WindowCloseEvent event; - data.EventCallback(event); - data.Exit = true; }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + WindowCloseEvent event; + data.EventCallback(event); + data.Exit = true; }); glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focused) { - Window* lmWindow = Application::Get().GetWindow(); - - if(lmWindow) - lmWindow->SetWindowFocus(focused); }); + Window* lmWindow = Application::Get().GetWindow(); + + if(lmWindow) + lmWindow->SetWindowFocus(focused); }); glfwSetWindowIconifyCallback(m_Handle, [](GLFWwindow* window, int32_t state) { - switch(state) - { - case GL_TRUE: - Application::Get().GetWindow()->SetWindowFocus(false); - break; - case GL_FALSE: - Application::Get().GetWindow()->SetWindowFocus(true); - break; - default: - LINFO("Unsupported window iconify state from callback"); - } }); + switch(state) + { + case GL_TRUE: + Application::Get().GetWindow()->SetWindowFocus(false); + break; + case GL_FALSE: + Application::Get().GetWindow()->SetWindowFocus(true); + break; + default: + LINFO("Unsupported window iconify state from callback"); + } }); glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - - switch(action) - { - case GLFW_PRESS: - { - KeyPressedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(key), 0); - data.EventCallback(event); - break; - } - case GLFW_RELEASE: - { - KeyReleasedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(key)); - data.EventCallback(event); - break; - } - case GLFW_REPEAT: - { - KeyPressedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(key), 1); - data.EventCallback(event); - break; - } - } }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + + switch(action) + { + case GLFW_PRESS: + { + KeyPressedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(key), 0); + data.EventCallback(event); + break; + } + case GLFW_RELEASE: + { + KeyReleasedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(key)); + data.EventCallback(event); + break; + } + case GLFW_REPEAT: + { + KeyPressedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(key), 1); + data.EventCallback(event); + break; + } + } }); glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - - switch(action) - { - case GLFW_PRESS: - { - MouseButtonPressedEvent event(GLFWKeyCodes::GLFWToLumosMouseKey(button)); - data.EventCallback(event); - break; - } - case GLFW_RELEASE: - { - MouseButtonReleasedEvent event(GLFWKeyCodes::GLFWToLumosMouseKey(button)); - data.EventCallback(event); - break; - } - } }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + + switch(action) + { + case GLFW_PRESS: + { + MouseButtonPressedEvent event(GLFWKeyCodes::GLFWToLumosMouseKey(button)); + data.EventCallback(event); + break; + } + case GLFW_RELEASE: + { + MouseButtonReleasedEvent event(GLFWKeyCodes::GLFWToLumosMouseKey(button)); + data.EventCallback(event); + break; + } + } }); glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xOffset, double yOffset) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - MouseScrolledEvent event((float)xOffset, (float)yOffset); - data.EventCallback(event); }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + MouseScrolledEvent event((float)xOffset, (float)yOffset); + data.EventCallback(event); }); glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xPos, double yPos) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - MouseMovedEvent event((float)xPos /* * data.DPIScale*/, (float)yPos /* * data.DPIScale*/); - data.EventCallback(event); }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + MouseMovedEvent event((float)xPos /* * data.DPIScale*/, (float)yPos /* * data.DPIScale*/); + data.EventCallback(event); }); glfwSetCursorEnterCallback(m_Handle, [](GLFWwindow* window, int enter) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - - MouseEnterEvent event(enter > 0); - data.EventCallback(event); }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + + MouseEnterEvent event(enter > 0); + data.EventCallback(event); }); glfwSetCharCallback(m_Handle, [](GLFWwindow* window, unsigned int keycode) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - - KeyTypedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(keycode), char(keycode)); - data.EventCallback(event); }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + + KeyTypedEvent event(GLFWKeyCodes::GLFWToLumosKeyboardKey(keycode), char(keycode)); + data.EventCallback(event); }); glfwSetDropCallback(m_Handle, [](GLFWwindow* window, int numDropped, const char** filenames) { - WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); - - std::string filePath = filenames[0]; - WindowFileEvent event(filePath); - data.EventCallback(event); }); + WindowData& data = *static_cast((glfwGetWindowUserPointer(window))); + + std::string filePath = filenames[0]; + WindowFileEvent event(filePath); + data.EventCallback(event); }); g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); @@ -331,6 +324,19 @@ namespace Lumos g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); g_MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR); + // Setting fullscreen overrides width and heigh in Init + auto propCopy = properties; + propCopy.Width = m_Data.Width; + propCopy.Height = m_Data.Height; + + m_GraphicsContext = SharedPtr(Graphics::GraphicsContext::Create()); + m_GraphicsContext->Init(); + + m_SwapChain = SharedPtr(Graphics::SwapChain::Create(m_Data.Width, m_Data.Height)); + m_SwapChain->Init(m_VSync, (Window*)this); + + m_Init = true; + LINFO("Initialised GLFW version : %s", glfwGetVersionString()); return true; } @@ -473,9 +479,9 @@ namespace Lumos CreateFunc = CreateFuncGLFW; } - Window* GLFWWindow::CreateFuncGLFW(const WindowDesc& properties) + Window* GLFWWindow::CreateFuncGLFW() { - return new GLFWWindow(properties); + return new GLFWWindow(); } void GLFWWindow::UpdateCursorImGui() @@ -524,7 +530,7 @@ namespace Lumos #ifdef LUMOS_PLATFORM_MACOS // TODO: Move to glfw extensions or something - OS::Instance()->MaximiseWindow(); + OS::Get().MaximiseWindow(); #endif } diff --git a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.h b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.h index cca6ea36d..de7111fd2 100644 --- a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.h +++ b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.h @@ -14,9 +14,10 @@ namespace Lumos class LUMOS_EXPORT GLFWWindow : public Window { public: - GLFWWindow(const WindowDesc& properties); + GLFWWindow(); ~GLFWWindow(); + bool Init(const WindowDesc& properties) override; void ToggleVSync() override; void SetVSync(bool set) override; void SetWindowTitle(const std::string& title) override; @@ -29,8 +30,6 @@ namespace Lumos void Maximise() override; void UpdateControllers() override; - bool Init(const WindowDesc& properties); - inline void* GetHandle() override { return m_Handle; @@ -79,7 +78,7 @@ namespace Lumos static void MakeDefault(); protected: - static Window* CreateFuncGLFW(const WindowDesc& properties); + static Window* CreateFuncGLFW(); GLFWwindow* m_Handle; diff --git a/Lumos/Source/Lumos/Platform/Headless/RenderAPINone.h b/Lumos/Source/Lumos/Platform/Headless/RenderAPINone.h index 180e50158..d429e531c 100644 --- a/Lumos/Source/Lumos/Platform/Headless/RenderAPINone.h +++ b/Lumos/Source/Lumos/Platform/Headless/RenderAPINone.h @@ -16,10 +16,10 @@ namespace Lumos void BeginRecording() override; void BeginRecordingSecondary(RenderPass* renderPass, Framebuffer* framebuffer) override; void EndRecording() override; - void Execute(bool waitFence) override {}; + void Execute(bool waitFence) override { }; void ExecuteSecondary(CommandBuffer* primaryCmdBuffer) override; - void UpdateViewport(uint32_t width, uint32_t height) override {}; + void UpdateViewport(uint32_t width, uint32_t height) override { }; static void MakeDefault(); protected: diff --git a/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm b/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm index a53ea4f20..48f774771 100644 --- a/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm +++ b/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm @@ -36,7 +36,7 @@ else LINFO("Power - Outlet"); - auto systemInfo = MemoryManager::Get()->GetSystemInfo(); + auto systemInfo = MemoryManager::Get().GetSystemInfo(); systemInfo.Log(); auto& app = Lumos::Application::Get(); diff --git a/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp b/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp index 6263ed9d9..f99ca51b9 100644 --- a/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp +++ b/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp @@ -50,6 +50,7 @@ namespace Lumos void ALManager::OnUpdate(const TimeStep& dt, Scene* scene) { LUMOS_PROFILE_FUNCTION(); + m_LatestNodeCount = 0; auto& registry = scene->GetRegistry(); auto listenerView = registry.view(); if(listenerView.size_hint() > 0) @@ -65,6 +66,7 @@ namespace Lumos auto soundNode = soundsView.get(entity).GetSoundNode(); soundNode->SetPosition(soundsView.get(entity).GetWorldPosition()); soundNode->OnUpdate((float)dt.GetMillis()); + m_LatestNodeCount++; } } @@ -117,7 +119,7 @@ namespace Lumos ImGui::TextUnformatted("Number Of Audio Sources"); ImGui::NextColumn(); ImGui::PushItemWidth(-1); - ImGui::Text("%5.2lu", m_SoundNodes.Size()); + ImGui::Text("%5.2lu", m_LatestNodeCount); ImGui::PopItemWidth(); ImGui::NextColumn(); diff --git a/Lumos/Source/Lumos/Platform/OpenAL/ALManager.h b/Lumos/Source/Lumos/Platform/OpenAL/ALManager.h index 9fc12cfa4..d07aa3161 100644 --- a/Lumos/Source/Lumos/Platform/OpenAL/ALManager.h +++ b/Lumos/Source/Lumos/Platform/OpenAL/ALManager.h @@ -29,7 +29,8 @@ namespace Lumos ALCcontext* m_Context; ALCdevice* m_Device; - int m_NumChannels = 0; + int m_NumChannels = 0; + u32 m_LatestNodeCount = 0; }; } } diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.h b/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.h index cf67e5b33..c75f38a53 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.h +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.h @@ -22,8 +22,8 @@ namespace Lumos void BindPipeline(Pipeline* pipeline) override; void BindPipeline(Pipeline* pipeline, uint32_t layer) override; void UnBindPipeline() override; - void EndCurrentRenderPass() override {}; - void UpdateViewport(uint32_t width, uint32_t height, bool flipViewport) override {}; + void EndCurrentRenderPass() override { }; + void UpdateViewport(uint32_t width, uint32_t height, bool flipViewport) override { }; static void MakeDefault(); protected: diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLContext.h b/Lumos/Source/Lumos/Platform/OpenGL/GLContext.h index f35c584d8..7101e2e2f 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLContext.h +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLContext.h @@ -13,7 +13,7 @@ namespace Lumos ~GLContext(); void Present() override; - void Init() override {}; + void Init() override { }; size_t GetMinUniformBufferOffsetAlignment() const override { return 256; } diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.h b/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.h index 6fb209ef5..f2121fa43 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.h +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.h @@ -15,7 +15,7 @@ namespace Lumos public: GLDescriptorSet(const DescriptorDesc& descriptorDesc); - ~GLDescriptorSet() {}; + ~GLDescriptorSet() { }; void Update(CommandBuffer* cmdBuffer) override; void SetTexture(const std::string& name, Texture* texture, uint32_t mipIndex, TextureType textureType) override; diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.cpp deleted file mode 100644 index c635ef22b..000000000 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "Precompiled.h" -#include "GLRenderDevice.h" - -namespace Lumos::Graphics -{ - void GLRenderDevice::Init() - { - } - - void GLRenderDevice::MakeDefault() - { - CreateFunc = CreateFuncGL; - } - - RenderDevice* GLRenderDevice::CreateFuncGL() - { - return new GLRenderDevice(); - } -} diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.h b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.h deleted file mode 100644 index 78a865edb..000000000 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "Graphics/RHI/RenderDevice.h" - -namespace Lumos -{ - namespace Graphics - { - class GLRenderDevice : public RenderDevice - { - public: - GLRenderDevice() = default; - ~GLRenderDevice() = default; - - void Init() override; - - static void MakeDefault(); - - protected: - static RenderDevice* CreateFuncGL(); - }; - } -} diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.h b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.h index 33aadf426..77242ddcd 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.h +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.h @@ -67,7 +67,7 @@ namespace Lumos protected: static Renderer* CreateFuncGL(); - const char* m_RendererTitle; + const char* m_RendererTitle; int32_t m_BoundVertexBuffer = -1; int32_t m_BoundIndexBuffer = -1; GLPipeline* m_BoundPipeline = nullptr; diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLShader.h b/Lumos/Source/Lumos/Platform/OpenGL/GLShader.h index e3a424534..775453c5a 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLShader.h +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLShader.h @@ -19,7 +19,7 @@ namespace Lumos struct GLShaderErrorInfo { GLShaderErrorInfo() - : shader(0) {}; + : shader(0) { }; uint32_t shader; std::string message[6]; uint32_t line[6]; diff --git a/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp b/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp index 463ad1664..e2298cb28 100644 --- a/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp +++ b/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp @@ -23,7 +23,7 @@ namespace Lumos LINFO(" System Information "); LINFO("--------------------"); - auto systemInfo = MemoryManager::Get()->GetSystemInfo(); + auto systemInfo = MemoryManager::Get().GetSystemInfo(); systemInfo.Log(); app.Init(); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp index 213685e4f..5456949d1 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp @@ -299,7 +299,7 @@ namespace Lumos m_State = CommandBufferState::Idle; if(!m_Fence->WaitAndReset()) - return false; + return false; return true; } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp index 73c3d84f3..3a0869039 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp @@ -18,21 +18,21 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); m_FramesInFlight = uint32_t(VKRenderer::GetMainSwapChain()->GetSwapChainBufferCount()); - m_Shader = descriptorDesc.shader; + m_Shader = descriptorDesc.shader; DescriptorSetInfo descriptorSetInfo = m_Shader->GetDescriptorInfo(descriptorDesc.layoutIndex); - for (auto& descriptor : descriptorSetInfo.descriptors) + for(auto& descriptor : descriptorSetInfo.descriptors) { DescriptorData info; info.HasUpdated[0] = false; info.HasUpdated[1] = false; info.HasUpdated[2] = false; - info.Desc = descriptor; - info.Binding = descriptor.binding; + info.Desc = descriptor; + info.Binding = descriptor.binding; - if (descriptor.type == DescriptorType::UNIFORM_BUFFER) + if(descriptor.type == DescriptorType::UNIFORM_BUFFER) { - for (uint32_t frame = 0; frame < m_FramesInFlight; frame++) + for(uint32_t frame = 0; frame < m_FramesInFlight; frame++) { // Uniform Buffer per frame in flight auto buffer = SharedPtr(Graphics::UniformBuffer::Create()); @@ -44,18 +44,16 @@ namespace Lumos localStorage.Allocate(descriptor.size); localStorage.InitialiseEmpty(); info.LocalStorage = localStorage; - } - info.valid = true; + info.valid = true; m_DescriptorData[descriptor.binding] = info; - } - for (uint32_t frame = 0; frame < m_FramesInFlight; frame++) + for(uint32_t frame = 0; frame < m_FramesInFlight; frame++) { - m_DescriptorDirty[frame] = true; + m_DescriptorDirty[frame] = true; m_DescriptorUpdated[frame] = false; - m_DescriptorSet[frame] = nullptr; + m_DescriptorSet[frame] = nullptr; g_DescriptorSetCount++; auto layout = static_cast(descriptorDesc.shader)->GetDescriptorLayout(descriptorDesc.layoutIndex); VKRenderer::GetRenderer()->AllocateDescriptorSet(&m_DescriptorSet[frame], m_DescriptorPoolCreatedFrom[frame], *layout, descriptorDesc.count); @@ -64,21 +62,21 @@ namespace Lumos VKDescriptorSet::~VKDescriptorSet() { - for (uint32_t frame = 0; frame < m_FramesInFlight; frame++) + for(uint32_t frame = 0; frame < m_FramesInFlight; frame++) { - if (!m_DescriptorSet[frame]) + if(!m_DescriptorSet[frame]) continue; auto descriptorSet = m_DescriptorSet[frame]; - auto pool = m_DescriptorPoolCreatedFrom[frame]; - auto device = VKDevice::GetHandle(); + auto pool = m_DescriptorPoolCreatedFrom[frame]; + auto device = VKDevice::GetHandle(); DeletionQueue& deletionQueue = VKRenderer::GetCurrentDeletionQueue(); deletionQueue.PushFunction([descriptorSet, pool, device] - { vkFreeDescriptorSets(device, pool, 1, &descriptorSet); }); + { vkFreeDescriptorSets(device, pool, 1, &descriptorSet); }); } - for (auto bufferData : m_DescriptorData) + for(auto bufferData : m_DescriptorData) { bufferData.LocalStorage.Release(); } @@ -98,29 +96,29 @@ namespace Lumos void TransitionImageToCorrectLayout(Texture* texture, CommandBuffer* cmdBuffer) { - if (!texture) + if(!texture) return; auto commandBuffer = cmdBuffer ? cmdBuffer : Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); - if (texture->GetType() == TextureType::COLOUR) + if(texture->GetType() == TextureType::COLOUR) { - if (((VKTexture2D*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) + if(((VKTexture2D*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { ((VKTexture2D*)texture)->TransitionImage(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } } - else if (texture->GetType() == TextureType::CUBE) + else if(texture->GetType() == TextureType::CUBE) { - if (((VKTextureCube*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) + if(((VKTextureCube*)texture)->GetImageLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { ((VKTextureCube*)texture)->TransitionImage(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } } - else if (texture->GetType() == TextureType::DEPTH) + else if(texture->GetType() == TextureType::DEPTH) { ((VKTextureDepth*)texture)->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } - else if (texture->GetType() == TextureType::DEPTHARRAY) + else if(texture->GetType() == TextureType::DEPTHARRAY) { ((VKTextureDepthArray*)texture)->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, (VKCommandBuffer*)commandBuffer); } @@ -129,125 +127,125 @@ namespace Lumos void VKDescriptorSet::Update(CommandBuffer* cmdBuffer) { LUMOS_PROFILE_FUNCTION_LOW(); - m_Dynamic = false; + m_Dynamic = false; int descriptorWritesCount = 0; - uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); - for (auto& bufferInfo : m_DescriptorData) + for(auto& bufferInfo : m_DescriptorData) { - if (bufferInfo.valid && !bufferInfo.Desc.m_Members.Empty() && bufferInfo.HasUpdated[currentFrame]) + if(bufferInfo.valid && !bufferInfo.Desc.m_Members.Empty() && bufferInfo.HasUpdated[currentFrame]) { m_UniformBuffers[currentFrame][bufferInfo.Binding]->SetData(bufferInfo.LocalStorage.Data); bufferInfo.HasUpdated[currentFrame] = false; } } - if (m_DescriptorDirty[currentFrame] || !m_DescriptorUpdated[currentFrame]) + if(m_DescriptorDirty[currentFrame] || !m_DescriptorUpdated[currentFrame]) { m_DescriptorDirty[currentFrame] = false; - uint32_t imageIndex = 0; - uint32_t index = 0; + uint32_t imageIndex = 0; + uint32_t index = 0; - ArenaTemp scratch = ScratchBegin(nullptr, 0); - VkDescriptorBufferInfo* bufferInfos = PushArrayNoZero(scratch.arena, VkDescriptorBufferInfo, 32); - VkDescriptorImageInfo* imageInfos = PushArrayNoZero(scratch.arena, VkDescriptorImageInfo, 32); + ArenaTemp scratch = ScratchBegin(nullptr, 0); + VkDescriptorBufferInfo* bufferInfos = PushArrayNoZero(scratch.arena, VkDescriptorBufferInfo, 32); + VkDescriptorImageInfo* imageInfos = PushArrayNoZero(scratch.arena, VkDescriptorImageInfo, 32); VkWriteDescriptorSet* writeDescriptorSets = PushArrayNoZero(scratch.arena, VkWriteDescriptorSet, 32); - for (auto& imageInfo : m_DescriptorData) + for(auto& imageInfo : m_DescriptorData) { - if (imageInfo.valid && imageInfo.Desc.type == DescriptorType::IMAGE_SAMPLER && (imageInfo.Desc.texture || imageInfo.Desc.textures)) + if(imageInfo.valid && imageInfo.Desc.type == DescriptorType::IMAGE_SAMPLER && (imageInfo.Desc.texture || imageInfo.Desc.textures)) { - if (imageInfo.Desc.textureCount == 1) + if(imageInfo.Desc.textureCount == 1) { - if (imageInfo.Desc.texture) + if(imageInfo.Desc.texture) { TransitionImageToCorrectLayout(imageInfo.Desc.texture, cmdBuffer); - VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.texture->GetDescriptorInfo()); + VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.texture->GetDescriptorInfo()); imageInfos[imageIndex].imageLayout = des.imageLayout; - imageInfos[imageIndex].imageView = des.imageView; - imageInfos[imageIndex].sampler = des.sampler; + imageInfos[imageIndex].imageView = des.imageView; + imageInfos[imageIndex].sampler = des.sampler; } } else { - if (imageInfo.Desc.textures) + if(imageInfo.Desc.textures) { - for (uint32_t i = 0; i < imageInfo.Desc.textureCount; i++) + for(uint32_t i = 0; i < imageInfo.Desc.textureCount; i++) { TransitionImageToCorrectLayout(imageInfo.Desc.textures[i], cmdBuffer); - VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.textures[i]->GetDescriptorInfo()); + VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.textures[i]->GetDescriptorInfo()); imageInfos[i + imageIndex].imageLayout = des.imageLayout; - imageInfos[i + imageIndex].imageView = des.imageView; - imageInfos[i + imageIndex].sampler = des.sampler; + imageInfos[i + imageIndex].imageView = des.imageView; + imageInfos[i + imageIndex].sampler = des.sampler; } } } VkWriteDescriptorSet writeDescriptorSet = {}; - writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; - writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - writeDescriptorSet.dstBinding = imageInfo.Desc.binding; - writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; - writeDescriptorSet.descriptorCount = imageInfo.Desc.textureCount; + writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; + writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + writeDescriptorSet.dstBinding = imageInfo.Desc.binding; + writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; + writeDescriptorSet.descriptorCount = imageInfo.Desc.textureCount; writeDescriptorSets[descriptorWritesCount] = writeDescriptorSet; imageIndex++; descriptorWritesCount++; } - else if (imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE && imageInfo.Desc.texture) + else if(imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE && imageInfo.Desc.texture) { - if (imageInfo.Desc.texture) + if(imageInfo.Desc.texture) { ((VKTexture2D*)imageInfo.Desc.texture)->TransitionImage(VK_IMAGE_LAYOUT_GENERAL); - VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.texture->GetDescriptorInfo()); + VkDescriptorImageInfo& des = *static_cast(imageInfo.Desc.texture->GetDescriptorInfo()); imageInfos[imageIndex].imageLayout = des.imageLayout; - imageInfos[imageIndex].imageView = imageInfo.Desc.mipLevel > 0 ? ((VKTexture2D*)imageInfo.Desc.texture)->GetMipImageView(imageInfo.Desc.mipLevel) : des.imageView; - imageInfos[imageIndex].sampler = des.sampler; + imageInfos[imageIndex].imageView = imageInfo.Desc.mipLevel > 0 ? ((VKTexture2D*)imageInfo.Desc.texture)->GetMipImageView(imageInfo.Desc.mipLevel) : des.imageView; + imageInfos[imageIndex].sampler = des.sampler; } VkWriteDescriptorSet writeDescriptorSet = {}; - writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; - writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; - writeDescriptorSet.dstBinding = imageInfo.Desc.binding; - writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; - writeDescriptorSet.descriptorCount = imageInfo.Desc.textureCount; + writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; + writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + writeDescriptorSet.dstBinding = imageInfo.Desc.binding; + writeDescriptorSet.pImageInfo = &imageInfos[imageIndex]; + writeDescriptorSet.descriptorCount = imageInfo.Desc.textureCount; writeDescriptorSets[descriptorWritesCount] = writeDescriptorSet; imageIndex++; descriptorWritesCount++; } - else if (imageInfo.Desc.type == DescriptorType::UNIFORM_BUFFER) + else if(imageInfo.Desc.type == DescriptorType::UNIFORM_BUFFER) { VKUniformBuffer* vkUniformBuffer = m_UniformBuffers[currentFrame][imageInfo.Desc.binding].As().get(); - bufferInfos[index].buffer = *vkUniformBuffer->GetBuffer(); - bufferInfos[index].offset = imageInfo.Desc.offset; - bufferInfos[index].range = imageInfo.Desc.size; + bufferInfos[index].buffer = *vkUniformBuffer->GetBuffer(); + bufferInfos[index].offset = imageInfo.Desc.offset; + bufferInfos[index].range = imageInfo.Desc.size; VkWriteDescriptorSet writeDescriptorSet = {}; - writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; - writeDescriptorSet.descriptorType = VKUtilities::DescriptorTypeToVK(imageInfo.Desc.type); - writeDescriptorSet.dstBinding = imageInfo.Desc.binding; - writeDescriptorSet.pBufferInfo = &bufferInfos[index]; - writeDescriptorSet.descriptorCount = 1; + writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + writeDescriptorSet.dstSet = m_DescriptorSet[currentFrame]; + writeDescriptorSet.descriptorType = VKUtilities::DescriptorTypeToVK(imageInfo.Desc.type); + writeDescriptorSet.dstBinding = imageInfo.Desc.binding; + writeDescriptorSet.pBufferInfo = &bufferInfos[index]; + writeDescriptorSet.descriptorCount = 1; writeDescriptorSets[descriptorWritesCount] = writeDescriptorSet; index++; descriptorWritesCount++; - if (imageInfo.Desc.type == DescriptorType::UNIFORM_BUFFER_DYNAMIC) + if(imageInfo.Desc.type == DescriptorType::UNIFORM_BUFFER_DYNAMIC) m_Dynamic = true; } } vkUpdateDescriptorSets(VKDevice::Get().GetDevice(), descriptorWritesCount, - writeDescriptorSets, 0, nullptr); + writeDescriptorSets, 0, nullptr); ScratchEnd(scratch); m_DescriptorUpdated[currentFrame] = true; @@ -256,15 +254,15 @@ namespace Lumos void VKDescriptorSet::TransitionImages(CommandBuffer* commandBuffer) { - for (auto& imageInfo : m_DescriptorData) + for(auto& imageInfo : m_DescriptorData) { - if (imageInfo.valid && (imageInfo.Desc.type == DescriptorType::IMAGE_SAMPLER || imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE) && (imageInfo.Desc.texture || imageInfo.Desc.textures)) + if(imageInfo.valid && (imageInfo.Desc.type == DescriptorType::IMAGE_SAMPLER || imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE) && (imageInfo.Desc.texture || imageInfo.Desc.textures)) { - if (imageInfo.Desc.textureCount == 1) + if(imageInfo.Desc.textureCount == 1) { - if (imageInfo.Desc.texture) + if(imageInfo.Desc.texture) { - if (imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE) + if(imageInfo.Desc.type == DescriptorType::IMAGE_STORAGE) ((VKTexture2D*)imageInfo.Desc.texture)->TransitionImage(VK_IMAGE_LAYOUT_GENERAL, (VKCommandBuffer*)commandBuffer); else TransitionImageToCorrectLayout(imageInfo.Desc.texture, commandBuffer); @@ -278,14 +276,14 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); - for (auto& descriptor : m_DescriptorData) + for(auto& descriptor : m_DescriptorData) { - if (descriptor.valid && (descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && descriptor.Desc.name == name) + if(descriptor.valid && (descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && descriptor.Desc.name == name) { - descriptor.Desc.texture = texture; - descriptor.Desc.textureType = textureType; + descriptor.Desc.texture = texture; + descriptor.Desc.textureType = textureType; descriptor.Desc.textureCount = texture ? 1 : 0; - descriptor.Desc.mipLevel = mipIndex; + descriptor.Desc.mipLevel = mipIndex; m_DescriptorDirty[0] = true; m_DescriptorDirty[1] = true; @@ -298,13 +296,13 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); - for (auto& descriptor : m_DescriptorData) + for(auto& descriptor : m_DescriptorData) { - if (descriptor.valid && (descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && descriptor.Desc.name == name) + if(descriptor.valid && (descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && descriptor.Desc.name == name) { descriptor.Desc.textureCount = textureCount; - descriptor.Desc.textures = texture; - descriptor.Desc.textureType = textureType; + descriptor.Desc.textures = texture; + descriptor.Desc.textureType = textureType; m_DescriptorDirty[0] = true; m_DescriptorDirty[1] = true; @@ -333,14 +331,14 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = nullptr; - for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) + for(u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == name) + if(!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == name) { lBufferInfo = &m_DescriptorData[i]; } } - if (lBufferInfo) + if(lBufferInfo) { lBufferInfo->HasUpdated[0] = true; lBufferInfo->HasUpdated[1] = true; @@ -373,18 +371,18 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = nullptr; - for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) + for(u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) + if(!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) { lBufferInfo = &m_DescriptorData[i]; } } - if (lBufferInfo) + if(lBufferInfo) { - for (auto& member : lBufferInfo->Desc.m_Members) + for(auto& member : lBufferInfo->Desc.m_Members) { - if (member.name == uniformName) + if(member.name == uniformName) { lBufferInfo->LocalStorage.Write(data, member.size, member.offset); lBufferInfo->HasUpdated[0] = true; @@ -403,18 +401,18 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = nullptr; - for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) + for(u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) + if(!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) { lBufferInfo = &m_DescriptorData[i]; } } - if (lBufferInfo) + if(lBufferInfo) { - for (auto& member : lBufferInfo->Desc.m_Members) + for(auto& member : lBufferInfo->Desc.m_Members) { - if (member.name == uniformName) + if(member.name == uniformName) { lBufferInfo->LocalStorage.Write(data, size, member.offset); lBufferInfo->HasUpdated[0] = true; @@ -433,14 +431,14 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = nullptr; - for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) + for(u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) + if(!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) { lBufferInfo = &m_DescriptorData[i]; } } - if (lBufferInfo) + if(lBufferInfo) { lBufferInfo->LocalStorage.Write(data, lBufferInfo->LocalStorage.GetSize(), 0); lBufferInfo->HasUpdated[0] = true; @@ -455,18 +453,18 @@ namespace Lumos void VKDescriptorSet::SetUniformDynamic(const std::string& bufferName, uint32_t size) { DescriptorData* lBufferInfo = nullptr; - for (u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) + for(u8 i = 0; i < DESCRIPTOR_MAX_DESCRIPTORS; i++) { - if (!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) + if(!m_DescriptorData[i].Desc.m_Members.Empty() && m_DescriptorData[i].Desc.name == bufferName) { lBufferInfo = &m_DescriptorData[i]; } } - if (lBufferInfo) + if(lBufferInfo) { lBufferInfo->LocalStorage.Allocate(size); - for (auto& member : lBufferInfo->Desc.m_Members) + for(auto& member : lBufferInfo->Desc.m_Members) { member.size = size; } @@ -477,29 +475,28 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); auto& descriptor = m_DescriptorData[binding]; - if ((descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && texture) + if((descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && texture) { - descriptor.Desc.texture = texture; - descriptor.Desc.textureType = textureType; + descriptor.Desc.texture = texture; + descriptor.Desc.textureType = textureType; descriptor.Desc.textureCount = texture ? 1 : 0; - descriptor.Desc.mipLevel = mipIndex; + descriptor.Desc.mipLevel = mipIndex; m_DescriptorDirty[0] = true; m_DescriptorDirty[1] = true; m_DescriptorDirty[2] = true; } - } void VKDescriptorSet::SetTexture(u8 binding, Texture** texture, uint32_t textureCount, TextureType textureType) { LUMOS_PROFILE_FUNCTION(); auto& descriptor = m_DescriptorData[binding]; - if ((descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && texture) + if((descriptor.Desc.type == DescriptorType::IMAGE_SAMPLER || descriptor.Desc.type == DescriptorType::IMAGE_STORAGE) && texture) { descriptor.Desc.textureCount = textureCount; - descriptor.Desc.textures = texture; - descriptor.Desc.textureType = textureType; + descriptor.Desc.textures = texture; + descriptor.Desc.textureType = textureType; m_DescriptorDirty[0] = true; m_DescriptorDirty[1] = true; @@ -510,7 +507,7 @@ namespace Lumos void VKDescriptorSet::SetBuffer(u8 binding, UniformBuffer* buffer) { LUMOS_PROFILE_FUNCTION(); - uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); m_DescriptorData[binding].Desc.buffer = buffer; LWARN("Check"); } @@ -519,7 +516,7 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = &m_DescriptorData[binding]; - if (lBufferInfo) + if(lBufferInfo) { lBufferInfo->HasUpdated[0] = true; lBufferInfo->HasUpdated[1] = true; @@ -552,11 +549,11 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = &m_DescriptorData[binding]; - if (lBufferInfo) + if(lBufferInfo) { - for (auto& member : lBufferInfo->Desc.m_Members) + for(auto& member : lBufferInfo->Desc.m_Members) { - if (member.name == uniformName) + if(member.name == uniformName) { lBufferInfo->LocalStorage.Write(data, member.size, member.offset); lBufferInfo->HasUpdated[0] = true; @@ -575,11 +572,11 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = &m_DescriptorData[binding]; - if (lBufferInfo) + if(lBufferInfo) { - for (auto& member : lBufferInfo->Desc.m_Members) + for(auto& member : lBufferInfo->Desc.m_Members) { - if (member.name == uniformName) + if(member.name == uniformName) { lBufferInfo->LocalStorage.Write(data, size, member.offset); lBufferInfo->HasUpdated[0] = true; @@ -590,7 +587,7 @@ namespace Lumos } } - LWARN("Uniform not found %d.%s",int(binding), uniformName.c_str()); + LWARN("Uniform not found %d.%s", int(binding), uniformName.c_str()); } void VKDescriptorSet::SetUniformBufferData(u8 binding, void* data) @@ -598,7 +595,7 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = &m_DescriptorData[binding]; - if (lBufferInfo) + if(lBufferInfo) { lBufferInfo->LocalStorage.Write(data, lBufferInfo->LocalStorage.GetSize(), 0); lBufferInfo->HasUpdated[0] = true; @@ -615,7 +612,7 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); DescriptorData* lBufferInfo = &m_DescriptorData[binding]; - if (lBufferInfo) + if(lBufferInfo) { ASSERT(size <= lBufferInfo->LocalStorage.GetSize()); lBufferInfo->LocalStorage.Write(data, size, 0); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h index 07a2a4404..69db159ad 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.h @@ -11,16 +11,16 @@ namespace Lumos { class VKDescriptorSet : public DescriptorSet { - public: + public: VKDescriptorSet(const DescriptorDesc& descriptorDesc); ~VKDescriptorSet(); - + VkDescriptorSet GetDescriptorSet() { uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); return m_DescriptorSet[currentFrame]; } - //Slow + // Slow void Update(CommandBuffer* cmdBuffer) override; void SetTexture(const std::string& name, Texture* texture, uint32_t mipIndex, TextureType textureType) override; void SetTexture(const std::string& name, Texture** texture, uint32_t textureCount, TextureType textureType) override; @@ -38,7 +38,7 @@ namespace Lumos void SetUniformBufferData(u8 binding, void* data, float size) override; void TransitionImages(CommandBuffer* commandBuffer) override; - + Buffer* GetUniformBufferLocalData(const std::string& name) override; Graphics::UniformBuffer* GetUniformBuffer(const std::string& name) override; @@ -46,26 +46,26 @@ namespace Lumos Graphics::UniformBuffer* GetUniformBuffer(u8 binding) override; bool GetIsDynamic() const { return m_Dynamic; } - + void SetDynamicOffset(uint32_t offset) override { m_DynamicOffset = offset; } uint32_t GetDynamicOffset() const override { return m_DynamicOffset; } bool GetHasUpdated(uint32_t frame) { return m_DescriptorUpdated[frame]; } void SetUniformDynamic(const std::string& bufferName, uint32_t size) override; - + static void MakeDefault(); - - protected: + + protected: void UpdateInternal(TDArray* imageInfos); - + static DescriptorSet* CreateFuncVulkan(const DescriptorDesc&); - - private: + + private: uint32_t m_DynamicOffset = 0; Shader* m_Shader = nullptr; bool m_Dynamic = false; - + uint32_t m_FramesInFlight = 0; - + struct DescriptorData { Descriptor Desc; @@ -75,7 +75,7 @@ namespace Lumos // Per frame in flight bool HasUpdated[MAX_FRAMES_FLIGHT]; }; - + DescriptorData m_DescriptorData[DESCRIPTOR_MAX_DESCRIPTORS]; SharedPtr m_UniformBuffers[MAX_FRAMES_FLIGHT][DESCRIPTOR_MAX_DESCRIPTORS]; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp index 98d5ba650..8c0d0eb4e 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp @@ -77,7 +77,7 @@ namespace Lumos bool VKFence::WaitAndReset() { - LUMOS_PROFILE_FUNCTION(); + LUMOS_PROFILE_FUNCTION(); bool succeeded = true; if(!IsSignaled()) succeeded = Wait(); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.h b/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.h index 2d3e7b270..dcfc07f41 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.h @@ -15,7 +15,7 @@ namespace Lumos const VkFramebuffer& GetFramebuffer() const { return m_Framebuffer; } - void SetClearColour(const Vec4& colour) override {}; + void SetClearColour(const Vec4& colour) override { }; uint32_t GetWidth() const override { return m_Width; } uint32_t GetHeight() const override { return m_Height; } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp index 906e53372..492e68eac 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp @@ -7,7 +7,6 @@ #include "VKIMGUIRenderer.h" #include "VKIndexBuffer.h" #include "VKPipeline.h" -#include "VKRenderDevice.h" #include "VKRenderer.h" #include "VKRenderPass.h" #include "VKShader.h" @@ -25,7 +24,6 @@ void Lumos::Graphics::Vulkan::MakeDefault() VKIMGUIRenderer::MakeDefault(); VKIndexBuffer::MakeDefault(); VKPipeline::MakeDefault(); - VKRenderDevice::MakeDefault(); VKRenderer::MakeDefault(); VKRenderPass::MakeDefault(); VKShader::MakeDefault(); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp index def77fc0d..1f74da310 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp @@ -12,6 +12,7 @@ #include "VKRenderPass.h" #include "VKTexture.h" #include "Graphics/RHI/GPUProfile.h" +#include "Core/Application.h" static ImGui_ImplVulkanH_Window g_WindowData; static VkAllocationCallbacks* g_Allocator = nullptr; @@ -192,9 +193,10 @@ namespace Lumos u32 currentImageIndex = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); vkResetDescriptorPool(VKDevice::Get().GetDevice(), g_DescriptorPool[currentImageIndex], 0); - ImGui_ImplVulkan_ClearDescriptors(currentImageIndex); + m_CurrentFrameTextures = { Application::Get().GetFrameArena() }; + m_CurrentFrameTextures.Reserve(1024); - m_CurrentTextureIDIndex = 0; + ImGui::GetIO().Fonts->TexID = (ImTextureID)AddTexture(m_FontTexture, TextureType::COLOUR, 0, 0); } void VKIMGUIRenderer::FrameRender(ImGui_ImplVulkanH_Window* wd) @@ -205,7 +207,6 @@ namespace Lumos wd->FrameIndex = VKRenderer::GetMainSwapChain()->GetCurrentImageIndex(); auto currentCommandBuffer = (VKCommandBuffer*)Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(); - auto& descriptorImageMap = ImGui_ImplVulkan_GetDescriptorImageMap(); auto swapChain = static_cast(VKRenderer::GetMainSwapChain()); if(wd->Swapchain != swapChain->GetSwapChain()) @@ -213,43 +214,29 @@ namespace Lumos { auto draw_data = ImGui::GetDrawData(); - for(int n = 0; n < draw_data->CmdListsCount; n++) + for(auto texture : m_CurrentFrameTextures) { - const ImDrawList* cmd_list = draw_data->CmdLists[n]; - for(int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + if(!texture) + continue; + + if(texture->GetType() == TextureType::COLOUR) + { + auto tex = (VKTexture2D*)texture; + tex->TransitionImage(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, currentCommandBuffer); + } + else if(texture->GetType() == TextureType::DEPTH) + { + auto textureDepth = (VKTextureDepth*)texture; + textureDepth->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, currentCommandBuffer); + } + else if(texture->GetType() == TextureType::DEPTHARRAY) { - const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; - ImGuiTextureID* texID = (ImGuiTextureID*)pcmd->TextureId; - - if(texID && texID->texture) - { - if(texID->type == TextureType::COLOUR) - { - - auto texture = (VKTexture2D*)texID->texture; - texture->TransitionImage(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, currentCommandBuffer); - descriptorImageMap[pcmd->TextureId] = *texture->GetDescriptor(); - } - else if(texID->type == TextureType::DEPTH) - { - auto texture = (VKTextureDepth*)texID->texture; - texture->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, currentCommandBuffer); - descriptorImageMap[pcmd->TextureId] = *texture->GetDescriptor(); - } - else if(texID->type == TextureType::DEPTHARRAY) - { - auto texture = (VKTextureDepthArray*)texID->texture; - texture->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, currentCommandBuffer); - descriptorImageMap[pcmd->TextureId] = *texture->GetDescriptor(); - descriptorImageMap[pcmd->TextureId].imageView = texture->GetImageView(texID->level); - } - } + auto textureDepth = (VKTextureDepthArray*)texture; + textureDepth->TransitionImage(VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, currentCommandBuffer); } } } - ImGui_ImplVulkan_CreateDescriptorSets(ImGui::GetDrawData(), VKRenderer::GetMainSwapChain()->GetCurrentBufferIndex()); - float clearColour[4] = { 0.1f, 0.1f, 0.1f, 1.0f }; m_Renderpass->BeginRenderPass(currentCommandBuffer, clearColour, m_Framebuffers[wd->FrameIndex], Graphics::SubPassContents::INLINE, wd->Width, wd->Height); @@ -346,13 +333,36 @@ namespace Lumos auto desc = TextureDesc(TextureFilter::NEAREST, TextureFilter::NEAREST, TextureWrap::REPEAT); desc.flags = TextureFlags::Texture_Sampled; - m_FontTexture = new VKTexture2D(width, height, pixels, desc); - m_FontTextureID.level = 0; - m_FontTextureID.mip = 0; - m_FontTextureID.type = TextureType::COLOUR; - m_FontTextureID.texture = m_FontTexture; - io.Fonts->TexID = (ImTextureID)&m_FontTextureID; + m_FontTexture = new VKTexture2D(width, height, pixels, desc); + io.Fonts->TexID = (ImTextureID)AddTexture(m_FontTexture, TextureType::COLOUR, 0, 0); + m_CurrentFrameTextures.PushBack(m_FontTexture); + } + } + + ImTextureID VKIMGUIRenderer::AddTexture(Texture* texture, TextureType type, uint32_t level, uint32_t mip) + { + u32 currentImageIndex = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + + // Layout is transitioned to these before rendering + m_CurrentFrameTextures.PushBack(texture); + if(type == TextureType::COLOUR) + { + auto tex = (VKTexture2D*)texture; + return ImGui_ImplVulkan_AddTexture(tex->GetSampler(), tex->GetMipImageView(mip), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, g_DescriptorPool[currentImageIndex]); } + else if(type == TextureType::DEPTH) + { + auto depthTex = (VKTextureDepth*)texture; + return ImGui_ImplVulkan_AddTexture(depthTex->GetSampler(), depthTex->GetImageView(), VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, g_DescriptorPool[currentImageIndex]); + } + else if(type == TextureType::DEPTHARRAY) + { + auto depthTex = (VKTextureDepthArray*)texture; + return ImGui_ImplVulkan_AddTexture(depthTex->GetSampler(), depthTex->GetImageView(level), VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, g_DescriptorPool[currentImageIndex]); + } + + ASSERT("Unsupported Texture Type with ImGui"); + return nullptr; } } } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.h b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.h index 073ba5569..63cf4d2ca 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.h @@ -30,6 +30,7 @@ namespace Lumos void SetupVulkanWindowData(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height); bool Implemented() const override { return true; } void RebuildFontTexture() override; + ImTextureID AddTexture(Texture* texture, TextureType type, uint32_t level, uint32_t mip) override; static void MakeDefault(); @@ -43,8 +44,10 @@ namespace Lumos VKFramebuffer* m_Framebuffers[3]; VKRenderPass* m_Renderpass; VKTexture2D* m_FontTexture; - ImGuiTextureID m_FontTextureID; + ImTextureID m_FontTextureID; bool m_ClearScreen; + + TDArray m_CurrentFrameTextures; }; } } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.cpp deleted file mode 100644 index 18f29ee05..000000000 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "Precompiled.h" -#include "VKRenderDevice.h" - -namespace Lumos::Graphics -{ - void VKRenderDevice::Init() - { - } - - void VKRenderDevice::MakeDefault() - { - CreateFunc = CreateFuncVulkan; - } - - RenderDevice* VKRenderDevice::CreateFuncVulkan() - { - return new VKRenderDevice(); - } -} diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.h b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.h deleted file mode 100644 index 0376a5903..000000000 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "Graphics/RHI/RenderDevice.h" - -namespace Lumos -{ - namespace Graphics - { - class VKRenderDevice : public RenderDevice - { - public: - VKRenderDevice() = default; - ~VKRenderDevice() = default; - - void Init() override; - - static void MakeDefault(); - - protected: - static RenderDevice* CreateFuncVulkan(); - }; - } -} diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp index 50a427a13..b468a53df 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp @@ -603,7 +603,7 @@ file.close(); VkDescriptorPool VKRenderer::GetPool() { - //TODO: Add pools to freelist once all descriptor sets have been marked as freed + // TODO: Add pools to freelist once all descriptor sets have been marked as freed if(m_FreeDescriptorPools.Size() > 0) { VkDescriptorPool pool = m_FreeDescriptorPools.Back(); @@ -671,15 +671,15 @@ file.close(); return false; } - - bool VKRenderer::DeallocateDescriptorSet(VkDescriptorSet* set, VkDescriptorPool& pool) - { - //Find pool index - //Decrease Pool capcity by 1 - //Check if capacity is 0 - //Add to free list if empty + + bool VKRenderer::DeallocateDescriptorSet(VkDescriptorSet* set, VkDescriptorPool& pool) + { + // Find pool index + // Decrease Pool capcity by 1 + // Check if capacity is 0 + // Add to free list if empty return false; - } + } void VKRenderer::ReleaseDescriptorPools() { diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.h b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.h index ebb0c3a48..df183b6d9 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.h @@ -63,7 +63,7 @@ namespace Lumos void Dispatch(CommandBuffer* commandBuffer, uint32_t workGroupSizeX, uint32_t workGroupSizeY, uint32_t workGroupSizeZ) override; bool AllocateDescriptorSet(VkDescriptorSet* set, VkDescriptorPool& pool, VkDescriptorSetLayout layout, uint32_t descriptorCount); - bool DeallocateDescriptorSet(VkDescriptorSet* set, VkDescriptorPool& pool); + bool DeallocateDescriptorSet(VkDescriptorSet* set, VkDescriptorPool& pool); void ReleaseDescriptorPools(); static DeletionQueue& GetDeletionQueue(int frameIndex) @@ -105,8 +105,8 @@ namespace Lumos const char* m_RendererTitle; VkDescriptorPool m_CurrentPool; - - TDArray m_UsedDescriptorPoolsCapacity; + + TDArray m_UsedDescriptorPoolsCapacity; TDArray m_UsedDescriptorPools; TDArray m_FreeDescriptorPools; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp index 44fb2e59d..6ff515c94 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp @@ -772,18 +772,18 @@ namespace Lumos m_Compiled = true; } - for (auto& infos : m_DescriptorInfos) + for(auto& infos : m_DescriptorInfos) { Algorithms::BubbleSort(infos.second.descriptors.begin(), infos.second.descriptors.end(), - [](Descriptor& a, Descriptor& b) - { - return a.binding < b.binding; - }); - - /* infos.second.descriptors.Unique([](Descriptor& a, Descriptor& b) - { - return a.binding == b.binding; - });*/ + [](Descriptor& a, Descriptor& b) + { + return a.binding < b.binding; + }); + + /* infos.second.descriptors.Unique([](Descriptor& a, Descriptor& b) + { + return a.binding == b.binding; + });*/ } VK_CHECK_RESULT(result); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.h b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.h index 9f7361ff4..24f9a98e6 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.h @@ -22,8 +22,8 @@ namespace Lumos VkPipelineShaderStageCreateInfo* GetShaderStages() const; uint32_t GetStageCount() const; - void Bind() const override {}; - void Unbind() const override {}; + void Bind() const override { }; + void Unbind() const override { }; const TDArray GetShaderTypes() const override { diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp index 306996538..3e9e9cd16 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp @@ -342,14 +342,14 @@ namespace Lumos { if(!commandBuffer->Wait()) { - //Exit app + // Exit app LFATAL("Failed to submit command buffer"); Application::Get().SetAppState(AppState::Closing); return; } } - //TODO: Check if in pending state before resetting + // TODO: Check if in pending state before resetting commandBuffer->Reset(); VKRenderer::GetDeletionQueue(m_CurrentBuffer).Flush(); AcquireNextImage(); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp index 96c66c8c9..b0794ae23 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp @@ -1309,16 +1309,16 @@ namespace Lumos m_VKFormat = VKUtilities::FormatToVK(m_Format); #ifdef LUMOS_PLATFORM_MACOS - //Bug on macos with shadows having artifacts when using the VK_IMAGE_USAGE_SAMPLED_BIT flag - #ifndef LUMOS_PRODUCTION - VkImageUsageFlags usage; - if(((VKContext*)Graphics::Renderer::GetGraphicsContext())->ValidationEnabled()) - usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; - else - usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; - #else + // Bug on macos with shadows having artifacts when using the VK_IMAGE_USAGE_SAMPLED_BIT flag +#ifndef LUMOS_PRODUCTION + VkImageUsageFlags usage; + if(((VKContext*)Graphics::Renderer::GetGraphicsContext())->ValidationEnabled()) + usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + else + usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; +#else VkImageUsageFlags usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; - #endif +#endif #else VkImageUsageFlags usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; #endif @@ -1331,7 +1331,7 @@ namespace Lumos for(uint32_t i = 0; i < m_Count; i++) { - VkImageView imageView = CreateImageView(m_TextureImage, m_VKFormat, 1, VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_ASPECT_DEPTH_BIT, 1, i, 0); + VkImageView imageView = CreateImageView(m_TextureImage, m_VKFormat, 1, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT, 1, i, 0); m_IndividualImageViews.PushBack(imageView); } diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h index bf17ed97e..386379b49 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h @@ -24,8 +24,8 @@ namespace Lumos void DeleteResources(); - void Bind(uint32_t slot = 0) const override {}; - void Unbind(uint32_t slot = 0) const override {}; + void Bind(uint32_t slot = 0) const override { }; + void Unbind(uint32_t slot = 0) const override { }; void Load(uint32_t width, uint32_t height, void* data, TextureDesc parameters = TextureDesc(), TextureLoadOptions loadOptions = TextureLoadOptions()) override; virtual void SetData(const void* pixels) override; @@ -194,8 +194,8 @@ namespace Lumos void TransitionImage(VkImageLayout newLayout, VKCommandBuffer* commandBuffer); - void Bind(uint32_t slot = 0) const override {}; - void Unbind(uint32_t slot = 0) const override {}; + void Bind(uint32_t slot = 0) const override { }; + void Unbind(uint32_t slot = 0) const override { }; inline uint32_t GetSize() const override { @@ -344,8 +344,8 @@ namespace Lumos VKTextureDepth(uint32_t width, uint32_t height, RHIFormat format, uint8_t samples); ~VKTextureDepth(); - void Bind(uint32_t slot = 0) const override {}; - void Unbind(uint32_t slot = 0) const override {}; + void Bind(uint32_t slot = 0) const override { }; + void Unbind(uint32_t slot = 0) const override { }; void Resize(uint32_t width, uint32_t height) override; inline uint32_t GetWidth(uint32_t mip) const override @@ -458,8 +458,8 @@ namespace Lumos VKTextureDepthArray(uint32_t width, uint32_t height, uint32_t count, RHIFormat format); ~VKTextureDepthArray(); - void Bind(uint32_t slot = 0) const override {}; - void Unbind(uint32_t slot = 0) const override {}; + void Bind(uint32_t slot = 0) const override { }; + void Unbind(uint32_t slot = 0) const override { }; void Resize(uint32_t width, uint32_t height, uint32_t count) override; inline uint32_t GetWidth(uint32_t mip) const override diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp index 95c303b05..cb3fdfc61 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp @@ -24,11 +24,11 @@ namespace Lumos fpCmdBeginDebugUtilsLabelEXT = (PFN_vkCmdBeginDebugUtilsLabelEXT)(vkGetInstanceProcAddr(VKContext::GetVKInstance(), "vkCmdBeginDebugUtilsLabelEXT")); if(fpCmdBeginDebugUtilsLabelEXT == nullptr) - fpCmdBeginDebugUtilsLabelEXT = [](VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT* pLabelInfo) {}; + fpCmdBeginDebugUtilsLabelEXT = [](VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT* pLabelInfo) { }; fpCmdEndDebugUtilsLabelEXT = (PFN_vkCmdEndDebugUtilsLabelEXT)(vkGetInstanceProcAddr(VKContext::GetVKInstance(), "vkCmdEndDebugUtilsLabelEXT")); if(fpCmdEndDebugUtilsLabelEXT == nullptr) - fpCmdEndDebugUtilsLabelEXT = [](VkCommandBuffer commandBuffer) {}; + fpCmdEndDebugUtilsLabelEXT = [](VkCommandBuffer commandBuffer) { }; } uint32_t VKUtilities::FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp index 756af9d7f..6f503a717 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp @@ -41,7 +41,7 @@ namespace Lumos else LINFO("Power - Outlet"); - auto systemInfo = MemoryManager::Get()->GetSystemInfo(); + auto systemInfo = MemoryManager::Get().GetSystemInfo(); systemInfo.Log(); auto& app = Lumos::Application::Get(); diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp index 164a6efe5..8abc7649f 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp @@ -53,20 +53,10 @@ namespace Lumos #define HID_USAGE_GENERIC_KEYBOARD ((USHORT)0x06) #endif - WindowsWindow::WindowsWindow(const WindowDesc& properties) + WindowsWindow::WindowsWindow() : hWnd(nullptr) { - m_Init = false; - m_VSync = properties.VSync; - SetHasResized(true); - m_Data.m_RenderAPI = static_cast(properties.RenderAPI); - - m_Init = Init(properties); - m_GraphicsContext = SharedPtr(Graphics::GraphicsContext::Create()); - m_GraphicsContext->Init(); - - m_SwapChain = SharedPtr(Graphics::SwapChain::Create(m_Data.Width, m_Data.Height)); - m_SwapChain->Init(m_VSync, this); + m_Init = false; } WindowsWindow::~WindowsWindow() @@ -173,6 +163,10 @@ namespace Lumos bool WindowsWindow::Init(const WindowDesc& properties) { + m_VSync = properties.VSync; + SetHasResized(true); + m_Data.m_RenderAPI = static_cast(properties.RenderAPI); + m_Data.Title = (const char*)properties.Title.str; m_Data.Width = properties.Width; m_Data.Height = properties.Height; @@ -312,20 +306,20 @@ namespace Lumos if(properties.RenderAPI == RenderAPI::OpenGL) { HDC hDc = GetDC(static_cast(GetHandle())); - + HGLRC tempContext = wglCreateContext(hDc); wglMakeCurrent(hDc, tempContext); - + if(!wglMakeCurrent(hDc, tempContext)) { LERROR("Failed to initialise OpenGL context"); } - + if(!gladLoadWGL(hDc)) LERROR("glad failed to load WGL!"); if(!gladLoadGL()) LERROR("glad failed to load OpenGL!"); - + const int contextAttribsList[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4, @@ -342,7 +336,7 @@ namespace Lumos #endif 0, }; - + HGLRC hrc = wglCreateContextAttribsARB(hDc, nullptr, contextAttribsList); if(hrc == nullptr) { @@ -365,6 +359,14 @@ namespace Lumos rid.hwndTarget = hWnd; RegisterRawInputDevices(&rid, 1, sizeof(rid)); + m_GraphicsContext = SharedPtr(Graphics::GraphicsContext::Create()); + m_GraphicsContext->Init(); + + m_SwapChain = SharedPtr(Graphics::SwapChain::Create(m_Data.Width, m_Data.Height)); + m_SwapChain->Init(m_VSync, this); + + m_Init = true; + return true; } @@ -723,8 +725,8 @@ namespace Lumos CreateFunc = CreateFuncWindows; } - Window* WindowsWindow::CreateFuncWindows(const WindowDesc& properties) + Window* WindowsWindow::CreateFuncWindows() { - return new WindowsWindow(properties); + return new WindowsWindow(); } } diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.h b/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.h index cd0086f91..0ce1093ef 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.h +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.h @@ -14,23 +14,22 @@ namespace Lumos class LUMOS_EXPORT WindowsWindow : public Window { public: - WindowsWindow(const WindowDesc& properties); + WindowsWindow(); ~WindowsWindow(); + bool Init(const WindowDesc& properties) override; void ToggleVSync() override; void SetWindowTitle(const std::string& title) override; void SetBorderlessWindow(bool borderless) override; void OnUpdate() override; void ProcessInput() override; - void SetVSync(bool set) override {}; - void HideMouse(bool hide) override {}; - void SetMousePosition(const Vec2& pos) override {}; + void SetVSync(bool set) override { }; + void HideMouse(bool hide) override { }; + void SetMousePosition(const Vec2& pos) override { }; void UpdateCursorImGui() override; void SetIcon(const WindowDesc& desc) override; - bool Init(const WindowDesc& properties); - inline std::string GetTitle() const override { return m_Data.Title; @@ -90,7 +89,7 @@ namespace Lumos static void MakeDefault(); protected: - static Window* CreateFuncWindows(const WindowDesc& properties); + static Window* CreateFuncWindows(); HINSTANCE hInstance {}; HDC hDc {}; diff --git a/Lumos/Source/Lumos/Platform/iOS/iOSOS.h b/Lumos/Source/Lumos/Platform/iOS/iOSOS.h index 709421c7c..af83caa56 100644 --- a/Lumos/Source/Lumos/Platform/iOS/iOSOS.h +++ b/Lumos/Source/Lumos/Platform/iOS/iOSOS.h @@ -1,67 +1,67 @@ -#pragma once -#include "Precompiled.h" -#include "Core/OS/OS.h" - -namespace Lumos -{ - class iOSOS : public OS - { - public: - iOSOS(); - ~iOSOS(); - - void Init(); - void Run() override - { - } - std::string GetExecutablePath() override; - std::string GetAssetPath() override; - void Vibrate() const override; - - void* GetIOSView() const - { - return m_IOSView; - } - void SetIOSView(void* view) - { - m_IOSView = view; - } - - void ShowKeyboard(bool open); - bool HasWifiConnection(); - - void OnFrame(); - void OnQuit(); - void OnKeyPressed(char keycode, bool down); - void OnScreenPressed(uint32_t x, uint32_t y, uint32_t count, bool down); - void OnMouseMovedEvent(uint32_t xPos, uint32_t yPos); - void OnScreenResize(uint32_t width, uint32_t height); - - static void Alert(const char* message, const char* title); - - std::string GetModelName() const; - - void SetWindowSize(float x, float y) - { - m_X = x; - m_Y = y; - } - float GetWidth() - { - return m_X; - } - float GetHeight() - { - return m_Y; - } - - static iOSOS* Get() - { - return (iOSOS*)s_Instance; - } - - private: - void* m_IOSView; - float m_X, m_Y; - }; -} +#pragma once +#include "Precompiled.h" +#include "Core/OS/OS.h" + +namespace Lumos +{ + class iOSOS : public OS + { + public: + iOSOS(); + ~iOSOS(); + + void Init(); + void Run() override + { + } + std::string GetExecutablePath() override; + std::string GetAssetPath() override; + void Vibrate() const override; + + void* GetIOSView() const + { + return m_IOSView; + } + void SetIOSView(void* view) + { + m_IOSView = view; + } + + void ShowKeyboard(bool open); + bool HasWifiConnection(); + + void OnFrame(); + void OnQuit(); + void OnKeyPressed(char keycode, bool down); + void OnScreenPressed(uint32_t x, uint32_t y, uint32_t count, bool down); + void OnMouseMovedEvent(uint32_t xPos, uint32_t yPos); + void OnScreenResize(uint32_t width, uint32_t height); + + static void Alert(const char* message, const char* title); + + std::string GetModelName() const; + + void SetWindowSize(float x, float y) + { + m_X = x; + m_Y = y; + } + float GetWidth() + { + return m_X; + } + float GetHeight() + { + return m_Y; + } + + static iOSOS* Get() + { + return (iOSOS*)m_pInstance; + } + + private: + void* m_IOSView; + float m_X, m_Y; + }; +} diff --git a/Lumos/Source/Lumos/Platform/iOS/iOSOS.mm b/Lumos/Source/Lumos/Platform/iOS/iOSOS.mm index e17e0eae0..d3d78b4d4 100644 --- a/Lumos/Source/Lumos/Platform/iOS/iOSOS.mm +++ b/Lumos/Source/Lumos/Platform/iOS/iOSOS.mm @@ -72,7 +72,7 @@ void AudioInterruptionListenerCallback(void* user_data, UInt32 interruption_stat iOSWindow::MakeDefault(); - s_Instance = this; + OS::SetInstance(this); //TODO: Replace with non depricated functions AudioSessionInitialize(NULL, NULL, AudioInterruptionListenerCallback, NULL); diff --git a/Lumos/Source/Lumos/Platform/iOS/iOSWindow.h b/Lumos/Source/Lumos/Platform/iOS/iOSWindow.h index 958fcc3a0..9190e29f7 100644 --- a/Lumos/Source/Lumos/Platform/iOS/iOSWindow.h +++ b/Lumos/Source/Lumos/Platform/iOS/iOSWindow.h @@ -10,16 +10,15 @@ namespace Lumos class iOSWindow : public Window { public: - iOSWindow(const WindowDesc& properties); + iOSWindow(); ~iOSWindow(); + bool Init(const WindowDesc& properties) override; void ToggleVSync() override; void SetWindowTitle(const std::string& title) override; void SetBorderlessWindow(bool borderless) override; void OnUpdate() override; - bool Init(const WindowDesc& properties, const std::string& title); - void* GetHandle() override { return (void*)m_Handle; @@ -59,8 +58,8 @@ namespace Lumos m_Data.EventCallback = callback; }; - void SetIcon(const WindowDesc& desc) override {}; - void UpdateCursorImGui() override {}; + void SetIcon(const WindowDesc& desc) override { }; + void UpdateCursorImGui() override { }; void OnKeyEvent(Lumos::InputCode::Key key, bool down); void OnTouchEvent(uint32_t xPos, uint32_t yPos, uint32_t count, bool down); @@ -75,7 +74,7 @@ namespace Lumos static void MakeDefault(); protected: - static Window* CreateFunciOS(const WindowDesc& properties); + static Window* CreateFunciOS(); struct WindowData { diff --git a/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm b/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm index 3b5db19a8..8fc6ea614 100644 --- a/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm +++ b/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm @@ -16,63 +16,62 @@ iOSWindow::iOSWindow(const WindowDesc& properties) { m_Init = false; + } + + iOSWindow::~iOSWindow() + { + } + + + bool iOSWindow::Init(const WindowDesc& properties) + { auto prop = properties; - + auto iosOS = (iOSOS*)iOSOS::Instance(); - + prop.Width = (uint32_t)iosOS->GetWidth(); prop.Height = (uint32_t)iosOS->GetHeight(); - - m_Init = Init(prop, "title"); - + m_Handle = iosOS->GetIOSView(); - - m_GraphicsContext = SharedPtr(Graphics::GraphicsContext::Create()); - m_GraphicsContext->Init(); - - m_SwapChain = SharedPtr(Graphics::SwapChain::Create(m_Data.Width, m_Data.Height)); - m_SwapChain->Init(m_Data.VSync, (Window*)this); - - - } - - iOSWindow::~iOSWindow() - { - } - - - bool iOSWindow::Init(const WindowDesc& properties, const std::string& title) - { + LINFO("Creating window - Title : %s, Width : %i, Height : %i", (const char*)properties.Title.str, properties.Width, properties.Height); - + m_Data.Title = ToStdString(properties.Title); m_Data.Width = properties.Width; m_Data.Height = properties.Height; m_Data.Exit = false; - + + m_GraphicsContext = SharedPtr(Graphics::GraphicsContext::Create()); + m_GraphicsContext->Init(); + + m_SwapChain = SharedPtr(Graphics::SwapChain::Create(m_Data.Width, m_Data.Height)); + m_SwapChain->Init(m_Data.VSync, (Window*)this); + + m_Init = true; + return true; } - + void iOSWindow::SetWindowTitle(const std::string& title) { - + } - + void iOSWindow::ToggleVSync() { - + } - + void iOSWindow::OnUpdate() { - + } - + void iOSWindow::SetBorderlessWindow(bool borderless) { - + } - + void iOSWindow::ProcessInput() { for(auto& event : m_QueuedEvents) @@ -80,20 +79,20 @@ m_Data.EventCallback(*event); delete event; } - + m_QueuedEvents.Clear(); } - + void iOSWindow::MakeDefault() { CreateFunc = CreateFunciOS; } - - Window* iOSWindow::CreateFunciOS(const WindowDesc& properties) + + Window* iOSWindow::CreateFunciOS() { - return new iOSWindow(properties); + return new iOSWindow(); } - + void iOSWindow::OnKeyEvent(Lumos::InputCode::Key key, bool down) { if(down) @@ -107,13 +106,13 @@ m_QueuedEvents.PushBack(event); } } - + void iOSWindow::OnTouchEvent(uint32_t xPos, uint32_t yPos, uint32_t count, bool down) { MouseMovedEvent* event = new MouseMovedEvent((float)xPos, (float)yPos); m_QueuedEvents.PushBack(event); - - + + if(down) { MouseButtonPressedEvent* event2 = new MouseButtonPressedEvent((Lumos::InputCode::MouseKey)Lumos::iOSKeyCodes::iOSTouchToLumosMouseKey(count)); @@ -123,16 +122,16 @@ { MouseButtonReleasedEvent* event2 = new MouseButtonReleasedEvent((Lumos::InputCode::MouseKey)Lumos::iOSKeyCodes::iOSTouchToLumosMouseKey(count)); m_QueuedEvents.PushBack(event2); - + } } - + void iOSWindow::OnMouseMovedEvent(uint32_t xPos, uint32_t yPos) { MouseMovedEvent* event = new MouseMovedEvent(xPos, yPos); m_QueuedEvents.PushBack(event); } - + void iOSWindow::OnResizeEvent(uint32_t width, uint32_t height) { WindowResizeEvent* event = new WindowResizeEvent(width, height); diff --git a/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp b/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp index 41f6227c1..3f8092771 100644 --- a/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp @@ -45,12 +45,12 @@ namespace Lumos RigidBody3DComponent::RigidBody3DComponent(const RigidBody3DComponent& other) { - m_RigidBody = other.m_RigidBody; + m_RigidBody = other.m_RigidBody; m_OwnRigidBody = other.m_OwnRigidBody; - - //TODO: Create Separate Move constructor and change this to duplicate the rigidbody - //auto properties = other.m_RigidBody->Body->GetProperties(); - //m_RigidBody = CreateSharedPtr(properties); + + // TODO: Create Separate Move constructor and change this to duplicate the rigidbody + // auto properties = other.m_RigidBody->Body->GetProperties(); + // m_RigidBody = CreateSharedPtr(properties); } RigidBody3DComponent::~RigidBody3DComponent() diff --git a/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp b/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp index 9f7a9de81..889e4487a 100644 --- a/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp @@ -21,9 +21,6 @@ namespace Lumos void SoundComponent::Init() { - - // TODO Remove - Application::Get().GetSystem()->AddSoundNode(m_SoundNode.get()); } void SoundComponent::OnImGui() diff --git a/Lumos/Source/Lumos/Scene/Entity.cpp b/Lumos/Source/Lumos/Scene/Entity.cpp index 34b981971..2f066dcfe 100644 --- a/Lumos/Source/Lumos/Scene/Entity.cpp +++ b/Lumos/Source/Lumos/Scene/Entity.cpp @@ -40,7 +40,7 @@ namespace Lumos uint64_t Entity::GetID() { LUMOS_PROFILE_FUNCTION_LOW(); - return m_Scene->GetRegistry().get(m_EntityHandle).ID; + return m_Scene->GetRegistry().get_or_emplace(m_EntityHandle).ID; } const std::string& Entity::GetName() diff --git a/Lumos/Source/Lumos/Scene/Scene.cpp b/Lumos/Source/Lumos/Scene/Scene.cpp index 77f08f46b..2e9e5bd76 100644 --- a/Lumos/Source/Lumos/Scene/Scene.cpp +++ b/Lumos/Source/Lumos/Scene/Scene.cpp @@ -268,23 +268,10 @@ namespace Lumos void Scene::OnCleanupScene() { LUMOS_PROFILE_FUNCTION(); - DeleteAllGameObjects(); - + m_EntityManager->Clear(); LuaManager::Get().CollectGarbage(); - - auto audioManager = Application::Get().GetSystem(); - if(audioManager) - { - audioManager->ClearNodes(); - } }; - void Scene::DeleteAllGameObjects() - { - LUMOS_PROFILE_FUNCTION(); - m_EntityManager->Clear(); - } - void Scene::OnUpdate(const TimeStep& timeStep) { LUMOS_PROFILE_FUNCTION(); @@ -449,7 +436,7 @@ namespace Lumos input(*this); if(m_SceneSerialisationVersion == 0) LERROR("Invalid Scene Version"); - else if (m_SceneSerialisationVersion < MIN_SCENE_VERSION) + else if(m_SceneSerialisationVersion < MIN_SCENE_VERSION) LERROR("Invalid Scene Version - Version too low %d. Minimum version supported %d", m_SceneSerialisationVersion, MIN_SCENE_VERSION); #if MIN_SCENE_VERSION <= 2 else if(m_SceneSerialisationVersion < 2) @@ -546,7 +533,7 @@ namespace Lumos if(m_SceneSerialisationVersion == 0) LERROR("Invalid Scene Version - Invalid Scene Version"); - else if (m_SceneSerialisationVersion < MIN_SCENE_VERSION) + else if(m_SceneSerialisationVersion < MIN_SCENE_VERSION) LERROR("Invalid Scene Version - Version too low %d. Minimum version supported %d", m_SceneSerialisationVersion, MIN_SCENE_VERSION); #if MIN_SCENE_VERSION <= 2 else if(m_SceneSerialisationVersion < 2) diff --git a/Lumos/Source/Lumos/Scene/Scene.h b/Lumos/Source/Lumos/Scene/Scene.h index 43ecb1bb8..b5d427156 100644 --- a/Lumos/Source/Lumos/Scene/Scene.h +++ b/Lumos/Source/Lumos/Scene/Scene.h @@ -55,11 +55,8 @@ namespace Lumos // - Called once per frame and should contain all time-sensitive update logic // Note: This is time relative to seconds not milliseconds! (e.g. msec / 1000) virtual void OnUpdate(const TimeStep& timeStep); - virtual void OnImGui() {}; + virtual void OnImGui() { }; virtual void OnEvent(Event& e); - // Delete all contained Objects - // - This is the default action upon firing OnCleanupScene() - void DeleteAllGameObjects(); // The friendly name associated with this scene instance const std::string& GetSceneName() const diff --git a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h index e6397418e..55e8acc96 100644 --- a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h +++ b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h @@ -209,21 +209,21 @@ namespace Lumos static const int AssetRegistrySerialisationVersion = 2; template void save(Archive& archive, const AssetRegistry& registry) - { - std::vector> elems(registry.m_NameMap.begin(), registry.m_NameMap.end()); + { + std::vector> elems(registry.m_NameMap.begin(), registry.m_NameMap.end()); - elems.erase(std::remove_if(elems.begin(), elems.end(), [](std::pair& a) { - return StringUtilities::StringContains(a.first, std::string("Cache/")); - }), elems.end()); + elems.erase(std::remove_if(elems.begin(), elems.end(), [](std::pair& a) + { return StringUtilities::StringContains(a.first, std::string("Cache/")); }), + elems.end()); - std::sort(elems.begin(), elems.end(), [](std::pair& a, std::pair& b) - { return a.second < b.second; }); + std::sort(elems.begin(), elems.end(), [](std::pair& a, std::pair& b) + { return a.second < b.second; }); - archive(cereal::make_nvp("Version", AssetRegistrySerialisationVersion)); - archive(cereal::make_nvp("Count", (int)elems.size())); + archive(cereal::make_nvp("Version", AssetRegistrySerialisationVersion)); + archive(cereal::make_nvp("Count", (int)elems.size())); - for(auto& entry : elems) - archive(cereal::make_nvp("Name", entry.first), cereal::make_nvp("UUID", (uint64_t)entry.second), cereal::make_nvp("AssetType", registry.Contains(entry.second) ? (uint16_t)registry.Get(entry.second).Type : 0)); + for(auto& entry : elems) + archive(cereal::make_nvp("Name", entry.first), cereal::make_nvp("UUID", (uint64_t)entry.second), cereal::make_nvp("AssetType", registry.Contains(entry.second) ? (uint16_t)registry.Get(entry.second).Type : 0)); } template diff --git a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp index 09535e9de..867fb5567 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp +++ b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp @@ -770,124 +770,114 @@ namespace Lumos { // Enums lua.new_enum("WidgetFlags", - "Clickable", Lumos::WidgetFlags_Clickable, - "DrawText", Lumos::WidgetFlags_DrawText, - "DrawBorder", Lumos::WidgetFlags_DrawBorder, - "DrawBackground", Lumos::WidgetFlags_DrawBackground, - "Draggable", Lumos::WidgetFlags_Draggable, - "StackVertically", Lumos::WidgetFlags_StackVertically, - "StackHorizontally", Lumos::WidgetFlags_StackHorizontally, - "Floating_X", Lumos::WidgetFlags_Floating_X, - "Floating_Y", Lumos::WidgetFlags_Floating_Y, - "CentreX", Lumos::WidgetFlags_CentreX, - "CentreY", Lumos::WidgetFlags_CentreY - ); + "Clickable", Lumos::WidgetFlags_Clickable, + "DrawText", Lumos::WidgetFlags_DrawText, + "DrawBorder", Lumos::WidgetFlags_DrawBorder, + "DrawBackground", Lumos::WidgetFlags_DrawBackground, + "Draggable", Lumos::WidgetFlags_Draggable, + "StackVertically", Lumos::WidgetFlags_StackVertically, + "StackHorizontally", Lumos::WidgetFlags_StackHorizontally, + "Floating_X", Lumos::WidgetFlags_Floating_X, + "Floating_Y", Lumos::WidgetFlags_Floating_Y, + "CentreX", Lumos::WidgetFlags_CentreX, + "CentreY", Lumos::WidgetFlags_CentreY); lua.new_enum("UITextAlignment", - "None", Lumos::UI_Text_Alignment_None, - "Center_X", Lumos::UI_Text_Alignment_Center_X, - "Center_Y", Lumos::UI_Text_Alignment_Center_Y - ); + "None", Lumos::UI_Text_Alignment_None, + "Center_X", Lumos::UI_Text_Alignment_Center_X, + "Center_Y", Lumos::UI_Text_Alignment_Center_Y); lua.new_enum("SizeKind", - "Pixels", Lumos::SizeKind_Pixels, - "TextContent", Lumos::SizeKind_TextContent, - "PercentOfParent", Lumos::SizeKind_PercentOfParent, - "ChildSum", Lumos::SizeKind_ChildSum, - "MaxChild", Lumos::SizeKind_MaxChild - ); + "Pixels", Lumos::SizeKind_Pixels, + "TextContent", Lumos::SizeKind_TextContent, + "PercentOfParent", Lumos::SizeKind_PercentOfParent, + "ChildSum", Lumos::SizeKind_ChildSum, + "MaxChild", Lumos::SizeKind_MaxChild); lua.new_enum("UIAxis", - "X", Lumos::UIAxis_X, - "Y", Lumos::UIAxis_Y, - "Count", Lumos::UIAxis_Count - ); + "X", Lumos::UIAxis_X, + "Y", Lumos::UIAxis_Y, + "Count", Lumos::UIAxis_Count); lua.new_enum("StyleVar", - "Padding", Lumos::StyleVar_Padding, - "Border", Lumos::StyleVar_Border, - "BorderColor", Lumos::StyleVar_BorderColor, - "BackgroundColor", Lumos::StyleVar_BackgroundColor, - "TextColor", Lumos::StyleVar_TextColor, - "HotBorderColor", Lumos::StyleVar_HotBorderColor, - "HotBackgroundColor", Lumos::StyleVar_HotBackgroundColor, - "HotTextColor", Lumos::StyleVar_HotTextColor, - "ActiveBorderColor", Lumos::StyleVar_ActiveBorderColor, - "ActiveBackgroundColor", Lumos::StyleVar_ActiveBackgroundColor, - "ActiveTextColor", Lumos::StyleVar_ActiveTextColor, - "FontSize", Lumos::StyleVar_FontSize, - "Count", Lumos::StyleVar_Count - ); + "Padding", Lumos::StyleVar_Padding, + "Border", Lumos::StyleVar_Border, + "BorderColor", Lumos::StyleVar_BorderColor, + "BackgroundColor", Lumos::StyleVar_BackgroundColor, + "TextColor", Lumos::StyleVar_TextColor, + "HotBorderColor", Lumos::StyleVar_HotBorderColor, + "HotBackgroundColor", Lumos::StyleVar_HotBackgroundColor, + "HotTextColor", Lumos::StyleVar_HotTextColor, + "ActiveBorderColor", Lumos::StyleVar_ActiveBorderColor, + "ActiveBackgroundColor", Lumos::StyleVar_ActiveBackgroundColor, + "ActiveTextColor", Lumos::StyleVar_ActiveTextColor, + "FontSize", Lumos::StyleVar_FontSize, + "Count", Lumos::StyleVar_Count); // Structs lua.new_usertype("UI_Size", - sol::constructors(), - "kind", &Lumos::UI_Size::kind, - "value", &Lumos::UI_Size::value - ); + sol::constructors(), + "kind", &Lumos::UI_Size::kind, + "value", &Lumos::UI_Size::value); lua.new_usertype("UI_Widget", - "parent", &Lumos::UI_Widget::parent, - "first", &Lumos::UI_Widget::first, - "last", &Lumos::UI_Widget::last, - "next", &Lumos::UI_Widget::next, - "prev", &Lumos::UI_Widget::prev, - "style_vars", &Lumos::UI_Widget::style_vars, - "hash", &Lumos::UI_Widget::hash, - "flags", &Lumos::UI_Widget::flags, - "text", &Lumos::UI_Widget::text, - "texture", &Lumos::UI_Widget::texture, - "semantic_size", &Lumos::UI_Widget::semantic_size, - "LayoutingAxis", &Lumos::UI_Widget::LayoutingAxis, - "TextAlignment", &Lumos::UI_Widget::TextAlignment, - "cursor", &Lumos::UI_Widget::cursor, - "position", &Lumos::UI_Widget::position, - "relative_position", &Lumos::UI_Widget::relative_position, - "size", &Lumos::UI_Widget::size, - "clicked", &Lumos::UI_Widget::clicked, - "is_initial_dragging_position_set", &Lumos::UI_Widget::is_initial_dragging_position_set, - "dragging", &Lumos::UI_Widget::dragging, - "drag_constraint_x", &Lumos::UI_Widget::drag_constraint_x, - "drag_constraint_y", &Lumos::UI_Widget::drag_constraint_y, - "drag_offset", &Lumos::UI_Widget::drag_offset, - "drag_mouse_p", &Lumos::UI_Widget::drag_mouse_p, - "HotTransition", &Lumos::UI_Widget::HotTransition, - "ActiveTransition", &Lumos::UI_Widget::ActiveTransition, - "LastFrameIndexActive", &Lumos::UI_Widget::LastFrameIndexActive - ); + "parent", &Lumos::UI_Widget::parent, + "first", &Lumos::UI_Widget::first, + "last", &Lumos::UI_Widget::last, + "next", &Lumos::UI_Widget::next, + "prev", &Lumos::UI_Widget::prev, + "style_vars", &Lumos::UI_Widget::style_vars, + "hash", &Lumos::UI_Widget::hash, + "flags", &Lumos::UI_Widget::flags, + "text", &Lumos::UI_Widget::text, + "texture", &Lumos::UI_Widget::texture, + "semantic_size", &Lumos::UI_Widget::semantic_size, + "LayoutingAxis", &Lumos::UI_Widget::LayoutingAxis, + "TextAlignment", &Lumos::UI_Widget::TextAlignment, + "cursor", &Lumos::UI_Widget::cursor, + "position", &Lumos::UI_Widget::position, + "relative_position", &Lumos::UI_Widget::relative_position, + "size", &Lumos::UI_Widget::size, + "clicked", &Lumos::UI_Widget::clicked, + "is_initial_dragging_position_set", &Lumos::UI_Widget::is_initial_dragging_position_set, + "dragging", &Lumos::UI_Widget::dragging, + "drag_constraint_x", &Lumos::UI_Widget::drag_constraint_x, + "drag_constraint_y", &Lumos::UI_Widget::drag_constraint_y, + "drag_offset", &Lumos::UI_Widget::drag_offset, + "drag_mouse_p", &Lumos::UI_Widget::drag_mouse_p, + "HotTransition", &Lumos::UI_Widget::HotTransition, + "ActiveTransition", &Lumos::UI_Widget::ActiveTransition, + "LastFrameIndexActive", &Lumos::UI_Widget::LastFrameIndexActive); lua.new_usertype("UI_Interaction", - "widget", &Lumos::UI_Interaction::widget, - "hovering", &Lumos::UI_Interaction::hovering, - "clicked", &Lumos::UI_Interaction::clicked, - "dragging", &Lumos::UI_Interaction::dragging - ); + "widget", &Lumos::UI_Interaction::widget, + "hovering", &Lumos::UI_Interaction::hovering, + "clicked", &Lumos::UI_Interaction::clicked, + "dragging", &Lumos::UI_Interaction::dragging); // Functions - lua["GetUIState"] = &Lumos::GetUIState; + lua["GetUIState"] = &Lumos::GetUIState; lua["GetStringSize"] = &Lumos::GetStringSize; - lua["InitialiseUI"] = &Lumos::InitialiseUI; - lua["ShutDownUI"] = &Lumos::ShutDownUI; - lua["UIBeginFrame"] = &Lumos::UIBeginFrame; - lua["UIEndFrame"] = &Lumos::UIEndFrame; - lua["UIBeginPanel"] = sol::overload( - static_cast(&Lumos::UIBeginPanel), - static_cast(&Lumos::UIBeginPanel) - ); - lua["UIEndPanel"] = &Lumos::UIEndPanel; + lua["InitialiseUI"] = &Lumos::InitialiseUI; + lua["ShutDownUI"] = &Lumos::ShutDownUI; + lua["UIBeginFrame"] = &Lumos::UIBeginFrame; + lua["UIEndFrame"] = &Lumos::UIEndFrame; + lua["UIBeginPanel"] = sol::overload( + static_cast(&Lumos::UIBeginPanel), + static_cast(&Lumos::UIBeginPanel)); + lua["UIEndPanel"] = &Lumos::UIEndPanel; lua["UIPushStyle"] = sol::overload( - static_cast(&Lumos::UIPushStyle), - static_cast(&Lumos::UIPushStyle), - static_cast(&Lumos::UIPushStyle), - static_cast(&Lumos::UIPushStyle) - ); - - lua["UIPopStyle"] = &Lumos::UIPopStyle; - lua["UILabel"] = &Lumos::UILabel; - lua["UIButton"] = &Lumos::UIButton; - lua["UIImage"] = &Lumos::UIImage; - lua["UISlider"] = &Lumos::UISlider; - lua["UIToggle"] = &Lumos::UIToggle; + static_cast(&Lumos::UIPushStyle), + static_cast(&Lumos::UIPushStyle), + static_cast(&Lumos::UIPushStyle), + static_cast(&Lumos::UIPushStyle)); + + lua["UIPopStyle"] = &Lumos::UIPopStyle; + lua["UILabel"] = &Lumos::UILabel; + lua["UIButton"] = &Lumos::UIButton; + lua["UIImage"] = &Lumos::UIImage; + lua["UISlider"] = &Lumos::UISlider; + lua["UIToggle"] = &Lumos::UIToggle; lua["UILayoutRoot"] = &Lumos::UILayoutRoot; } diff --git a/Lumos/Source/Lumos/Utilities/TSingleton.h b/Lumos/Source/Lumos/Utilities/TSingleton.h index 33658c608..8bed215d0 100644 --- a/Lumos/Source/Lumos/Utilities/TSingleton.h +++ b/Lumos/Source/Lumos/Utilities/TSingleton.h @@ -19,6 +19,12 @@ namespace Lumos return *m_pInstance; } + static void SetInstance(T* instance) + { + Release(); + m_pInstance = instance; + } + // Provide global access to release/delete this class static void Release() { @@ -44,6 +50,48 @@ namespace Lumos template T* TSingleton::m_pInstance = nullptr; + template + class TSingletonAbstract + { + public: + // Provide global access to the only instance of this class + static T& Get() + { + ASSERT(m_pInstance != nullptr, "Singleton hasn't been Created"); + return *m_pInstance; + } + + static void SetInstance(T* instance) + { + Release(); + m_pInstance = instance; + } + + // Provide global access to release/delete this class + static void Release() + { + if(m_pInstance) + { + delete m_pInstance; + m_pInstance = nullptr; + } + } + + protected: + // Only allow the class to be created and destroyed by itself + TSingletonAbstract() { } + ~TSingletonAbstract() { } + + static T* m_pInstance; + + private: + NONCOPYABLE(TSingletonAbstract); + }; + + // Finally make sure that the instance is initialised to NULL at the start of the program + template + T* TSingletonAbstract::m_pInstance = nullptr; + template class TSingletonInit { @@ -72,6 +120,12 @@ namespace Lumos } } + static void SetInstance(T* instance) + { + Release(); + m_pInstance = instance; + } + protected: // Only allow the class to be created and destroyed by itself TSingletonInit() { } @@ -116,6 +170,12 @@ namespace Lumos } } + static void SetInstance(T* instance) + { + Release(); + m_pInstance = instance; + } + protected: // Only allow the class to be created and destroyed by itself ThreadSafeSingleton() { } diff --git a/Runtime/Runtime.cpp b/Runtime/Runtime.cpp index 3ce74b00e..243eb15a2 100644 --- a/Runtime/Runtime.cpp +++ b/Runtime/Runtime.cpp @@ -23,6 +23,7 @@ class Runtime : public Application explicit Runtime() : Application() { + Application::SetInstance(this); } ~Runtime() @@ -46,13 +47,13 @@ class Runtime : public Application void Init() override { TDArray projectLocations = { - OS::Instance()->GetExecutablePath() + "../../../../../ExampleProject/", + OS::Get().GetExecutablePath() + "../../../../../ExampleProject/", "/Users/jmorton/dev/Lumos/ExampleProject/Example.lmproj", "ExampleProject/Example.lmproj", "../ExampleProject/Example.lmproj", - OS::Instance()->GetExecutablePath() + "/ExampleProject/Example.lmproj", - OS::Instance()->GetExecutablePath() + "/../ExampleProject/Example.lmproj", - OS::Instance()->GetExecutablePath() + "/../../ExampleProject/Example.lmproj" + OS::Get().GetExecutablePath() + "/ExampleProject/Example.lmproj", + OS::Get().GetExecutablePath() + "/../ExampleProject/Example.lmproj", + OS::Get().GetExecutablePath() + "/../../ExampleProject/Example.lmproj" }; bool fileFound = false;