diff --git a/Editor/Source/ApplicationInfoPanel.cpp b/Editor/Source/ApplicationInfoPanel.cpp index 695ef3516..a5fe1359c 100644 --- a/Editor/Source/ApplicationInfoPanel.cpp +++ b/Editor/Source/ApplicationInfoPanel.cpp @@ -3,13 +3,13 @@ #include #include #include -#include +#include #include "Editor.h" #include #include -#include +#include #include #include #include @@ -141,10 +141,10 @@ namespace Lumos ImGui::TreePop(); } - auto RenderPasses = Application::Get().GetRenderPasses(); - if(ImGui::TreeNode("RenderPasses")) + auto SceneRenderer = Application::Get().GetSceneRenderer(); + if(ImGui::TreeNode("SceneRenderer")) { - RenderPasses->OnImGui(); + SceneRenderer->OnImGui(); ImGui::TreePop(); } @@ -169,7 +169,7 @@ namespace Lumos ImGui::Text("Num Rendered Objects %u", Engine::Get().Statistics().NumRenderedObjects); ImGui::Text("Num Shadow Objects %u", Engine::Get().Statistics().NumShadowObjects); ImGui::Text("Bound Pipelines %u", Engine::Get().Statistics().BoundPipelines); - ImGui::Text("Bound RenderPasses %u", Engine::Get().Statistics().BoundRenderPasses); + ImGui::Text("Bound SceneRenderer %u", Engine::Get().Statistics().BoundSceneRenderer); if(ImGui::TreeNodeEx("Arenas", 0)) { uint64_t totalAllocated = 0; diff --git a/Editor/Source/AssetManagerPanel.cpp b/Editor/Source/AssetManagerPanel.cpp index 9ff63b274..a368ce2b1 100644 --- a/Editor/Source/AssetManagerPanel.cpp +++ b/Editor/Source/AssetManagerPanel.cpp @@ -3,13 +3,14 @@ #include #include #include -#include +#include +#include #include "Editor.h" #include #include -#include +#include #include #include #include @@ -49,7 +50,7 @@ namespace Lumos ImGui::TableHeadersRow(); ImGui::TableNextRow(); - Lumos::AssetRegistry& registry = m_Editor->GetAssetManager()->GetAssetRegistry(); + Lumos::AssetRegistry& registry = *m_Editor->GetAssetManager()->GetAssetRegistry(); auto DrawEntry = [®istry](AssetMetaData& metaData, uint64_t ID) { diff --git a/Editor/Source/ConsolePanel.cpp b/Editor/Source/ConsolePanel.cpp index c021e77ef..8a0bfaa6e 100644 --- a/Editor/Source/ConsolePanel.cpp +++ b/Editor/Source/ConsolePanel.cpp @@ -255,8 +255,8 @@ namespace Lumos { auto& msg = m_MessageBuffer[i]; - if(Filter.IsActive() && !Filter.PassFilter(msg.m_Message.c_str())) - continue; + if(Filter.IsActive() && !Filter.PassFilter(msg.m_Message.c_str())) + continue; DrawMessage(&msg); } diff --git a/Editor/Source/Editor.cpp b/Editor/Source/Editor.cpp index 3905a31bc..c6708ca84 100644 --- a/Editor/Source/Editor.cpp +++ b/Editor/Source/Editor.cpp @@ -13,8 +13,11 @@ #include "SceneSettingsPanel.h" #include "EditorSettingsPanel.h" #include "ProjectSettingsPanel.h" +#include "FileBrowserPanel.h" +#include "PreviewDraw.h" +#include "EditorPanel.h" -#include +#include #include #include #include @@ -47,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -104,7 +109,9 @@ namespace Lumos m_GridRenderer.reset(); m_Panels.clear(); - m_PreviewDraw.ReleaseResources(); + m_PreviewDraw->ReleaseResources(); + delete m_PreviewDraw; + delete m_FileBrowserPanel; Application::OnQuit(); } @@ -303,6 +310,9 @@ namespace Lumos for(auto& panel : m_Panels) panel->SetEditor(this); + m_FileBrowserPanel = new FileBrowserPanel(); + m_PreviewDraw = new PreviewDraw(); + CreateGridRenderer(); m_Settings.m_ShowImGuiDemo = false; @@ -320,7 +330,8 @@ namespace Lumos ImGuizmo::SetGizmoSizeClipSpace(m_Settings.m_ImGuizmoScale); // ImGuizmo::SetGizmoSizeScale(Application::Get().GetWindowDPI()); - m_PreviewDraw.CreateDefaultScene(); + m_PreviewDraw->CreateDefaultScene(); + } bool Editor::IsTextFile(const std::string& filePath) @@ -441,7 +452,7 @@ namespace Lumos m_Settings.m_View2D = m_CurrentCamera->IsOrthographic(); - m_FileBrowserPanel.OnImGui(); + m_FileBrowserPanel->OnImGui(); auto& io = ImGui::GetIO(); auto ctrl = io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl; if(ctrl && Input::Get().GetKeyPressed(Lumos::InputCode::Key::P)) @@ -511,14 +522,14 @@ namespace Lumos // Set filePath to working directory auto path = OS::Instance()->GetExecutablePath(); std::filesystem::current_path(path); - m_FileBrowserPanel.SetCallback(BIND_FILEBROWSER_FN(Editor::FileOpenCallback)); - m_FileBrowserPanel.Open(); + m_FileBrowserPanel->SetCallback(BIND_FILEBROWSER_FN(Editor::FileOpenCallback)); + m_FileBrowserPanel->Open(); } void Editor::EmbedFile() { - m_FileBrowserPanel.SetCallback(BIND_FILEBROWSER_FN(Editor::FileEmbedCallback)); - m_FileBrowserPanel.Open(); + m_FileBrowserPanel->SetCallback(BIND_FILEBROWSER_FN(Editor::FileEmbedCallback)); + m_FileBrowserPanel->Open(); } static std::string projectLocation = "../"; @@ -573,9 +584,9 @@ namespace Lumos if(ImGui::MenuItem("Open File")) { - m_FileBrowserPanel.SetCurrentPath(m_ProjectSettings.m_ProjectRoot); - m_FileBrowserPanel.SetCallback(BIND_FILEBROWSER_FN(Editor::FileOpenCallback)); - m_FileBrowserPanel.Open(); + m_FileBrowserPanel->SetCurrentPath(m_ProjectSettings.m_ProjectRoot); + m_FileBrowserPanel->SetCallback(BIND_FILEBROWSER_FN(Editor::FileOpenCallback)); + m_FileBrowserPanel->Open(); } ImGui::Separator(); @@ -1092,7 +1103,7 @@ namespace Lumos if(ImGui::Button("OK", ImVec2(120, 0))) { Application::Get().GetSceneManager()->GetCurrentScene()->Serialise(m_ProjectSettings.m_ProjectRoot + "Assets/Scenes/", false); - Graphics::Renderer::GetRenderer()->SaveScreenshot(m_ProjectSettings.m_ProjectRoot + "Assets/Scenes/Cache/" + Application::Get().GetSceneManager()->GetCurrentScene()->GetSceneName() + ".png", m_RenderPasses->GetForwardData().m_RenderTexture); + Graphics::Renderer::GetRenderer()->SaveScreenshot(m_ProjectSettings.m_ProjectRoot + "Assets/Scenes/Cache/" + Application::Get().GetSceneManager()->GetCurrentScene()->GetSceneName() + ".png", m_SceneRenderer->GetForwardData().m_RenderTexture); ImGui::CloseCurrentPopup(); } ImGui::SetItemDefaultFocus(); @@ -1107,7 +1118,7 @@ namespace Lumos if(locationPopupOpened) { // Cancel clicked on project location popups - if(!m_FileBrowserPanel.IsOpen()) + if(!m_FileBrowserPanel->IsOpen()) { m_NewProjectPopupOpen = false; locationPopupOpened = false; @@ -1211,12 +1222,12 @@ namespace Lumos // Set filePath to working directory const auto& path = OS::Instance()->GetExecutablePath(); - auto& browserPath = m_FileBrowserPanel.GetPath(); + auto& browserPath = m_FileBrowserPanel->GetPath(); browserPath = std::filesystem::path(path); - m_FileBrowserPanel.SetFileTypeFilters({ ".lmproj" }); - m_FileBrowserPanel.SetOpenDirectory(false); - m_FileBrowserPanel.SetCallback(BIND_FILEBROWSER_FN(ProjectOpenCallback)); - m_FileBrowserPanel.Open(); + m_FileBrowserPanel->SetFileTypeFilters({ ".lmproj" }); + m_FileBrowserPanel->SetOpenDirectory(false); + m_FileBrowserPanel->SetCallback(BIND_FILEBROWSER_FN(ProjectOpenCallback)); + m_FileBrowserPanel->Open(); } ImGui::Separator(); @@ -1234,12 +1245,12 @@ namespace Lumos // Set filePath to working directory const auto& path = OS::Instance()->GetExecutablePath(); - auto& browserPath = m_FileBrowserPanel.GetPath(); + auto& browserPath = m_FileBrowserPanel->GetPath(); browserPath = std::filesystem::path(path); - m_FileBrowserPanel.ClearFileTypeFilters(); - m_FileBrowserPanel.SetOpenDirectory(true); - m_FileBrowserPanel.SetCallback(BIND_FILEBROWSER_FN(NewProjectLocationCallback)); - m_FileBrowserPanel.Open(); + m_FileBrowserPanel->ClearFileTypeFilters(); + m_FileBrowserPanel->SetOpenDirectory(true); + m_FileBrowserPanel->SetCallback(BIND_FILEBROWSER_FN(NewProjectLocationCallback)); + m_FileBrowserPanel->Open(); } ImGui::SameLine(); @@ -1251,7 +1262,7 @@ namespace Lumos if(ImGui::Button("Create", ImVec2(120, 0))) { Application::Get().OpenNewProject(projectLocation, newProjectName); - m_FileBrowserPanel.SetOpenDirectory(false); + m_FileBrowserPanel->SetOpenDirectory(false); for(int i = 0; i < int(m_Panels.size()); i++) { @@ -1327,7 +1338,7 @@ namespace Lumos if(m_SelectedEntities.size() == 1) { - Entity m_SelectedEntity = {}; + Entity m_SelectedEntity = {}; m_SelectedEntity = m_SelectedEntities.front(); if(m_SelectedEntity.Valid()) @@ -1737,7 +1748,6 @@ namespace Lumos std::string Configuration; std::string Platform; std::string RenderAPI; - std::string dash = " - "; #ifdef LUMOS_DEBUG Configuration = "Debug"; @@ -1786,10 +1796,10 @@ namespace Lumos break; } - std::stringstream Title; - Title << Platform << dash << RenderAPI << dash << Configuration << dash << scene->GetSceneName() << dash << Application::Get().GetWindow()->GetTitle(); - - Application::Get().GetWindow()->SetWindowTitle(Title.str()); + // std::stringstream Title; + // Title << Platform << dash << RenderAPI << dash << Configuration << dash << scene->GetSceneName() << dash << Application::Get().GetWindow()->GetTitle(); + String8 title = PushStr8F(m_Arena, "%s - %s - %s - %s - %s", Platform.c_str(), RenderAPI.c_str(), Configuration.c_str(), scene->GetSceneName().c_str(), Application::Get().GetWindow()->GetTitle().c_str()); + Application::Get().GetWindow()->SetWindowTitle((const char*)(title.str)); } void Editor::Draw3DGrid() @@ -1807,7 +1817,7 @@ namespace Lumos m_GridRenderer->OnImGui(); - m_GridRenderer->SetDepthTarget(m_RenderPasses->GetForwardData().m_DepthTexture); + m_GridRenderer->SetDepthTarget(m_SceneRenderer->GetForwardData().m_DepthTexture); m_GridRenderer->BeginScene(Application::Get().GetSceneManager()->GetCurrentScene(), m_EditorCamera.get(), &m_EditorCameraTransform); m_GridRenderer->RenderScene(); #endif @@ -2425,10 +2435,10 @@ namespace Lumos void Editor::SelectObject(const Maths::Ray& ray, bool hoveredOnly) { LUMOS_PROFILE_FUNCTION(); - auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); - auto& registry = scene->GetRegistry(); - float closestEntityDist = Maths::M_INFINITY; - Entity currentClosestEntity = {}; + auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); + auto& registry = scene->GetRegistry(); + float closestEntityDist = Maths::M_INFINITY; + Entity currentClosestEntity = {}; auto group = registry.group(entt::get); @@ -2456,7 +2466,7 @@ namespace Lumos if(distance < closestEntityDist) { closestEntityDist = distance; - currentClosestEntity = { entity, scene }; + currentClosestEntity = { entity, scene }; } } } @@ -2510,7 +2520,7 @@ namespace Lumos if(distance < closestEntityDist) { closestEntityDist = distance; - currentClosestEntity = { entity, scene }; + currentClosestEntity = { entity, scene }; } } } @@ -2531,7 +2541,7 @@ namespace Lumos if(distance < closestEntityDist) { closestEntityDist = distance; - currentClosestEntity = { entity, scene }; + currentClosestEntity = { entity, scene }; } } } @@ -2643,8 +2653,8 @@ namespace Lumos if(m_DrawPreview) { - m_PreviewDraw.Draw(); - m_PreviewDraw.DeletePreviewModel(); + m_PreviewDraw->Draw(); + m_PreviewDraw->DeletePreviewModel(); m_DrawPreview = false; } @@ -2655,7 +2665,7 @@ namespace Lumos String8 assetCachePath = StringUtilities::AbsolutePathToRelativeFileSystemPath(m_FrameArena, texturePath, basePath, Str8Lit("//Assets/Cache")); String8 cacheAbsolutePath = StringUtilities::AbsolutePathToRelativeFileSystemPath(m_FrameArena, assetCachePath, Str8Lit("//Assets"), basePath); - m_PreviewDraw.SaveTexture(cacheAbsolutePath); + m_PreviewDraw->SaveTexture(cacheAbsolutePath); m_SavePreviewTexture = false; } @@ -2703,12 +2713,12 @@ namespace Lumos String8 extension = StringUtilities::Str8PathSkipLastPeriod(asset); if(strcmp((char*)extension.str, "lmat") == 0) { - m_PreviewDraw.LoadMaterial(asset); + m_PreviewDraw->LoadMaterial(asset); } else { // Assume mesh - m_PreviewDraw.LoadMesh(asset); + m_PreviewDraw->LoadMesh(asset); } m_DrawPreview = true; @@ -2793,7 +2803,7 @@ namespace Lumos m_NewProjectPopupOpen = false; reopenNewProjectPopup = false; locationPopupOpened = false; - m_FileBrowserPanel.ClearFileTypeFilters(); + m_FileBrowserPanel->ClearFileTypeFilters(); if(FileSystem::FileExists(filePath)) { @@ -2813,7 +2823,7 @@ namespace Lumos void Editor::NewProjectOpenCallback(const std::string& filePath) { Application::Get().OpenNewProject(filePath); - m_FileBrowserPanel.SetOpenDirectory(false); + m_FileBrowserPanel->SetOpenDirectory(false); for(int i = 0; i < int(m_Panels.size()); i++) { @@ -2956,7 +2966,7 @@ namespace Lumos SharedPtr Editor::GetPreviewTexture() const { - return m_PreviewDraw.m_PreviewTexture; + return m_PreviewDraw->m_PreviewTexture; } const char* Editor::GetIconFontIcon(const std::string& filePath) diff --git a/Editor/Source/Editor.h b/Editor/Source/Editor.h index 1bafe90b0..a4c2848a0 100644 --- a/Editor/Source/Editor.h +++ b/Editor/Source/Editor.h @@ -1,13 +1,8 @@ #pragma once -#include "EditorPanel.h" -#include "FileBrowserPanel.h" -#include "PreviewDraw.h" - #include #include #include -#include #include #include #include @@ -25,7 +20,11 @@ namespace Lumos class WindowResizeEvent; class WindowFileEvent; class TimeStep; - class Entity; + class Entity; + class FileBrowserPanel; + class PreviewDraw; + class EditorPanel; + class Camera; namespace Graphics { @@ -33,13 +32,13 @@ namespace Lumos class GridRenderer; class Mesh; class Environment; - class RenderPasses; + class SceneRenderer; } - namespace Maths - { - class Ray; - } + namespace Maths + { + class Ray; + } enum EditorDebugFlags : uint32_t { @@ -217,7 +216,7 @@ namespace Lumos FileBrowserPanel& GetFileBrowserPanel() { - return m_FileBrowserPanel; + return *m_FileBrowserPanel; } void AddDefaultEditorSettings(); @@ -312,7 +311,9 @@ namespace Lumos std::unordered_map m_ComponentIconMap; - FileBrowserPanel m_FileBrowserPanel; + FileBrowserPanel* m_FileBrowserPanel; + PreviewDraw* m_PreviewDraw; + Camera* m_CurrentCamera = nullptr; EditorCameraController m_EditorCameraController; Maths::Transform m_EditorCameraTransform; @@ -331,7 +332,6 @@ namespace Lumos String8 m_RequestedThumbnailPath; IniFile m_IniFile; - PreviewDraw m_PreviewDraw; static Editor* s_Editor; }; diff --git a/Editor/Source/EditorSettingsPanel.cpp b/Editor/Source/EditorSettingsPanel.cpp index 7ef2c062e..06adf7bb7 100644 --- a/Editor/Source/EditorSettingsPanel.cpp +++ b/Editor/Source/EditorSettingsPanel.cpp @@ -1,5 +1,6 @@ #include "EditorSettingsPanel.h" #include "Editor.h" +#include "FileBrowserPanel.h" #include #include #include diff --git a/Editor/Source/GameViewPanel.cpp b/Editor/Source/GameViewPanel.cpp index c4d25ca2e..4170c4a61 100644 --- a/Editor/Source/GameViewPanel.cpp +++ b/Editor/Source/GameViewPanel.cpp @@ -6,10 +6,11 @@ #include #include #include -#include +#include #include #include #include +#include #include #include @@ -27,8 +28,8 @@ namespace Lumos m_Width = 800; m_Height = 600; - m_RenderPasses = CreateUniquePtr(m_Width, m_Height); - m_RenderPasses->m_DebugRenderEnabled = false; + m_SceneRenderer = CreateUniquePtr(m_Width, m_Height); + m_SceneRenderer->m_DebugRenderEnabled = false; } static std::string AspectToString(float aspect) @@ -107,7 +108,7 @@ namespace Lumos Maths::Transform* transform = nullptr; { - m_RenderPasses->SetOverrideCamera(nullptr, nullptr); + m_SceneRenderer->SetOverrideCamera(nullptr, nullptr); auto& registry = m_CurrentScene->GetRegistry(); auto cameraView = registry.view(); @@ -207,17 +208,17 @@ namespace Lumos { ImGuiIO& io = ImGui::GetIO(); - static Engine::Stats stats = Engine::Get().Statistics(); - static Graphics::RenderPassesStats RenderPassesStats = m_RenderPasses->GetRenderPassesStats(); + static Engine::Stats stats = Engine::Get().Statistics(); + static Graphics::SceneRendererStats SceneRendererStats = m_SceneRenderer->GetSceneRendererStats(); static float timer = 1.0f; timer += io.DeltaTime; if(timer > 1.0f) { - timer = 0.0f; - stats = Engine::Get().Statistics(); - RenderPassesStats = m_RenderPasses->GetRenderPassesStats(); + timer = 0.0f; + stats = Engine::Get().Statistics(); + SceneRendererStats = m_SceneRenderer->GetSceneRendererStats(); } ImGui::Text("%.2f ms (%i FPS)", stats.FrameTime, stats.FramesPerSecond); @@ -228,9 +229,9 @@ namespace Lumos else ImGui::TextUnformatted("Mouse Position: "); - ImGui::Text("Num Rendered Objects %u", RenderPassesStats.NumRenderedObjects); - ImGui::Text("Num Shadow Objects %u", RenderPassesStats.NumShadowObjects); - ImGui::Text("Num Draw Calls %u", RenderPassesStats.NumDrawCalls); + ImGui::Text("Num Rendered Objects %u", SceneRendererStats.NumRenderedObjects); + ImGui::Text("Num Shadow Objects %u", SceneRendererStats.NumShadowObjects); + ImGui::Text("Num Draw Calls %u", SceneRendererStats.NumDrawCalls); ImGui::Text("Used GPU Memory : %.1f mb | Total : %.1f mb", stats.UsedGPUMemory * 0.000001f, stats.TotalGPUMemory * 0.000001f); if(ImGui::BeginPopupContextWindow()) @@ -261,10 +262,10 @@ namespace Lumos LUMOS_PROFILE_FUNCTION(); m_CurrentScene = scene; - // m_RenderPasses - m_RenderPasses->OnNewScene(scene); - m_RenderPasses->SetRenderTarget(m_GameViewTexture.get(), true); - m_RenderPasses->SetOverrideCamera(nullptr, nullptr); + // m_SceneRenderer + m_SceneRenderer->OnNewScene(scene); + m_SceneRenderer->SetRenderTarget(m_GameViewTexture.get(), true); + m_SceneRenderer->SetOverrideCamera(nullptr, nullptr); } void GameViewPanel::Resize(uint32_t width, uint32_t height) @@ -294,8 +295,8 @@ namespace Lumos if(resize) { m_GameViewTexture->Resize(m_Width, m_Height); - m_RenderPasses->SetRenderTarget(m_GameViewTexture.get(), true, false); - m_RenderPasses->OnResize(width, height); + m_SceneRenderer->SetRenderTarget(m_GameViewTexture.get(), true, false); + m_SceneRenderer->OnResize(width, height); } } @@ -303,8 +304,8 @@ namespace Lumos { if(m_GameViewVisible && m_Active) { - m_RenderPasses->BeginScene(m_CurrentScene); - m_RenderPasses->OnRender(); + m_SceneRenderer->BeginScene(m_CurrentScene); + m_SceneRenderer->OnRender(); } } diff --git a/Editor/Source/GameViewPanel.h b/Editor/Source/GameViewPanel.h index ad37710bf..526ff1ed5 100644 --- a/Editor/Source/GameViewPanel.h +++ b/Editor/Source/GameViewPanel.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include namespace Lumos @@ -29,7 +29,7 @@ namespace Lumos SharedPtr m_GameViewTexture = nullptr; Scene* m_CurrentScene = nullptr; uint32_t m_Width, m_Height; - UniquePtr m_RenderPasses; + UniquePtr m_SceneRenderer; bool m_GameViewVisible = false; bool m_ShowStats = false; }; diff --git a/Editor/Source/HierarchyPanel.cpp b/Editor/Source/HierarchyPanel.cpp index 5e715de2a..24174039d 100644 --- a/Editor/Source/HierarchyPanel.cpp +++ b/Editor/Source/HierarchyPanel.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -32,19 +33,19 @@ namespace Lumos { - ImGuiTextFilter m_HierarchyFilter; - Entity m_DoubleClicked; - Entity m_HadRecentDroppedEntity; - Entity m_CurrentPrevious; - + ImGuiTextFilter m_HierarchyFilter; + Entity m_DoubleClicked; + Entity m_HadRecentDroppedEntity; + Entity m_CurrentPrevious; + HierarchyPanel::HierarchyPanel() { m_Name = ICON_MDI_FILE_TREE " Hierarchy###hierarchy"; m_SimpleName = "Hierarchy"; m_StringArena = ArenaAlloc(Kilobytes(32)); - m_HadRecentDroppedEntity = {}; - m_DoubleClicked = {}; + m_HadRecentDroppedEntity = {}; + m_DoubleClicked = {}; } HierarchyPanel::~HierarchyPanel() @@ -62,7 +63,7 @@ namespace Lumos Entity nodeEntity = { node, Application::Get().GetSceneManager()->GetCurrentScene() }; - String8 name = PushStr8Copy(m_StringArena, node.GetName().c_str()); // StringUtilities::ToString(entt::to_integral(node)); + String8 name = PushStr8Copy(m_StringArena, node.GetName().c_str()); // StringUtilities::ToString(entt::to_integral(node)); if(m_HierarchyFilter.IsActive()) { @@ -110,7 +111,7 @@ namespace Lumos if(m_HadRecentDroppedEntity == node) { ImGui::SetNextItemOpen(true); - m_HadRecentDroppedEntity = { }; + m_HadRecentDroppedEntity = {}; } String8 icon = Str8C((char*)ICON_MDI_CUBE_OUTLINE); @@ -200,7 +201,7 @@ namespace Lumos m_Editor->UnSelect(node); } else if(m_DoubleClicked == node && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsItemHovered(ImGuiHoveredFlags_None)) - m_DoubleClicked = {}; + m_DoubleClicked = {}; } if(ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered(ImGuiHoveredFlags_None)) @@ -347,9 +348,8 @@ namespace Lumos ImGui::EndPopup(); } - auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); - auto& registry = scene->GetRegistry(); - + auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); + auto& registry = scene->GetRegistry(); if(ImGui::BeginDragDropTarget()) { @@ -382,7 +382,7 @@ namespace Lumos if(ImGui::IsItemClicked() && !deleteEntity) m_Editor->SetSelected(node); else if(m_DoubleClicked == node && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsItemHovered(ImGuiHoveredFlags_None)) - m_DoubleClicked = {}; + m_DoubleClicked = {}; if(ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered(ImGuiHoveredFlags_None)) { @@ -457,7 +457,7 @@ namespace Lumos verticalLineStart.x += SmallOffsetX; // to nicely line up with the arrow symbol ImVec2 verticalLineEnd = verticalLineStart; - if(!noChildren) + if(!noChildren) { entt::entity child = hierarchyComponent->First(); while(child != entt::null && registry.valid(child)) @@ -476,8 +476,8 @@ namespace Lumos HorizontalTreeLineSize *= 0.4f; } } - auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); - DrawNode(Entity(child, scene)); + auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); + DrawNode(Entity(child, scene)); ImGui::Unindent(10.0f); const ImRect childRect = ImRect(currentPos, currentPos + ImVec2(0.0f, ImGui::GetFontSize() + (ImGui::GetStyle().FramePadding.y * 2))); @@ -504,33 +504,33 @@ namespace Lumos bool HierarchyPanel::IsParentOfEntity(Entity entity, Entity child) { LUMOS_PROFILE_FUNCTION(); - return entity.IsParent(child); -// auto nodeHierarchyComponent = child.TryGetComponent(); -// if(nodeHierarchyComponent) -// { -// auto parent = nodeHierarchyComponent->Parent(); -// while(parent != entt::null) -// { -// if(parent == entity) -// { -// return true; -// } -// else -// { -// nodeHierarchyComponent = registry.try_get(parent); -// parent = nodeHierarchyComponent ? nodeHierarchyComponent->Parent() : entt::null; -// } -// } -// } -// -// return false; + return entity.IsParent(child); + // auto nodeHierarchyComponent = child.TryGetComponent(); + // if(nodeHierarchyComponent) + // { + // auto parent = nodeHierarchyComponent->Parent(); + // while(parent != entt::null) + // { + // if(parent == entity) + // { + // return true; + // } + // else + // { + // nodeHierarchyComponent = registry.try_get(parent); + // parent = nodeHierarchyComponent ? nodeHierarchyComponent->Parent() : entt::null; + // } + // } + // } + // + // return false; } void HierarchyPanel::OnImGui() { LUMOS_PROFILE_FUNCTION(); auto flags = ImGuiWindowFlags_NoCollapse; - m_CurrentPrevious = {}; + m_CurrentPrevious = {}; m_SelectUp = false; m_SelectDown = false; @@ -738,7 +738,7 @@ ImGui::GetStyle().ChildBorderSize = backup_border_size; Entity copiedEntity = { entity, scene }; if(!copiedEntity.Valid()) { - m_Editor->SetCopiedEntity({}); + m_Editor->SetCopiedEntity({}); } else { @@ -781,7 +781,7 @@ ImGui::GetStyle().ChildBorderSize = backup_border_size; ImGui::Indent(); - auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); + auto scene = Application::Get().GetSceneManager()->GetCurrentScene(); for(auto [entity] : registry.storage().each()) { @@ -790,7 +790,7 @@ ImGui::GetStyle().ChildBorderSize = backup_border_size; auto hierarchyComponent = registry.try_get(entity); if(!hierarchyComponent || hierarchyComponent->Parent() == entt::null) - DrawNode({ entity, scene }); + DrawNode({ entity, scene }); } } diff --git a/Editor/Source/HierarchyPanel.h b/Editor/Source/HierarchyPanel.h index fe382d272..f2f9ca9f1 100644 --- a/Editor/Source/HierarchyPanel.h +++ b/Editor/Source/HierarchyPanel.h @@ -5,7 +5,7 @@ namespace Lumos { - class Entity; + class Entity; class HierarchyPanel : public EditorPanel { public: diff --git a/Editor/Source/InspectorPanel.cpp b/Editor/Source/InspectorPanel.cpp index 9fd21d466..542a97f70 100644 --- a/Editor/Source/InspectorPanel.cpp +++ b/Editor/Source/InspectorPanel.cpp @@ -39,12 +39,14 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -53,8 +55,9 @@ #include #include #include +#include +#include -#include #include #include @@ -180,7 +183,7 @@ end return; } - ImGui::TextUnformatted("Loaded Functions : "); + // ImGui::TextUnformatted("Loaded Functions : "); /* ImGui::Indent(); for(auto&& function : solEnv) @@ -2843,7 +2846,7 @@ namespace Lumos if(!currentScene) { - m_Editor->SetSelected({}); + m_Editor->SetSelected({}); ImGuiUtilities::PopID(); ImGui::End(); return; @@ -2852,7 +2855,7 @@ namespace Lumos auto& registry = currentScene->GetRegistry(); if(selectedEntities.size() != 1 || !registry.valid(selectedEntities.front())) { - m_Editor->SetSelected({}); + m_Editor->SetSelected({}); ImGuiUtilities::PopID(); ImGui::End(); return; @@ -2875,14 +2878,14 @@ namespace Lumos ImGui::TextUnformatted(ICON_MDI_CUBE); ImGui::SameLine(); - bool hasName = registry.all_of(selected); - std::string name = selected.GetName(); + bool hasName = registry.all_of(selected); + std::string name = selected.GetName(); if(m_DebugMode) { if(selected.Valid()) { - //ImGui::Text("ID: %d, Version: %d", static_cast(registry.entity(selected)), registry.version(selected)); + // ImGui::Text("ID: %d, Version: %d", static_cast(registry.entity(selected)), registry.version(selected)); } else { @@ -3034,7 +3037,7 @@ namespace Lumos } ImGui::BeginChild("Components", ImVec2(0.0f, 0.0f), false, ImGuiWindowFlags_None); - auto entityHandle = (entt::entity)selected.GetHandle(); + auto entityHandle = (entt::entity)selected.GetHandle(); m_EnttEditor.RenderImGui(registry, entityHandle); ImGui::EndChild(); diff --git a/Editor/Source/PreviewDraw.cpp b/Editor/Source/PreviewDraw.cpp index 84e18715b..f631c3540 100644 --- a/Editor/Source/PreviewDraw.cpp +++ b/Editor/Source/PreviewDraw.cpp @@ -1,13 +1,15 @@ #include "PreviewDraw.h" -#include +#include #include -#include +#include #include +#include #include #include #include #include #include +#include namespace Lumos { @@ -38,7 +40,7 @@ namespace Lumos if(!m_PreviewRenderer) { - m_PreviewRenderer = CreateSharedPtr(256, 256); + m_PreviewRenderer = CreateSharedPtr(256, 256); m_PreviewRenderer->m_DebugRenderEnabled = false; } diff --git a/Editor/Source/PreviewDraw.h b/Editor/Source/PreviewDraw.h index 6e3ff77b0..71b30688f 100644 --- a/Editor/Source/PreviewDraw.h +++ b/Editor/Source/PreviewDraw.h @@ -14,7 +14,7 @@ namespace Lumos { class Environment; class Texture2D; - class RenderPasses; + class SceneRenderer; } class Scene; @@ -42,7 +42,7 @@ namespace Lumos Entity m_CameraEntity; Scene* m_PreviewScene = nullptr; - SharedPtr m_PreviewRenderer; + SharedPtr m_PreviewRenderer; SharedPtr m_PreviewTexture; u32 m_Width = 256; diff --git a/Editor/Source/ProjectSettingsPanel.cpp b/Editor/Source/ProjectSettingsPanel.cpp index c02c95de4..831ef34a1 100644 --- a/Editor/Source/ProjectSettingsPanel.cpp +++ b/Editor/Source/ProjectSettingsPanel.cpp @@ -1,7 +1,11 @@ #include "ProjectSettingsPanel.h" #include "Editor.h" - #include +#if __has_include() +#include +#elif __has_include() +#include +#endif namespace Lumos { diff --git a/Editor/Source/ResourcePanel.cpp b/Editor/Source/ResourcePanel.cpp index d0f22b2ed..89f418af7 100644 --- a/Editor/Source/ResourcePanel.cpp +++ b/Editor/Source/ResourcePanel.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef LUMOS_PLATFORM_WINDOWS #include diff --git a/Editor/Source/ResourcePanel.h b/Editor/Source/ResourcePanel.h index d54b18437..7b253dbdd 100644 --- a/Editor/Source/ResourcePanel.h +++ b/Editor/Source/ResourcePanel.h @@ -1,7 +1,6 @@ #pragma once #include "EditorPanel.h" -#include #include #if __has_include() diff --git a/Editor/Source/SceneSettingsPanel.cpp b/Editor/Source/SceneSettingsPanel.cpp index c88a8c4b8..166f067a7 100644 --- a/Editor/Source/SceneSettingsPanel.cpp +++ b/Editor/Source/SceneSettingsPanel.cpp @@ -7,6 +7,12 @@ #include #include +#if __has_include() +#include +#elif __has_include() +#include +#endif + namespace Lumos { SceneSettingsPanel::SceneSettingsPanel() diff --git a/Editor/Source/SceneViewPanel.cpp b/Editor/Source/SceneViewPanel.cpp index c0cb9b6f1..39cb8bc94 100644 --- a/Editor/Source/SceneViewPanel.cpp +++ b/Editor/Source/SceneViewPanel.cpp @@ -8,8 +8,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -41,7 +40,7 @@ namespace Lumos m_Width = 800; m_Height = 600; - Application::Get().GetRenderPasses()->SetDisablePostProcess(false); + Application::Get().GetSceneRenderer()->SetDisablePostProcess(false); } void SceneViewPanel::OnImGui() @@ -55,7 +54,7 @@ namespace Lumos if(!ImGui::Begin(m_Name.c_str(), &m_Active, flags) || !m_CurrentScene) { - app.SetDisableMainRenderPasses(true); + app.SetDisableMainSceneRenderer(true); ImGui::End(); return; } @@ -63,7 +62,7 @@ namespace Lumos Camera* camera = nullptr; Maths::Transform* transform = nullptr; - app.SetDisableMainRenderPasses(false); + app.SetDisableMainSceneRenderer(false); // if(app.GetEditorState() == EditorState::Preview) { @@ -71,7 +70,7 @@ namespace Lumos camera = m_Editor->GetCamera(); transform = &m_Editor->GetEditorCameraTransform(); - app.GetRenderPasses()->SetOverrideCamera(camera, transform); + app.GetSceneRenderer()->SetOverrideCamera(camera, transform); } ImVec2 offset = { 0.0f, 0.0f }; @@ -587,11 +586,11 @@ namespace Lumos m_Editor->GetSettings().m_AspectRatio = 1.0f; m_CurrentScene = scene; - auto RenderPasses = Application::Get().GetRenderPasses(); - RenderPasses->SetRenderTarget(m_GameViewTexture.get(), true); - RenderPasses->SetOverrideCamera(m_Editor->GetCamera(), &m_Editor->GetEditorCameraTransform()); + auto SceneRenderer = Application::Get().GetSceneRenderer(); + SceneRenderer->SetRenderTarget(m_GameViewTexture.get(), true); + SceneRenderer->SetOverrideCamera(m_Editor->GetCamera(), &m_Editor->GetEditorCameraTransform()); m_Editor->GetGridRenderer()->SetRenderTarget(m_GameViewTexture.get(), true); - m_Editor->GetGridRenderer()->SetDepthTarget(RenderPasses->GetForwardData().m_DepthTexture); + m_Editor->GetGridRenderer()->SetDepthTarget(SceneRenderer->GetForwardData().m_DepthTexture); } void SceneViewPanel::Resize(uint32_t width, uint32_t height) @@ -621,19 +620,19 @@ namespace Lumos { m_GameViewTexture->Resize(m_Width, m_Height); - auto RenderPasses = Application::Get().GetRenderPasses(); - RenderPasses->SetRenderTarget(m_GameViewTexture.get(), true, false); + auto SceneRenderer = Application::Get().GetSceneRenderer(); + SceneRenderer->SetRenderTarget(m_GameViewTexture.get(), true, false); if(!m_Editor->GetGridRenderer()) m_Editor->CreateGridRenderer(); m_Editor->GetGridRenderer()->SetRenderTarget(m_GameViewTexture.get(), false); - m_Editor->GetGridRenderer()->SetDepthTarget(RenderPasses->GetForwardData().m_DepthTexture); + m_Editor->GetGridRenderer()->SetDepthTarget(SceneRenderer->GetForwardData().m_DepthTexture); WindowResizeEvent e(width, height); auto& app = Application::Get(); - app.GetRenderPasses()->OnResize(width, height); + app.GetSceneRenderer()->OnResize(width, height); - RenderPasses->OnEvent(e); + SceneRenderer->OnEvent(e); m_Editor->GetGridRenderer()->OnResize(m_Width, m_Height); diff --git a/Editor/Source/SceneViewPanel.h b/Editor/Source/SceneViewPanel.h index 88b154103..9ce3897c3 100644 --- a/Editor/Source/SceneViewPanel.h +++ b/Editor/Source/SceneViewPanel.h @@ -44,7 +44,7 @@ namespace Lumos auto inside = frustum.IsInside(pos); - if(inside == Intersection::OUTSIDE) + if(inside == Maths::Intersection::OUTSIDE) continue; glm::vec2 screenPos = Maths::WorldToScreen(pos, viewProj, width, height, xpos, ypos); diff --git a/Editor/premake5.lua b/Editor/premake5.lua index 51ad200e8..4eda841b5 100755 --- a/Editor/premake5.lua +++ b/Editor/premake5.lua @@ -162,8 +162,6 @@ project "LumosEditor" "glfw", } - SetRecommendedXcodeSettings() - filter "system:ios" cppdialect "C++17" staticruntime "Off" @@ -273,8 +271,6 @@ project "LumosEditor" "Example.lmproj" } - SetRecommendedXcodeSettings() - filter "system:linux" cppdialect "C++17" staticruntime "Off" diff --git a/ExampleProject/AssetRegistry.lmar b/ExampleProject/AssetRegistry.lmar index 6feeba173..b2c9005ff 100644 --- a/ExampleProject/AssetRegistry.lmar +++ b/ExampleProject/AssetRegistry.lmar @@ -67,10 +67,10 @@ "AssetType": 6, "Name": "//Assets/Meshes/Scene/scene.gltf", "UUID": 3853544921239423074, - "AssetType": 0, + "AssetType": 9, "Name": "//Assets/Meshes/stormtrooper/stormtrooper.gltf", "UUID": 4378391369236188799, - "AssetType": 0, + "AssetType": 9, "Name": "DepthPrePass", "UUID": 4415649574143950547, "AssetType": 6, @@ -82,7 +82,7 @@ "AssetType": 1, "Name": "//Assets/Meshes/lowpoly_bonfire/scene.gltf", "UUID": 7027018599794543603, - "AssetType": 0, + "AssetType": 9, "Name": "ChromaticAberation", "UUID": 7375714513771862660, "AssetType": 6, @@ -130,7 +130,7 @@ "AssetType": 6, "Name": "//Assets/Meshes/DamagedHelmet/glTF/DamagedHelmet.gltf", "UUID": 13579337366301463653, - "AssetType": 0, + "AssetType": 9, "Name": "//Assets/Textures/fire.png", "UUID": 13831315025881660061, "AssetType": 1, diff --git a/Lumos/External/sol/config.hpp b/Lumos/External/sol/config.hpp index 563d8cd24..d8d641ee5 100644 --- a/Lumos/External/sol/config.hpp +++ b/Lumos/External/sol/config.hpp @@ -48,6 +48,14 @@ the build system, or the command line options of your compiler. */ + +#define SOL_IN_DEBUG_DETECTED 0 +#define SOL_SAFE_USERTYPE 0 +#define SOL_SAFE_REFERENCES 0 +#define SOL_SAFE_FUNCTION_CALLS 0 +#define SOL_USING_CXX_LUA 0 +#define SOL_EXCEPTIONS_SAFE_PROPAGATION 0 + // end of sol/config.hpp #endif // SOL_SINGLE_CONFIG_HPP diff --git a/Lumos/Source/Lumos/AI/AStar.cpp b/Lumos/Source/Lumos/AI/AStar.cpp index e3121bd3b..7b7fda818 100644 --- a/Lumos/Source/Lumos/AI/AStar.cpp +++ b/Lumos/Source/Lumos/AI/AStar.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "AStar.h" #include "PathEdge.h" @@ -117,4 +119,4 @@ namespace Lumos return success; } -} \ No newline at end of file +} diff --git a/Lumos/Source/Lumos/AI/PathEdge.cpp b/Lumos/Source/Lumos/AI/PathEdge.cpp index 6c007f20d..40d3e04d7 100644 --- a/Lumos/Source/Lumos/AI/PathEdge.cpp +++ b/Lumos/Source/Lumos/AI/PathEdge.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "PathEdge.h" namespace Lumos diff --git a/Lumos/Source/Lumos/AI/PathNode.cpp b/Lumos/Source/Lumos/AI/PathNode.cpp index 4566a9500..eb1e7503e 100644 --- a/Lumos/Source/Lumos/AI/PathNode.cpp +++ b/Lumos/Source/Lumos/AI/PathNode.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "PathNode.h" #include "PathEdge.h" @@ -25,4 +27,4 @@ namespace Lumos return glm::length(GetWorldSpaceTransform()[3] - other.GetWorldSpaceTransform()[3]); } -} \ No newline at end of file +} diff --git a/Lumos/Source/Lumos/Audio/AudioManager.cpp b/Lumos/Source/Lumos/Audio/AudioManager.cpp index 0cb641f33..90bc6670a 100644 --- a/Lumos/Source/Lumos/Audio/AudioManager.cpp +++ b/Lumos/Source/Lumos/Audio/AudioManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "AudioManager.h" #include "Core/Application.h" #include "Scene/Scene.h" diff --git a/Lumos/Source/Lumos/Audio/OggLoader.cpp b/Lumos/Source/Lumos/Audio/OggLoader.cpp index c315656e2..1752121b2 100644 --- a/Lumos/Source/Lumos/Audio/OggLoader.cpp +++ b/Lumos/Source/Lumos/Audio/OggLoader.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "OggLoader.h" #include "Core/OS/FileSystem.h" #include "Sound.h" diff --git a/Lumos/Source/Lumos/Audio/Sound.cpp b/Lumos/Source/Lumos/Audio/Sound.cpp index 0ad3bc95f..689eefd61 100644 --- a/Lumos/Source/Lumos/Audio/Sound.cpp +++ b/Lumos/Source/Lumos/Audio/Sound.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Sound.h" #include "Core/OS/FileSystem.h" diff --git a/Lumos/Source/Lumos/Audio/SoundNode.cpp b/Lumos/Source/Lumos/Audio/SoundNode.cpp index a877a01ab..dc75238a1 100644 --- a/Lumos/Source/Lumos/Audio/SoundNode.cpp +++ b/Lumos/Source/Lumos/Audio/SoundNode.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SoundNode.h" #include "Maths/MathsUtilities.h" diff --git a/Lumos/Source/Lumos/Audio/WavLoader.cpp b/Lumos/Source/Lumos/Audio/WavLoader.cpp index 8401e0113..1e56fd5ee 100644 --- a/Lumos/Source/Lumos/Audio/WavLoader.cpp +++ b/Lumos/Source/Lumos/Audio/WavLoader.cpp @@ -1,5 +1,8 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "WavLoader.h" +#include namespace Lumos { diff --git a/Lumos/Source/Lumos/Core/Application.cpp b/Lumos/Source/Lumos/Core/Application.cpp index 4aa496040..4545d7968 100644 --- a/Lumos/Source/Lumos/Core/Application.cpp +++ b/Lumos/Source/Lumos/Core/Application.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Application.h" #include "Scene/Scene.h" @@ -7,7 +9,7 @@ #include "Graphics/RHI/Renderer.h" #include "Graphics/RHI/GraphicsContext.h" -#include "Graphics/Renderers/RenderPasses.h" +#include "Graphics/Renderers/SceneRenderer.h" #include "Graphics/Camera/Camera.h" #include "Graphics/Material.h" #include "Graphics/Renderers/DebugRenderer.h" @@ -28,7 +30,7 @@ #include "Core/String.h" #include "Core/DataStructures/TDArray.h" #include "Core/CommandLine.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" #include "Scripting/Lua/LuaManager.h" #include "ImGui/ImGuiManager.h" #include "Events/ApplicationEvent.h" @@ -37,7 +39,7 @@ #include "Physics/B2PhysicsEngine/B2PhysicsEngine.h" #include "Physics/LumosPhysicsEngine/LumosPhysicsEngine.h" #include "Embedded/EmbedAsset.h" - +#include "Core/Asset/AssetRegistry.h" #include "Core/DataStructures/Map.h" #define SERIALISATION_INCLUDE_ONLY @@ -211,7 +213,7 @@ namespace Lumos m_ImGuiManager->OnInit(); LUMOS_LOG_INFO("Initialised ImGui Manager"); - m_RenderPasses = CreateUniquePtr(screenWidth, screenHeight); + m_SceneRenderer = CreateUniquePtr(screenWidth, screenHeight); System::JobSystem::Wait(context); @@ -219,7 +221,7 @@ namespace Lumos Graphics::Material::InitDefaultTexture(); Graphics::Font::InitDefaultFont(); - m_RenderPasses->EnableDebugRenderer(true); + m_SceneRenderer->EnableDebugRenderer(true); // updateThread = std::thread(Application::UpdateSystems); } @@ -239,7 +241,7 @@ namespace Lumos m_AssetManager.reset(); m_SceneManager.reset(); - m_RenderPasses.reset(); + m_SceneRenderer.reset(); m_SystemManager.reset(); m_ImGuiManager.reset(); LuaManager::Release(); @@ -554,10 +556,10 @@ namespace Lumos if(!m_SceneManager->GetCurrentScene()) return; - if(!m_DisableMainRenderPasses) + if(!m_DisableMainSceneRenderer) { - m_RenderPasses->BeginScene(m_SceneManager->GetCurrentScene()); - m_RenderPasses->OnRender(); + m_SceneRenderer->BeginScene(m_SceneManager->GetCurrentScene()); + m_SceneRenderer->OnRender(); } } @@ -593,8 +595,8 @@ namespace Lumos if(e.Handled()) return; - if(m_RenderPasses) - m_RenderPasses->OnEvent(e); + if(m_SceneRenderer) + m_SceneRenderer->OnEvent(e); if(e.Handled()) return; @@ -617,7 +619,7 @@ namespace Lumos void Application::OnNewScene(Scene* scene) { LUMOS_PROFILE_FUNCTION(); - m_RenderPasses->OnNewScene(scene); + m_SceneRenderer->OnNewScene(scene); } SharedPtr& Application::GetAssetManager() @@ -679,8 +681,8 @@ namespace Lumos Graphics::Renderer::GetRenderer()->OnResize(width, height); - if(m_RenderPasses) - m_RenderPasses->OnResize(width, height); + if(m_SceneRenderer) + m_SceneRenderer->OnResize(width, height); Graphics::Renderer::GetGraphicsContext()->WaitIdle(); @@ -723,8 +725,8 @@ namespace Lumos return; } m_Minimized = false; - m_RenderPasses->OnResize(width, height); - m_RenderPasses->OnEvent(e); + m_SceneRenderer->OnResize(width, height); + m_SceneRenderer->OnEvent(e); Graphics::Renderer::GetGraphicsContext()->WaitIdle(); } @@ -747,7 +749,7 @@ namespace Lumos // Save Asset Registry { String8 path = PushStr8F(m_FrameArena, "%sAssetRegistry.lmar", m_ProjectSettings.m_ProjectRoot.c_str()); // m_ProjectSettings.m_ProjectRoot + std::string("AssetRegistry.lmar"); - SerialiseAssetRegistry(path, m_AssetManager->GetAssetRegistry()); + SerialiseAssetRegistry(path, *m_AssetManager->GetAssetRegistry()); } } @@ -836,7 +838,7 @@ namespace Lumos String8 path = PushStr8F(m_FrameArena, "%sAssetRegistry.lmar", m_ProjectSettings.m_ProjectRoot.c_str()); if(FileSystem::FileExists((const char*)path.str)) { - DeserialiseAssetRegistry(path, m_AssetManager->GetAssetRegistry()); + DeserialiseAssetRegistry(path, *m_AssetManager->GetAssetRegistry()); } } } diff --git a/Lumos/Source/Lumos/Core/Application.h b/Lumos/Source/Lumos/Core/Application.h index 00412bb25..ad718d44e 100644 --- a/Lumos/Source/Lumos/Core/Application.h +++ b/Lumos/Source/Lumos/Core/Application.h @@ -25,7 +25,7 @@ namespace Lumos namespace Graphics { - class RenderPasses; + class SceneRenderer; enum class RenderAPI : uint32_t; } @@ -83,7 +83,7 @@ namespace Lumos virtual void OnDebugDraw(); SceneManager* GetSceneManager() const { return m_SceneManager.get(); } - Graphics::RenderPasses* GetRenderPasses() const { return m_RenderPasses.get(); } + Graphics::SceneRenderer* GetSceneRenderer() const { return m_SceneRenderer.get(); } Window* GetWindow() const { return m_Window.get(); } AppState GetState() const { return m_CurrentState; } EditorState GetEditorState() const { return m_EditorState; } @@ -94,7 +94,7 @@ namespace Lumos void SetAppState(AppState state) { m_CurrentState = state; } void SetEditorState(EditorState state) { m_EditorState = state; } void SetSceneActive(bool active) { m_SceneActive = active; } - void SetDisableMainRenderPasses(bool disable) { m_DisableMainRenderPasses = disable; } + void SetDisableMainSceneRenderer(bool disable) { m_DisableMainSceneRenderer = disable; } bool GetSceneActive() const { return m_SceneActive; } glm::vec2 GetWindowSize() const; @@ -209,12 +209,12 @@ namespace Lumos bool OnWindowClose(WindowCloseEvent& e); bool ShouldUpdateSystems = false; - uint32_t m_Frames = 0; - uint32_t m_Updates = 0; - float m_SecondTimer = 0.0f; - bool m_Minimized = false; - bool m_SceneActive = true; - bool m_DisableMainRenderPasses = false; + uint32_t m_Frames = 0; + uint32_t m_Updates = 0; + float m_SecondTimer = 0.0f; + bool m_Minimized = false; + bool m_SceneActive = true; + bool m_DisableMainSceneRenderer = false; uint32_t m_SceneViewWidth = 0; uint32_t m_SceneViewHeight = 0; @@ -227,7 +227,7 @@ namespace Lumos UniquePtr m_Window; UniquePtr m_SceneManager; UniquePtr m_SystemManager; - UniquePtr m_RenderPasses; + UniquePtr m_SceneRenderer; UniquePtr m_ImGuiManager; UniquePtr m_Timer; SharedPtr m_AssetManager; diff --git a/Lumos/Source/Lumos/Core/Asset.h b/Lumos/Source/Lumos/Core/Asset/Asset.h similarity index 99% rename from Lumos/Source/Lumos/Core/Asset.h rename to Lumos/Source/Lumos/Core/Asset/Asset.h index 4c6af3351..e14bbd1ad 100644 --- a/Lumos/Source/Lumos/Core/Asset.h +++ b/Lumos/Source/Lumos/Core/Asset/Asset.h @@ -1,6 +1,6 @@ #pragma once #include "Core/Core.h" -#include "UUID.h" +#include "Core/UUID.h" #define SET_ASSET_TYPE(type) \ static AssetType GetStaticType() \ diff --git a/Lumos/Source/Lumos/Core/Asset/AssetManager.cpp b/Lumos/Source/Lumos/Core/Asset/AssetManager.cpp new file mode 100644 index 000000000..7ea4a2e3d --- /dev/null +++ b/Lumos/Source/Lumos/Core/Asset/AssetManager.cpp @@ -0,0 +1,211 @@ +#ifndef LUMOS_PLATFORM_MACOS +#include "Precompiled.h" +#endif +#include "AssetManager.h" +#include "AssetRegistry.h" +#include "Core/Application.h" +#include "Graphics/RHI/Texture.h" +#include + +namespace Lumos +{ + static std::vector> m_Futures; + + AssetManager::AssetManager() + { + m_Arena = ArenaAlloc(Megabytes(4)); + m_AssetRegistry = new AssetRegistry(); + } + + AssetManager::~AssetManager() + { + ArenaRelease(m_Arena); + delete m_AssetRegistry; + } + + SharedPtr AssetManager::GetAsset(UUID ID) + { + if(m_AssetRegistry->Contains(ID)) + { + AssetMetaData& metaData = (*m_AssetRegistry)[ID]; + metaData.lastAccessed = (float)Engine::GetTimeStep().GetElapsedSeconds(); + return metaData.data; + } + + LUMOS_LOG_WARN("Asset not found {0}", ID); + return nullptr; + } + + AssetMetaData& AssetManager::AddAsset(const std::string& name, SharedPtr data, bool keepUnreferenced) + { + UUID ID = UUID(); + m_AssetRegistry->GetID(name, ID); + + AssetMetaData& metaData = AddAsset(ID, data, keepUnreferenced); + m_AssetRegistry->AddName(name, ID); + return metaData; + } + + AssetMetaData& AssetManager::AddAsset(UUID name, SharedPtr data, bool keepUnreferenced) + { + AssetRegistry& registry = *m_AssetRegistry; + if(m_AssetRegistry->Contains(name)) + { + AssetMetaData& metaData = registry[name]; + metaData.lastAccessed = (float)Engine::GetTimeStep().GetElapsedSeconds(); + metaData.data = data; + metaData.Expire = !keepUnreferenced; + metaData.Type = data ? data->GetAssetType() : AssetType::Unkown; + metaData.IsDataLoaded = data ? true : false; + return metaData; + } + + AssetMetaData newResource; + newResource.data = data; + newResource.timeSinceReload = 0; + newResource.onDisk = true; + newResource.lastAccessed = (float)Engine::GetTimeStep().GetElapsedSeconds(); + newResource.Type = data->GetAssetType(); + newResource.Expire = !keepUnreferenced; + newResource.IsDataLoaded = data ? true : false; + + registry[name] = newResource; + + return registry[name]; + } + + AssetMetaData AssetManager::GetAsset(const std::string& name) + { + UUID ID; + if(m_AssetRegistry->GetID(name, ID)) + { + AssetRegistry& registry = *m_AssetRegistry; + if(registry[ID].IsDataLoaded) + return registry[ID]; + else + { + return AssetMetaData(); + } + } + + return AssetMetaData(); + } + + SharedPtr AssetManager::GetAssetData(const std::string& name) + { + return GetAsset(name).data; + } + + void AssetManager::Destroy() + { + m_AssetRegistry->Clear(); + } + + void AssetManager::Update(float elapsedSeconds) + { + m_AssetRegistry->Update(elapsedSeconds); + } + + bool AssetManager::AssetExists(const std::string& name) + { + UUID ID; + if(m_AssetRegistry->GetID(name, ID)) + return m_AssetRegistry->Contains(ID) && (*m_AssetRegistry)[ID].IsDataLoaded; + + return false; + } + + bool AssetManager::AssetExists(UUID name) + { + return m_AssetRegistry->Contains(name); + } + + bool AssetManager::LoadShader(const std::string& filePath, SharedPtr& shader, bool keepUnreferenced) + { + shader = SharedPtr(Graphics::Shader::CreateFromFile(filePath)); + AddAsset(filePath, shader, keepUnreferenced); + return true; + } + + bool AssetManager::LoadAsset(const std::string& filePath, SharedPtr& shader, bool keepUnreferenced) + { + shader = SharedPtr(Graphics::Shader::CreateFromFile(filePath)); + AddAsset(filePath, shader, keepUnreferenced); + return true; + } + + static void LoadTexture2D(Graphics::Texture2D* tex, const std::string& path) + { + LUMOS_PROFILE_FUNCTION(); + ImageLoadDesc imageLoadDesc = {}; + imageLoadDesc.filePath = path.c_str(); + imageLoadDesc.maxHeight = 256; + imageLoadDesc.maxWidth = 256; + Lumos::LoadImageFromFile(imageLoadDesc); + + Graphics::TextureDesc desc; + desc.format = imageLoadDesc.outBits / 4 == 8 ? Graphics::RHIFormat::R8G8B8A8_Unorm : Graphics::RHIFormat::R32G32B32A32_Float; + + Application::Get().SubmitToMainThread([tex, imageLoadDesc, desc]() + { tex->Load(imageLoadDesc.outWidth, imageLoadDesc.outHeight, imageLoadDesc.outPixels, desc); }); + } + + bool AssetManager::LoadTexture(const std::string& filePath, SharedPtr& texture, bool thread) + { + texture = SharedPtr(Graphics::Texture2D::Create({}, 1, 1)); + if(thread) + m_Futures.push_back(std::async(std::launch::async, &LoadTexture2D, texture.get(), filePath)); + else + LoadTexture2D(texture.get(), filePath); + + AddAsset(filePath, texture); + return true; + } + + SharedPtr AssetManager::LoadTextureAsset(const std::string& filePath, bool thread) + { + SharedPtr texture; + LoadTexture(filePath, texture, thread); + return texture; + } + + static std::mutex s_AssetRegistryMutex; + + AssetMetaData& AssetRegistry::operator[](UUID handle) + { + std::scoped_lock lock(s_AssetRegistryMutex); + return m_AssetRegistry[handle]; + } + + const AssetMetaData& AssetRegistry::Get(UUID handle) const + { + std::scoped_lock lock(s_AssetRegistryMutex); + + LUMOS_ASSERT(m_AssetRegistry.find(handle) != m_AssetRegistry.end()); + return m_AssetRegistry.at(handle); + } + + AssetMetaData& AssetRegistry::Get(UUID handle) + { + std::scoped_lock lock(s_AssetRegistryMutex); + return m_AssetRegistry[handle]; + } + + bool AssetRegistry::Contains(UUID handle) const + { + std::scoped_lock lock(s_AssetRegistryMutex); + return m_AssetRegistry.find(handle) != m_AssetRegistry.end(); + } + + size_t AssetRegistry::Remove(UUID handle) + { + std::scoped_lock lock(s_AssetRegistryMutex); + return m_AssetRegistry.erase(handle); + } + + void AssetRegistry::Clear() + { + std::scoped_lock lock(s_AssetRegistryMutex); + m_AssetRegistry.clear(); + } +} diff --git a/Lumos/Source/Lumos/Core/Asset/AssetManager.h b/Lumos/Source/Lumos/Core/Asset/AssetManager.h new file mode 100644 index 000000000..051fe3d07 --- /dev/null +++ b/Lumos/Source/Lumos/Core/Asset/AssetManager.h @@ -0,0 +1,78 @@ +#pragma once +#include "Core/Engine.h" +#include "Audio/Sound.h" +#include "Graphics/RHI/Shader.h" +#include "Utilities/TSingleton.h" +#include "Utilities/LoadImage.h" +#include "Graphics/Font.h" +#include "Graphics/Model.h" +#include "Utilities/CombineHash.h" +#include "Asset.h" +#include "AssetMetaData.h" + +namespace Lumos +{ + class AssetRegistry; + namespace Graphics + { + class Model; + } + + class AssetManager + { + public: + AssetManager(); + ~AssetManager(); + + SharedPtr GetAsset(UUID ID); + AssetMetaData& AddAsset(const std::string& name, SharedPtr data, bool keepUnreferenced = false); + AssetMetaData& AddAsset(UUID name, SharedPtr data, bool keepUnreferenced = false); + AssetMetaData GetAsset(const std::string& name); + + SharedPtr GetAssetData(const std::string& name); + + void Destroy(); + void Update(float elapsedSeconds); + bool AssetExists(const std::string& name); + bool AssetExists(UUID name); + bool LoadShader(const std::string& filePath, SharedPtr& shader, bool keepUnreferenced = true); + bool LoadAsset(const std::string& filePath, SharedPtr& shader, bool keepUnreferenced = true); + + SharedPtr operator[](UUID name) { return GetAsset(name); } + SharedPtr LoadTextureAsset(const std::string& filePath, bool thread); + + template + SharedPtr CreateMemoryOnlyAsset(const char* name, TArgs&&... args) + { + static_assert(std::is_base_of::value, "CreateMemoryOnlyAsset only works for types derived from Asset"); + + uint64_t hash = 0; + HashCombine(hash, std::forward(args)...); + SharedPtr asset = SharedPtr::CreateSharedPtr(std::forward(args)...); + AssetMetaData metaData = AddAsset(name, asset); + metaData.IsMemoryAsset = true; + metaData.ParameterCache = hash; + return asset; + } + + template + SharedPtr CreateMemoryOnlyAsset(const char* name, TAsset* asset) + { + static_assert(std::is_base_of::value, "CreateMemoryOnlyAsset only works for types derived from Asset"); + + uint64_t hash = 0; + SharedPtr sharedAsset = SharedPtr::SharedPtr(asset); + AssetMetaData metaData = AddAsset(name, sharedAsset); + metaData.IsMemoryAsset = true; + return asset; + } + + AssetRegistry* GetAssetRegistry() { return m_AssetRegistry; } + + protected: + bool LoadTexture(const std::string& filePath, SharedPtr& texture, bool thread); + + Arena* m_Arena; + AssetRegistry* m_AssetRegistry; + }; +} diff --git a/Lumos/Source/Lumos/Core/Asset/AssetMetaData.h b/Lumos/Source/Lumos/Core/Asset/AssetMetaData.h new file mode 100644 index 000000000..7c142736a --- /dev/null +++ b/Lumos/Source/Lumos/Core/Asset/AssetMetaData.h @@ -0,0 +1,20 @@ +#pragma once + +namespace Lumos +{ + class Asset; + enum class AssetType : uint16_t; + + struct AssetMetaData + { + float timeSinceReload = 0.0f; + float lastAccessed = 0.0f; + SharedPtr data = nullptr; + bool onDisk = false; + bool Expire = true; + AssetType Type; + bool IsDataLoaded = false; + bool IsMemoryAsset = false; + uint64_t ParameterCache = 0; + }; +} \ No newline at end of file diff --git a/Lumos/Source/Lumos/Core/Asset/AssetRegistry.cpp b/Lumos/Source/Lumos/Core/Asset/AssetRegistry.cpp new file mode 100644 index 000000000..896d2e708 --- /dev/null +++ b/Lumos/Source/Lumos/Core/Asset/AssetRegistry.cpp @@ -0,0 +1,28 @@ +#ifndef LUMOS_PLATFORM_MACOS +#include "Precompiled.h" +#endif +#include "AssetRegistry.h" +#include "Asset.h" + +namespace Lumos +{ + void AssetRegistry::Update(float elapsedSeconds) + { + static UUID keysToDelete[256]; + std::size_t keysToDeleteCount = 0; + + for(auto&& [key, value] : m_AssetRegistry) + { + if(value.Expire && value.IsDataLoaded && value.data.GetCounter()->GetReferenceCount() == 1 && m_ExpirationTime < (elapsedSeconds - value.lastAccessed)) + { + keysToDelete[keysToDeleteCount] = key; + keysToDeleteCount++; + } + } + + for(std::size_t i = 0; i < keysToDeleteCount; i++) + { + m_AssetRegistry.erase(keysToDelete[i]); + } + } +} diff --git a/Lumos/Source/Lumos/Core/Asset/AssetRegistry.h b/Lumos/Source/Lumos/Core/Asset/AssetRegistry.h new file mode 100644 index 000000000..09093228a --- /dev/null +++ b/Lumos/Source/Lumos/Core/Asset/AssetRegistry.h @@ -0,0 +1,71 @@ +#pragma once +#include "AssetMetaData.h" + +namespace Lumos +{ + class AssetRegistry + { + template + friend void save(Archive& archive, const AssetRegistry& registry); + + template + friend void load(Archive& archive, AssetRegistry& registry); + + public: + AssetMetaData& operator[](const UUID handle); + AssetMetaData& Get(const UUID handle); + const AssetMetaData& Get(const UUID handle) const; + + void Update(float elapsedSeconds); + + size_t Count() const { return m_AssetRegistry.size(); } + bool Contains(const UUID handle) const; + size_t Remove(const UUID handle); + void Clear(); + + auto begin() { return m_AssetRegistry.begin(); } + auto end() { return m_AssetRegistry.end(); } + auto begin() const { return m_AssetRegistry.cbegin(); } + auto end() const { return m_AssetRegistry.cend(); } + + void AddName(const std::string& name, UUID ID) + { + m_NameMap.emplace(name, ID); +#ifndef LUMOS_PRODUCTION + m_UUIDNameMap.emplace(ID, name); +#endif + } + bool GetID(const std::string& name, UUID& ID) + { + if(m_NameMap.find(name) != m_NameMap.end()) + { + ID = m_NameMap[name]; + return true; + } + + return false; + } + +#ifndef LUMOS_PRODUCTION + bool GetName(UUID ID, std::string& name) + { + if(m_UUIDNameMap.find(ID) != m_UUIDNameMap.end()) + { + name = m_UUIDNameMap[ID]; + return true; + } + + return false; + } +#endif + + private: + std::unordered_map m_AssetRegistry; + std::unordered_map m_NameMap; +#ifndef LUMOS_PRODUCTION + std::unordered_map m_UUIDNameMap; // Debug Only +#endif + + float m_ExpirationTime = 3.0f; + }; +} \ No newline at end of file diff --git a/Lumos/Source/Lumos/Core/CommandLine.cpp b/Lumos/Source/Lumos/Core/CommandLine.cpp index f5f7c8da1..c6bdf73e0 100644 --- a/Lumos/Source/Lumos/Core/CommandLine.cpp +++ b/Lumos/Source/Lumos/Core/CommandLine.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "CommandLine.h" #include "Maths/MathsUtilities.h" #include "Core/Thread.h" diff --git a/Lumos/Source/Lumos/Core/Core.h b/Lumos/Source/Lumos/Core/Core.h index fa6bd3c09..87d32773d 100644 --- a/Lumos/Source/Lumos/Core/Core.h +++ b/Lumos/Source/Lumos/Core/Core.h @@ -78,8 +78,8 @@ #define MAX_OBJECTS 2048 -#define _STRINGIZE(s) #s -#define STRINGIZE(s) _STRINGIZE(s) +#define STRINGIZE2(s) #s +#define STRINGIZE(s) STRINGIZE2(s) #if LUMOS_PLATFORM_WINDOWS #define LUMOS_BREAK() __debugbreak() diff --git a/Lumos/Source/Lumos/Core/CoreSystem.cpp b/Lumos/Source/Lumos/Core/CoreSystem.cpp index 65ddd8f93..b1a4d3518 100644 --- a/Lumos/Source/Lumos/Core/CoreSystem.cpp +++ b/Lumos/Source/Lumos/Core/CoreSystem.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "CoreSystem.h" #include "OS/FileSystem.h" #include "JobSystem.h" diff --git a/Lumos/Source/Lumos/Core/DataStructures/Map.cpp b/Lumos/Source/Lumos/Core/DataStructures/Map.cpp index f6fc7416e..2763c274b 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/Map.cpp +++ b/Lumos/Source/Lumos/Core/DataStructures/Map.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Map.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/DataStructures/Map.h b/Lumos/Source/Lumos/Core/DataStructures/Map.h index a12f69964..a3c894423 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/Map.h +++ b/Lumos/Source/Lumos/Core/DataStructures/Map.h @@ -67,8 +67,8 @@ namespace Lumos K key; \ V value; \ }* data; \ - int length; \ - int capacity; \ + int length; \ + int capacity; \ } typedef HashMap(char, char) HashMapRaw; diff --git a/Lumos/Source/Lumos/Core/DataStructures/TArray.h b/Lumos/Source/Lumos/Core/DataStructures/TArray.h index 8bdf19103..2b6fcf9a3 100644 --- a/Lumos/Source/Lumos/Core/DataStructures/TArray.h +++ b/Lumos/Source/Lumos/Core/DataStructures/TArray.h @@ -87,7 +87,7 @@ namespace Lumos private: T* m_Data; - size_t m_Size = 0; + size_t m_Size = 0; Arena* m_Arena = nullptr; }; @@ -98,7 +98,7 @@ namespace Lumos , m_Size(_Size) { m_Data = nullptr; - if (m_Arena) + if(m_Arena) m_Data = PushArrayNoZero(m_Arena, T, m_Size); else m_Data = new T[m_Size]; @@ -106,15 +106,16 @@ namespace Lumos template TArray::TArray(const TArray& other) - : m_Size(other.m_Size), m_Arena(other.m_Arena) + : m_Size(other.m_Size) + , m_Arena(other.m_Arena) { m_Data = nullptr; - if (m_Arena) + if(m_Arena) m_Data = PushArrayNoZero(m_Arena, T, m_Size); else m_Data = new T[m_Size]; - for (size_t i = 0; i < m_Size; ++i) + for(size_t i = 0; i < m_Size; ++i) { m_Data[i] = other.m_Data[i]; } @@ -122,15 +123,16 @@ namespace Lumos template TArray::TArray(TArray&& other) noexcept - : m_Size(other.m_Size), m_Arena(other.m_Arena) + : m_Size(other.m_Size) + , m_Arena(other.m_Arena) { m_Data = nullptr; - if (m_Arena) + if(m_Arena) m_Data = PushArrayNoZero(m_Arena, T, m_Size); else m_Data = new T[m_Size]; - for (size_t i = 0; i < m_Size; ++i) + for(size_t i = 0; i < m_Size; ++i) { m_Data[i] = std::move(other.m_Data[i]); } @@ -141,11 +143,11 @@ namespace Lumos template TArray& TArray::operator=(const TArray& other) { - if (this != &other) + if(this != &other) { - m_Size = other.m_Size; + m_Size = other.m_Size; m_Arena = other.m_Arena; - for (size_t i = 0; i < m_Size; ++i) + for(size_t i = 0; i < m_Size; ++i) { m_Data[i] = other.m_Data[i]; } @@ -157,18 +159,18 @@ namespace Lumos template TArray& TArray::operator=(TArray&& other) noexcept { - if (this != &other) + if(this != &other) { - m_Size = other.m_Size; + m_Size = other.m_Size; m_Arena = other.m_Arena; m_Data = nullptr; - if (m_Arena) + if(m_Arena) m_Data = PushArrayNoZero(m_Arena, T, m_Size); else m_Data = new T[m_Size]; - for (size_t i = 0; i < m_Size; ++i) + for(size_t i = 0; i < m_Size; ++i) { m_Data[i] = std::move(other.m_Data[i]); } diff --git a/Lumos/Source/Lumos/Core/Engine.cpp b/Lumos/Source/Lumos/Core/Engine.cpp old mode 100755 new mode 100644 index ffae4f68e..7ccdf487f --- a/Lumos/Source/Lumos/Core/Engine.cpp +++ b/Lumos/Source/Lumos/Core/Engine.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Engine.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/Engine.h b/Lumos/Source/Lumos/Core/Engine.h index 678946b92..22638514e 100644 --- a/Lumos/Source/Lumos/Core/Engine.h +++ b/Lumos/Source/Lumos/Core/Engine.h @@ -27,7 +27,7 @@ namespace Lumos uint32_t NumShadowObjects = 0; uint32_t NumDrawCalls = 0; uint32_t BoundPipelines = 0; - uint32_t BoundRenderPasses = 0; + uint32_t BoundSceneRenderer = 0; double FrameTime = 0.0; float UsedGPUMemory = 0.0f; float UsedRam = 0.0f; @@ -44,7 +44,7 @@ namespace Lumos m_Stats.NumDrawCalls = 0; m_Stats.TotalGPUMemory = 0.0f; m_Stats.BoundPipelines = 0; - m_Stats.BoundRenderPasses = 0; + m_Stats.BoundSceneRenderer = 0; } Stats& Statistics() { return m_Stats; } diff --git a/Lumos/Source/Lumos/Core/JobSystem.cpp b/Lumos/Source/Lumos/Core/JobSystem.cpp index 0169c15aa..41ba2b4f8 100644 --- a/Lumos/Source/Lumos/Core/JobSystem.cpp +++ b/Lumos/Source/Lumos/Core/JobSystem.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "JobSystem.h" #include "Maths/MathsUtilities.h" #include "Core/DataStructures/TDArray.h" diff --git a/Lumos/Source/Lumos/Core/LMLog.cpp b/Lumos/Source/Lumos/Core/LMLog.cpp index 068fbf8ec..5e391ee04 100644 --- a/Lumos/Source/Lumos/Core/LMLog.cpp +++ b/Lumos/Source/Lumos/Core/LMLog.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "LMLog.h" #include diff --git a/Lumos/Source/Lumos/Core/LMLog.h b/Lumos/Source/Lumos/Core/LMLog.h index 6219d10c5..deb52ed59 100644 --- a/Lumos/Source/Lumos/Core/LMLog.h +++ b/Lumos/Source/Lumos/Core/LMLog.h @@ -1,7 +1,11 @@ #pragma once #include "Core.h" +#ifdef LUMOS_PRODUCTION #define LUMOS_ENABLE_LOG 1 +#else +#define LUMOS_ENABLE_LOG 1 +#endif #if LUMOS_ENABLE_LOG #ifdef LUMOS_PLATFORM_WINDOWS @@ -10,6 +14,10 @@ #endif #endif +#ifndef FMT_HEADER_ONLY +#define FMT_HEADER_ONLY +#endif + #include #include diff --git a/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.cpp b/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.cpp index 1f101f4b3..245137b66 100644 --- a/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.cpp +++ b/Lumos/Source/Lumos/Core/OS/Allocators/BinAllocator.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "BinAllocator.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp b/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp index 73d6f3cc9..b151130b3 100644 --- a/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp +++ b/Lumos/Source/Lumos/Core/OS/Allocators/DefaultAllocator.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "DefaultAllocator.h" #include "Core/OS/MemoryManager.h" diff --git a/Lumos/Source/Lumos/Core/OS/Allocators/StbAllocator.cpp b/Lumos/Source/Lumos/Core/OS/Allocators/StbAllocator.cpp index f49483136..1e3bdd05a 100644 --- a/Lumos/Source/Lumos/Core/OS/Allocators/StbAllocator.cpp +++ b/Lumos/Source/Lumos/Core/OS/Allocators/StbAllocator.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "StbAllocator.h" #define STB_LEAKCHECK_IMPLEMENTATION @@ -20,4 +22,4 @@ namespace Lumos { stb_leakcheck_dumpmem(); } -} \ No newline at end of file +} diff --git a/Lumos/Source/Lumos/Core/OS/FileSystem.cpp b/Lumos/Source/Lumos/Core/OS/FileSystem.cpp index 56fdd141f..3657b5144 100644 --- a/Lumos/Source/Lumos/Core/OS/FileSystem.cpp +++ b/Lumos/Source/Lumos/Core/OS/FileSystem.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "FileSystem.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/OS/Input.cpp b/Lumos/Source/Lumos/Core/OS/Input.cpp index 167149b12..6974afd9d 100644 --- a/Lumos/Source/Lumos/Core/OS/Input.cpp +++ b/Lumos/Source/Lumos/Core/OS/Input.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Input.h" namespace Lumos @@ -8,7 +10,7 @@ namespace Lumos { Reset(); - HashMapInit(&m_Controllers); + HashMapInit(&m_Controllers); } void Input::Reset() @@ -92,31 +94,31 @@ namespace Lumos bool Input::IsControllerPresent(int id) { - return HashMapFindPtr(&m_Controllers, id); - // return m_Controllers.find(id) != m_Controllers.end(); + return HashMapFindPtr(&m_Controllers, id); + // return m_Controllers.find(id) != m_Controllers.end(); } std::vector Input::GetConnectedControllerIDs() { std::vector ids; -// ids.reserve(m_Controllers.size()); -// for(auto [id, controller] : m_Controllers) -// ids.emplace_back(id); + // ids.reserve(m_Controllers.size()); + // for(auto [id, controller] : m_Controllers) + // ids.emplace_back(id); return ids; } Controller* Input::GetController(int id) { - return (Controller*)HashMapFindPtr(&m_Controllers, id); + return (Controller*)HashMapFindPtr(&m_Controllers, id); } Controller* Input::GetOrAddController(int id) { { - //TODO: FIX + // TODO: FIX Controller* value = nullptr; - if (HashMapFind(&m_Controllers, id, value)) + if(HashMapFind(&m_Controllers, id, value)) { return value; } @@ -128,12 +130,12 @@ namespace Lumos HashMapInsert(&m_Controllers, id, value); Controller* valuePtr = nullptr; - if (HashMapFind(&m_Controllers, id, valuePtr)) + if(HashMapFind(&m_Controllers, id, valuePtr)) { return valuePtr; } } - + return nullptr; } @@ -142,7 +144,7 @@ namespace Lumos if(!Input::IsControllerPresent(id)) return {}; - Controller& controller = *GetController(id); + Controller& controller = *GetController(id); return controller.Name; } @@ -151,7 +153,7 @@ namespace Lumos if(!Input::IsControllerPresent(controllerID)) return false; - Controller& controller = *GetController(controllerID); + Controller& controller = *GetController(controllerID); ControllerButtonData& data = controller.ButtonStates[button]; return data.State == KeyState::Pressed; } @@ -162,7 +164,7 @@ namespace Lumos return 0.0f; float data; - Controller* controller = GetController(controllerID); + Controller* controller = GetController(controllerID); return controller->AxisStates[axis]; } @@ -171,13 +173,13 @@ namespace Lumos if(!Input::IsControllerPresent(controllerID)) return 0; - Controller& controller = *GetController(controllerID); - uint8_t value = 0; + Controller& controller = *GetController(controllerID); + uint8_t value = 0; return controller.HatStates[hat]; } void Input::RemoveController(int id) { - HashMapRemove(&m_Controllers, id); + HashMapRemove(&m_Controllers, id); } } diff --git a/Lumos/Source/Lumos/Core/OS/Input.h b/Lumos/Source/Lumos/Core/OS/Input.h index cfe800563..250a657ba 100644 --- a/Lumos/Source/Lumos/Core/OS/Input.h +++ b/Lumos/Source/Lumos/Core/OS/Input.h @@ -51,7 +51,7 @@ namespace Lumos class LUMOS_EXPORT Input : public ThreadSafeSingleton { friend class TSingleton; - friend class GLFWWindow; + friend class GLFWWindow; public: Input(); diff --git a/Lumos/Source/Lumos/Core/OS/Memory.cpp b/Lumos/Source/Lumos/Core/OS/Memory.cpp index 2bc7ced88..a6064572e 100644 --- a/Lumos/Source/Lumos/Core/OS/Memory.cpp +++ b/Lumos/Source/Lumos/Core/OS/Memory.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Memory.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp b/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp index 5875c6266..db5ace50e 100644 --- a/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp +++ b/Lumos/Source/Lumos/Core/OS/MemoryManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "MemoryManager.h" #include "Utilities/StringUtilities.h" diff --git a/Lumos/Source/Lumos/Core/OS/OS.cpp b/Lumos/Source/Lumos/Core/OS/OS.cpp index 7532fb1f0..413fdbfbd 100644 --- a/Lumos/Source/Lumos/Core/OS/OS.cpp +++ b/Lumos/Source/Lumos/Core/OS/OS.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "OS.h" #if defined(LUMOS_PLATFORM_WINDOWS) diff --git a/Lumos/Source/Lumos/Core/OS/Window.cpp b/Lumos/Source/Lumos/Core/OS/Window.cpp index 162879e43..2805a5356 100644 --- a/Lumos/Source/Lumos/Core/OS/Window.cpp +++ b/Lumos/Source/Lumos/Core/OS/Window.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Window.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/Reference.cpp b/Lumos/Source/Lumos/Core/Reference.cpp index 079465509..38dd42fae 100644 --- a/Lumos/Source/Lumos/Core/Reference.cpp +++ b/Lumos/Source/Lumos/Core/Reference.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Reference.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/String.cpp b/Lumos/Source/Lumos/Core/String.cpp index 39f5cc331..1cba3ef26 100644 --- a/Lumos/Source/Lumos/Core/String.cpp +++ b/Lumos/Source/Lumos/Core/String.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "String.h" #include diff --git a/Lumos/Source/Lumos/Core/Thread.cpp b/Lumos/Source/Lumos/Core/Thread.cpp index e0aba9f93..e1817cfb6 100644 --- a/Lumos/Source/Lumos/Core/Thread.cpp +++ b/Lumos/Source/Lumos/Core/Thread.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Thread.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Core/UUID.cpp b/Lumos/Source/Lumos/Core/UUID.cpp index 6b5bc20e4..d60a21b02 100644 --- a/Lumos/Source/Lumos/Core/UUID.cpp +++ b/Lumos/Source/Lumos/Core/UUID.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "UUID.h" #include "Maths/Random.h" diff --git a/Lumos/Source/Lumos/Embedded/EmbedAsset.cpp b/Lumos/Source/Lumos/Embedded/EmbedAsset.cpp index 73893b720..33d2385f5 100644 --- a/Lumos/Source/Lumos/Embedded/EmbedAsset.cpp +++ b/Lumos/Source/Lumos/Embedded/EmbedAsset.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "EmbedAsset.h" #include "Graphics/RHI/Texture.h" #include "Graphics/RHI/Shader.h" @@ -7,6 +9,7 @@ #include "Utilities/LoadImage.h" #include +#include namespace Lumos { diff --git a/Lumos/Source/Lumos/Events/ApplicationEvent.h b/Lumos/Source/Lumos/Events/ApplicationEvent.h index 342e83030..a6d2057a8 100644 --- a/Lumos/Source/Lumos/Events/ApplicationEvent.h +++ b/Lumos/Source/Lumos/Events/ApplicationEvent.h @@ -2,8 +2,6 @@ #include "Event.h" -#include - namespace Lumos { class LUMOS_EXPORT WindowResizeEvent : public Event diff --git a/Lumos/Source/Lumos/Events/MouseEvent.h b/Lumos/Source/Lumos/Events/MouseEvent.h index 2bef2de10..02f9c27ec 100644 --- a/Lumos/Source/Lumos/Events/MouseEvent.h +++ b/Lumos/Source/Lumos/Events/MouseEvent.h @@ -1,8 +1,6 @@ #pragma once #include "Event.h" -#include - namespace Lumos { diff --git a/Lumos/Source/Lumos/Graphics/AnimatedSprite.cpp b/Lumos/Source/Lumos/Graphics/AnimatedSprite.cpp index 3de61e599..717e69648 100644 --- a/Lumos/Source/Lumos/Graphics/AnimatedSprite.cpp +++ b/Lumos/Source/Lumos/Graphics/AnimatedSprite.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "AnimatedSprite.h" namespace Lumos::Graphics diff --git a/Lumos/Source/Lumos/Graphics/Animation/Animation.cpp b/Lumos/Source/Lumos/Graphics/Animation/Animation.cpp index 2968a73a4..eb9601b85 100644 --- a/Lumos/Source/Lumos/Graphics/Animation/Animation.cpp +++ b/Lumos/Source/Lumos/Graphics/Animation/Animation.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Animation.h" #include "Skeleton.h" diff --git a/Lumos/Source/Lumos/Graphics/Animation/Animation.h b/Lumos/Source/Lumos/Graphics/Animation/Animation.h index b190d2ee5..d9c6a85da 100644 --- a/Lumos/Source/Lumos/Graphics/Animation/Animation.h +++ b/Lumos/Source/Lumos/Graphics/Animation/Animation.h @@ -1,6 +1,6 @@ #pragma once -#include "Core/Asset.h" +#include "Core/Asset/Asset.h" #include namespace ozz diff --git a/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp b/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp index 1cc86c4b5..d6519d715 100644 --- a/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp +++ b/Lumos/Source/Lumos/Graphics/Animation/AnimationController.cpp @@ -1,11 +1,21 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Skeleton.h" #include "AnimationController.h" +#include "SamplingContext.h" #include "Graphics/Renderers/DebugRenderer.h" #include "Graphics/RHI/DescriptorSet.h" #include "Graphics/RHI/Shader.h" #include "Core/Application.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" + +#include +#include +#include +#include +#include +#include #include #include @@ -19,11 +29,21 @@ #define GLM_ENABLE_EXPERIMENTAL #include #include +#include namespace Lumos { namespace Graphics { + struct AnimationData + { + std::vector> m_AnimationStates; + std::vector m_AnimationNames; + ozz::vector m_JointWorldMats; + std::vector m_BindPoses; + ozz::vector m_JointRemap; + }; + glm::mat4 ConvertToGLM(const ozz::math::Float4x4& ozzMat) { LUMOS_PROFILE_FUNCTION_LOW(); @@ -48,75 +68,26 @@ namespace Lumos return glmMat; } - SamplingContext::SamplingContext() - { - } - - SamplingContext::SamplingContext(const SamplingContext& other) - : LocalTranslations(other.LocalTranslations) - , LocalScales(other.LocalScales) - , LocalRotations(other.LocalRotations) - , m_LocalSpaceSoaTransforms(other.m_LocalSpaceSoaTransforms) - { - m_Context.Resize(other.m_Context.max_tracks()); - } - - SamplingContext::~SamplingContext() - { - } - - SamplingContext& SamplingContext::operator=(const SamplingContext& other) - { - LocalTranslations = other.LocalTranslations; - LocalScales = other.LocalScales; - LocalRotations = other.LocalRotations; - m_LocalSpaceSoaTransforms = other.m_LocalSpaceSoaTransforms; - - m_Context.Resize(other.m_Context.max_tracks()); - return *this; - } - - void SamplingContext::resize(uint32_t size) - { - if(m_Size != size) - { - m_Size = size; - m_Context.Resize(size); - LocalTranslations.resize(size); - LocalScales.resize(size); - LocalRotations.resize(size); - } - } - - void SamplingContext::resizeSao(uint32_t size) - { - if(m_SaoSize != size) - { - m_SaoSize = size; - m_LocalSpaceSoaTransforms.resize(size); - } - } - AnimationController::AnimationController() { + m_Data = new AnimationData(); } - AnimationController::AnimationController(const AnimationController& copy) - { - } + AnimationController::AnimationController(const AnimationController& copy) = default; AnimationController::~AnimationController() { + delete m_Data; } void AnimationController::Update(float& animationTime, SamplingContext& context) { LUMOS_PROFILE_FUNCTION(); - if(m_AnimationStates.empty()) + if(m_Data->m_AnimationStates.empty()) return; - m_JointWorldMats = ozz::vector(); + m_Data->m_JointWorldMats = ozz::vector(); - float ratio = animationTime / m_AnimationStates[m_StateIndex]->GetAnimation().duration(); + float ratio = animationTime / m_Data->m_AnimationStates[m_StateIndex]->GetAnimation().duration(); if(ratio >= 1.0f) { animationTime = 0.0f; @@ -127,16 +98,16 @@ namespace Lumos { context.resize(m_Skeleton->GetSkeleton().num_joints()); context.resizeSao(m_Skeleton->GetSkeleton().num_soa_joints()); - updateSampling(ratio, context); + UpdateSampling(ratio, context); - if(m_JointWorldMats.size() != m_Skeleton->GetSkeleton().num_joints()) - m_JointWorldMats.resize(m_Skeleton->GetSkeleton().num_joints()); + if(m_Data->m_JointWorldMats.size() != m_Skeleton->GetSkeleton().num_joints()) + m_Data->m_JointWorldMats.resize(m_Skeleton->GetSkeleton().num_joints()); // Setup local-to-model conversion job. ozz::animation::LocalToModelJob ltmJob; ltmJob.skeleton = &m_Skeleton->GetSkeleton(); ltmJob.input = ozz::make_span(context.GetLocalTransforms()); - ltmJob.output = ozz::make_span(m_JointWorldMats); + ltmJob.output = ozz::make_span(m_Data->m_JointWorldMats); // Runs ltm job. if(!ltmJob.Run()) @@ -153,9 +124,9 @@ namespace Lumos void AnimationController::SetCurrentState(const std::string& name) { - for(size_t i = 0; i < m_AnimationNames.size(); ++i) + for(size_t i = 0; i < m_Data->m_AnimationNames.size(); ++i) { - if(m_AnimationNames[i] == name) + if(m_Data->m_AnimationNames[i] == name) { m_StateIndex = i; return; @@ -164,7 +135,7 @@ namespace Lumos } void AnimationController::AddState(const std::string_view name, const SharedPtr& animation) { - for(const auto& animName : m_AnimationNames) + for(const auto& animName : m_Data->m_AnimationNames) { if(animName == name) { @@ -172,14 +143,23 @@ namespace Lumos return; } } - m_AnimationNames.push_back(std::string(name)); - m_AnimationStates.push_back(animation); + m_Data->m_AnimationNames.push_back(std::string(name)); + m_Data->m_AnimationStates.push_back(animation); } void AnimationController::SetState(size_t index, const std::string_view name, const SharedPtr& animation) { - m_AnimationNames[index] = name; - m_AnimationStates[index] = animation; + m_Data->m_AnimationNames[index] = name; + m_Data->m_AnimationStates[index] = animation; + } + + const std::vector& AnimationController::GetStateNames() const + { + return m_Data->m_AnimationNames; + } + const std::vector>& AnimationController::GetAnimationStates() const + { + return m_Data->m_AnimationStates; } SharedPtr AnimationController::GetDescriptorSet() @@ -204,13 +184,13 @@ namespace Lumos { LUMOS_PROFILE_FUNCTION_LOW(); std::vector glmMats; - for(size_t i = 0; i < m_JointWorldMats.size(); i++) + for(size_t i = 0; i < m_Data->m_JointWorldMats.size(); i++) { - ozz::math::Float4x4 skin_matrix = m_JointWorldMats[i]; - glmMats.push_back(ConvertToGLM(skin_matrix) * m_BindPoses[i]); + ozz::math::Float4x4 skin_matrix = m_Data->m_JointWorldMats[i]; + glmMats.push_back(ConvertToGLM(skin_matrix) * m_Data->m_BindPoses[i]); } - if(m_JointWorldMats.empty()) + if(m_Data->m_JointWorldMats.empty()) { LUMOS_LOG_INFO("Using identy for joint matrices"); for(size_t i = 0; i < 100; i++) @@ -246,8 +226,8 @@ namespace Lumos } // Selects joint matrices. - const math::Float4x4& parent = m_JointWorldMats[parent_id]; - const math::Float4x4& current = m_JointWorldMats[i]; + const math::Float4x4& parent = m_Data->m_JointWorldMats[parent_id]; + const math::Float4x4& current = m_Data->m_JointWorldMats[i]; // Copy parent joint's raw matrix, to render a bone between the parent // and current matrix. @@ -286,11 +266,16 @@ namespace Lumos } } - void AnimationController::updateSampling(float ratio, SamplingContext& context) + void AnimationController::SetBindPoses(const std::vector& mats) + { + m_Data->m_BindPoses = mats; + } + + void AnimationController::UpdateSampling(float ratio, SamplingContext& context) { LUMOS_PROFILE_FUNCTION(); ozz::animation::SamplingJob sampling_job; - sampling_job.animation = &m_AnimationStates[m_StateIndex]->GetAnimation(); + sampling_job.animation = &m_Data->m_AnimationStates[m_StateIndex]->GetAnimation(); sampling_job.context = &context.m_Context; sampling_job.ratio = ratio; sampling_job.output = ozz::make_span(context.m_LocalSpaceSoaTransforms); diff --git a/Lumos/Source/Lumos/Graphics/Animation/AnimationController.h b/Lumos/Source/Lumos/Graphics/Animation/AnimationController.h index 6a96003bf..c57719c69 100644 --- a/Lumos/Source/Lumos/Graphics/Animation/AnimationController.h +++ b/Lumos/Source/Lumos/Graphics/Animation/AnimationController.h @@ -3,52 +3,15 @@ #include "Utilities/TimeStep.h" #include "Animation.h" -#define GLM_ENABLE_EXPERIMENTAL -#include -#include - -#include -#include -#include -#include -#include -#include +#include namespace Lumos { namespace Graphics { class DescriptorSet; - - struct SamplingContext - { - SamplingContext(); - SamplingContext(const SamplingContext& other); - - ~SamplingContext(); - - SamplingContext& operator=(const SamplingContext& other); - - std::vector LocalTranslations; - std::vector LocalScales; - std::vector LocalRotations; - - ozz::vector& GetLocalTransforms() { return m_LocalSpaceSoaTransforms; } - const ozz::vector& GetLocalTransforms() const { return m_LocalSpaceSoaTransforms; } - - private: - void resize(uint32_t size); - void resizeSao(uint32_t size); - - private: - ozz::animation::SamplingJob::Context m_Context; - ozz::vector m_LocalSpaceSoaTransforms; - - uint32_t m_SaoSize = 0; - uint32_t m_Size = 0; - - friend class AnimationController; - }; + struct SamplingContext; + struct AnimationData; // Controls which animation (or animations) is playing on a mesh. class AnimationController : public Asset @@ -72,8 +35,8 @@ namespace Lumos size_t GetCurrentState() const { return m_StateIndex; } const SharedPtr& GetSkeleton() const { return m_Skeleton; } - const std::vector& GetStateNames() const { return m_AnimationNames; } - const std::vector>& GetAnimationStates() const { return m_AnimationStates; } + const std::vector& GetStateNames() const; + const std::vector>& GetAnimationStates() const; SharedPtr GetDescriptorSet(); static AssetType GetStaticType() { return AssetType::AnimationController; } @@ -82,19 +45,15 @@ namespace Lumos std::vector GetJointMatrices(); void DebugDraw(const glm::mat4& transform); + void SetBindPoses(const std::vector& mats); + private: - void updateSampling(float ratio, SamplingContext& context); + void UpdateSampling(float ratio, SamplingContext& context); private: SharedPtr m_Skeleton; - std::vector> m_AnimationStates; - std::vector m_AnimationNames; - - ozz::vector m_JointWorldMats; - std::vector m_BindPoses; - ozz::vector m_JointRemap; - SharedPtr m_Descriptor; + AnimationData* m_Data; size_t m_StateIndex = 0; }; diff --git a/Lumos/Source/Lumos/Graphics/Animation/SamplingContext.cpp b/Lumos/Source/Lumos/Graphics/Animation/SamplingContext.cpp new file mode 100644 index 000000000..6ecdaa37e --- /dev/null +++ b/Lumos/Source/Lumos/Graphics/Animation/SamplingContext.cpp @@ -0,0 +1,59 @@ +#ifndef LUMOS_PLATFORM_MACOS +#include "Precompiled.h" +#endif +#include "SamplingContext.h" + +namespace Lumos +{ + namespace Graphics + { + SamplingContext::SamplingContext() + { + } + + SamplingContext::SamplingContext(const SamplingContext& other) + : LocalTranslations(other.LocalTranslations) + , LocalScales(other.LocalScales) + , LocalRotations(other.LocalRotations) + , m_LocalSpaceSoaTransforms(other.m_LocalSpaceSoaTransforms) + { + m_Context.Resize(other.m_Context.max_tracks()); + } + + SamplingContext::~SamplingContext() + { + } + + SamplingContext& SamplingContext::operator=(const SamplingContext& other) + { + LocalTranslations = other.LocalTranslations; + LocalScales = other.LocalScales; + LocalRotations = other.LocalRotations; + m_LocalSpaceSoaTransforms = other.m_LocalSpaceSoaTransforms; + + m_Context.Resize(other.m_Context.max_tracks()); + return *this; + } + + void SamplingContext::resize(uint32_t size) + { + if(m_Size != size) + { + m_Size = size; + m_Context.Resize(size); + LocalTranslations.resize(size); + LocalScales.resize(size); + LocalRotations.resize(size); + } + } + + void SamplingContext::resizeSao(uint32_t size) + { + if(m_SaoSize != size) + { + m_SaoSize = size; + m_LocalSpaceSoaTransforms.resize(size); + } + } + } +} diff --git a/Lumos/Source/Lumos/Graphics/Animation/SamplingContext.h b/Lumos/Source/Lumos/Graphics/Animation/SamplingContext.h new file mode 100644 index 000000000..ed8ee3e1f --- /dev/null +++ b/Lumos/Source/Lumos/Graphics/Animation/SamplingContext.h @@ -0,0 +1,51 @@ +#pragma once +#include "Core/Reference.h" +#include "Utilities/TimeStep.h" +#include "Animation.h" + +#define GLM_ENABLE_EXPERIMENTAL +#include +#include + +#include +#include +#include +#include + +namespace Lumos +{ + namespace Graphics + { + class DescriptorSet; + + struct SamplingContext + { + SamplingContext(); + SamplingContext(const SamplingContext& other); + + ~SamplingContext(); + + SamplingContext& operator=(const SamplingContext& other); + + std::vector LocalTranslations; + std::vector LocalScales; + std::vector LocalRotations; + + ozz::vector& GetLocalTransforms() { return m_LocalSpaceSoaTransforms; } + const ozz::vector& GetLocalTransforms() const { return m_LocalSpaceSoaTransforms; } + + private: + void resize(uint32_t size); + void resizeSao(uint32_t size); + + private: + ozz::animation::SamplingJob::Context m_Context; + ozz::vector m_LocalSpaceSoaTransforms; + + uint32_t m_SaoSize = 0; + uint32_t m_Size = 0; + + friend class AnimationController; + }; + } +} \ No newline at end of file diff --git a/Lumos/Source/Lumos/Graphics/Animation/Skeleton.cpp b/Lumos/Source/Lumos/Graphics/Animation/Skeleton.cpp index d766ab96c..f6b52bbe2 100644 --- a/Lumos/Source/Lumos/Graphics/Animation/Skeleton.cpp +++ b/Lumos/Source/Lumos/Graphics/Animation/Skeleton.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Skeleton.h" #include diff --git a/Lumos/Source/Lumos/Graphics/Animation/Skeleton.h b/Lumos/Source/Lumos/Graphics/Animation/Skeleton.h index e8805440c..9c7fe0812 100644 --- a/Lumos/Source/Lumos/Graphics/Animation/Skeleton.h +++ b/Lumos/Source/Lumos/Graphics/Animation/Skeleton.h @@ -1,6 +1,6 @@ #pragma once -#include "Core/Asset.h" +#include "Core/Asset/Asset.h" #include namespace ozz diff --git a/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp b/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp index 7d23fd9ef..28e7504da 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp +++ b/Lumos/Source/Lumos/Graphics/Camera/Camera.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Camera.h" #include diff --git a/Lumos/Source/Lumos/Graphics/Camera/Camera2D.cpp b/Lumos/Source/Lumos/Graphics/Camera/Camera2D.cpp index 29705021c..a0780ef46 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/Camera2D.cpp +++ b/Lumos/Source/Lumos/Graphics/Camera/Camera2D.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Camera2D.h" #include "Core/OS/Input.h" #include "Maths/MathsUtilities.h" diff --git a/Lumos/Source/Lumos/Graphics/Camera/EditorCamera.cpp b/Lumos/Source/Lumos/Graphics/Camera/EditorCamera.cpp index 4956fb000..fe7a487db 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/EditorCamera.cpp +++ b/Lumos/Source/Lumos/Graphics/Camera/EditorCamera.cpp @@ -1,5 +1,9 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "EditorCamera.h" #include "Graphics/Camera/Camera.h" #include "Core/Application.h" diff --git a/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.cpp b/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.cpp index d34c3f95e..2a565f5e4 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.cpp +++ b/Lumos/Source/Lumos/Graphics/Camera/FPSCamera.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "FPSCamera.h" #include "Core/Application.h" #include "Core/OS/Input.h" diff --git a/Lumos/Source/Lumos/Graphics/Camera/ThirdPersonCamera.cpp b/Lumos/Source/Lumos/Graphics/Camera/ThirdPersonCamera.cpp index 11f3ca74a..f23ff8734 100644 --- a/Lumos/Source/Lumos/Graphics/Camera/ThirdPersonCamera.cpp +++ b/Lumos/Source/Lumos/Graphics/Camera/ThirdPersonCamera.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ThirdPersonCamera.h" #include "Core/OS/Input.h" #include "Camera.h" diff --git a/Lumos/Source/Lumos/Graphics/Environment.cpp b/Lumos/Source/Lumos/Graphics/Environment.cpp index 9ff61ea0f..c43a51972 100644 --- a/Lumos/Source/Lumos/Graphics/Environment.cpp +++ b/Lumos/Source/Lumos/Graphics/Environment.cpp @@ -1,7 +1,9 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Environment.h" #include "Core/Application.h" -#include "Renderers/RenderPasses.h" +#include "Renderers/SceneRenderer.h" #include "RHI/Texture.h" #include "Core/OS/FileSystem.h" #include "Utilities/StringUtilities.h" @@ -66,7 +68,7 @@ namespace Lumos if(m_FileType == ".hdr") { - Application::Get().GetRenderPasses()->CreateCubeMap(m_FilePath + "_Env_" + StringUtilities::ToString(0) + "_" + StringUtilities::ToString(currWidth) + "x" + StringUtilities::ToString(currHeight) + m_FileType, m_Parameters, m_Environmnet, m_IrradianceMap); + Application::Get().GetSceneRenderer()->CreateCubeMap(m_FilePath + "_Env_" + StringUtilities::ToString(0) + "_" + StringUtilities::ToString(currWidth) + "x" + StringUtilities::ToString(currHeight) + m_FileType, m_Parameters, m_Environmnet, m_IrradianceMap); delete[] envFiles; delete[] irrFiles; @@ -137,7 +139,7 @@ namespace Lumos else // if (m_Mode == 1) { m_Parameters.w = m_Mode; - Application::Get().GetRenderPasses()->CreateCubeMap("", m_Parameters, m_Environmnet, m_IrradianceMap); + Application::Get().GetSceneRenderer()->CreateCubeMap("", m_Parameters, m_Environmnet, m_IrradianceMap); } delete[] envFiles; diff --git a/Lumos/Source/Lumos/Graphics/Font.cpp b/Lumos/Source/Lumos/Graphics/Font.cpp index 0f019cb0f..b28690751 100644 --- a/Lumos/Source/Lumos/Graphics/Font.cpp +++ b/Lumos/Source/Lumos/Graphics/Font.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Font.h" #include "MSDFData.h" #include "Core/OS/FileSystem.h" @@ -16,6 +18,7 @@ #include #include #include +#include #define FONT_DEBUG_LOG 0 #if FONT_DEBUG_LOG @@ -133,6 +136,8 @@ namespace Lumos param.wrap = TextureWrap::CLAMP; param.generateMipMaps = false; param.flags = TextureFlags::Texture_Sampled; + param.anisotropicFiltering = false; + return SharedPtr(Texture2D::CreateFromSource(header.Width, header.Height, pixels, param)); } @@ -194,7 +199,6 @@ namespace Lumos fontInput.fontScale = -1; Configuration config = {}; - config.imageType = ImageType::MSDF; config.imageFormat = msdf_atlas::ImageFormat::BINARY_FLOAT; config.yDirection = YDirection::BOTTOM_UP; config.edgeColoring = msdfgen::edgeColoringInkTrap; @@ -209,7 +213,7 @@ namespace Lumos int fixedWidth = -1; int fixedHeight = -1; double minEmSize = 0; - double rangeValue = 2.0; + double rangeValue = 8.0; TightAtlasPacker::DimensionsConstraint atlasSizeConstraint = TightAtlasPacker::DimensionsConstraint::MULTIPLE_OF_FOUR_SQUARE; // Load fonts diff --git a/Lumos/Source/Lumos/Graphics/Font.h b/Lumos/Source/Lumos/Graphics/Font.h index bb3d7b8b9..4b9f1f334 100644 --- a/Lumos/Source/Lumos/Graphics/Font.h +++ b/Lumos/Source/Lumos/Graphics/Font.h @@ -1,5 +1,5 @@ #pragma once -#include "Core/Asset.h" +#include "Core/Asset/Asset.h" namespace Lumos { diff --git a/Lumos/Source/Lumos/Graphics/GBuffer.cpp b/Lumos/Source/Lumos/Graphics/GBuffer.cpp deleted file mode 100644 index 06a17a0b5..000000000 --- a/Lumos/Source/Lumos/Graphics/GBuffer.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "Precompiled.h" -#include "GBuffer.h" -#include "RHI/Framebuffer.h" -#include "RHI/Texture.h" - -namespace Lumos -{ - namespace Graphics - { - GBuffer::GBuffer(uint32_t width, uint32_t height) - : m_Width(width) - , m_Height(height) - { - Init(); - } - - GBuffer::~GBuffer() - { - for(auto& m_Texture : m_ScreenTex) - { - delete m_Texture; - } - - delete m_DepthTexture; - } - - void GBuffer::UpdateTextureSize(uint32_t width, uint32_t height) - { - m_Width = width; - m_Height = height; - - BuildTextures(); - } - - void GBuffer::Init() - { - for(auto& texture : m_ScreenTex) - { - texture = nullptr; - } - - m_DepthTexture = nullptr; - - BuildTextures(); - } - - void GBuffer::BuildTextures() - { - if(!m_ScreenTex[0]) - { - for(auto& m_Texture : m_ScreenTex) - { - // m_Texture = Texture2D::Create(); - } - - m_DepthTexture = TextureDepth::Create(m_Width, m_Height); - } - -#ifdef LUMOS_PLATFORM_IOS - // Unless all render targets were rgba32 there were visual glitches on ios - m_Formats[0] = RHIFormat::R32G32B32A32_Float; - m_Formats[1] = RHIFormat::R32G32B32A32_Float; - m_Formats[2] = RHIFormat::R32G32B32A32_Float; - m_Formats[3] = RHIFormat::R32G32B32A32_Float; - m_Formats[4] = RHIFormat::R32G32B32A32_Float; -#else - m_Formats[0] = RHIFormat::R8G8B8A8_Unorm; - m_Formats[1] = RHIFormat::R32G32B32A32_Float; - m_Formats[2] = RHIFormat::R16G16B16A16_Float; - m_Formats[3] = RHIFormat::R16G16B16A16_Float; - m_Formats[4] = RHIFormat::R8G8B8A8_Unorm; -#endif - /* - m_ScreenTex[SCREENTEX_COLOUR]->BuildTexture(m_Formats[0], m_Width, m_Height, false, false, false); - m_ScreenTex[SCREENTEX_POSITION]->BuildTexture(m_Formats[1], m_Width, m_Height, false, false, false); - m_ScreenTex[SCREENTEX_NORMALS]->BuildTexture(m_Formats[2], m_Width, m_Height, false, false, false); - m_ScreenTex[SCREENTEX_PBR]->BuildTexture(m_Formats[3], m_Width, m_Height, false, false, false); - m_ScreenTex[SCREENTEX_OFFSCREEN0]->BuildTexture(m_Formats[4], m_Width, m_Height, false, false, false); - */ - m_DepthTexture->Resize(m_Width, m_Height); - } - - void GBuffer::Bind(int32_t mode) - { - } - - void GBuffer::SetReadBuffer(ScreenTextures type) - { - } - } -} diff --git a/Lumos/Source/Lumos/Graphics/GBuffer.h b/Lumos/Source/Lumos/Graphics/GBuffer.h deleted file mode 100644 index 87798b67a..000000000 --- a/Lumos/Source/Lumos/Graphics/GBuffer.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once -#include "RHI/Definitions.h" - -namespace Lumos -{ - namespace Graphics - { - enum LUMOS_EXPORT ScreenTextures - { - SCREENTEX_COLOUR = 0, // Main Render - SCREENTEX_POSITION = 1, // Deferred Render - World Space Positions - SCREENTEX_NORMALS = 2, // Deferred Render - World Space Normals - SCREENTEX_PBR = 3, // Metallic/Roughness/Ao Stored Here - SCREENTEX_OFFSCREEN0 = 4, // Extra Textures for multipass post processing - SCREENTEX_OFFSCREEN1 = 5, // Or Displaying scene in editor mode - SCREENTEX_DEPTH = 6, // Depth Buffer - SCREENTEX_STENCIL = 7, // Stencil Buffer (Same Tex as Depth) - SCREENTEX_MAX - }; - - class LUMOS_EXPORT GBuffer - { - public: - GBuffer(uint32_t width, uint32_t height); - ~GBuffer(); - - void BuildTextures(); - - void Bind(int32_t mode = 0); - void UpdateTextureSize(uint32_t width, uint32_t height); - void SetReadBuffer(ScreenTextures type); - - inline uint32_t GetWidth() const { return m_Width; } - inline uint32_t GetHeight() const { return m_Height; } - - inline Texture2D* GetTexture(uint32_t index) const { return m_ScreenTex[index]; } - inline TextureDepth* GetDepthTexture() const { return m_DepthTexture; }; - inline RHIFormat GetFormat(uint32_t index) const { return m_Formats[index]; }; - - private: - void Init(); - - private: - Texture2D* m_ScreenTex[ScreenTextures::SCREENTEX_MAX] {}; - TextureDepth* m_DepthTexture {}; - RHIFormat m_Formats[ScreenTextures::SCREENTEX_MAX]; - uint32_t m_Width, m_Height; - }; - } -} diff --git a/Lumos/Source/Lumos/Graphics/Light.cpp b/Lumos/Source/Lumos/Graphics/Light.cpp index f15bdbc6b..066ef3725 100644 --- a/Lumos/Source/Lumos/Graphics/Light.cpp +++ b/Lumos/Source/Lumos/Graphics/Light.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Light.h" #include "ImGui/ImGuiUtilities.h" diff --git a/Lumos/Source/Lumos/Graphics/Material.cpp b/Lumos/Source/Lumos/Graphics/Material.cpp index c7e9969a9..f0f50b35c 100644 --- a/Lumos/Source/Lumos/Graphics/Material.cpp +++ b/Lumos/Source/Lumos/Graphics/Material.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Material.h" #include "Graphics/RHI/Shader.h" #include "Graphics/RHI/Texture.h" @@ -10,7 +12,7 @@ #include "Core/OS/FileSystem.h" #include "Core/Application.h" #include "Scene/Scene.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" #include diff --git a/Lumos/Source/Lumos/Graphics/Mesh.cpp b/Lumos/Source/Lumos/Graphics/Mesh.cpp index 6a3bfe03f..9c6b2854c 100644 --- a/Lumos/Source/Lumos/Graphics/Mesh.cpp +++ b/Lumos/Source/Lumos/Graphics/Mesh.cpp @@ -1,10 +1,15 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Mesh.h" #include "RHI/Renderer.h" +#include "RHI/VertexBuffer.h" +#include "RHI/IndexBuffer.h" #include "Scene/Serialisation/SerialisationImplementation.h" #include "Core/OS/FileSystem.h" -#include +#include "Maths/MathsUtilities.h" +#include #include #include @@ -158,7 +163,7 @@ namespace Lumos else { // It's just a list of triangles, so generate face normals - for(uint32_t i = 0; i < vertexCount; i += 3) + for(uint32_t i = 0; i < vertexCount - 3; i += 3) { glm::vec3& a = vertices[i].Position; glm::vec3& b = vertices[i + 1].Position; @@ -290,7 +295,7 @@ namespace Lumos else { // It's just a list of triangles, so generate face normals - for(uint32_t i = 0; i < numVertices; i += 3) + for(uint32_t i = 0; i < numVertices - 3; i += 3) { glm::vec3& a = vertices[i]; glm::vec3& b = vertices[i + 1]; @@ -369,6 +374,11 @@ namespace Lumos } } + void Mesh::SetMaterial(const SharedPtr& material) + { + m_Material = material; + } + void Mesh::SetAndLoadMaterial(const std::string& filePath) { std::string data = FileSystem::Get().ReadTextFileVFS(filePath); diff --git a/Lumos/Source/Lumos/Graphics/Mesh.h b/Lumos/Source/Lumos/Graphics/Mesh.h index 3372d76b2..34d3c4ac6 100644 --- a/Lumos/Source/Lumos/Graphics/Mesh.h +++ b/Lumos/Source/Lumos/Graphics/Mesh.h @@ -1,17 +1,17 @@ #pragma once -#include "RHI/IndexBuffer.h" -#include "RHI/VertexBuffer.h" -#include "Graphics/RHI/CommandBuffer.h" -#include "Graphics/RHI/DescriptorSet.h" -#include "Maths/BoundingBox.h" -#include "Material.h" - namespace Lumos { + namespace Maths + { + class BoundingBox; + } namespace Graphics { class Texture2D; + class Material; + class VertexBuffer; + class IndexBuffer; struct LUMOS_EXPORT BasicVertex { @@ -144,7 +144,7 @@ namespace Lumos const SharedPtr& GetMaterial() const { return m_Material; } const SharedPtr& GetBoundingBox() const { return m_BoundingBox; } - void SetMaterial(const SharedPtr& material) { m_Material = material; } + void SetMaterial(const SharedPtr& material); void SetAndLoadMaterial(const std::string& filePath); bool& GetActive() { return m_Active; } diff --git a/Lumos/Source/Lumos/Graphics/MeshFactory.cpp b/Lumos/Source/Lumos/Graphics/MeshFactory.cpp index ebbb12f91..7ad5e521c 100644 --- a/Lumos/Source/Lumos/Graphics/MeshFactory.cpp +++ b/Lumos/Source/Lumos/Graphics/MeshFactory.cpp @@ -1,9 +1,11 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "MeshFactory.h" #include "Mesh.h" #include "Material.h" #include "Terrain.h" - +#include "Maths/MathsUtilities.h" #include "Graphics/RHI/GraphicsContext.h" #include diff --git a/Lumos/Source/Lumos/Graphics/Model.cpp b/Lumos/Source/Lumos/Graphics/Model.cpp index f0dadee59..a08c5cc55 100644 --- a/Lumos/Source/Lumos/Graphics/Model.cpp +++ b/Lumos/Source/Lumos/Graphics/Model.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Model.h" #include "Mesh.h" #include "Material.h" @@ -7,6 +9,7 @@ #include "Animation/Skeleton.h" #include "Animation/Animation.h" #include "Animation/AnimationController.h" +#include "Animation/SamplingContext.h" #include "AI/AStar.h" namespace Lumos::Graphics @@ -91,7 +94,7 @@ namespace Lumos::Graphics { m_AnimationController->AddState(anim->GetName(), anim); } - m_AnimationController->m_BindPoses = m_BindPoses; + m_AnimationController->SetBindPoses(m_BindPoses); } static float time = 0.0f; @@ -118,7 +121,7 @@ namespace Lumos::Graphics { m_AnimationController->AddState(anim->GetName(), anim); } - m_AnimationController->m_BindPoses = m_BindPoses; + m_AnimationController->SetBindPoses(m_BindPoses); } m_AnimationController->SetCurrentState(m_CurrentAnimation); diff --git a/Lumos/Source/Lumos/Graphics/Model.h b/Lumos/Source/Lumos/Graphics/Model.h index 4b024d110..56f9839d2 100644 --- a/Lumos/Source/Lumos/Graphics/Model.h +++ b/Lumos/Source/Lumos/Graphics/Model.h @@ -1,6 +1,6 @@ #pragma once #include "MeshFactory.h" -#include "Core/Asset.h" +#include "Core/Asset/Asset.h" #include "Utilities/TimeStep.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/ModelLoader/FBXLoader.cpp b/Lumos/Source/Lumos/Graphics/ModelLoader/FBXLoader.cpp index f9915b6a3..4e9c2eb96 100644 --- a/Lumos/Source/Lumos/Graphics/ModelLoader/FBXLoader.cpp +++ b/Lumos/Source/Lumos/Graphics/ModelLoader/FBXLoader.cpp @@ -1,13 +1,16 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Graphics/Model.h" #include "Graphics/Mesh.h" #include "Graphics/Material.h" #include "Core/OS/FileSystem.h" #include "Graphics/RHI/Texture.h" #include "Maths/Transform.h" +#include "Maths/MathsUtilities.h" #include "Core/Application.h" #include "Utilities/StringUtilities.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" #include diff --git a/Lumos/Source/Lumos/Graphics/ModelLoader/GLTFLoader.cpp b/Lumos/Source/Lumos/Graphics/ModelLoader/GLTFLoader.cpp index 40e9ce796..4f64b6d30 100644 --- a/Lumos/Source/Lumos/Graphics/ModelLoader/GLTFLoader.cpp +++ b/Lumos/Source/Lumos/Graphics/ModelLoader/GLTFLoader.cpp @@ -3,7 +3,9 @@ #undef __OPTIMIZE__ #endif +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Graphics/Model.h" #include "Graphics/Mesh.h" #include "Graphics/Material.h" @@ -16,7 +18,8 @@ #include "Maths/Transform.h" #include "Core/Application.h" #include "Utilities/StringUtilities.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" +#include "Maths/MathsUtilities.h" #define TINYGLTF_IMPLEMENTATION #define TINYGLTF_USE_CPP14 diff --git a/Lumos/Source/Lumos/Graphics/ModelLoader/OBJLoader.cpp b/Lumos/Source/Lumos/Graphics/ModelLoader/OBJLoader.cpp index ab481a522..c3b7d2de2 100644 --- a/Lumos/Source/Lumos/Graphics/ModelLoader/OBJLoader.cpp +++ b/Lumos/Source/Lumos/Graphics/ModelLoader/OBJLoader.cpp @@ -1,12 +1,15 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Graphics/Model.h" #include "Graphics/Mesh.h" #include "Graphics/Material.h" #include "Maths/Transform.h" +#include "Maths/BoundingBox.h" #include "Graphics/RHI/Texture.h" #include "Utilities/StringUtilities.h" #include "Core/Application.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" #define TINYOBJLOADER_IMPLEMENTATION #include @@ -112,13 +115,13 @@ namespace Lumos vertex.Colours = colour; - /* if(uniqueVertices.count(vertex) == 0) - { - uniqueVertices[vertex] = static_cast(vertexCount);*/ - vertices[vertexCount] = vertex; - //} + /* if(uniqueVertices.count(vertex) == 0) + { + uniqueVertices[vertex] = static_cast(vertexCount);*/ + vertices[vertexCount] = vertex; + //} - indices[vertexCount] = vertexCount;// uniqueVertices[vertex]; + indices[vertexCount] = vertexCount; // uniqueVertices[vertex]; vertexCount++; } diff --git a/Lumos/Source/Lumos/Graphics/ParticleManager.cpp b/Lumos/Source/Lumos/Graphics/ParticleManager.cpp index f81347a33..963efe67b 100644 --- a/Lumos/Source/Lumos/Graphics/ParticleManager.cpp +++ b/Lumos/Source/Lumos/Graphics/ParticleManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ParticleManager.h" #include "Maths/Random.h" #include "Maths/MathsUtilities.h" diff --git a/Lumos/Source/Lumos/Graphics/RHI/BufferLayout.cpp b/Lumos/Source/Lumos/Graphics/RHI/BufferLayout.cpp index 490a89b38..e7fa89812 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/BufferLayout.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/BufferLayout.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "BufferLayout.h" #include "GraphicsContext.h" diff --git a/Lumos/Source/Lumos/Graphics/RHI/CommandBuffer.cpp b/Lumos/Source/Lumos/Graphics/RHI/CommandBuffer.cpp index 333d3a1cc..cd3452df5 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/CommandBuffer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/CommandBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "CommandBuffer.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/RHI/Definitions.h b/Lumos/Source/Lumos/Graphics/RHI/Definitions.h index c3fe107c0..c4f520d2f 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Definitions.h +++ b/Lumos/Source/Lumos/Graphics/RHI/Definitions.h @@ -54,6 +54,7 @@ namespace Lumos None = 0, OneZero, ZeroSrcColor, + OneMinusSrcAlpha, SrcAlphaOneMinusSrcAlpha, SrcAlphaOne }; diff --git a/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.cpp b/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.cpp index 1df9435b8..ea247d2c6 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/DescriptorSet.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "DescriptorSet.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.cpp b/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.cpp index 20a34ceef..90b0fad68 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/Framebuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Framebuffer.h" #include "Texture.h" #include "Graphics/RHI/GraphicsContext.h" diff --git a/Lumos/Source/Lumos/Graphics/RHI/GraphicsContext.cpp b/Lumos/Source/Lumos/Graphics/RHI/GraphicsContext.cpp index aeabb3824..0eaa837ef 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/GraphicsContext.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/GraphicsContext.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GraphicsContext.h" #ifdef LUMOS_RENDER_API_OPENGL diff --git a/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp b/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp index c349a8667..1196c0bd4 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/IMGUIRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "IMGUIRenderer.h" #include "GraphicsContext.h" #include "Graphics/RHI/Texture.h" @@ -31,7 +33,7 @@ namespace Lumos if(Graphics::GraphicsContext::GetRenderAPI() == RenderAPI::OPENGL) return (ImGuiTextureID*)texture->GetHandle(); - if(m_CurrentTextureIDIndex > MAX_IMGUI_TEXTURES) + if(m_CurrentTextureIDIndex >= MAX_IMGUI_TEXTURES) { LUMOS_LOG_ERROR("Exceeded max imgui textures"); return &m_TextureIDs[0]; diff --git a/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.cpp b/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.cpp index 0112be48f..6eb22c7a7 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/IndexBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "IndexBuffer.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/RHI/Pipeline.cpp b/Lumos/Source/Lumos/Graphics/RHI/Pipeline.cpp index efde9506e..d89292b06 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Pipeline.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/Pipeline.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Pipeline.h" #include "Core/Engine.h" #include "SwapChain.h" diff --git a/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.cpp b/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.cpp index 555a87a88..50f92bec5 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/RenderDevice.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "RenderDevice.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/RHI/RenderPass.cpp b/Lumos/Source/Lumos/Graphics/RHI/RenderPass.cpp index 1bd3181ac..30622d974 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/RenderPass.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/RenderPass.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "RenderPass.h" #include "Core/Engine.h" #include "Utilities/CombineHash.h" diff --git a/Lumos/Source/Lumos/Graphics/RHI/Renderer.cpp b/Lumos/Source/Lumos/Graphics/RHI/Renderer.cpp index 3e5e1d011..d748828ec 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Renderer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/Renderer.cpp @@ -1,11 +1,15 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Renderer.h" #include "Graphics/Mesh.h" #include "Core/Application.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" #include "Core/OS/Window.h" +#include "IndexBuffer.h" +#include "VertexBuffer.h" #include "CompiledSPV/Headers/Shadowvertspv.hpp" #include "CompiledSPV/Headers/Shadowfragspv.hpp" @@ -96,7 +100,7 @@ namespace Lumos LUMOS_LOG_INFO("Loading shaders - embedded"); LoadShaderEmbedded("Skybox", Skybox, Skybox); LoadShaderEmbedded("ForwardPBR", ForwardPBR, ForwardPBR); - LoadShaderEmbedded("ForwardPBRAnim", ForwardPBRAnim, ForwardPBR); + LoadShaderEmbedded("ForwardPBRAnim", ForwardPBRAnim, ForwardPBR); LoadShaderEmbedded("Shadow", Shadow, Shadow); LoadShaderEmbedded("ShadowAlpha", Shadow, ShadowAlpha); LoadShaderEmbedded("ShadowAnim", ShadowAnim, Shadow); diff --git a/Lumos/Source/Lumos/Graphics/RHI/Shader.cpp b/Lumos/Source/Lumos/Graphics/RHI/Shader.cpp index 93d76017f..9da5e0cc2 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Shader.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/Shader.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Shader.h" #include "Graphics/RHI/GraphicsContext.h" diff --git a/Lumos/Source/Lumos/Graphics/RHI/Shader.h b/Lumos/Source/Lumos/Graphics/RHI/Shader.h index 351d2a85e..cae20c976 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Shader.h +++ b/Lumos/Source/Lumos/Graphics/RHI/Shader.h @@ -1,7 +1,7 @@ #pragma once #include "Definitions.h" #include "Core/Profiler.h" -#include "Core/Asset.h" +#include "Core/Asset/Asset.h" namespace spirv_cross { diff --git a/Lumos/Source/Lumos/Graphics/RHI/SwapChain.cpp b/Lumos/Source/Lumos/Graphics/RHI/SwapChain.cpp index d6fa20e4a..38de221a9 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/SwapChain.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/SwapChain.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SwapChain.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/RHI/Texture.cpp b/Lumos/Source/Lumos/Graphics/RHI/Texture.cpp index 179e218fa..e7ca55c0a 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Texture.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/Texture.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Texture.h" #include "Utilities/LoadImage.h" diff --git a/Lumos/Source/Lumos/Graphics/RHI/Texture.h b/Lumos/Source/Lumos/Graphics/RHI/Texture.h index 13d034e0e..1b064703a 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/Texture.h +++ b/Lumos/Source/Lumos/Graphics/RHI/Texture.h @@ -1,6 +1,6 @@ #pragma once #include "Definitions.h" -#include "Core/Asset.h" +#include "Core/Asset/Asset.h" namespace Lumos { diff --git a/Lumos/Source/Lumos/Graphics/RHI/UniformBuffer.cpp b/Lumos/Source/Lumos/Graphics/RHI/UniformBuffer.cpp index 3cebfe793..f0900579b 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/UniformBuffer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/UniformBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "UniformBuffer.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/RHI/VertexBuffer.cpp b/Lumos/Source/Lumos/Graphics/RHI/VertexBuffer.cpp index 22aaa1fb3..7f83778bf 100644 --- a/Lumos/Source/Lumos/Graphics/RHI/VertexBuffer.cpp +++ b/Lumos/Source/Lumos/Graphics/RHI/VertexBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VertexBuffer.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Graphics/Renderable2D.cpp b/Lumos/Source/Lumos/Graphics/Renderable2D.cpp index 3ad0649c7..3e450180e 100644 --- a/Lumos/Source/Lumos/Graphics/Renderable2D.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderable2D.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Renderable2D.h" #include diff --git a/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.cpp b/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.cpp index 55617b363..d36284310 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "DebugRenderer.h" #include "Core/OS/Window.h" #include "Graphics/RHI/Shader.h" @@ -11,13 +13,12 @@ #include "Graphics/RHI/Pipeline.h" #include "Graphics/RHI/IndexBuffer.h" #include "Graphics/RHI/Texture.h" -#include "Graphics/GBuffer.h" #include "Graphics/Sprite.h" #include "Graphics/Light.h" #include "Graphics/Camera/Camera.h" #include "Scene/Scene.h" #include "Core/Application.h" -#include "RenderPasses.h" +#include "SceneRenderer.h" #include "Platform/OpenGL/GLDescriptorSet.h" #include "Graphics/Renderable2D.h" #include "Graphics/Camera/Camera.h" @@ -26,6 +27,7 @@ #include "Maths/BoundingBox.h" #include "Maths/BoundingSphere.h" #include "Maths/Ray.h" +#include "Maths/MathsUtilities.h" #include "Audio/SoundNode.h" #include #include diff --git a/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.h b/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.h index 57193691c..d0971ad04 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.h +++ b/Lumos/Source/Lumos/Graphics/Renderers/DebugRenderer.h @@ -114,7 +114,7 @@ namespace Lumos { friend class Scene; friend class Application; - friend class RenderPasses; + friend class SceneRenderer; public: static void Init(); diff --git a/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp b/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp index 39c6a1b68..0c647f083 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/GridRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GridRenderer.h" #include "Graphics/RHI/Shader.h" #include "Graphics/RHI/Framebuffer.h" @@ -10,7 +12,8 @@ #include "Graphics/RHI/RenderPass.h" #include "Graphics/RHI/Pipeline.h" #include "Graphics/RHI/GraphicsContext.h" -#include "Graphics/GBuffer.h" +#include "Graphics/RHI/IndexBuffer.h" +#include "Graphics/RHI/VertexBuffer.h" #include "Graphics/Mesh.h" #include "Graphics/MeshFactory.h" #include "Scene/Scene.h" @@ -18,8 +21,8 @@ #include "Graphics/RHI/GPUProfile.h" #include "Graphics/Camera/Camera.h" #include "Maths/Transform.h" -#include "Graphics/Renderers/RenderPasses.h" -#include "Utilities/AssetManager.h" +#include "Graphics/Renderers/SceneRenderer.h" +#include "Core/Asset/AssetManager.h" #include #include @@ -192,7 +195,7 @@ namespace Lumos if(m_DepthTexture && m_DepthTexture->GetSamples() == 1) { - pipelineDesc.depthTarget = reinterpret_cast(m_DepthTexture); // reinterpret_cast(Application::Get().GetRenderPasses()->GetDepthTexture()); + pipelineDesc.depthTarget = reinterpret_cast(m_DepthTexture); // reinterpret_cast(Application::Get().GetSceneRenderer()->GetDepthTexture()); } if(m_RenderTexture) diff --git a/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.cpp b/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.cpp index ccb36292c..f085f8f34 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/IRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "IRenderer.h" // #include "Graphics/RHI/Shader.h" diff --git a/Lumos/Source/Lumos/Graphics/Renderers/RenderCommand.h b/Lumos/Source/Lumos/Graphics/Renderers/RenderCommand.h index 76cdfdbf5..1c10f761a 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/RenderCommand.h +++ b/Lumos/Source/Lumos/Graphics/Renderers/RenderCommand.h @@ -1,13 +1,11 @@ #pragma once -#include "Graphics/Mesh.h" -#include "Graphics/RHI/Shader.h" - namespace Lumos { namespace Graphics { + class Mesh; class Material; class Pipeline; class DescriptorSet; diff --git a/Lumos/Source/Lumos/Graphics/Renderers/RenderPasses.cpp b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp similarity index 96% rename from Lumos/Source/Lumos/Graphics/Renderers/RenderPasses.cpp rename to Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp index 7f20b80dd..c875bf78c 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/RenderPasses.cpp +++ b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.cpp @@ -1,5 +1,7 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" -#include "RenderPasses.h" +#endif +#include "SceneRenderer.h" #include "Scene/Entity.h" #include "Scene/Component/ModelComponent.h" #include "Graphics/Model.h" @@ -9,9 +11,13 @@ #include "Graphics/Light.h" #include "Graphics/Camera/Camera.h" #include "Graphics/Environment.h" +#include "Graphics/Material.h" +#include "Graphics/Mesh.h" #include "Graphics/Sprite.h" #include "Graphics/AnimatedSprite.h" #include "Graphics/RHI/GPUProfile.h" +#include "Graphics/RHI/VertexBuffer.h" +#include "Graphics/RHI/IndexBuffer.h" #include "Graphics/Font.h" #include "Graphics/MSDFData.h" #include "Graphics/ParticleManager.h" @@ -19,12 +25,14 @@ #include "Core/JobSystem.h" #include "Core/OS/Window.h" #include "Maths/BoundingSphere.h" - +#include "Maths/BoundingBox.h" +#include "Maths/Rect.h" +#include "Maths/MathsUtilities.h" #include "Events/ApplicationEvent.h" #include "Embedded/BRDFTexture.inl" #include "Embedded/CheckerBoardTextureArray.inl" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" #include "Core/Application.h" #include "Scene/Component/Components.h" #include "Maths/Random.h" @@ -52,7 +60,7 @@ static const uint32_t RENDERER_LINE_BUFFER_SIZE = RENDERER_LINE_SIZE * MaxLineVe namespace Lumos::Graphics { - RenderPasses::RenderPasses(uint32_t width, uint32_t height) + SceneRenderer::SceneRenderer(uint32_t width, uint32_t height) { LUMOS_PROFILE_FUNCTION(); m_CubeMap = nullptr; @@ -362,7 +370,7 @@ namespace Lumos::Graphics { m_Renderer2DData.m_PreviousFrameTextureCount[i] = 0; m_Renderer2DData.m_DescriptorSet[i].resize(2); - if(i == 0) + // if(i == 0) { descriptorDesc.layoutIndex = 0; m_Renderer2DData.m_DescriptorSet[0][0] = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); @@ -511,10 +519,10 @@ namespace Lumos::Graphics { m_TextRendererData.m_PreviousFrameTextureCount[i] = 0; m_TextRendererData.m_DescriptorSet[i].resize(2); - if(i == 0) + // if(i == 0) { descriptorDesc.layoutIndex = 0; - m_TextRendererData.m_DescriptorSet[0][0] = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); + m_TextRendererData.m_DescriptorSet[i][0] = SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); } descriptorDesc.layoutIndex = 1; m_TextRendererData.m_DescriptorSet[i][1] = nullptr; // SharedPtr(Graphics::DescriptorSet::Create(descriptorDesc)); @@ -553,7 +561,7 @@ namespace Lumos::Graphics InitDebugRenderData(); } - RenderPasses::~RenderPasses() + SceneRenderer::~SceneRenderer() { Memory::AlignedFree(m_ForwardData.m_TransformData); @@ -655,7 +663,7 @@ namespace Lumos::Graphics DebugRenderer::Release(); } - void RenderPasses::OnResize(uint32_t width, uint32_t height) + void SceneRenderer::OnResize(uint32_t width, uint32_t height) { LUMOS_PROFILE_FUNCTION(); @@ -678,7 +686,7 @@ namespace Lumos::Graphics m_NormalTexture->Resize(width, height); } - void RenderPasses::EnableDebugRenderer(bool enable) + void SceneRenderer::EnableDebugRenderer(bool enable) { m_DebugRenderEnabled = enable; @@ -691,7 +699,7 @@ namespace Lumos::Graphics DebugRenderer::Release(); } - void RenderPasses::BeginScene(Scene* scene) + void SceneRenderer::BeginScene(Scene* scene) { LUMOS_PROFILE_FUNCTION(); auto& registry = scene->GetRegistry(); @@ -875,7 +883,7 @@ namespace Lumos::Graphics { auto inside = m_ForwardData.m_Frustum.IsInside(Maths::BoundingSphere(glm::vec3(light.Position), light.Radius * 100)); - if(inside == Intersection::OUTSIDE) + if(inside == Maths::Intersection::OUTSIDE) continue; } @@ -1170,13 +1178,13 @@ namespace Lumos::Graphics } } - void RenderPasses::SetRenderTarget(Graphics::Texture* texture, bool onlyIfTargetsScreen, bool rebuildFramebuffer) + void SceneRenderer::SetRenderTarget(Graphics::Texture* texture, bool onlyIfTargetsScreen, bool rebuildFramebuffer) { LUMOS_PROFILE_FUNCTION(); m_ForwardData.m_RenderTexture = texture; } - void RenderPasses::OnRender() + void SceneRenderer::OnRender() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Render Passes"); @@ -1235,16 +1243,11 @@ namespace Lumos::Graphics if(sceneRenderSettings.Renderer2DEnabled) Render2DPass(); - TextPass(); - if(m_DebugRenderEnabled && sceneRenderSettings.DebugRenderEnabled) DebugPass(); m_LastRenderTarget = m_MainTextureSamples > 1 ? m_ResolveTexture : m_MainTexture; - // if (sceneRenderSettings.EyeAdaptation) - // EyeAdaptationPass(); - if(sceneRenderSettings.DepthOfFieldEnabled && !m_DisablePostProcess) DepthOfFieldPass(); @@ -1268,28 +1271,27 @@ namespace Lumos::Graphics if(sceneRenderSettings.FilmicGrainEnabled && !m_DisablePostProcess) FilmicGrainPass(); - // if(sceneRenderSettings.OutlineEnabled - // OutlinePass(); + TextPass(); FinalPass(); } - void RenderPasses::OnUpdate(const TimeStep& timeStep, Scene* scene) + void SceneRenderer::OnUpdate(const TimeStep& timeStep, Scene* scene) { } - bool RenderPasses::OnWindowResizeEvent(WindowResizeEvent& e) + bool SceneRenderer::OnWindowResizeEvent(WindowResizeEvent& e) { LUMOS_PROFILE_FUNCTION(); return false; } - void RenderPasses::OnEvent(Event& e) + void SceneRenderer::OnEvent(Event& e) { LUMOS_PROFILE_FUNCTION(); // EventDispatcher dispatcher(e); - // dispatcher.Dispatch(BIND_EVENT_FN(RenderPasses::OnwindowResizeEvent)); + // dispatcher.Dispatch(BIND_EVENT_FN(SceneRenderer::OnwindowResizeEvent)); } std::string RenderModeToString(int mode) @@ -1317,7 +1319,7 @@ namespace Lumos::Graphics } } - void RenderPasses::OnImGui() + void SceneRenderer::OnImGui() { LUMOS_PROFILE_FUNCTION(); @@ -1399,7 +1401,7 @@ namespace Lumos::Graphics ImGui::PopStyleVar(); } - void RenderPasses::OnNewScene(Scene* scene) + void SceneRenderer::OnNewScene(Scene* scene) { m_ForwardData.m_EnvironmentMap = m_DefaultTextureCube; m_ForwardData.m_IrradianceMap = m_DefaultTextureCube; @@ -1427,7 +1429,7 @@ namespace Lumos::Graphics return result; } - void RenderPasses::UpdateCascades(Scene* scene, Light* light) + void SceneRenderer::UpdateCascades(Scene* scene, Light* light) { LUMOS_PROFILE_FUNCTION(); float cascadeSplits[SHADOWMAP_MAX]; @@ -1551,7 +1553,7 @@ namespace Lumos::Graphics } } - void RenderPasses::GenerateBRDFLUTPass() + void SceneRenderer::GenerateBRDFLUTPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("BRDF Pass"); @@ -1578,7 +1580,7 @@ namespace Lumos::Graphics commandBuffer->UnBindPipeline(); } - void RenderPasses::ShadowPass() + void SceneRenderer::ShadowPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Shadow Pass"); @@ -1652,7 +1654,7 @@ namespace Lumos::Graphics } } - void RenderPasses::DepthPrePass() + void SceneRenderer::DepthPrePass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Depth Pre Pass"); @@ -1707,7 +1709,7 @@ namespace Lumos::Graphics } } - void RenderPasses::SSAOPass() + void SceneRenderer::SSAOPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("SSAO Pass"); @@ -1775,7 +1777,7 @@ namespace Lumos::Graphics Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); } - void RenderPasses::SSAOBlurPass() + void SceneRenderer::SSAOBlurPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("SSAO Blur Pass"); @@ -1837,7 +1839,7 @@ namespace Lumos::Graphics Renderer::Draw(commandBuffer, DrawType::TRIANGLE, 3); } - void RenderPasses::ForwardPass() + void SceneRenderer::ForwardPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Forward Pass"); @@ -1877,7 +1879,7 @@ namespace Lumos::Graphics } } - void RenderPasses::SkyboxPass() + void SceneRenderer::SkyboxPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("SkyBox Pass"); @@ -1922,7 +1924,7 @@ namespace Lumos::Graphics Renderer::DrawMesh(commandBuffer, pipeline.get(), m_ScreenQuad); } - void RenderPasses::DepthOfFieldPass() + void SceneRenderer::DepthOfFieldPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Depth Of Field Pass"); @@ -1974,7 +1976,7 @@ namespace Lumos::Graphics std::swap(m_LastRenderTarget, m_PostProcessTexture1); } - void RenderPasses::SharpenPass() + void SceneRenderer::SharpenPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Sharpen Pass"); @@ -2005,7 +2007,7 @@ namespace Lumos::Graphics std::swap(m_PostProcessTexture1, m_LastRenderTarget); } - void RenderPasses::ToneMappingPass() + void SceneRenderer::ToneMappingPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Tone Mapping Pass"); @@ -2045,7 +2047,7 @@ namespace Lumos::Graphics std::swap(m_PostProcessTexture1, m_LastRenderTarget); } - void RenderPasses::FinalPass() + void SceneRenderer::FinalPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Final Pass"); @@ -2112,7 +2114,7 @@ namespace Lumos::Graphics commandBuffer->EndCurrentRenderPass(); } - void RenderPasses::BloomPass() + void SceneRenderer::BloomPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Bloom Pass"); @@ -2478,7 +2480,7 @@ namespace Lumos::Graphics } } - void RenderPasses::FXAAPass() + void SceneRenderer::FXAAPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("FXAA Pass"); @@ -2530,7 +2532,7 @@ namespace Lumos::Graphics std::swap(m_PostProcessTexture1, m_LastRenderTarget); } - void RenderPasses::DebandingPass() + void SceneRenderer::DebandingPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Debanding Pass"); @@ -2561,7 +2563,7 @@ namespace Lumos::Graphics std::swap(m_PostProcessTexture1, m_LastRenderTarget); } - void RenderPasses::FilmicGrainPass() + void SceneRenderer::FilmicGrainPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Filmic Grain Pass"); @@ -2603,7 +2605,7 @@ namespace Lumos::Graphics std::swap(m_PostProcessTexture1, m_LastRenderTarget); } - void RenderPasses::OutlinePass() + void SceneRenderer::OutlinePass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Outline Pass"); @@ -2634,7 +2636,7 @@ namespace Lumos::Graphics std::swap(m_PostProcessTexture1, m_LastRenderTarget); } - void RenderPasses::ChromaticAberationPass() + void SceneRenderer::ChromaticAberationPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("ChromaticAberation Pass"); @@ -2668,11 +2670,11 @@ namespace Lumos::Graphics std::swap(m_PostProcessTexture1, m_LastRenderTarget); } - void RenderPasses::EyeAdaptationPass() + void SceneRenderer::EyeAdaptationPass() { } - float RenderPasses::SubmitTexture(Texture* texture) + float SceneRenderer::SubmitTexture(Texture* texture) { LUMOS_PROFILE_FUNCTION_LOW(); float result = 0.0f; @@ -2702,7 +2704,7 @@ namespace Lumos::Graphics return result; } - void RenderPasses::Render2DPass() + void SceneRenderer::Render2DPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Render2D Pass"); @@ -2799,7 +2801,7 @@ namespace Lumos::Graphics Render2DFlush(); } - void RenderPasses::Renderer2DBeginBatch() + void SceneRenderer::Renderer2DBeginBatch() { uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); @@ -2818,7 +2820,7 @@ namespace Lumos::Graphics m_Renderer2DData.m_Buffer = m_2DBufferBase[currentFrame][m_Renderer2DData.m_BatchDrawCallIndex]; } - void RenderPasses::Render2DFlush() + void SceneRenderer::Render2DFlush() { LUMOS_PROFILE_FUNCTION(); uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); @@ -2829,7 +2831,7 @@ namespace Lumos::Graphics m_Renderer2DData.m_VertexBuffers[currentFrame][m_Renderer2DData.m_BatchDrawCallIndex]->SetData(dataSize, (void*)m_2DBufferBase[currentFrame][m_Renderer2DData.m_BatchDrawCallIndex], true); commandBuffer->BindPipeline(m_Renderer2DData.m_Pipeline); - if(m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1] == nullptr || m_Renderer2DData.m_TextureCount != m_Renderer2DData.m_PreviousFrameTextureCount[m_Renderer2DData.m_BatchDrawCallIndex]) + if(m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1] == nullptr /*|| m_Renderer2DData.m_TextureCount != m_Renderer2DData.m_PreviousFrameTextureCount[m_Renderer2DData.m_BatchDrawCallIndex]*/) { /* || m_Renderer2DData.m_TextureCount != m_Renderer2DData.m_PreviousFrameTextureCount[m_Renderer2DData.m_BatchDrawCallIndex]) @@ -2864,7 +2866,7 @@ namespace Lumos::Graphics Arena* frameArena = Application::Get().GetFrameArena(); DescriptorSet** currentDescriptors = PushArrayNoZero(frameArena, DescriptorSet*, 2); - currentDescriptors[0] = m_Renderer2DData.m_DescriptorSet[0][0].get(); + currentDescriptors[0] = m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0].get(); currentDescriptors[1] = m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][1].get(); m_Renderer2DData.m_IndexBuffer->SetCount(m_Renderer2DData.m_IndexCount); @@ -2880,7 +2882,7 @@ namespace Lumos::Graphics m_Renderer2DData.m_TextureCount = 0; } - void RenderPasses::TextFlush(Renderer2DData& textRenderData, std::vector& textVertexBufferBase, TextVertexData*& textVertexBufferPtr) + void SceneRenderer::TextFlush(Renderer2DData& textRenderData, std::vector& textVertexBufferBase, TextVertexData*& textVertexBufferPtr) { LUMOS_PROFILE_FUNCTION(); uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); @@ -2935,7 +2937,7 @@ namespace Lumos::Graphics Arena* frameArena = Application::Get().GetFrameArena(); DescriptorSet** currentDescriptors = PushArrayNoZero(frameArena, DescriptorSet*, 2); - currentDescriptors[0] = textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][0].get(); + currentDescriptors[0] = textRenderData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0].get(); currentDescriptors[1] = textRenderData.m_DescriptorSet[textRenderData.m_BatchDrawCallIndex][1].get(); textRenderData.m_VertexBuffers[currentFrame][textRenderData.m_BatchDrawCallIndex]->Bind(Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(), textRenderData.m_Pipeline.get()); @@ -2956,7 +2958,7 @@ namespace Lumos::Graphics textRenderData.m_TextureCount = 0; } - void RenderPasses::TextPass() + void SceneRenderer::TextPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Text Pass"); @@ -2975,12 +2977,12 @@ namespace Lumos::Graphics pipelineDesc.transparencyEnabled = true; pipelineDesc.blendMode = BlendMode::SrcAlphaOneMinusSrcAlpha; pipelineDesc.clearTargets = false; - pipelineDesc.colourTargets[0] = m_MainTexture; + pipelineDesc.colourTargets[0] = m_LastRenderTarget; pipelineDesc.DebugName = "Text"; - pipelineDesc.samples = m_MainTextureSamples; + pipelineDesc.samples = 1; - if(m_MainTextureSamples > 1) - pipelineDesc.resolveTexture = m_ResolveTexture; + // if(m_MainTextureSamples > 1) + // pipelineDesc.resolveTexture = m_ResolveTexture; m_TextRendererData.m_Pipeline = Graphics::Pipeline::Get(pipelineDesc); @@ -2997,8 +2999,8 @@ namespace Lumos::Graphics // m_TextBuffer = m_TextRendererData.m_VertexBuffers[currentFrame][m_TextRendererData.m_BatchDrawCallIndex]->GetPointer(); auto projView = m_Camera->GetProjectionMatrix() * glm::inverse(m_CameraTransform->GetWorldMatrix()); - m_TextRendererData.m_DescriptorSet[0][0]->SetUniform("UBO", "projView", &projView); - m_TextRendererData.m_DescriptorSet[0][0]->Update(); + m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->Update(); m_TextRendererData.m_TextureCount = 0; for(auto entity : textGroup) @@ -3143,7 +3145,94 @@ namespace Lumos::Graphics // m_TextRendererData.m_VertexBuffers[currentFrame][m_TextRendererData.m_BatchDrawCallIndex]->ReleasePointer(); } - void RenderPasses::DebugPass() + void SceneRenderer::Begin2DPass() + { + Renderer::GetMainSwapChain()->GetCurrentCommandBuffer()->UnBindPipeline(); + + Graphics::PipelineDesc pipelineDesc; + pipelineDesc.shader = m_Renderer2DData.m_Shader; + pipelineDesc.polygonMode = Graphics::PolygonMode::FILL; + pipelineDesc.cullMode = Graphics::CullMode::BACK; + pipelineDesc.transparencyEnabled = true; + pipelineDesc.blendMode = BlendMode::SrcAlphaOneMinusSrcAlpha; + pipelineDesc.clearTargets = false; + // pipelineDesc.depthTarget = reinterpret_cast(m_ForwardData.m_DepthTexture); + pipelineDesc.colourTargets[0] = m_LastRenderTarget; + pipelineDesc.DebugName = "2D"; + pipelineDesc.samples = 1; // m_MainTextureSamples; + pipelineDesc.DepthTest = false; + if(pipelineDesc.samples > 1) + pipelineDesc.resolveTexture = m_ResolveTexture; + + m_Renderer2DData.m_Pipeline = Graphics::Pipeline::Get(pipelineDesc); + + Renderer2DBeginBatch(); + + auto projView = glm::ortho(0.0f, (float)m_MainTexture->GetWidth(), 0.0f, (float)m_MainTexture->GetHeight()); // m_Camera->GetProjectionMatrix();// *glm::inverse(m_CameraTransform->GetWorldMatrix()); + float scale = 10.0f; + float aspectRatio = (float)m_MainTexture->GetWidth() / (float)m_MainTexture->GetHeight(); + // projView = glm::ortho(-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]->SetUniform("UBO", "projView", &projView); + m_Renderer2DData.m_DescriptorSet[m_Renderer2DData.m_BatchDrawCallIndex][0]->Update(); + } + + void SceneRenderer::BeginTextPass() + { + Renderer::GetMainSwapChain()->GetCurrentCommandBuffer()->UnBindPipeline(); + + Graphics::PipelineDesc pipelineDesc; + pipelineDesc.shader = m_TextRendererData.m_Shader; + pipelineDesc.polygonMode = Graphics::PolygonMode::FILL; + pipelineDesc.cullMode = Graphics::CullMode::BACK; + pipelineDesc.transparencyEnabled = true; + pipelineDesc.blendMode = BlendMode::OneMinusSrcAlpha; + pipelineDesc.clearTargets = false; + pipelineDesc.colourTargets[0] = m_LastRenderTarget; + pipelineDesc.DebugName = "Text"; + pipelineDesc.DepthTest = false; + pipelineDesc.samples = 1; // m_MainTextureSamples; + + if(pipelineDesc.samples > 1) + pipelineDesc.resolveTexture = m_ResolveTexture; + + m_TextRendererData.m_Pipeline = Graphics::Pipeline::Get(pipelineDesc); + + uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); + + if((int)m_TextRendererData.m_VertexBuffers[currentFrame].size() - 1 < (int)m_TextRendererData.m_BatchDrawCallIndex) + { + auto& vertexBuffer = m_TextRendererData.m_VertexBuffers[currentFrame].emplace_back(Graphics::VertexBuffer::Create(RENDERER_LINE_BUFFER_SIZE, nullptr, BufferUsage::DYNAMIC)); + // vertexBuffer->Resize(RENDERER_LINE_BUFFER_SIZE); + } + + m_TextRendererData.m_VertexBuffers[currentFrame][m_TextRendererData.m_BatchDrawCallIndex]->Bind(Renderer::GetMainSwapChain()->GetCurrentCommandBuffer(), m_TextRendererData.m_Pipeline.get()); + TextVertexBufferPtr = TextVertexBufferBase[currentFrame]; + // m_TextBuffer = m_TextRendererData.m_VertexBuffers[currentFrame][m_TextRendererData.m_BatchDrawCallIndex]->GetPointer(); + + // if (m_Camera) + { + auto projView = glm::ortho(0.0f, (float)m_MainTexture->GetWidth(), 0.0f, (float)m_MainTexture->GetHeight(), -10.0f, 10.0f); // m_Camera->GetProjectionMatrix();// *glm::inverse(m_CameraTransform->GetWorldMatrix()); + float scale = 10.0f; + float aspectRatio = (float)m_MainTexture->GetWidth() / (float)m_MainTexture->GetHeight(); + // projView = glm::ortho(-aspectRatio * scale, aspectRatio * scale, 0.0f, scale, -10.0f, 10.0f); + + m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->SetUniform("UBO", "projView", &projView); + } + m_TextRendererData.m_DescriptorSet[m_TextRendererData.m_BatchDrawCallIndex][0]->Update(); + + m_TextRendererData.m_TextureCount = 0; + } + + void SceneRenderer::DebugPass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Debug Pass"); @@ -3994,7 +4083,7 @@ namespace Lumos::Graphics } } - void RenderPasses::DebugLineFlush(Graphics::Pipeline* pipeline) + void SceneRenderer::DebugLineFlush(Graphics::Pipeline* pipeline) { LUMOS_PROFILE_FUNCTION(); @@ -4028,7 +4117,7 @@ namespace Lumos::Graphics m_DebugDrawData.LineIndexCount = 0; } - void RenderPasses::DebugPointFlush(Graphics::Pipeline* pipeline) + void SceneRenderer::DebugPointFlush(Graphics::Pipeline* pipeline) { LUMOS_PROFILE_FUNCTION(); @@ -4061,7 +4150,7 @@ namespace Lumos::Graphics m_DebugDrawData.PointIndexCount = 0; } - void RenderPasses::CreateCubeMap(const std::string& filePath, const glm::vec4& params, SharedPtr& outEnv, SharedPtr& outIrr) + void SceneRenderer::CreateCubeMap(const std::string& filePath, const glm::vec4& params, SharedPtr& outEnv, SharedPtr& outIrr) { // Create shader and pipeline // Create Empty Cube Map @@ -4240,7 +4329,7 @@ namespace Lumos::Graphics outIrr = SharedPtr(irradianceMap); } - void RenderPasses::InitDebugRenderData() + void SceneRenderer::InitDebugRenderData() { if(m_DebugRenderDataInitialised || !m_DebugRenderEnabled) return; @@ -4399,12 +4488,12 @@ namespace Lumos::Graphics m_DebugRenderDataInitialised = true; } - void RenderPasses::Init2DRenderData() + void SceneRenderer::Init2DRenderData() { m_DebugRenderDataInitialised = true; } - float RenderPasses::SubmitParticleTexture(Texture* texture) + float SceneRenderer::SubmitParticleTexture(Texture* texture) { LUMOS_PROFILE_FUNCTION_LOW(); float result = 0.0f; @@ -4444,7 +4533,7 @@ namespace Lumos::Graphics return distanceSqA > distanceSqB; } - void RenderPasses::ParticlePass() + void SceneRenderer::ParticlePass() { LUMOS_PROFILE_FUNCTION(); LUMOS_PROFILE_GPU("Particle Pass"); @@ -4655,7 +4744,7 @@ namespace Lumos::Graphics ParticleFlush(); } - void RenderPasses::ParticleBeginBatch() + void SceneRenderer::ParticleBeginBatch() { uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); @@ -4674,7 +4763,7 @@ namespace Lumos::Graphics m_ParticleData.m_Buffer = m_ParticleBufferBase[currentFrame][m_ParticleData.m_BatchDrawCallIndex]; } - void RenderPasses::ParticleFlush() + void SceneRenderer::ParticleFlush() { LUMOS_PROFILE_FUNCTION(); uint32_t currentFrame = Renderer::GetMainSwapChain()->GetCurrentBufferIndex(); diff --git a/Lumos/Source/Lumos/Graphics/Renderers/RenderPasses.h b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.h similarity index 96% rename from Lumos/Source/Lumos/Graphics/Renderers/RenderPasses.h rename to Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.h index 1b2f9dec3..76910be77 100644 --- a/Lumos/Source/Lumos/Graphics/Renderers/RenderPasses.h +++ b/Lumos/Source/Lumos/Graphics/Renderers/SceneRenderer.h @@ -11,6 +11,7 @@ namespace Lumos class WindowResizeEvent; class Event; struct SceneRenderSettings; + struct UI_Widget; namespace Maths { @@ -29,6 +30,8 @@ namespace Lumos class CommandBuffer; class Model; struct Light; + class VertexBuffer; + class IndexBuffer; struct LineVertexData { @@ -54,7 +57,7 @@ namespace Lumos } }; - struct RenderPassesStats + struct SceneRendererStats { uint32_t UpdatesPerSecond; uint32_t FramesPerSecond; @@ -63,11 +66,11 @@ namespace Lumos uint32_t NumDrawCalls = 0; }; - class RenderPasses + class SceneRenderer { public: - RenderPasses(uint32_t width, uint32_t height); - ~RenderPasses(); + SceneRenderer(uint32_t width, uint32_t height); + ~SceneRenderer(); void EnableDebugRenderer(bool enable); @@ -109,6 +112,10 @@ namespace Lumos void FinalPass(); void TextPass(); + void Begin2DPass(); + void BeginTextPass(); + void draw_ui(UI_Widget* widget); + // Post Process void ToneMappingPass(); void BloomPass(); @@ -126,7 +133,6 @@ namespace Lumos void UpdateCascades(Scene* scene, Light* light); bool m_DebugRenderEnabled = false; - struct LUMOS_EXPORT RenderCommand2D { Renderable2D* renderable = nullptr; @@ -270,7 +276,7 @@ namespace Lumos ForwardData& GetForwardData() { return m_ForwardData; } ShadowData& GetShadowData() { return m_ShadowData; } - RenderPassesStats& GetRenderPassesStats() { return m_Stats; } + SceneRendererStats& GetSceneRendererStats() { return m_Stats; } void CreateCubeMap(const std::string& filePath, const glm::vec4& params, SharedPtr& outEnv, SharedPtr& outIrr); @@ -389,7 +395,7 @@ namespace Lumos SharedPtr m_SharpenPassDescriptorSet; SharedPtr m_SharpenShader; - RenderPassesStats m_Stats; + SceneRendererStats m_Stats; #ifdef LUMOS_PLATFORM_WINDOWS uint8_t m_MainTextureSamples = 4; @@ -404,6 +410,8 @@ namespace Lumos SceneRenderSettings* m_OverrideSceneRenderSettings = nullptr; // For editor viewport void TextFlush(Renderer2DData& textRenderData, std::vector& textVertexBufferBase, TextVertexData*& textVertexBufferPtr); + + bool m_CurrentUIText = false; }; } } diff --git a/Lumos/Source/Lumos/Graphics/Sprite.cpp b/Lumos/Source/Lumos/Graphics/Sprite.cpp index bcbaf1533..99bc481b1 100644 --- a/Lumos/Source/Lumos/Graphics/Sprite.cpp +++ b/Lumos/Source/Lumos/Graphics/Sprite.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Sprite.h" #include "Graphics/RHI/Texture.h" #include "Graphics/RHI/GraphicsContext.h" diff --git a/Lumos/Source/Lumos/Graphics/Terrain.cpp b/Lumos/Source/Lumos/Graphics/Terrain.cpp index 9d2e56250..10a3df588 100644 --- a/Lumos/Source/Lumos/Graphics/Terrain.cpp +++ b/Lumos/Source/Lumos/Graphics/Terrain.cpp @@ -1,6 +1,10 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Terrain.h" #include "Maths/BoundingBox.h" +#include "Graphics/RHI/IndexBuffer.h" +#include "Graphics/RHI/VertexBuffer.h" #include namespace Lumos diff --git a/Lumos/Source/Lumos/ImGui/ImGuiManager.cpp b/Lumos/Source/Lumos/ImGui/ImGuiManager.cpp index 27fc50ba9..006fc4700 100644 --- a/Lumos/Source/Lumos/ImGui/ImGuiManager.cpp +++ b/Lumos/Source/Lumos/ImGui/ImGuiManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ImGuiManager.h" #include "Core/OS/Input.h" #include "Core/OS/Window.h" diff --git a/Lumos/Source/Lumos/ImGui/ImGuiUtilities.cpp b/Lumos/Source/Lumos/ImGui/ImGuiUtilities.cpp index 1161f30f4..c1c3a72cc 100644 --- a/Lumos/Source/Lumos/ImGui/ImGuiUtilities.cpp +++ b/Lumos/Source/Lumos/ImGui/ImGuiUtilities.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ImGui/ImGuiUtilities.h" #include "Graphics/RHI/Renderer.h" #include "Graphics/RHI/Texture.h" diff --git a/Lumos/Source/Lumos/ImGui/ImGuiUtilities.h b/Lumos/Source/Lumos/ImGui/ImGuiUtilities.h index 8a9056135..f59f7ce0a 100644 --- a/Lumos/Source/Lumos/ImGui/ImGuiUtilities.h +++ b/Lumos/Source/Lumos/ImGui/ImGuiUtilities.h @@ -276,13 +276,13 @@ static inline ImVec4& operator/=(ImVec4& lhs, const float rhs) lhs.y /= rhs; return lhs; } -//static inline std::ostream& operator<<(std::ostream& ostream, const ImVec2 a) +// static inline std::ostream& operator<<(std::ostream& ostream, const ImVec2 a) //{ -// ostream << "{ " << a.x << ", " << a.y << " }"; -// return ostream; -//} -//static inline std::ostream& operator<<(std::ostream& ostream, const ImVec4 a) +// ostream << "{ " << a.x << ", " << a.y << " }"; +// return ostream; +// } +// static inline std::ostream& operator<<(std::ostream& ostream, const ImVec4 a) //{ -// ostream << "{ " << a.x << ", " << a.y << ", " << a.z << ", " << a.w << " }"; -// return ostream; -//} +// ostream << "{ " << a.x << ", " << a.y << ", " << a.z << ", " << a.w << " }"; +// return ostream; +// } diff --git a/Lumos/Source/Lumos/Maths/BoundingBox.cpp b/Lumos/Source/Lumos/Maths/BoundingBox.cpp index f7be118e6..c90f87fa8 100644 --- a/Lumos/Source/Lumos/Maths/BoundingBox.cpp +++ b/Lumos/Source/Lumos/Maths/BoundingBox.cpp @@ -1,6 +1,10 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "BoundingBox.h" #include "BoundingSphere.h" +#include "Rect.h" +#include "Maths/MathsUtilities.h" #include diff --git a/Lumos/Source/Lumos/Maths/BoundingBox.h b/Lumos/Source/Lumos/Maths/BoundingBox.h index 7f25da646..d5b77212d 100644 --- a/Lumos/Source/Lumos/Maths/BoundingBox.h +++ b/Lumos/Source/Lumos/Maths/BoundingBox.h @@ -1,14 +1,13 @@ #pragma once -#include "Maths/Rect.h" -#include "MathsUtilities.h" #include namespace Lumos { namespace Maths { - + enum Intersection : u8; class BoundingSphere; + class Rect; class BoundingBox { friend class BoundingSphere; diff --git a/Lumos/Source/Lumos/Maths/BoundingSphere.cpp b/Lumos/Source/Lumos/Maths/BoundingSphere.cpp index 601605ac1..6692f13fb 100644 --- a/Lumos/Source/Lumos/Maths/BoundingSphere.cpp +++ b/Lumos/Source/Lumos/Maths/BoundingSphere.cpp @@ -1,7 +1,10 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "BoundingSphere.h" #include "BoundingBox.h" #include "Frustum.h" +#include "Maths/MathsUtilities.h" #include #include diff --git a/Lumos/Source/Lumos/Maths/Frustum.cpp b/Lumos/Source/Lumos/Maths/Frustum.cpp index 3f5d92953..f62bc3ee8 100644 --- a/Lumos/Source/Lumos/Maths/Frustum.cpp +++ b/Lumos/Source/Lumos/Maths/Frustum.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Maths/Frustum.h" #include "Maths/BoundingBox.h" #include "Maths/BoundingSphere.h" diff --git a/Lumos/Source/Lumos/Maths/MathsUtilities.cpp b/Lumos/Source/Lumos/Maths/MathsUtilities.cpp index f54e3df87..e287b5273 100644 --- a/Lumos/Source/Lumos/Maths/MathsUtilities.cpp +++ b/Lumos/Source/Lumos/Maths/MathsUtilities.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Maths/MathsUtilities.h" #include #include diff --git a/Lumos/Source/Lumos/Maths/MathsUtilities.h b/Lumos/Source/Lumos/Maths/MathsUtilities.h index 9c13a6a5a..34a8747fb 100644 --- a/Lumos/Source/Lumos/Maths/MathsUtilities.h +++ b/Lumos/Source/Lumos/Maths/MathsUtilities.h @@ -16,15 +16,15 @@ namespace Lumos { - /// Intersection test result. - enum Intersection - { - OUTSIDE = 0, - INTERSECTS = 1, - INSIDE = 2 - }; namespace Maths { + /// Intersection test result. + enum Intersection : u8 + { + OUTSIDE = 0, + INTERSECTS = 1, + INSIDE = 2 + }; #undef M_PI static constexpr float M_PI = 3.14159265358979323846264338327950288f; static constexpr float M_HALF_PI = M_PI * 0.5f; diff --git a/Lumos/Source/Lumos/Maths/Plane.cpp b/Lumos/Source/Lumos/Maths/Plane.cpp index 53a7194e4..9f67868ce 100644 --- a/Lumos/Source/Lumos/Maths/Plane.cpp +++ b/Lumos/Source/Lumos/Maths/Plane.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Maths/Plane.h" #include "MathsUtilities.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Maths/Random.cpp b/Lumos/Source/Lumos/Maths/Random.cpp index 296ecb913..80b8ae3de 100644 --- a/Lumos/Source/Lumos/Maths/Random.cpp +++ b/Lumos/Source/Lumos/Maths/Random.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Random.h" #include diff --git a/Lumos/Source/Lumos/Maths/Ray.cpp b/Lumos/Source/Lumos/Maths/Ray.cpp index 34148d0f9..88d6a6b2f 100644 --- a/Lumos/Source/Lumos/Maths/Ray.cpp +++ b/Lumos/Source/Lumos/Maths/Ray.cpp @@ -1,6 +1,9 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Ray.h" #include "BoundingBox.h" +#include "Maths/MathsUtilities.h" namespace Lumos { diff --git a/Lumos/Source/Lumos/Maths/Rect.cpp b/Lumos/Source/Lumos/Maths/Rect.cpp index 028b00212..8823a22ab 100644 --- a/Lumos/Source/Lumos/Maths/Rect.cpp +++ b/Lumos/Source/Lumos/Maths/Rect.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Rect.h" #include diff --git a/Lumos/Source/Lumos/Maths/Rect.h b/Lumos/Source/Lumos/Maths/Rect.h index 06967cd03..e434c60d3 100644 --- a/Lumos/Source/Lumos/Maths/Rect.h +++ b/Lumos/Source/Lumos/Maths/Rect.h @@ -1,5 +1,4 @@ #pragma once -#include "MathsUtilities.h" #include #include diff --git a/Lumos/Source/Lumos/Maths/Transform.cpp b/Lumos/Source/Lumos/Maths/Transform.cpp index 0d2528b82..93adb1e91 100644 --- a/Lumos/Source/Lumos/Maths/Transform.cpp +++ b/Lumos/Source/Lumos/Maths/Transform.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Transform.h" #include diff --git a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2DebugDraw.cpp b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2DebugDraw.cpp index 7a874987c..8b4467f06 100644 --- a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2DebugDraw.cpp +++ b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2DebugDraw.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "B2DebugDraw.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.cpp b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.cpp old mode 100755 new mode 100644 index d0ea24ee5..80e28405e --- a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.cpp +++ b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/B2PhysicsEngine.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "B2PhysicsEngine.h" #include "RigidBody2D.h" diff --git a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/RigidBody2D.cpp b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/RigidBody2D.cpp index 497814d2a..fa543a9a2 100644 --- a/Lumos/Source/Lumos/Physics/B2PhysicsEngine/RigidBody2D.cpp +++ b/Lumos/Source/Lumos/Physics/B2PhysicsEngine/RigidBody2D.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "RigidBody2D.h" #include "B2PhysicsEngine.h" #include "Core/Application.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/Broadphase.h b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/Broadphase.h index c223bd106..8f9aa8251 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/Broadphase.h +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/Broadphase.h @@ -15,8 +15,8 @@ namespace Lumos class LUMOS_EXPORT Broadphase { public: - virtual ~Broadphase() = default; + virtual ~Broadphase() = default; virtual void FindPotentialCollisionPairs(RigidBody3D* rootObject, TDArray& collisionPairs, uint32_t totalRigidBodyCount) = 0; - virtual void DebugDraw() = 0; + virtual void DebugDraw() = 0; }; } diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/BruteForceBroadphase.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/BruteForceBroadphase.cpp index 445255d0d..dc54ba820 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/BruteForceBroadphase.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/BruteForceBroadphase.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "BruteForceBroadphase.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp index d45da89b0..9408687d2 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Broadphase/OctreeBroadphase.cpp @@ -1,8 +1,11 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "OctreeBroadphase.h" #include "Graphics/Renderers/DebugRenderer.h" #include "Core/DataStructures/Set.h" +#include "Maths/MathsUtilities.h" #define DEBUG_CHECK_DUPLICATES 0 namespace Lumos @@ -195,13 +198,13 @@ namespace Lumos continue; const Maths::BoundingBox& boundingBox = physicsObject->GetWorldSpaceAABB(); - Intersection intersection = chileNode.boundingBox.IsInside(boundingBox); - if(intersection != OUTSIDE) + Maths::Intersection intersection = chileNode.boundingBox.IsInside(boundingBox); + if(intersection != Maths::Intersection::OUTSIDE) { chileNode.PhysicsObjects[chileNode.PhysicsObjectCount] = physicsObject; chileNode.PhysicsObjectCount++; - if(intersection == INSIDE) + if(intersection == Maths::Intersection::INSIDE) division.PhysicsObjects[i] = nullptr; } } diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CapsuleCollisionShape.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CapsuleCollisionShape.cpp index 4f02c14c4..197f73730 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CapsuleCollisionShape.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CapsuleCollisionShape.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "CapsuleCollisionShape.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CuboidCollisionShape.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CuboidCollisionShape.cpp index cd5433591..15f1e3d83 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CuboidCollisionShape.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/CuboidCollisionShape.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "CuboidCollisionShape.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" #include diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/Hull.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/Hull.cpp index be2e158d9..f99cba78f 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/Hull.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/Hull.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Hull.h" #include "Graphics/Renderers/DebugRenderer.h" #include diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/HullCollisionShape.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/HullCollisionShape.cpp index 9cefd9b4d..f5600c5c9 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/HullCollisionShape.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/HullCollisionShape.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "HullCollisionShape.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" #include diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/PyramidCollisionShape.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/PyramidCollisionShape.cpp index a206440f7..41d2c196a 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/PyramidCollisionShape.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/PyramidCollisionShape.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "PyramidCollisionShape.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/SphereCollisionShape.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/SphereCollisionShape.cpp index 81ca30f33..a7ad05169 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/SphereCollisionShape.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/CollisionShapes/SphereCollisionShape.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SphereCollisionShape.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/AxisConstraint.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/AxisConstraint.cpp index 5479fc8a4..644440ee0 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/AxisConstraint.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/AxisConstraint.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "AxisConstraint.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/DistanceConstraint.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/DistanceConstraint.cpp index 615f7f73f..d8932af2e 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/DistanceConstraint.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/DistanceConstraint.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Physics/LumosPhysicsEngine/LumosPhysicsEngine.h" #include "DistanceConstraint.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/SpringConstraint.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/SpringConstraint.cpp index 105c602bd..6ac196e56 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/SpringConstraint.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/SpringConstraint.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SpringConstraint.h" #include "Physics/LumosPhysicsEngine/LumosPhysicsEngine.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/WeldConstraint.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/WeldConstraint.cpp index 949472861..cdf58ee54 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/WeldConstraint.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Constraints/WeldConstraint.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "WeldConstraint.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Integration.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Integration.cpp index b042454b1..c5f996eb6 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Integration.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Integration.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Integration.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/LumosPhysicsEngine.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/LumosPhysicsEngine.cpp index 5a12172e2..693879099 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/LumosPhysicsEngine.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/LumosPhysicsEngine.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "LumosPhysicsEngine.h" #include "RigidBody3D.h" #include "Narrowphase/CollisionDetection.h" @@ -15,7 +17,7 @@ #include "Scene/Scene.h" #include "Scene/Entity.h" #include "Graphics/Renderers/DebugRenderer.h" - +#include "Maths/MathsUtilities.h" #include "Maths/Transform.h" #include "ImGui/ImGuiUtilities.h" #include "Utilities/Colour.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.cpp index c9314981a..b3a7ffee5 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "CollisionDetection.h" #include "Physics/LumosPhysicsEngine/CollisionShapes/SphereCollisionShape.h" #include "Physics/LumosPhysicsEngine/CollisionShapes/CuboidCollisionShape.h" @@ -953,4 +955,90 @@ CollisionData colData; *out_polygon = *output; } + + bool CollisionDetection::CheckSphereOverlap(const glm::vec3& pos1, float radius1, const glm::vec3& pos2, float radius2) + { + return glm::distance2(pos2, pos1) <= Maths::Squared(radius1 + radius2); + } + + bool CollisionDetection::CheckAABBOverlap(const glm::vec3& pos1, const glm::vec3& halfHidth1, const glm::vec3& pos2, const glm::vec3& halfHidth2) + { + if(abs(pos1.x - pos2.x) >= (halfHidth1.x + halfHidth2.x)) + return false; + if(abs(pos1.y - pos2.y) >= (halfHidth1.y + halfHidth2.y)) + return false; + if(abs(pos1.z - pos2.z) >= (halfHidth1.z + halfHidth2.z)) + return false; + return true; + } + + bool CollisionDetection::CheckAABBSphereOverlap(const glm::vec3& center, const glm::vec3& halfVol, const glm::vec3& spherePos, float sphereRad) + { + const glm::vec3 minVol = center - halfVol; + const glm::vec3 maxVol = center + halfVol; + float distSquared = sphereRad * sphereRad; + + if(spherePos.x <= minVol.x) + distSquared -= Maths::Squared(spherePos.x - minVol.x); + else if(spherePos.x >= maxVol.x) + distSquared -= Maths::Squared(spherePos.x - maxVol.x); + + if(spherePos.y <= minVol.y) + distSquared -= Maths::Squared(spherePos.y - minVol.y); + else if(spherePos.y >= maxVol.y) + distSquared -= Maths::Squared(spherePos.y - maxVol.y); + + if(spherePos.z <= minVol.z) + distSquared -= Maths::Squared(spherePos.z - minVol.z); + else if(spherePos.z >= maxVol.z) + distSquared -= Maths::Squared(spherePos.z - maxVol.z); + + return distSquared > 0; + } + + bool CollisionDetection::CheckSphereInsideAABB(const glm::vec3& spherePos, float sphereRadius, const glm::vec3& AABBCenter, const glm::vec3& AABBHalfVol) + { + // min check + glm::vec3 minPoint = AABBCenter - AABBHalfVol; + if(minPoint.x > spherePos.x - sphereRadius) + return false; + if(minPoint.y > spherePos.y - sphereRadius) + return false; + if(minPoint.z > spherePos.z - sphereRadius) + return false; + // max check + glm::vec3 maxPoint = AABBCenter + AABBHalfVol; + if(maxPoint.x < spherePos.x + sphereRadius) + return false; + if(maxPoint.y < spherePos.y + sphereRadius) + return false; + if(maxPoint.z < spherePos.z + sphereRadius) + return false; + + return true; + } + + bool CollisionDetection::CheckAABBInsideAABB(const glm::vec3& AABBInsideCenter, const glm::vec3& AABBInsideHalfVol, const glm::vec3& AABBCenter, const glm::vec3& AABBHalfVol) + { + // min check + glm::vec3 minPoint = AABBCenter - AABBHalfVol; + glm::vec3 minInsidePoint = AABBInsideCenter - AABBInsideHalfVol; + if(minPoint.x > minInsidePoint.x) + return false; + if(minPoint.y > minInsidePoint.y) + return false; + if(minPoint.z > minInsidePoint.z) + return false; + // max check + glm::vec3 maxPoint = AABBCenter + AABBHalfVol; + glm::vec3 maxInsidePoint = AABBInsideCenter + AABBInsideHalfVol; + if(maxPoint.x < maxInsidePoint.x) + return false; + if(maxPoint.y < maxInsidePoint.y) + return false; + if(maxPoint.z < maxInsidePoint.z) + return false; + + return true; + } } diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.h b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.h index 9adcd5ea1..9fba793ec 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.h +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/CollisionDetection.h @@ -36,91 +36,11 @@ namespace Lumos bool BuildCollisionManifold(RigidBody3D* obj1, RigidBody3D* obj2, CollisionShape* shape1, CollisionShape* shape2, CollisionData& coldata, Manifold* out_manifold); - static inline bool CheckSphereOverlap(const glm::vec3& pos1, float radius1, const glm::vec3& pos2, float radius2) - { - return glm::distance2(pos2, pos1) <= Maths::Squared(radius1 + radius2); - } - - static inline bool CheckAABBOverlap(const glm::vec3& pos1, const glm::vec3& halfHidth1, const glm::vec3& pos2, const glm::vec3& halfHidth2) - { - if(abs(pos1.x - pos2.x) >= (halfHidth1.x + halfHidth2.x)) - return false; - if(abs(pos1.y - pos2.y) >= (halfHidth1.y + halfHidth2.y)) - return false; - if(abs(pos1.z - pos2.z) >= (halfHidth1.z + halfHidth2.z)) - return false; - return true; - } - - static inline bool CheckAABBSphereOverlap(const glm::vec3& center, const glm::vec3& halfVol, const glm::vec3& spherePos, float sphereRad) - { - const glm::vec3 minVol = center - halfVol; - const glm::vec3 maxVol = center + halfVol; - float distSquared = sphereRad * sphereRad; - - if(spherePos.x <= minVol.x) - distSquared -= Maths::Squared(spherePos.x - minVol.x); - else if(spherePos.x >= maxVol.x) - distSquared -= Maths::Squared(spherePos.x - maxVol.x); - - if(spherePos.y <= minVol.y) - distSquared -= Maths::Squared(spherePos.y - minVol.y); - else if(spherePos.y >= maxVol.y) - distSquared -= Maths::Squared(spherePos.y - maxVol.y); - - if(spherePos.z <= minVol.z) - distSquared -= Maths::Squared(spherePos.z - minVol.z); - else if(spherePos.z >= maxVol.z) - distSquared -= Maths::Squared(spherePos.z - maxVol.z); - - return distSquared > 0; - } - - static inline bool CheckSphereInsideAABB(const glm::vec3& spherePos, float sphereRadius, const glm::vec3& AABBCenter, const glm::vec3& AABBHalfVol) - { - // min check - glm::vec3 minPoint = AABBCenter - AABBHalfVol; - if(minPoint.x > spherePos.x - sphereRadius) - return false; - if(minPoint.y > spherePos.y - sphereRadius) - return false; - if(minPoint.z > spherePos.z - sphereRadius) - return false; - // max check - glm::vec3 maxPoint = AABBCenter + AABBHalfVol; - if(maxPoint.x < spherePos.x + sphereRadius) - return false; - if(maxPoint.y < spherePos.y + sphereRadius) - return false; - if(maxPoint.z < spherePos.z + sphereRadius) - return false; - - return true; - } - - static inline bool CheckAABBInsideAABB(const glm::vec3& AABBInsideCenter, const glm::vec3& AABBInsideHalfVol, const glm::vec3& AABBCenter, const glm::vec3& AABBHalfVol) - { - // min check - glm::vec3 minPoint = AABBCenter - AABBHalfVol; - glm::vec3 minInsidePoint = AABBInsideCenter - AABBInsideHalfVol; - if(minPoint.x > minInsidePoint.x) - return false; - if(minPoint.y > minInsidePoint.y) - return false; - if(minPoint.z > minInsidePoint.z) - return false; - // max check - glm::vec3 maxPoint = AABBCenter + AABBHalfVol; - glm::vec3 maxInsidePoint = AABBInsideCenter + AABBInsideHalfVol; - if(maxPoint.x < maxInsidePoint.x) - return false; - if(maxPoint.y < maxInsidePoint.y) - return false; - if(maxPoint.z < maxInsidePoint.z) - return false; - - return true; - } + static bool CheckSphereOverlap(const glm::vec3& pos1, float radius1, const glm::vec3& pos2, float radius2); + static bool CheckAABBOverlap(const glm::vec3& pos1, const glm::vec3& halfHidth1, const glm::vec3& pos2, const glm::vec3& halfHidth2); + static bool CheckAABBSphereOverlap(const glm::vec3& center, const glm::vec3& halfVol, const glm::vec3& spherePos, float sphereRad); + static bool CheckSphereInsideAABB(const glm::vec3& spherePos, float sphereRadius, const glm::vec3& AABBCenter, const glm::vec3& AABBHalfVol); + static bool CheckAABBInsideAABB(const glm::vec3& AABBInsideCenter, const glm::vec3& AABBInsideHalfVol, const glm::vec3& AABBCenter, const glm::vec3& AABBHalfVol); protected: bool CheckPolyhedronCollision(RigidBody3D* obj1, RigidBody3D* obj2, CollisionShape* shape1, CollisionShape* shape2, CollisionData* out_coldata = nullptr); diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp index aed84cbd0..b9e113e4b 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/Narrowphase/Manifold.cpp @@ -1,8 +1,12 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Manifold.h" #include "Physics/LumosPhysicsEngine/LumosPhysicsEngine.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" #include "Graphics/Renderers/DebugRenderer.h" +#include "Maths/MathsUtilities.h" + #include #include diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp index 08aaea4b0..a0a1034ce 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "RigidBody3D.h" #include "LumosPhysicsEngine.h" #include "Graphics/Renderers/DebugRenderer.h" diff --git a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h index f34178ddd..c5ac6d7e0 100644 --- a/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h +++ b/Lumos/Source/Lumos/Physics/LumosPhysicsEngine/RigidBody3D.h @@ -1,5 +1,6 @@ #pragma once #include "Core/UUID.h" +#include "Core/DataStructures/TDArray.h" #include "Maths/BoundingBox.h" #include #include @@ -158,8 +159,8 @@ namespace Lumos void FireOnCollisionManifoldCallback(RigidBody3D* a, RigidBody3D* b, Manifold* manifold) { - for(auto it = m_OnCollisionManifoldCallbacks.begin(); it != m_OnCollisionManifoldCallbacks.end(); ++it) - it->operator()(a, b, manifold); + for(auto& callback : m_OnCollisionManifoldCallbacks) + callback(a, b, manifold); } void AutoResizeBoundingBox(); @@ -169,7 +170,7 @@ namespace Lumos typedef std::function OnCollisionManifoldCallback; - void AddOnCollisionManifoldCallback(const OnCollisionManifoldCallback callback) { m_OnCollisionManifoldCallbacks.push_back(callback); } + void AddOnCollisionManifoldCallback(const OnCollisionManifoldCallback callback) { m_OnCollisionManifoldCallbacks.PushBack(callback); } void SetCollisionShape(CollisionShapeType type); void SetCollisionShape(const SharedPtr& shape); @@ -245,6 +246,6 @@ namespace Lumos SharedPtr m_CollisionShape; PhysicsCollisionCallback m_OnCollisionCallback; - std::vector m_OnCollisionManifoldCallbacks; //!< Collision callbacks post manifold generation + TDArray m_OnCollisionManifoldCallbacks; //!< Collision callbacks post manifold generation }; } diff --git a/Lumos/Source/Lumos/Platform/Android/AndroidOS.h b/Lumos/Source/Lumos/Platform/Android/AndroidOS.h index 8f1faa164..c7352e99c 100644 --- a/Lumos/Source/Lumos/Platform/Android/AndroidOS.h +++ b/Lumos/Source/Lumos/Platform/Android/AndroidOS.h @@ -1,5 +1,5 @@ #pragma once -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "Core/OS/OS.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp index e561cece4..0bc8c8a20 100644 --- a/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp +++ b/Lumos/Source/Lumos/Platform/GLFW/GLFWWindow.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #if defined(LUMOS_PLATFORM_MACOS) #define GLFW_EXPOSE_NATIVE_COCOA @@ -220,7 +222,7 @@ namespace Lumos data.Exit = true; }); glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focused) - { + { Window* lmWindow = Application::Get().GetWindow(); if(lmWindow) @@ -505,19 +507,19 @@ namespace Lumos LUMOS_PROFILE_SCOPE("GLFW PollEvents"); glfwPollEvents(); - auto& controllers = Input::Get().m_Controllers; + auto& controllers = Input::Get().m_Controllers; + + ForHashMapEach(int, Controller, &controllers, it) + { + int key = *it.key; + Controller& value = *it.value; - ForHashMapEach(int, Controller, &controllers, it) - { - int key = *it.key; - Controller& value = *it.value; - - if (glfwJoystickPresent(key) != GLFW_TRUE) + if(glfwJoystickPresent(key) != GLFW_TRUE) { LUMOS_LOG_INFO("Controller disconnected : {0}", value.Name); Input::Get().RemoveController(key); } - } + } UpdateControllers(); } @@ -535,28 +537,27 @@ namespace Lumos void GLFWWindow::UpdateControllers() { - auto& controllers = Input::Get().m_Controllers; + auto& controllers = Input::Get().m_Controllers; // Update controllers for(int id = GLFW_JOYSTICK_1; id < GLFW_JOYSTICK_LAST; id++) { if(glfwJoystickPresent(id) == GLFW_TRUE) { - auto& controllers = Input::Get().m_Controllers; - Controller* controller = (Controller*)HashMapFindPtr(&controllers, id); - if(!controller) - { - Controller newController; - newController.ID = id; - newController.Name = glfwGetJoystickName(id); - HashMapInsert(&controllers, id, newController); + auto& controllers = Input::Get().m_Controllers; + Controller* controller = (Controller*)HashMapFindPtr(&controllers, id); + if(!controller) + { + Controller newController; + newController.ID = id; + newController.Name = glfwGetJoystickName(id); + HashMapInsert(&controllers, id, newController); controller = (Controller*)HashMapFindPtr(&controllers, id); - if (!controller) + if(!controller) { LUMOS_LOG_INFO("Failed to find controller {0}", newController.Name); - } - } + } LUMOS_LOG_INFO("Controller connected {0}", controller->Name); int buttonCount; diff --git a/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm b/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm index 9f8dc8f4e..79e38af8b 100644 --- a/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm +++ b/Lumos/Source/Lumos/Platform/MacOS/MacOSOS.mm @@ -7,7 +7,6 @@ #include -#import #define GLFW_EXPOSE_NATIVE_COCOA #include #include @@ -22,12 +21,12 @@ auto percentage = power.GetPowerPercentageLeft(); auto secondsLeft = power.GetPowerSecondsLeft(); auto state = power.GetPowerState(); - + int hours, minutes; minutes = secondsLeft / 60; hours = minutes / 60; minutes = minutes % 60; - + LUMOS_LOG_INFO("--------------------"); LUMOS_LOG_INFO(" System Information "); LUMOS_LOG_INFO("--------------------"); @@ -36,10 +35,10 @@ LUMOS_LOG_INFO("Battery Info - Percentage : {0} , Time Left {1}s , State : {2}", percentage, secondsLeft, PowerStateToString(state)); else LUMOS_LOG_INFO("Power - Outlet"); - + auto systemInfo = MemoryManager::Get()->GetSystemInfo(); systemInfo.Log(); - + auto& app = Lumos::Application::Get(); app.Init(); @@ -59,7 +58,7 @@ NSWindow* window = (NSWindow*)glfwGetCocoaWindow(static_cast(app.GetWindow()->GetHandle())); window.titlebarAppearsTransparent = YES; //window.titleVisibility = NSWindowTitleHidden; - + NSColor *titleColour = [NSColor colorWithSRGBRed:colour.x green:colour.y blue:colour.z alpha:colour.w]; window.backgroundColor = titleColour; if(dark) @@ -87,7 +86,7 @@ } return buffer.data(); } - + void MacOSOS::Delay(uint32_t usec) { struct timespec requested = { static_cast(usec / 1000000), (static_cast(usec) % 1000000) * 1000 }; diff --git a/Lumos/Source/Lumos/Platform/MacOS/MacOSVulkanContext.mm b/Lumos/Source/Lumos/Platform/MacOS/MacOSVulkanContext.mm index d903864c6..47d66b05f 100644 --- a/Lumos/Source/Lumos/Platform/MacOS/MacOSVulkanContext.mm +++ b/Lumos/Source/Lumos/Platform/MacOS/MacOSVulkanContext.mm @@ -1,6 +1,5 @@ #ifdef LUMOS_RENDER_API_VULKAN -#import #include #include "Platform/Vulkan/VKSwapChain.h" @@ -18,14 +17,14 @@ { NSWindow* window = (NSWindow*)handle; NSView* view = window.contentView; - + if (![view.layer isKindOfClass:[CAMetalLayer class]]) { [view setLayer:[CAMetalLayer layer]]; [view setWantsLayer:YES]; [view.layer setContentsScale:[window backingScaleFactor]]; } - + return view.layer; } @@ -35,7 +34,7 @@ { VkSurfaceKHR surface; #if defined(VK_USE_PLATFORM_METAL_EXT) - + VkMetalSurfaceCreateInfoEXT surfaceInfo; surfaceInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT; surfaceInfo.pNext = NULL; @@ -50,13 +49,13 @@ surfaceInfo.pView = GetCAMetalLayer((void*)glfwGetCocoaWindow(static_cast(window->GetHandle()))); vkCreateMacOSSurfaceMVK(vkInstance, &surfaceInfo, nullptr, &surface); #endif - + auto libMoltenVK = dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOW | RTLD_LOCAL); auto getMoltenVKConfigurationMVK = (PFN_vkGetMoltenVKConfigurationMVK) dlsym(libMoltenVK, "vkGetMoltenVKConfigurationMVK"); auto setMoltenVKConfigurationMVK = (PFN_vkSetMoltenVKConfigurationMVK) dlsym(libMoltenVK, "vkSetMoltenVKConfigurationMVK"); - + MVKConfiguration mvkConfig; size_t pConfigurationSize = sizeof(MVKConfiguration); getMoltenVKConfigurationMVK(vkInstance, &mvkConfig, &pConfigurationSize); @@ -74,8 +73,8 @@ //mvkConfig.resumeLostDevice = true; setMoltenVKConfigurationMVK(vkInstance, &mvkConfig, &pConfigurationSize); - - + + return surface; } } diff --git a/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp b/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp index 493baa7aa..590b9bfaf 100644 --- a/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp +++ b/Lumos/Source/Lumos/Platform/OpenAL/ALManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ALManager.h" #include "ALSoundNode.h" #include "Graphics/Camera/Camera.h" diff --git a/Lumos/Source/Lumos/Platform/OpenAL/ALSound.cpp b/Lumos/Source/Lumos/Platform/OpenAL/ALSound.cpp index 2108873eb..2ca5a41a3 100644 --- a/Lumos/Source/Lumos/Platform/OpenAL/ALSound.cpp +++ b/Lumos/Source/Lumos/Platform/OpenAL/ALSound.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ALSound.h" #include "Audio/WavLoader.h" diff --git a/Lumos/Source/Lumos/Platform/OpenAL/ALSoundNode.cpp b/Lumos/Source/Lumos/Platform/OpenAL/ALSoundNode.cpp index c0c43f3d0..848bcb345 100644 --- a/Lumos/Source/Lumos/Platform/OpenAL/ALSoundNode.cpp +++ b/Lumos/Source/Lumos/Platform/OpenAL/ALSoundNode.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ALSoundNode.h" #include "ALSound.h" #include "ALManager.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.cpp index de7abacdb..3906fdfc5 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLCommandBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLCommandBuffer.h" #include "GLPipeline.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLContext.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLContext.cpp index 38ee82dc7..04d8de46b 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLContext.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLContext.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLContext.h" #include "GLDebug.h" #include "GL.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLDebug.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLDebug.cpp index 6bf166193..69bc2dbb7 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLDebug.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLDebug.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLDebug.h" #include "GL.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.cpp index 54cdfac26..78dbf9be1 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLDescriptorSet.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLDescriptorSet.h" #include "GLShader.h" #include "GLTexture.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLFramebuffer.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLFramebuffer.cpp index d90886672..06affdc4d 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLFramebuffer.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLFramebuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLFramebuffer.h" #include "Platform/OpenGL/GLDebug.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLFunctions.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLFunctions.cpp index 5ac914386..08abfbf73 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLFunctions.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLFunctions.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLFunctions.h" #include "GLCommandBuffer.h" #include "GLContext.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLIMGUIRenderer.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLIMGUIRenderer.cpp index 71bcd2198..22dec759c 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLIMGUIRenderer.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLIMGUIRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLIMGUIRenderer.h" #include "GL.h" #include diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLIndexBuffer.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLIndexBuffer.cpp index 8da3b1435..7e57642d7 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLIndexBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLIndexBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLIndexBuffer.h" #include "GLRenderer.h" #include "GL.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLPipeline.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLPipeline.cpp index 3d3df8e69..602dc0691 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLPipeline.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLPipeline.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLPipeline.h" #include "GLDescriptorSet.h" #include "GLShader.h" @@ -247,6 +249,10 @@ namespace Lumos { GLCall(glBlendFunc(GL_ONE, GL_ZERO)); } + else if(m_BlendMode == BlendMode::OneMinusSrcAlpha) + { + GLCall(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + } else { GLCall(glBlendFunc(GL_NONE, GL_NONE)); diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.cpp index c635ef22b..52439ec11 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderDevice.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLRenderDevice.h" namespace Lumos::Graphics diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderPass.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderPass.cpp index bf5baa2dd..81e995ccf 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderPass.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderPass.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLRenderPass.h" #include "Graphics/RHI/Renderer.h" #include "GLFramebuffer.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.cpp index 443c0a9ec..347f1eb3f 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLRenderer.h" #include "Graphics/RHI/Shader.h" #include "Graphics/RHI/GraphicsContext.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLShader.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLShader.cpp index c3c0d0674..71b0db907 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLShader.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLShader.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLShader.h" #include "Platform/OpenGL/GL.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLSwapChain.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLSwapChain.cpp index 5483fb87c..2a087ba22 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLSwapChain.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLSwapChain.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLSwapChain.h" #include "GLCommandBuffer.h" #include "Graphics/RHI/Framebuffer.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLTexture.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLTexture.cpp index fef0bef6f..7621deab7 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLTexture.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLTexture.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLTexture.h" #include "Platform/OpenGL/GL.h" #include "Platform/OpenGL/GLUtilities.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLUniformBuffer.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLUniformBuffer.cpp index 7918cd9d3..3cae34b63 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLUniformBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLUniformBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLUniformBuffer.h" #include "GL.h" #include "GLDebug.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLUtilities.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLUtilities.cpp index 9946c0345..32ae6a06f 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLUtilities.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLUtilities.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLUtilities.h" #include "GL.h" #include "GLRenderer.h" diff --git a/Lumos/Source/Lumos/Platform/OpenGL/GLVertexBuffer.cpp b/Lumos/Source/Lumos/Platform/OpenGL/GLVertexBuffer.cpp index 9edccce26..e61ad087c 100644 --- a/Lumos/Source/Lumos/Platform/OpenGL/GLVertexBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/OpenGL/GLVertexBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "GLVertexBuffer.h" #include "GLPipeline.h" #include "GLRenderer.h" diff --git a/Lumos/Source/Lumos/Platform/Unix/UnixFileSystem.cpp b/Lumos/Source/Lumos/Platform/Unix/UnixFileSystem.cpp index 8d54b2386..04ab47cd3 100644 --- a/Lumos/Source/Lumos/Platform/Unix/UnixFileSystem.cpp +++ b/Lumos/Source/Lumos/Platform/Unix/UnixFileSystem.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Core/OS/FileSystem.h" #include diff --git a/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp b/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp index a0a5d8d7e..9b7fefeb9 100644 --- a/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp +++ b/Lumos/Source/Lumos/Platform/Unix/UnixOS.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "UnixOS.h" #include "Platform/GLFW/GLFWWindow.h" #include "Core/CoreSystem.h" diff --git a/Lumos/Source/Lumos/Platform/Unix/UnixTimer.cpp b/Lumos/Source/Lumos/Platform/Unix/UnixTimer.cpp index 0c44767c9..397b3b03c 100644 --- a/Lumos/Source/Lumos/Platform/Unix/UnixTimer.cpp +++ b/Lumos/Source/Lumos/Platform/Unix/UnixTimer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Utilities/Timer.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VK.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VK.cpp index 44d9302ea..47a249668 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VK.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VK.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VK.h" #ifdef USE_VMA_ALLOCATOR #define VMA_IMPLEMENTATION diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKBuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKBuffer.cpp index 7e6d5a358..875dbb5ed 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKBuffer.h" #include "VKDevice.h" #include "VKRenderer.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp index d7325a127..125bd5e0c 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKCommandBuffer.h" #include "VKDevice.h" #include "VKCommandPool.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandPool.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandPool.cpp index a23fe89ef..bc39ed60b 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKCommandPool.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKCommandPool.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKCommandPool.h" #include "VKDevice.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp index e49282ede..a0d31685b 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKContext.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKContext.h" #include "VKDevice.h" #include "VKCommandPool.h" @@ -21,7 +23,7 @@ #define VK_LAYER_LUNARG_ASSISTENT_LAYER_NAME "VK_LAYER_LUNARG_assistant_layer" #define VK_LAYER_LUNARG_VALIDATION_NAME "VK_LAYER_KHRONOS_validation" -const bool EnableValidationLayers = false; +const bool EnableValidationLayers = true; namespace Lumos { @@ -30,56 +32,123 @@ namespace Lumos VkInstance VKContext::s_VkInstance = nullptr; uint32_t VKContext::m_VKVersion = 0; - const std::vector VKContext::GetRequiredExtensions(bool enableValidationLayers) + const TDArray VKContext::GetRequiredExtensions(bool enableValidationLayers) { - std::vector extensions; + if(m_InstanceExtensions.Empty()) + { + uint32_t extensionCount; + vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); + + m_InstanceExtensions.Resize(extensionCount); + vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, m_InstanceExtensions.Data()); + } + + auto CheckExtension = [&](const char* extensionName) + { + bool extensionFound = false; + + for(const auto& extensionProperties : m_InstanceExtensions) + { + if(strcmp(extensionName, extensionProperties.extensionName) == 0) + { + extensionFound = true; + break; + } + } + + if(!extensionFound) + { + LUMOS_LOG_WARN("[VULKAN] Extension not supported - {0}", extensionName); + } + + return extensionFound; + }; + + TDArray extensions; if(enableValidationLayers) { LUMOS_LOG_INFO("Vulkan : Enabled Validation Layers"); - extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + if(CheckExtension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) + extensions.PushBack(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + if(CheckExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) + extensions.PushBack(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); } - extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); - - extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); - extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + if(CheckExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) + extensions.PushBack(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + if(CheckExtension(VK_KHR_SURFACE_EXTENSION_NAME)) + extensions.PushBack(VK_KHR_SURFACE_EXTENSION_NAME); + if(CheckExtension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) + extensions.PushBack(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); #if 0 #if defined(TRACY_ENABLE) && defined(LUMOS_PLATFORM_WINDOWS) - extensions.push_back("VK_EXT_calibrated_timestamps"); + if (CheckExtension("VK_EXT_calibrated_timestamps")) + extensions.PushBack("VK_EXT_calibrated_timestamps"); #endif #endif - + const char* platformLayerName = nullptr; #if defined(_WIN32) - extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); + platformLayerName = VK_KHR_WIN32_SURFACE_EXTENSION_NAME; #elif defined(VK_USE_PLATFORM_ANDROID_KHR) - extensions.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); + platformLayerName = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME; #elif defined(_DIRECT2DISPLAY) - extensions.push_back(VK_KHR_DISPLAY_EXTENSION_NAME); + platformLayerName = VK_KHR_DISPLAY_EXTENSION_NAME; #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) - extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); + platformLayerName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME; #elif defined(VK_USE_PLATFORM_XCB_KHR) - extensions.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); + platformLayerName = VK_KHR_XCB_SURFACE_EXTENSION_NAME; #elif defined(VK_USE_PLATFORM_IOS_MVK) - extensions.push_back("VK_EXT_metal_surface"); + platformLayerName = "VK_EXT_metal_surface"; #elif defined(VK_USE_PLATFORM_MACOS_MVK) - extensions.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME); + platformLayerName = VK_MVK_MACOS_SURFACE_EXTENSION_NAME; #elif defined(VK_USE_PLATFORM_METAL_EXT) - extensions.push_back("VK_EXT_metal_surface"); + platformLayerName = "VK_EXT_metal_surface"; #endif + if(CheckExtension(platformLayerName)) + extensions.PushBack(platformLayerName); return extensions; } - const std::vector VKContext::GetRequiredLayers(bool enableValidationLayers) const + const TDArray VKContext::GetRequiredLayers(bool enableValidationLayers) { - std::vector layers; + if(m_InstanceLayers.Empty()) + { + uint32_t layerCount; + vkEnumerateInstanceLayerProperties(&layerCount, nullptr); + + m_InstanceLayers.Resize(layerCount); + vkEnumerateInstanceLayerProperties(&layerCount, m_InstanceLayers.Data()); + } + + auto CheckLayer = [&](const char* layerName) + { + bool layerFound = false; + + for(const auto& layerProperties : m_InstanceLayers) + { + if(strcmp(layerName, layerProperties.layerName) == 0) + { + layerFound = true; + break; + } + } + + if(!layerFound) + { + LUMOS_LOG_WARN("[VULKAN] Layer not supported - {0}", layerName); + } + + return layerFound; + }; + TDArray layers; if(enableValidationLayers) { - layers.emplace_back(VK_LAYER_LUNARG_VALIDATION_NAME); + if(CheckLayer(VK_LAYER_LUNARG_VALIDATION_NAME)) + layers.EmplaceBack(VK_LAYER_LUNARG_VALIDATION_NAME); } return layers; @@ -181,85 +250,6 @@ namespace Lumos return VK_FALSE; } - bool VKContext::CheckValidationLayerSupport(std::vector& validationLayers) - { - uint32_t layerCount; - vkEnumerateInstanceLayerProperties(&layerCount, nullptr); - - m_InstanceLayers.resize(layerCount); - vkEnumerateInstanceLayerProperties(&layerCount, m_InstanceLayers.data()); - bool removedLayer = false; - - validationLayers.erase( - std::remove_if( - validationLayers.begin(), - validationLayers.end(), - [&](const char* layerName) - { - bool layerFound = false; - - for(const auto& layerProperties : m_InstanceLayers) - { - if(strcmp(layerName, layerProperties.layerName) == 0) - { - layerFound = true; - break; - } - } - - if(!layerFound) - { - removedLayer = true; - LUMOS_LOG_WARN("[VULKAN] Layer not supported - {0}", layerName); - } - - return !layerFound; - }), - validationLayers.end()); - - return !removedLayer; - } - - bool VKContext::CheckExtensionSupport(std::vector& extensions) - { - uint32_t extensionCount; - vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); - - m_InstanceExtensions.resize(extensionCount); - vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, m_InstanceExtensions.data()); - - bool removedExtension = false; - - extensions.erase( - std::remove_if( - extensions.begin(), - extensions.end(), - [&](const char* extensionName) - { - bool extensionFound = false; - - for(const auto& extensionProperties : m_InstanceExtensions) - { - if(strcmp(extensionName, extensionProperties.extensionName) == 0) - { - extensionFound = true; - break; - } - } - - if(!extensionFound) - { - removedExtension = true; - LUMOS_LOG_WARN("[VULKAN] Extension not supported - {0}", extensionName); - } - - return !extensionFound; - }), - extensions.end()); - - return !removedExtension; - } - size_t VKContext::GetMinUniformBufferOffsetAlignment() const { return Graphics::VKDevice::Get().GetPhysicalDevice()->GetProperties().limits.minUniformBufferOffsetAlignment; @@ -290,15 +280,6 @@ namespace Lumos m_InstanceLayerNames = GetRequiredLayers(enableValidation); m_InstanceExtensionNames = GetRequiredExtensions(enableValidation); - if(!CheckValidationLayerSupport(m_InstanceLayerNames)) - { - LUMOS_LOG_WARN("[VULKAN] One or multiple Validation layers requested are not available!"); - } - - if(!CheckExtensionSupport(m_InstanceExtensionNames)) - { - LUMOS_LOG_WARN("[VULKAN] One or multiple Extensions requested are not available!"); - } VkApplicationInfo appInfo = {}; uint32_t sdkVersion = VK_HEADER_VERSION_COMPLETE; @@ -337,28 +318,27 @@ namespace Lumos appInfo.pEngineName = "Lumos"; appInfo.engineVersion = VK_MAKE_VERSION(LumosVersion.major, LumosVersion.minor, LumosVersion.patch); - VkInstanceCreateInfo createInfo = {}; - createInfo.pApplicationInfo = &appInfo; - createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; - createInfo.enabledExtensionCount = static_cast(m_InstanceExtensionNames.size()); - createInfo.ppEnabledExtensionNames = m_InstanceExtensionNames.data(); - createInfo.enabledLayerCount = static_cast(m_InstanceLayerNames.size()); - createInfo.ppEnabledLayerNames = m_InstanceLayerNames.data(); - createInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; - const std::vector validation_layers = { "VK_LAYER_KHRONOS_validation" }; + VkInstanceCreateInfo createInfo = {}; + createInfo.pApplicationInfo = &appInfo; + createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + createInfo.enabledExtensionCount = static_cast(m_InstanceExtensionNames.Size()); + createInfo.ppEnabledExtensionNames = m_InstanceExtensionNames.Data(); + createInfo.enabledLayerCount = static_cast(m_InstanceLayerNames.Size()); + createInfo.ppEnabledLayerNames = m_InstanceLayerNames.Data(); + createInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; const bool enableFeatureValidation = false; if(enableFeatureValidation) { - std::vector validation_extensions = {}; - validation_extensions.emplace_back(VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT); - validation_extensions.emplace_back(VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT); + TDArray validation_extensions = {}; + validation_extensions.EmplaceBack(VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT); + validation_extensions.EmplaceBack(VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT); VkValidationFeaturesEXT validation_features = {}; validation_features.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT; - validation_features.enabledValidationFeatureCount = static_cast(validation_extensions.size()); - validation_features.pEnabledValidationFeatures = validation_extensions.data(); + validation_features.enabledValidationFeatureCount = static_cast(validation_extensions.Size()); + validation_features.pEnabledValidationFeatures = validation_extensions.Data(); createInfo.pNext = &validation_features; } @@ -413,8 +393,8 @@ namespace Lumos void VKContext::OnImGui() { const auto& memoryProps = VKDevice::Get().GetPhysicalDevice()->GetMemoryProperties(); - std::vector budgets(memoryProps.memoryHeapCount); - vmaGetHeapBudgets(VKDevice::Get().GetAllocator(), budgets.data()); + TDArray budgets(memoryProps.memoryHeapCount); + vmaGetHeapBudgets(VKDevice::Get().GetAllocator(), budgets.Data()); for(VmaBudget& b : budgets) { diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKContext.h b/Lumos/Source/Lumos/Platform/Vulkan/VKContext.h index b48d6d691..81f3c54f9 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKContext.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKContext.h @@ -2,6 +2,7 @@ #include "Graphics/RHI/GraphicsContext.h" #include "Core/Reference.h" #include "VK.h" +#include "Core/DataStructures/TDArray.h" namespace Lumos { @@ -38,8 +39,8 @@ namespace Lumos float GetGPUMemoryUsed() override { return 0.0f; }; float GetTotalGPUMemory() override { return 0.0f; }; - const std::vector& GetLayerNames() const { return m_InstanceLayerNames; } - const std::vector& GetExtensionNames() const { return m_InstanceExtensionNames; } + const TDArray& GetLayerNames() const { return m_InstanceLayerNames; } + const TDArray& GetExtensionNames() const { return m_InstanceExtensionNames; } static void MakeDefault(); static uint32_t GetVKVersion() { return m_VKVersion; } @@ -49,21 +50,19 @@ namespace Lumos void CreateInstance(); void SetupDebugCallback(); - bool CheckValidationLayerSupport(std::vector& validationLayers); - bool CheckExtensionSupport(std::vector& extensions); - static const std::vector GetRequiredExtensions(bool enableValidationLayers); - const std::vector GetRequiredLayers(bool enableValidationLayers) const; + const TDArray GetRequiredExtensions(bool enableValidationLayers); + const TDArray GetRequiredLayers(bool enableValidationLayers); private: static VkInstance s_VkInstance; VkDebugReportCallbackEXT m_DebugCallback = VK_NULL_HANDLE; - std::vector m_InstanceLayers; - std::vector m_InstanceExtensions; + TDArray m_InstanceLayers; + TDArray m_InstanceExtensions; - std::vector m_InstanceLayerNames; - std::vector m_InstanceExtensionNames; + TDArray m_InstanceLayerNames; + TDArray m_InstanceExtensionNames; static uint32_t m_VKVersion; }; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp index beb3baa71..85d4a205b 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKDescriptorSet.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKDescriptorSet.h" #include "VKPipeline.h" #include "VKUtilities.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.cpp index b29e51211..77ee529b0 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Core/Application.h" #include "Core/Version.h" @@ -386,11 +388,12 @@ namespace Lumos vkDestroyPipelineCache(m_Device, m_PipelineCache, VK_NULL_HANDLE); #ifdef USE_VMA_ALLOCATOR - for(auto& pool : m_SmallAllocPools) + + ForHashMapEach(uint32_t, VmaPool, &m_SmallAllocPools, it) { - vmaDestroyPool(m_Allocator, pool.second); + VmaPool value = *it.value; + vmaDestroyPool(m_Allocator, value); } - m_SmallAllocPools.clear(); vmaDestroyAllocator(m_Allocator); #endif @@ -590,7 +593,7 @@ namespace Lumos VkCommandBuffer tracyBuffer; vkAllocateCommandBuffers(m_Device, &allocInfo, &tracyBuffer); - m_TracyContext.resize(4); + m_TracyContext.Resize(4); for(int i = 0; i < 4; i++) m_TracyContext[i] = TracyVkContext(m_PhysicalDevice->GetHandle(), m_Device, m_GraphicsQueue, tracyBuffer); @@ -616,8 +619,9 @@ namespace Lumos #ifdef USE_VMA_ALLOCATOR VmaPool VKDevice::GetOrCreateSmallAllocPool(uint32_t memTypeIndex) { - if(m_SmallAllocPools.find(memTypeIndex) != m_SmallAllocPools.end()) - return m_SmallAllocPools[memTypeIndex]; + VmaPool pool = VK_NULL_HANDLE; + if(HashMapFind(&m_SmallAllocPools, memTypeIndex, &pool)) + return pool; LUMOS_LOG_INFO("Creating VMA small objects pool for memory type index {0}", memTypeIndex); @@ -630,9 +634,8 @@ namespace Lumos pci.priority = 0.5f; pci.minAllocationAlignment = 0; pci.pMemoryAllocateNext = nullptr; - VmaPool pool = VK_NULL_HANDLE; VK_CHECK_RESULT(vmaCreatePool(m_Allocator, &pci, &pool)); - m_SmallAllocPools[memTypeIndex] = pool; + HashMapInsert(&m_SmallAllocPools, memTypeIndex, pool); return pool; } #endif diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.h b/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.h index 7e16f969b..0fee490cf 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKDevice.h @@ -194,13 +194,13 @@ namespace Lumos static uint32_t s_GraphicsQueueFamilyIndex; #if LUMOS_PROFILE && defined(TRACY_ENABLE) - std::vector m_TracyContext; + TDArray m_TracyContext; tracy::VkCtx* m_PresentTracyContext; #endif #ifdef USE_VMA_ALLOCATOR VmaAllocator m_Allocator {}; - std::unordered_map m_SmallAllocPools; + HashMap(uint32_t, VmaPool) m_SmallAllocPools; #endif }; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp index c4a30b0ae..8e7a107b5 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFence.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKFence.h" #include "VKDevice.h" #include "VKUtilities.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.cpp index 7be900920..1b7cdf3de 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFramebuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKFramebuffer.h" #include "VKDevice.h" #include "VKTexture.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp index 906e53372..3558c6ea7 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKFunctions.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKFunctions.h" #include "VKCommandBuffer.h" #include "VKContext.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp index a9f8d74d6..80c5d4b76 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKIMGUIRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKIMGUIRenderer.h" #include diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKIndexBuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKIndexBuffer.cpp index 3c3c8b013..bde3c9ea2 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKIndexBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKIndexBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKIndexBuffer.h" #include "VKVertexBuffer.h" #include "VKCommandBuffer.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKPipeline.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKPipeline.cpp index 696e4f6d1..5dd6c5974 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKPipeline.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKPipeline.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKPipeline.h" #include "VKDevice.h" #include "VKCommandBuffer.h" @@ -148,6 +150,13 @@ namespace Lumos blendAttachState[i].srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; blendAttachState[i].dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE; } + else if(pipelineDesc.blendMode == BlendMode::OneMinusSrcAlpha) + { + blendAttachState[i].srcColorBlendFactor = VK_BLEND_FACTOR_ONE; + blendAttachState[i].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + blendAttachState[i].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + blendAttachState[i].dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + } else if(pipelineDesc.blendMode == BlendMode::ZeroSrcColor) { blendAttachState[i].srcColorBlendFactor = VK_BLEND_FACTOR_ZERO; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.cpp index 18f29ee05..0775e963b 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderDevice.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKRenderDevice.h" namespace Lumos::Graphics diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderPass.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderPass.cpp index 38289b653..35525482a 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderPass.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderPass.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKRenderPass.h" #include "VKCommandBuffer.h" #include "VKDevice.h" @@ -305,14 +307,14 @@ namespace Lumos commandBuffer->UpdateViewport(width, height, m_SwapchainTarget); s_ActiveCount++; - Engine::Get().Statistics().BoundRenderPasses++; + Engine::Get().Statistics().BoundSceneRenderer++; } void VKRenderPass::EndRenderPass(CommandBuffer* commandBuffer) { LUMOS_PROFILE_FUNCTION_LOW(); - LUMOS_ASSERT(s_ActiveCount, "No active renderpasses to end"); + LUMOS_ASSERT(s_ActiveCount, "No active SceneRenderer to end"); s_ActiveCount--; vkCmdEndRenderPass(static_cast(commandBuffer)->GetHandle()); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp index 50574ebd2..162afa623 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKRenderer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKRenderer.h" #include "VKDevice.h" #include "VKShader.h" @@ -24,7 +26,7 @@ namespace Lumos { static VkFence s_ComputeFence = nullptr; - int VKRenderer::s_DeletionQueueIndex = 0; + int VKRenderer::s_DeletionQueueIndex = 0; TDArray VKRenderer::s_DeletionQueue = {}; void VKRenderer::InitInternal() diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKSemaphore.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKSemaphore.cpp index 2c2eda6ba..690e182e5 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKSemaphore.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKSemaphore.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKSemaphore.h" #include "VKDevice.h" #include "VKUtilities.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp index 674fc1215..33f3f6a9f 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKShader.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKShader.h" #include "VKDevice.h" #include "VKUtilities.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp index 3868af751..f9c405aac 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKDevice.h" #include "VKSwapChain.h" #include "VKUtilities.h" @@ -175,7 +177,7 @@ namespace Lumos m_Frames[i].ImageAcquireSemaphore = VK_NULL_HANDLE; } - m_SwapChainBuffers.clear(); + MemorySet(m_SwapChainBuffers, 0, sizeof(Texture*) * MAX_SWAPCHAIN_BUFFERS); vkDestroySwapchainKHR(VKDevice::Get().GetDevice(), m_OldSwapChain, VK_NULL_HANDLE); m_OldSwapChain = VK_NULL_HANDLE; @@ -215,7 +217,7 @@ namespace Lumos VKTexture2D* swapChainBuffer = new VKTexture2D(pSwapChainImages[i], imageView, m_ColourFormat, m_Width, m_Height); swapChainBuffer->TransitionImage(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); - m_SwapChainBuffers.push_back(swapChainBuffer); + m_SwapChainBuffers[i] = swapChainBuffer; } ScratchEnd(scratch); diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.h b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.h index c5a1b25cd..4f6a046a0 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKSwapChain.h @@ -4,6 +4,7 @@ #include "VKFramebuffer.h" #include "VKContext.h" #include "Graphics/RHI/SwapChain.h" +#include "Core/DataStructures/TDArray.h" #define MAX_SWAPCHAIN_BUFFERS 3 namespace Lumos @@ -61,11 +62,10 @@ namespace Lumos private: FrameData m_Frames[MAX_SWAPCHAIN_BUFFERS]; + Texture2D* m_SwapChainBuffers[MAX_SWAPCHAIN_BUFFERS]; void FindImageFormatAndColourSpace(); - std::vector m_SwapChainBuffers; - uint32_t m_CurrentBuffer = 0; uint32_t m_AcquireImageIndex = 0; uint32_t m_Width; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp index c580f8a46..032cfafc4 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKTexture.h" #include "VKDevice.h" #include "Utilities/LoadImage.h" @@ -60,7 +62,7 @@ namespace Lumos samplerInfo.anisotropyEnable = anisotropyEnable; samplerInfo.unnormalizedCoordinates = VK_FALSE; samplerInfo.compareEnable = VK_FALSE; // compareEnabled; - samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; + samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; samplerInfo.mipLodBias = 0.0f; samplerInfo.compareOp = compareEnabled ? VK_COMPARE_OP_GREATER_OR_EQUAL : VK_COMPARE_OP_NEVER; samplerInfo.minLod = minLod; @@ -283,15 +285,15 @@ namespace Lumos for(auto& view : m_MipImageViews) { - if(view.second) + if(view) { - auto imageView = view.second; + auto imageView = view; deletionQueue.PushFunction([imageView] { vkDestroyImageView(VKDevice::GetHandle(), imageView, nullptr); }); } } - m_MipImageViews.clear(); + m_MipImageViews.Clear(); if(m_DeleteImage) { @@ -577,11 +579,10 @@ namespace Lumos VkImageView VKTexture2D::GetMipImageView(uint32_t mip) { - if(m_MipImageViews.find(mip) == m_MipImageViews.end()) - { - m_MipImageViews[mip] = CreateImageView(m_TextureImage, m_VKFormat, 1, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, 1, 0, mip); - } - return m_MipImageViews.at(mip); + if(mip < m_MipImageViews.Size()) + return m_MipImageViews[mip]; + + return m_MipImageViews.EmplaceBack(CreateImageView(m_TextureImage, m_VKFormat, 1, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, 1, 0, mip)); } void VKTexture2D::Load(uint32_t width, uint32_t height, void* data, TextureDesc parameters, TextureLoadOptions loadOptions) diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h index db842412c..4c60577ba 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKTexture.h @@ -169,7 +169,7 @@ namespace Lumos VkSampler m_TextureSampler {}; VkDescriptorImageInfo m_Descriptor {}; - std::unordered_map m_MipImageViews; + TDArray m_MipImageViews; #ifdef USE_VMA_ALLOCATOR VmaAllocation m_Allocation {}; diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKUniformBuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKUniformBuffer.cpp index baaa34f29..29dc8e17f 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKUniformBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKUniformBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKUniformBuffer.h" #include "VKDevice.h" #include "VKUtilities.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp index 7857db55e..83da85b1d 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKUtilities.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKUtilities.h" #include "VKDevice.h" #include "VKShader.h" diff --git a/Lumos/Source/Lumos/Platform/Vulkan/VKVertexBuffer.cpp b/Lumos/Source/Lumos/Platform/Vulkan/VKVertexBuffer.cpp index 92eaa8fb3..f0ac15fd0 100644 --- a/Lumos/Source/Lumos/Platform/Vulkan/VKVertexBuffer.cpp +++ b/Lumos/Source/Lumos/Platform/Vulkan/VKVertexBuffer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "VKDevice.h" #include "VKVertexBuffer.h" #include "VKRenderer.h" diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsFileSystem.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsFileSystem.cpp index db67bca71..b32052f0e 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsFileSystem.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsFileSystem.cpp @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "Core/OS/FileSystem.h" #include "WindowsUtilities.h" @@ -126,4 +126,4 @@ namespace Lumos } } -#endif \ No newline at end of file +#endif diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp index e79f372c4..adb884a37 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsOS.cpp @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "WindowsOS.h" #include "WindowsPower.h" #include "WindowsWindow.h" diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsPower.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsPower.cpp index cc7885814..1297dc7ec 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsPower.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsPower.cpp @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "WindowsPower.h" #include diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsTimer.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsTimer.cpp index b4473e7ff..421f47271 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsTimer.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsTimer.cpp @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "Utilities/Timer.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsUtilities.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsUtilities.cpp index 5bfc7e4f2..0773e31b8 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsUtilities.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsUtilities.cpp @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "WindowsUtilities.h" #include @@ -18,4 +18,4 @@ namespace Lumos { return strconverter.from_bytes(str); } -} \ No newline at end of file +} diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsVulkan.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsVulkan.cpp index 89664cafa..5a0bc754d 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsVulkan.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsVulkan.cpp @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #ifdef LUMOS_RENDER_API_VULKAN @@ -40,4 +40,4 @@ namespace Lumos } } -#endif \ No newline at end of file +#endif diff --git a/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp b/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp index 127cc7131..845b443b8 100644 --- a/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp +++ b/Lumos/Source/Lumos/Platform/Windows/WindowsWindow.cpp @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #define NOMINMAX #undef NOGDI #include @@ -312,20 +312,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)) { LUMOS_LOG_ERROR("Failed to initialise OpenGL context"); } - + if(!gladLoadWGL(hDc)) LUMOS_LOG_ERROR("glad failed to load WGL!"); if(!gladLoadGL()) LUMOS_LOG_ERROR("glad failed to load OpenGL!"); - + const int contextAttribsList[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4, @@ -342,7 +342,7 @@ namespace Lumos #endif 0, }; - + HGLRC hrc = wglCreateContextAttribsARB(hDc, nullptr, contextAttribsList); if(hrc == nullptr) { diff --git a/Lumos/Source/Lumos/Platform/iOS/iOSFileSystem.mm b/Lumos/Source/Lumos/Platform/iOS/iOSFileSystem.mm index be55e4ac8..9fd254f8b 100644 --- a/Lumos/Source/Lumos/Platform/iOS/iOSFileSystem.mm +++ b/Lumos/Source/Lumos/Platform/iOS/iOSFileSystem.mm @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "Core/OS/FileSystem.h" #include "Utilities/StringUtilities.h" #include "iOSOS.h" @@ -64,11 +64,11 @@ { return filename; } - + std::string result; std::string appPath = iOSOS::Get()->GetExecutablePath(); std::string relFilename;// = filename.ToRelativePath(appPath); - + if (!forWrite) { static NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; @@ -83,7 +83,7 @@ result = cstr; result.append(relFilename); } - + return result; } @@ -109,7 +109,7 @@ static bool ReadFileInternal(FILE* file, void* buffer, int64_t size, bool readby struct stat buffer; return (stat (path.c_str(), &buffer) == 0); } - + bool FileSystem::FolderExists(const std::string& path) { struct stat buffer; diff --git a/Lumos/Source/Lumos/Platform/iOS/iOSOS.h b/Lumos/Source/Lumos/Platform/iOS/iOSOS.h index 709421c7c..0e3724df3 100644 --- a/Lumos/Source/Lumos/Platform/iOS/iOSOS.h +++ b/Lumos/Source/Lumos/Platform/iOS/iOSOS.h @@ -1,5 +1,5 @@ #pragma once -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "Core/OS/OS.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm b/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm index 8cc1ca10b..dde026821 100644 --- a/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm +++ b/Lumos/Source/Lumos/Platform/iOS/iOSWindow.mm @@ -1,4 +1,4 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" #endif #include "iOSWindow.h" #include "iOSOS.h" #include "Graphics/RHI/GraphicsContext.h" @@ -17,23 +17,23 @@ { m_Init = false; 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() @@ -49,7 +49,7 @@ m_Data.Width = properties.Width; m_Data.Height = properties.Height; m_Data.Exit = false; - + return true; } @@ -62,7 +62,7 @@ { } - + void iOSWindow::OnUpdate() { @@ -80,7 +80,7 @@ m_Data.EventCallback(*event); delete event; } - + m_QueuedEvents.clear(); } @@ -113,7 +113,7 @@ MouseMovedEvent* event = new MouseMovedEvent((float)xPos, (float)yPos); m_QueuedEvents.push_back(event); - + if(down) { MouseButtonPressedEvent* event2 = new MouseButtonPressedEvent((Lumos::InputCode::MouseKey)Lumos::iOSKeyCodes::iOSTouchToLumosMouseKey(count)); diff --git a/Lumos/Source/Lumos/Scene/Component/AIComponent.cpp b/Lumos/Source/Lumos/Scene/Component/AIComponent.cpp index 9bae38a6c..1a11a7374 100644 --- a/Lumos/Source/Lumos/Scene/Component/AIComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/AIComponent.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "AIComponent.h" #include diff --git a/Lumos/Source/Lumos/Scene/Component/ModelComponent.cpp b/Lumos/Source/Lumos/Scene/Component/ModelComponent.cpp index ddd997aab..85ca5a8ca 100644 --- a/Lumos/Source/Lumos/Scene/Component/ModelComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/ModelComponent.cpp @@ -1,7 +1,9 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ModelComponent.h" #include "Core/Application.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" namespace Lumos::Graphics { diff --git a/Lumos/Source/Lumos/Scene/Component/RigidBody2DComponent.cpp b/Lumos/Source/Lumos/Scene/Component/RigidBody2DComponent.cpp index 9051712e5..9f6707fbf 100644 --- a/Lumos/Source/Lumos/Scene/Component/RigidBody2DComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/RigidBody2DComponent.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "RigidBody2DComponent.h" #include diff --git a/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp b/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp index a58ce2053..e7a66bbf9 100644 --- a/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/RigidBody3DComponent.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "RigidBody3DComponent.h" #include "Scene/Scene.h" #include "Scene/EntityManager.h" diff --git a/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp b/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp index c789f5134..a1094b3f7 100644 --- a/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/SoundComponent.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SoundComponent.h" #include "Scene/Scene.h" #include "Core/Application.h" diff --git a/Lumos/Source/Lumos/Scene/Component/TextureMatrixComponent.cpp b/Lumos/Source/Lumos/Scene/Component/TextureMatrixComponent.cpp index e5d05d582..4e479e4f0 100644 --- a/Lumos/Source/Lumos/Scene/Component/TextureMatrixComponent.cpp +++ b/Lumos/Source/Lumos/Scene/Component/TextureMatrixComponent.cpp @@ -1,4 +1,6 @@ -#include "Precompiled.h" +#ifndef LUMOS_PLATFORM_MACOS +#include "Precompiled.h" +#endif #include "TextureMatrixComponent.h" namespace Lumos diff --git a/Lumos/Source/Lumos/Scene/EntityFactory.cpp b/Lumos/Source/Lumos/Scene/EntityFactory.cpp index 8c8a03558..a259efb71 100644 --- a/Lumos/Source/Lumos/Scene/EntityFactory.cpp +++ b/Lumos/Source/Lumos/Scene/EntityFactory.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "EntityFactory.h" #include "Physics/LumosPhysicsEngine/CollisionShapes/SphereCollisionShape.h" #include "Physics/LumosPhysicsEngine/CollisionShapes/PyramidCollisionShape.h" diff --git a/Lumos/Source/Lumos/Scene/EntityManager.cpp b/Lumos/Source/Lumos/Scene/EntityManager.cpp index 7682bd390..2a32d9ca2 100644 --- a/Lumos/Source/Lumos/Scene/EntityManager.cpp +++ b/Lumos/Source/Lumos/Scene/EntityManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Entity.h" #include "EntityManager.h" #include "Maths/Random.h" diff --git a/Lumos/Source/Lumos/Scene/Scene.cpp b/Lumos/Source/Lumos/Scene/Scene.cpp index 6f457ecd9..ffff6a82b 100644 --- a/Lumos/Source/Lumos/Scene/Scene.cpp +++ b/Lumos/Source/Lumos/Scene/Scene.cpp @@ -1,9 +1,11 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Scene.h" #include "Core/OS/Input.h" #include "Core/Application.h" #include "Graphics/RHI/GraphicsContext.h" -#include "Graphics/Renderers/RenderPasses.h" +#include "Graphics/Renderers/SceneRenderer.h" #include "Graphics/Camera/Camera.h" #include "Graphics/Sprite.h" #include "Graphics/AnimatedSprite.h" @@ -48,6 +50,8 @@ #include #include #include //For deleting sol::basic_environment> +#include +#include CEREAL_REGISTER_TYPE(Lumos::SphereCollisionShape); CEREAL_REGISTER_TYPE(Lumos::CuboidCollisionShape); @@ -61,6 +65,9 @@ CEREAL_REGISTER_POLYMORPHIC_RELATION(Lumos::CollisionShape, Lumos::PyramidCollis CEREAL_REGISTER_POLYMORPHIC_RELATION(Lumos::CollisionShape, Lumos::HullCollisionShape); CEREAL_REGISTER_POLYMORPHIC_RELATION(Lumos::CollisionShape, Lumos::CapsuleCollisionShape); +#define MIN_SCENE_VERSION 24 + +#if MIN_SCENE_VERSION < 21 #pragma warning(push, 0) // Legacy version of entt snapshot loaded to load older scene versions saved before updating entt namespace entt @@ -210,6 +217,7 @@ namespace entt }; } #pragma warning(pop) +#endif namespace Lumos { @@ -441,28 +449,52 @@ namespace Lumos std::ifstream file(path, std::ios::binary); cereal::BinaryInputArchive input(file); input(*this); - if(m_SceneSerialisationVersion < 2) + if(m_SceneSerialisationVersion == 0) + LUMOS_LOG_ERROR("Invalid Scene Version"); +#if MIN_SCENE_VERSION <= 2 + else if(m_SceneSerialisationVersion < 2) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); +#endif +#if MIN_SCENE_VERSION <= 3 else if(m_SceneSerialisationVersion == 3) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); +#endif +#if MIN_SCENE_VERSION <= 4 else if(m_SceneSerialisationVersion == 4) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); +#endif +#if MIN_SCENE_VERSION <= 5 else if(m_SceneSerialisationVersion == 5) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 6 else if(m_SceneSerialisationVersion == 6) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 7 else if(m_SceneSerialisationVersion == 7) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 13 else if(m_SceneSerialisationVersion >= 8 && m_SceneSerialisationVersion < 14) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 20 else if(m_SceneSerialisationVersion >= 14 && m_SceneSerialisationVersion < 21) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 21 else if(m_SceneSerialisationVersion >= 21 && m_SceneSerialisationVersion < 22) entt::snapshot_loader { m_EntityManager->GetRegistry() }.get(input).ALL_COMPONENTSENTTV8(input); +#endif +#if MIN_SCENE_VERSION <= 25 else if(m_SceneSerialisationVersion >= 22 && m_SceneSerialisationVersion < 25) entt::snapshot_loader { m_EntityManager->GetRegistry() }.get(input).ALL_COMPONENTSENTTV9(input); +#endif else if(m_SceneSerialisationVersion >= 25) entt::snapshot_loader { m_EntityManager->GetRegistry() }.get(input).ALL_COMPONENTSENTTV10(input); + +#if MIN_SCENE_VERSION <= 6 if(m_SceneSerialisationVersion < 6) { // m_EntityManager->GetRegistry().each([&](auto entity) @@ -471,7 +503,9 @@ namespace Lumos m_EntityManager->GetRegistry().emplace(entity, Random64::Rand(0, std::numeric_limits::max())); } } +#endif +#if MIN_SCENE_VERSION <= 7 if(m_SceneSerialisationVersion < 7) { // m_EntityManager->GetRegistry().each([&](auto entity) @@ -486,6 +520,7 @@ namespace Lumos } } } +#endif } catch(...) { @@ -509,28 +544,51 @@ namespace Lumos cereal::JSONInputArchive input(istr); input(*this); + if(m_SceneSerialisationVersion == 0) + LUMOS_LOG_ERROR("Invalid Scene Version"); +#if MIN_SCENE_VERSION <= 2 if(m_SceneSerialisationVersion < 2) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); +#endif +#if MIN_SCENE_VERSION <= 3 else if(m_SceneSerialisationVersion == 3) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); +#endif +#if MIN_SCENE_VERSION <= 4 else if(m_SceneSerialisationVersion == 4) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input).orphans(); +#endif +#if MIN_SCENE_VERSION <= 5 else if(m_SceneSerialisationVersion == 5) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 6 else if(m_SceneSerialisationVersion == 6) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 7 else if(m_SceneSerialisationVersion == 7) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 13 else if(m_SceneSerialisationVersion >= 8 && m_SceneSerialisationVersion < 14) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 20 else if(m_SceneSerialisationVersion >= 14 && m_SceneSerialisationVersion < 21) entt::basic_snapshot_loader_legacy { m_EntityManager->GetRegistry() }.entities(input).component(input); +#endif +#if MIN_SCENE_VERSION <= 21 else if(m_SceneSerialisationVersion >= 21 && m_SceneSerialisationVersion < 22) entt::snapshot_loader { m_EntityManager->GetRegistry() }.get(input).ALL_COMPONENTSENTTV8(input); +#endif +#if MIN_SCENE_VERSION <= 24 else if(m_SceneSerialisationVersion >= 22 && m_SceneSerialisationVersion < 25) entt::snapshot_loader { m_EntityManager->GetRegistry() }.get(input).ALL_COMPONENTSENTTV9(input); +#endif else if(m_SceneSerialisationVersion >= 25) entt::snapshot_loader { m_EntityManager->GetRegistry() }.get(input).ALL_COMPONENTSENTTV10(input); +#if MIN_SCENE_VERSION <= 6 if(m_SceneSerialisationVersion < 6) { // m_EntityManager->GetRegistry().each([&](auto entity) @@ -539,7 +597,8 @@ namespace Lumos m_EntityManager->GetRegistry().emplace(entity, Random64::Rand(0, std::numeric_limits::max())); } } - +#endif +#if MIN_SCENE_VERSION <= 7 if(m_SceneSerialisationVersion < 7) { // m_EntityManager->GetRegistry().each([&](auto entity) @@ -554,6 +613,7 @@ namespace Lumos } } } +#endif } catch(...) { diff --git a/Lumos/Source/Lumos/Scene/SceneGraph.cpp b/Lumos/Source/Lumos/Scene/SceneGraph.cpp index 144181be0..b619aa6de 100644 --- a/Lumos/Source/Lumos/Scene/SceneGraph.cpp +++ b/Lumos/Source/Lumos/Scene/SceneGraph.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SceneGraph.h" #include "Maths/Transform.h" diff --git a/Lumos/Source/Lumos/Scene/SceneManager.cpp b/Lumos/Source/Lumos/Scene/SceneManager.cpp index 6fcd4d4e1..3256ab08f 100644 --- a/Lumos/Source/Lumos/Scene/SceneManager.cpp +++ b/Lumos/Source/Lumos/Scene/SceneManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SceneManager.h" #include "Physics/B2PhysicsEngine/B2PhysicsEngine.h" diff --git a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.cpp b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.cpp index 87cbafb61..f7c502a60 100644 --- a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.cpp +++ b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SerialisationImplementation.h" #include diff --git a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h index e3c9cc93c..925e210c7 100644 --- a/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h +++ b/Lumos/Source/Lumos/Scene/Serialisation/SerialisationImplementation.h @@ -9,12 +9,14 @@ #include "Graphics/Material.h" #include "Graphics/Sprite.h" #include "Graphics/AnimatedSprite.h" -#include "Utilities/AssetManager.h" +#include "Core/Asset/AssetManager.h" #include "Utilities/StringUtilities.h" #include "Scene/Component/ModelComponent.h" #include "Scene/Component/Components.h" #include "Core/Application.h" #include "Physics/LumosPhysicsEngine/RigidBody3D.h" +#include "Core/Asset/Asset.h" +#include "Core/Asset/AssetRegistry.h" #include #include diff --git a/Lumos/Source/Lumos/Scene/SystemManager.cpp b/Lumos/Source/Lumos/Scene/SystemManager.cpp index 93aa1f74f..37714c1e0 100644 --- a/Lumos/Source/Lumos/Scene/SystemManager.cpp +++ b/Lumos/Source/Lumos/Scene/SystemManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "SystemManager.h" #include diff --git a/Lumos/Source/Lumos/Scripting/Lua/ImGuiLua.cpp b/Lumos/Source/Lumos/Scripting/Lua/ImGuiLua.cpp index 3a9c36659..0859099e3 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/ImGuiLua.cpp +++ b/Lumos/Source/Lumos/Scripting/Lua/ImGuiLua.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "ImGuiLua.h" #ifdef BIND_IMGUI_LUA diff --git a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp index f7a3171bc..a8513dc13 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp +++ b/Lumos/Source/Lumos/Scripting/Lua/LuaManager.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "LuaManager.h" #include "Maths/Transform.h" #include "Core/OS/Window.h" @@ -574,50 +576,49 @@ namespace Lumos state.new_enum("PrimitiveType", primitives); - state.new_usertype("Model", - // Constructors - sol::constructors< - Lumos::Graphics::Model(), - Lumos::Graphics::Model(const std::string&), - Lumos::Graphics::Model(const Lumos::SharedPtr&, Lumos::Graphics::PrimitiveType), - Lumos::Graphics::Model(Lumos::Graphics::PrimitiveType)>(), - // Properties - "meshes", &Lumos::Graphics::Model::GetMeshes, - "file_path", &Lumos::Graphics::Model::GetFilePath, - "primitive_type", sol::property(&Lumos::Graphics::Model::GetPrimitiveType, &Lumos::Graphics::Model::SetPrimitiveType), - // Methods - "add_mesh", &Lumos::Graphics::Model::AddMesh, - "load_model", &Lumos::Graphics::Model::LoadModel); + auto Modeltype = state.new_usertype("Model"); + + // Constructors + Modeltype[sol::call_constructor] = sol::constructors< + Lumos::Graphics::Model(), + Lumos::Graphics::Model(const std::string&), + Lumos::Graphics::Model(const Lumos::SharedPtr&, Lumos::Graphics::PrimitiveType), + Lumos::Graphics::Model(Lumos::Graphics::PrimitiveType)>(); + + // Properties + Modeltype["meshes"] = &Lumos::Graphics::Model::GetMeshes; + Modeltype["file_path"] = &Lumos::Graphics::Model::GetFilePath; + Modeltype["primitive_type"] = sol::property(&Lumos::Graphics::Model::GetPrimitiveType, &Lumos::Graphics::Model::SetPrimitiveType); + + // Methods + Modeltype["add_mesh"] = &Lumos::Graphics::Model::AddMesh; + Modeltype["load_model"] = &Lumos::Graphics::Model::LoadModel; REGISTER_COMPONENT_WITH_ECS(state, Model, static_cast(&Entity::AddComponent)); - // Member functions - sol::usertype material_type = state.new_usertype("Material", - - sol::constructors< - Lumos::Graphics::Material()>(), - // Setters - "set_albedo_texture", &Material::SetAlbedoTexture, - "set_normal_texture", &Material::SetNormalTexture, - "set_roughness_texture", &Material::SetRoughnessTexture, - "set_metallic_texture", &Material::SetMetallicTexture, - "set_ao_texture", &Material::SetAOTexture, - "set_emissive_texture", &Material::SetEmissiveTexture, - - // Getters - "get_name", &Material::GetName, - "get_properties", &Material::GetProperties, - //"get_textures", &Material::GetTextures, - "get_shader", &Material::GetShader, - - // Other member functions - "load_pbr_material", &Material::LoadPBRMaterial, - "load_material", &Material::LoadMaterial, - "set_textures", &Material::SetTextures, - "set_material_properties", &Material::SetMaterialProperites, - "update_material_properties_data", &Material::UpdateMaterialPropertiesData, - "set_name", &Material::SetName, - "bind", &Material::Bind); + auto material_type = state.new_usertype("Material"); + // Setters + material_type["set_albedo_texture"] = &Material::SetAlbedoTexture; + material_type["set_normal_texture"] = &Material::SetNormalTexture; + material_type["set_roughness_texture"] = &Material::SetRoughnessTexture; + material_type["set_metallic_texture"] = &Material::SetMetallicTexture; + material_type["set_ao_texture"] = &Material::SetAOTexture; + material_type["set_emissive_texture"] = &Material::SetEmissiveTexture; + + // Getters + material_type["get_name"] = &Material::GetName; + material_type["get_properties"] = &Material::GetProperties; + // material_type["get_textures"] = &Material::GetTextures; // Commented out in original + material_type["get_shader"] = &Material::GetShader; + + // Other member functions + material_type["load_pbr_material"] = &Material::LoadPBRMaterial; + material_type["load_material"] = &Material::LoadMaterial; + material_type["set_textures"] = &Material::SetTextures; + material_type["set_material_properties"] = &Material::SetMaterialProperites; + material_type["update_material_properties_data"] = &Material::UpdateMaterialPropertiesData; + material_type["set_name"] = &Material::SetName; + material_type["bind"] = &Material::Bind; // Enum for RenderFlags std::initializer_list> render_flags = { diff --git a/Lumos/Source/Lumos/Scripting/Lua/LuaScriptComponent.cpp b/Lumos/Source/Lumos/Scripting/Lua/LuaScriptComponent.cpp index 11f0d648d..562ccd413 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/LuaScriptComponent.cpp +++ b/Lumos/Source/Lumos/Scripting/Lua/LuaScriptComponent.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "LuaScriptComponent.h" #include "LuaManager.h" #include "Scene/Scene.h" diff --git a/Lumos/Source/Lumos/Scripting/Lua/MathsLua.cpp b/Lumos/Source/Lumos/Scripting/Lua/MathsLua.cpp index ee023ceaf..20427ae94 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/MathsLua.cpp +++ b/Lumos/Source/Lumos/Scripting/Lua/MathsLua.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "MathsLua.h" #include "Maths/Transform.h" #include @@ -14,27 +16,47 @@ namespace Lumos void BindMathsLua(sol::state& state) { LUMOS_PROFILE_FUNCTION(); - state.new_usertype( - "Vector2", - sol::constructors(), - "x", &glm::vec2::x, - "y", &glm::vec2::y, - sol::meta_function::addition, [](const glm::vec2& a, const glm::vec2& b) - { return a + b; }, - sol::meta_function::multiplication, [](const glm::vec2& a, const glm::vec2& b) - { return a * b; }, - sol::meta_function::subtraction, [](const glm::vec2& a, const glm::vec2& b) - { return a - b; }, - sol::meta_function::division, [](const glm::vec2& a, const glm::vec2& b) - { return a / b; }, - sol::meta_function::equal_to, [](const glm::vec2& a, const glm::vec2& b) - { return a == b; }, - "Length", [](const glm::vec2& v) - { return glm::length(v); }, - "Distance", [](const glm::vec2& a, const glm::vec2& b) - { return glm::distance(a, b); }, - "Distance2", [](const glm::vec2& a, const glm::vec2& b) - { return glm::distance2(a, b); }); + auto Vector2type = state.new_usertype("Vector2", sol::constructors()); + + // Fields + Vector2type["x"] = &glm::vec2::x; + Vector2type["y"] = &glm::vec2::y; + + // Meta functions + Vector2type[sol::meta_function::addition] = [](const glm::vec2& a, const glm::vec2& b) + { + return a + b; + }; + Vector2type[sol::meta_function::multiplication] = [](const glm::vec2& a, const glm::vec2& b) + { + return a * b; + }; + Vector2type[sol::meta_function::subtraction] = [](const glm::vec2& a, const glm::vec2& b) + { + return a - b; + }; + Vector2type[sol::meta_function::division] = [](const glm::vec2& a, const glm::vec2& b) + { + return a / b; + }; + Vector2type[sol::meta_function::equal_to] = [](const glm::vec2& a, const glm::vec2& b) + { + return a == b; + }; + + // Methods + Vector2type["Length"] = [](const glm::vec2& v) + { + return glm::length(v); + }; + Vector2type["Distance"] = [](const glm::vec2& a, const glm::vec2& b) + { + return glm::distance(a, b); + }; + Vector2type["Distance2"] = [](const glm::vec2& a, const glm::vec2& b) + { + return glm::distance2(a, b); + }; auto mult_overloads = sol::overload( [](const glm::vec3& v1, const glm::vec3& v2) -> glm::vec3 @@ -44,112 +66,209 @@ namespace Lumos [](float f, const glm::vec3& v1) -> glm::vec3 { return f * v1; }); - state.new_usertype( - "Vector3", - sol::constructors, sol::types>(), - "x", &glm::vec3::x, - "y", &glm::vec3::y, - "z", &glm::vec3::z, - sol::meta_function::addition, [](const glm::vec3& a, const glm::vec3& b) - { return a + b; }, - sol::meta_function::multiplication, mult_overloads, - sol::meta_function::subtraction, [](const glm::vec3& a, const glm::vec3& b) - { return a - b; }, - sol::meta_function::unary_minus, [](glm::vec3& v) -> glm::vec3 - { return -v; }, - sol::meta_function::division, [](const glm::vec3& a, const glm::vec3& b) - { return a / b; }, - sol::meta_function::equal_to, [](const glm::vec3& a, const glm::vec3& b) - { return a == b; }, - "Normalise", [](glm::vec3& v) - { return glm::normalize(v); }, - "Length", [](const glm::vec3& v) - { return glm::length(v); }, - "Distance", [](const glm::vec3& a, const glm::vec3& b) - { return glm::distance(a, b); }, - "Distance2", [](const glm::vec3& a, const glm::vec3& b) - { return glm::distance2(a, b); }); - - state.new_usertype( - "Vector4", - sol::constructors(), - "x", &glm::vec4::x, - "y", &glm::vec4::y, - "z", &glm::vec4::z, - "w", &glm::vec4::w, - sol::meta_function::addition, [](const glm::vec4& a, const glm::vec4& b) - { return a + b; }, - sol::meta_function::multiplication, [](const glm::vec4& a, const glm::vec4& b) - { return a * b; }, - sol::meta_function::multiplication, sol::overload([](const glm::vec4& v1, const glm::vec4& v2) -> glm::vec4 - { return v1 * v2; }, [](const glm::vec4& v1, float f) -> glm::vec4 - { return v1 * f; }, [](float f, const glm::vec4& v1) -> glm::vec4 - { return f * v1; }), - sol::meta_function::multiplication, [](float a, const glm::vec4& b) - { return a * b; }, - sol::meta_function::subtraction, [](const glm::vec4& a, const glm::vec4& b) - { return a - b; }, - sol::meta_function::division, [](const glm::vec4& a, const glm::vec4& b) - { return a / b; }, - sol::meta_function::equal_to, [](const glm::vec4& a, const glm::vec4& b) - { return a == b; }, - "Normalise", [](glm::vec4& v) - { return glm::normalize(v); }, - "Length", [](const glm::vec4& v) - { return glm::length(v); }, - "Distance", [](const glm::vec4& a, const glm::vec4& b) - { return glm::distance(a, b); }, - "Distance2", [](const glm::vec4& a, const glm::vec4& b) - { return glm::distance2(a, b); }); - - state.new_usertype( - "Quaternion", - sol::constructors(), - "x", &glm::quat::x, - "y", &glm::quat::y, - "z", &glm::quat::z, - "w", &glm::quat::w, - sol::meta_function::addition, [](const glm::quat& a, const glm::quat& b) - { return a + b; }, - sol::meta_function::multiplication, [](const glm::quat& a, const glm::quat& b) - { return a * b; }, - sol::meta_function::subtraction, [](const glm::quat& a, const glm::quat& b) - { return a - b; }, - sol::meta_function::equal_to, [](const glm::quat& a, const glm::quat& b) - { return a == b; }, - "Normalise", [](glm::quat& q) - { return glm::normalize(q); }); - - state.new_usertype("Matrix3", - sol::constructors(), - sol::meta_function::multiplication, [](const glm::mat3& a, const glm::mat3& b) - { return a * b; }); - - state.new_usertype( - "Matrix4", - sol::constructors(), - sol::meta_function::multiplication, [](const glm::mat4& a, const glm::mat4& b) - { return a * b; }, - sol::meta_function::addition, [](const glm::mat4& a, const glm::mat4& b) - { return a + b; }, - sol::meta_function::subtraction, [](const glm::mat4& a, const glm::mat4& b) - { return a - b; }); - - state.new_usertype("Transform", - sol::constructors(), - - "LocalScale", &Maths::Transform::GetLocalScale, - "LocalOrientation", &Maths::Transform::GetLocalOrientation, - "LocalPosition", &Maths::Transform::GetLocalPosition, - "ApplyTransform", &Maths::Transform::ApplyTransform, - "UpdateMatrices", &Maths::Transform::UpdateMatrices, - "SetLocalTransform", &Maths::Transform::SetLocalTransform, - "SetLocalPosition", &Maths::Transform::SetLocalPosition, - "SetLocalScale", &Maths::Transform::SetLocalScale, - "SetLocalOrientation", &Maths::Transform::SetLocalOrientation, - "GetWorldPosition", &Maths::Transform::GetWorldPosition, - "GetWorldOrientation", &Maths::Transform::GetWorldOrientation, - "GetForwardDirection", &Maths::Transform::GetForwardDirection, - "GetRightDirection", &Maths::Transform::GetRightDirection); + auto Vector3type = state.new_usertype("Vector3", sol::constructors()); + + // Fields + Vector3type["x"] = &glm::vec3::x; + Vector3type["y"] = &glm::vec3::y; + Vector3type["z"] = &glm::vec3::z; + + // Meta functions + Vector3type[sol::meta_function::addition] = [](const glm::vec3& a, const glm::vec3& b) + { + return a + b; + }; + + Vector3type[sol::meta_function::multiplication] = mult_overloads; + + Vector3type[sol::meta_function::subtraction] = [](const glm::vec3& a, const glm::vec3& b) + { + return a - b; + }; + + Vector3type[sol::meta_function::unary_minus] = [](glm::vec3& v) -> glm::vec3 + { + return -v; + }; + + Vector3type[sol::meta_function::division] = [](const glm::vec3& a, const glm::vec3& b) + { + return a / b; + }; + + Vector3type[sol::meta_function::equal_to] = [](const glm::vec3& a, const glm::vec3& b) + { + return a == b; + }; + + // Methods + Vector3type["Normalise"] = [](glm::vec3& v) + { + return glm::normalize(v); + }; + + Vector3type["Length"] = [](const glm::vec3& v) + { + return glm::length(v); + }; + + Vector3type["Distance"] = [](const glm::vec3& a, const glm::vec3& b) + { + return glm::distance(a, b); + }; + + Vector3type["Distance2"] = [](const glm::vec3& a, const glm::vec3& b) + { + return glm::distance2(a, b); + }; + + auto Vector4type = state.new_usertype("Vector4", sol::constructors()); + + // Fields + Vector4type["x"] = &glm::vec4::x; + Vector4type["y"] = &glm::vec4::y; + Vector4type["z"] = &glm::vec4::z; + Vector4type["w"] = &glm::vec4::w; + + // Meta functions + Vector4type[sol::meta_function::addition] = [](const glm::vec4& a, const glm::vec4& b) + { + return a + b; + }; + + Vector4type[sol::meta_function::multiplication] = sol::overload( + [](const glm::vec4& v1, const glm::vec4& v2) -> glm::vec4 + { + return v1 * v2; + }, + [](const glm::vec4& v1, float f) -> glm::vec4 + { + return v1 * f; + }, + [](float f, const glm::vec4& v1) -> glm::vec4 + { + return f * v1; + }); + + Vector4type[sol::meta_function::subtraction] = [](const glm::vec4& a, const glm::vec4& b) + { + return a - b; + }; + + Vector4type[sol::meta_function::division] = [](const glm::vec4& a, const glm::vec4& b) + { + return a / b; + }; + + Vector4type[sol::meta_function::equal_to] = [](const glm::vec4& a, const glm::vec4& b) + { + return a == b; + }; + + // Methods + Vector4type["Normalise"] = [](glm::vec4& v) + { + return glm::normalize(v); + }; + + Vector4type["Length"] = [](const glm::vec4& v) + { + return glm::length(v); + }; + + Vector4type["Distance"] = [](const glm::vec4& a, const glm::vec4& b) + { + return glm::distance(a, b); + }; + + Vector4type["Distance2"] = [](const glm::vec4& a, const glm::vec4& b) + { + return glm::distance2(a, b); + }; + + auto QuaternionType = state.new_usertype("Quaternion", sol::constructors()); + + // Fields + QuaternionType["x"] = &glm::quat::x; + QuaternionType["y"] = &glm::quat::y; + QuaternionType["z"] = &glm::quat::z; + QuaternionType["w"] = &glm::quat::w; + + // Meta functions + QuaternionType[sol::meta_function::addition] = [](const glm::quat& a, const glm::quat& b) + { + return a + b; + }; + + QuaternionType[sol::meta_function::multiplication] = [](const glm::quat& a, const glm::quat& b) + { + return a * b; + }; + + QuaternionType[sol::meta_function::subtraction] = [](const glm::quat& a, const glm::quat& b) + { + return a - b; + }; + + QuaternionType[sol::meta_function::equal_to] = [](const glm::quat& a, const glm::quat& b) + { + return a == b; + }; + + // Methods + QuaternionType["Normalise"] = [](glm::quat& q) + { + return glm::normalize(q); + }; + + auto Matrix3Type = state.new_usertype("Matrix3", sol::constructors()); + + // Meta functions + Matrix3Type[sol::meta_function::multiplication] = [](const glm::mat3& a, const glm::mat3& b) + { + return a * b; + }; + + auto Matrix4Type = state.new_usertype("Matrix4"); + + // Constructors + Matrix4Type[sol::call_constructor] = sol::constructors< + glm::mat4(float), + glm::mat4()>(); + + // Meta functions + Matrix4Type[sol::meta_function::multiplication] = [](const glm::mat4& a, const glm::mat4& b) + { + return a * b; + }; + + Matrix4Type[sol::meta_function::addition] = [](const glm::mat4& a, const glm::mat4& b) + { + return a + b; + }; + + Matrix4Type[sol::meta_function::subtraction] = [](const glm::mat4& a, const glm::mat4& b) + { + return a - b; + }; + + auto TransformType = state.new_usertype("Transform", sol::constructors()); + + // Fields + TransformType["LocalScale"] = &Maths::Transform::GetLocalScale; + TransformType["LocalOrientation"] = &Maths::Transform::GetLocalOrientation; + TransformType["LocalPosition"] = &Maths::Transform::GetLocalPosition; + + // Methods + TransformType["ApplyTransform"] = &Maths::Transform::ApplyTransform; + TransformType["UpdateMatrices"] = &Maths::Transform::UpdateMatrices; + TransformType["SetLocalTransform"] = &Maths::Transform::SetLocalTransform; + TransformType["SetLocalPosition"] = &Maths::Transform::SetLocalPosition; + TransformType["SetLocalScale"] = &Maths::Transform::SetLocalScale; + TransformType["SetLocalOrientation"] = &Maths::Transform::SetLocalOrientation; + TransformType["GetWorldPosition"] = &Maths::Transform::GetWorldPosition; + TransformType["GetWorldOrientation"] = &Maths::Transform::GetWorldOrientation; + TransformType["GetForwardDirection"] = &Maths::Transform::GetForwardDirection; + TransformType["GetRightDirection"] = &Maths::Transform::GetRightDirection; } } diff --git a/Lumos/Source/Lumos/Scripting/Lua/PhysicsLua.cpp b/Lumos/Source/Lumos/Scripting/Lua/PhysicsLua.cpp index 44d5e4cd9..d0935f43d 100644 --- a/Lumos/Source/Lumos/Scripting/Lua/PhysicsLua.cpp +++ b/Lumos/Source/Lumos/Scripting/Lua/PhysicsLua.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "PhysicsLua.h" #include "Scene/Component/RigidBody2DComponent.h" #include "Scene/Component/RigidBody3DComponent.h" @@ -12,21 +14,37 @@ namespace Lumos { void register_type_b2Vec2(sol::state& state) { - auto b2Vec2_addition_overloads = sol::overload( - [](b2Vec2& left, const b2Vec2& right) - { - b2Vec2 ret = left; - ret += right; - return ret; - }); - auto b2Vec2_subtraction_overloads = sol::overload( - [](b2Vec2& left, const b2Vec2& right) - { - b2Vec2 ret = left; - ret -= right; - return ret; - }); - auto b2Vec2_multiplication_overloads = sol::overload( + auto b2Vec2type = state.new_usertype("b2Vec2", sol::constructors()); + + // Fields + b2Vec2type["x"] = &b2Vec2::x; + b2Vec2type["y"] = &b2Vec2::y; + + // Methods + b2Vec2type["SetZero"] = &b2Vec2::SetZero; + b2Vec2type["Set"] = &b2Vec2::Set; + b2Vec2type["Length"] = &b2Vec2::Length; + b2Vec2type["LengthSquared"] = &b2Vec2::LengthSquared; + b2Vec2type["Normalize"] = &b2Vec2::Normalize; + b2Vec2type["IsValid"] = &b2Vec2::IsValid; + b2Vec2type["Skew"] = &b2Vec2::Skew; + + // Meta-functions + b2Vec2type[sol::meta_function::addition] = [](b2Vec2& left, const b2Vec2& right) + { + b2Vec2 ret = left; + ret += right; + return ret; + }; + + b2Vec2type[sol::meta_function::subtraction] = [](b2Vec2& left, const b2Vec2& right) + { + b2Vec2 ret = left; + ret -= right; + return ret; + }; + + b2Vec2type[sol::meta_function::multiplication] = sol::overload( [](const float& left, b2Vec2& right) { b2Vec2 ret = right; @@ -39,61 +57,36 @@ namespace Lumos ret *= right; return ret; }); - state.new_usertype("b2Vec2" - // fields - , - "x", - &b2Vec2::x, - "y", - &b2Vec2::y - // methods - , - "SetZero", - &b2Vec2::SetZero, - "Set", - &b2Vec2::Set, - "Length", - &b2Vec2::Length, - "LengthSquared", - &b2Vec2::LengthSquared, - "Normalise", - &b2Vec2::Normalize, - "IsValid", - &b2Vec2::IsValid, - "Skew", - &b2Vec2::Skew - // constructors - , - sol::call_constructor, - sol::constructors< - b2Vec2(), - b2Vec2(float, float)>() - // metas - , - sol::meta_function::addition, - b2Vec2_addition_overloads, - sol::meta_function::subtraction, - b2Vec2_subtraction_overloads, - sol::meta_function::multiplication, - b2Vec2_multiplication_overloads); } void register_type_b2Vec3(sol::state& state) { - auto b2Vec3_addition_overloads = sol::overload( - [](b2Vec3& left, const b2Vec3& right) - { - b2Vec3 ret = left; - ret += right; - return ret; - }); - auto b2Vec3_subtraction_overloads = sol::overload( - [](b2Vec3& left, const b2Vec3& right) - { - b2Vec3 ret = left; - ret -= right; - return ret; - }); - auto b2Vec3_multiplication_overloads = sol::overload( + auto b2Vec3type = state.new_usertype("b2Vec3", sol::constructors()); + + // Fields + b2Vec3type["x"] = &b2Vec3::x; + b2Vec3type["y"] = &b2Vec3::y; + b2Vec3type["z"] = &b2Vec3::z; + + // Methods + b2Vec3type["SetZero"] = &b2Vec3::SetZero; + b2Vec3type["Set"] = &b2Vec3::Set; + + // Meta-functions + b2Vec3type[sol::meta_function::addition] = [](b2Vec3& left, const b2Vec3& right) + { + b2Vec3 ret = left; + ret += right; + return ret; + }; + + b2Vec3type[sol::meta_function::subtraction] = [](b2Vec3& left, const b2Vec3& right) + { + b2Vec3 ret = left; + ret -= right; + return ret; + }; + + b2Vec3type[sol::meta_function::multiplication] = sol::overload( [](const float& left, b2Vec3& right) { b2Vec3 ret = right; @@ -106,172 +99,86 @@ namespace Lumos ret *= right; return ret; }); - state.new_usertype("b2Vec3" - // fields - , - "x", - &b2Vec3::x, - "y", - &b2Vec3::y, - "z", - &b2Vec3::z - // methods - , - "SetZero", - &b2Vec3::SetZero, - "Set", - &b2Vec3::Set - // constructors - , - sol::call_constructor, - sol::constructors< - b2Vec3(), - b2Vec3(float, float, float)>() - // metas - , - sol::meta_function::addition, - b2Vec3_addition_overloads, - sol::meta_function::subtraction, - b2Vec3_subtraction_overloads, - sol::meta_function::multiplication, - b2Vec3_multiplication_overloads); } void register_type_b2Mat22(sol::state& state) { - state.new_usertype("b2Mat22" - // fields - , - "ex", - &b2Mat22::ex, - "ey", - &b2Mat22::ey - // methods - , - "Set", - &b2Mat22::Set, - "SetIdentity", - &b2Mat22::SetIdentity, - "SetZero", - &b2Mat22::SetZero, - "GetInverse", - &b2Mat22::GetInverse, - "Solve", - &b2Mat22::Solve - // constructors - , - sol::call_constructor, - sol::constructors< - b2Mat22(), - b2Mat22(const b2Vec2&, const b2Vec2&), - b2Mat22(float, float, float, float)>()); + auto b2Mat22type = state.new_usertype("b2Mat22", sol::constructors()); + + // Fields + b2Mat22type["ex"] = &b2Mat22::ex; + b2Mat22type["ey"] = &b2Mat22::ey; + + // Methods + b2Mat22type["Set"] = &b2Mat22::Set; + b2Mat22type["SetIdentity"] = &b2Mat22::SetIdentity; + b2Mat22type["SetZero"] = &b2Mat22::SetZero; + b2Mat22type["GetInverse"] = &b2Mat22::GetInverse; + b2Mat22type["Solve"] = &b2Mat22::Solve; } void register_type_b2Mat33(sol::state& state) { - state.new_usertype("b2Mat33" - // fields - , - "ex", - &b2Mat33::ex, - "ey", - &b2Mat33::ey, - "ez", - &b2Mat33::ez - // methods - , - "SetZero", - &b2Mat33::SetZero, - "Solve33", - &b2Mat33::Solve33, - "Solve22", - &b2Mat33::Solve22, - "GetInverse22", - &b2Mat33::GetInverse22, - "GetSymInverse33", - &b2Mat33::GetSymInverse33 - // constructors - , - sol::call_constructor, - sol::constructors< - b2Mat33(), - b2Mat33(const b2Vec3&, const b2Vec3&, const b2Vec3&)>()); + auto b2Mat33type = state.new_usertype("b2Mat33", sol::constructors()); + + // Fields + b2Mat33type["ex"] = &b2Mat33::ex; + b2Mat33type["ey"] = &b2Mat33::ey; + b2Mat33type["ez"] = &b2Mat33::ez; + + // Methods + b2Mat33type["SetZero"] = &b2Mat33::SetZero; + b2Mat33type["Solve33"] = &b2Mat33::Solve33; + b2Mat33type["Solve22"] = &b2Mat33::Solve22; + b2Mat33type["GetInverse22"] = &b2Mat33::GetInverse22; + b2Mat33type["GetSymInverse33"] = &b2Mat33::GetSymInverse33; } void register_type_b2Rot(sol::state& state) { - state.new_usertype("b2Rot" - // fields - , - "s", - &b2Rot::s, - "c", - &b2Rot::c - // methods - , - "Set", - &b2Rot::Set, - "SetIdentity", - &b2Rot::SetIdentity, - "GetAngle", - &b2Rot::GetAngle, - "GetXAxis", - &b2Rot::GetXAxis, - "GetYAxis", - &b2Rot::GetYAxis - // constructors - , - sol::call_constructor, - sol::constructors< - b2Rot(), - b2Rot(float)>()); + auto b2Rottype = state.new_usertype("b2Rot", sol::constructors()); + + // Fields + b2Rottype["s"] = &b2Rot::s; + b2Rottype["c"] = &b2Rot::c; + + // Methods + b2Rottype["Set"] = &b2Rot::Set; + b2Rottype["SetIdentity"] = &b2Rot::SetIdentity; + b2Rottype["GetAngle"] = &b2Rot::GetAngle; + b2Rottype["GetXAxis"] = &b2Rot::GetXAxis; + b2Rottype["GetYAxis"] = &b2Rot::GetYAxis; } void register_type_b2Transform(sol::state& state) { - state.new_usertype("b2Transform" - // fields - , - "p", - &b2Transform::p, - "q", - &b2Transform::q - // methods - , - "SetIdentity", - &b2Transform::SetIdentity, - "Set", - &b2Transform::Set - // constructors - , - sol::call_constructor, - sol::constructors< - b2Transform(), - b2Transform(const b2Vec2&, const b2Rot&)>()); + auto b2Transformtype = state.new_usertype("b2Transform"); + + // Fields + b2Transformtype["p"] = &b2Transform::p; + b2Transformtype["q"] = &b2Transform::q; + + // Methods + b2Transformtype["SetIdentity"] = &b2Transform::SetIdentity; + b2Transformtype["Set"] = &b2Transform::Set; + + // Constructors + b2Transformtype[sol::call_constructor] = sol::constructors< + b2Transform(), + b2Transform(const b2Vec2&, const b2Rot&)>(); } void register_type_b2Sweep(sol::state& state) { - state.new_usertype("b2Sweep" - // fields - , - "localCenter", - &b2Sweep::localCenter, - "c0", - &b2Sweep::c0, - "c", - &b2Sweep::c, - "a0", - &b2Sweep::a0, - "a", - &b2Sweep::a, - "alpha0", - &b2Sweep::alpha0 - // methods - , - "GetTransform", - &b2Sweep::GetTransform, - "Advance", - &b2Sweep::Advance, - "Normalise", - &b2Sweep::Normalize - // constructors - ); + auto b2Sweeptype = state.new_usertype("b2Sweep"); + + // Fields + b2Sweeptype["localCenter"] = &b2Sweep::localCenter; + b2Sweeptype["c0"] = &b2Sweep::c0; + b2Sweeptype["c"] = &b2Sweep::c; + b2Sweeptype["a0"] = &b2Sweep::a0; + b2Sweeptype["a"] = &b2Sweep::a; + b2Sweeptype["alpha0"] = &b2Sweep::alpha0; + + // Methods + b2Sweeptype["GetTransform"] = &b2Sweep::GetTransform; + b2Sweeptype["Advance"] = &b2Sweep::Advance; + b2Sweeptype["Normalize"] = &b2Sweep::Normalize; } class ContactListener : public b2ContactListener @@ -384,44 +291,88 @@ namespace Lumos state.new_enum("b2BodyType", "b2_staticBody", b2BodyType::b2_staticBody, "b2_kinematicBody", b2BodyType::b2_kinematicBody, "b2_dynamicBody", b2BodyType::b2_dynamicBody); - state.new_usertype("b2BodyDef" - // fields - , - "type", - &b2BodyDef::type, - "position", - &b2BodyDef::position, - "angle", - &b2BodyDef::angle, - "linearVelocity", - &b2BodyDef::linearVelocity, - "angularVelocity", - &b2BodyDef::angularVelocity, - "linearDamping", - &b2BodyDef::linearDamping, - "angularDamping", - &b2BodyDef::angularDamping, - "allowSleep", - &b2BodyDef::allowSleep, - "awake", - &b2BodyDef::awake, - "fixedRotation", - &b2BodyDef::fixedRotation, - "bullet", - &b2BodyDef::bullet, - "userData", - &b2BodyDef::userData, - "gravityScale", - &b2BodyDef::gravityScale - // methods - // constructors - , - sol::call_constructor, - sol::constructors< - b2BodyDef()>()); - - state.new_usertype("b2Body", "CreateFixture", sol::overload(sol::resolve(&b2Body::CreateFixture), sol::resolve(&b2Body::CreateFixture)), "DestroyFixture", &b2Body::DestroyFixture, "SetTransform", &b2Body::SetTransform, "GetTransform", &b2Body::GetTransform, "GetPosition", &b2Body::GetPosition, "GetAngle", &b2Body::GetAngle, "GetWorldCenter", &b2Body::GetWorldCenter, "GetLocalCenter", &b2Body::GetLocalCenter, "SetLinearVelocity", &b2Body::SetLinearVelocity, "GetLinearVelocity", &b2Body::GetLinearVelocity, "SetAngularVelocity", &b2Body::SetAngularVelocity, "GetAngularVelocity", &b2Body::GetAngularVelocity, "ApplyForce", &b2Body::ApplyForce, "ApplyForceToCenter", &b2Body::ApplyForceToCenter, "ApplyTorque", &b2Body::ApplyTorque, "ApplyLinearImpulse", &b2Body::ApplyLinearImpulse, "ApplyAngularImpulse", &b2Body::ApplyAngularImpulse, "GetMass", &b2Body::GetMass, "GetInertia", &b2Body::GetInertia, "GetMassData", &b2Body::GetMassData, "SetMassData", &b2Body::SetMassData, "ResetMassData", &b2Body::ResetMassData, "GetWorldPoint", &b2Body::GetWorldPoint, "GetWorldVector", &b2Body::GetWorldVector, "GetLocalPoint", &b2Body::GetLocalPoint, "GetLocalVector", &b2Body::GetLocalVector, "GetLinearVelocityFromWorldPoint", &b2Body::GetLinearVelocityFromWorldPoint, "GetLinearVelocityFromLocalPoint", &b2Body::GetLinearVelocityFromLocalPoint, "GetLinearDamping", &b2Body::GetLinearDamping, "SetLinearDamping", &b2Body::SetLinearDamping, "GetAngularDamping", &b2Body::GetAngularDamping, "SetAngularDamping", &b2Body::SetAngularDamping, "GetGravityScale", &b2Body::GetGravityScale, "SetGravityScale", &b2Body::SetGravityScale, "SetType", &b2Body::SetType, "GetType", &b2Body::GetType, "SetBullet", &b2Body::SetBullet, "IsBullet", &b2Body::IsBullet, "SetSleepingAllowed", &b2Body::SetSleepingAllowed, "IsSleepingAllowed", &b2Body::IsSleepingAllowed, "SetAwake", &b2Body::SetAwake, "IsAwake", &b2Body::IsAwake, "SetFixedRotation", &b2Body::SetFixedRotation, "IsFixedRotation", &b2Body::IsFixedRotation, "GetFixtureList", sol::overload(sol::resolve(&b2Body::GetFixtureList), sol::resolve(&b2Body::GetFixtureList)), "GetJointList", sol::overload(sol::resolve(&b2Body::GetJointList), sol::resolve(&b2Body::GetJointList)), "GetContactList", sol::overload(sol::resolve(&b2Body::GetContactList), sol::resolve(&b2Body::GetContactList)), "GetNext", sol::overload(sol::resolve(&b2Body::GetNext), sol::resolve(&b2Body::GetNext)), "GetUserData", &b2Body::GetUserData, /*"SetUserData", &b2Body::SetUserData,*/ "GetWorld", sol::overload(sol::resolve(&b2Body::GetWorld), sol::resolve(&b2Body::GetWorld)), "Dump", &b2Body::Dump - // constructors - ); + auto b2BodyDeftype = state.new_usertype("b2BodyDef", sol::constructors()); + + // Fields + b2BodyDeftype["type"] = &b2BodyDef::type; + b2BodyDeftype["position"] = &b2BodyDef::position; + b2BodyDeftype["angle"] = &b2BodyDef::angle; + b2BodyDeftype["linearVelocity"] = &b2BodyDef::linearVelocity; + b2BodyDeftype["angularVelocity"] = &b2BodyDef::angularVelocity; + b2BodyDeftype["linearDamping"] = &b2BodyDef::linearDamping; + b2BodyDeftype["angularDamping"] = &b2BodyDef::angularDamping; + b2BodyDeftype["allowSleep"] = &b2BodyDef::allowSleep; + b2BodyDeftype["awake"] = &b2BodyDef::awake; + b2BodyDeftype["fixedRotation"] = &b2BodyDef::fixedRotation; + b2BodyDeftype["bullet"] = &b2BodyDef::bullet; + b2BodyDeftype["userData"] = &b2BodyDef::userData; + b2BodyDeftype["gravityScale"] = &b2BodyDef::gravityScale; + + auto b2Bodytype = state.new_usertype("b2Body"); + + // Methods + b2Bodytype["CreateFixture"] = sol::overload( + sol::resolve(&b2Body::CreateFixture), + sol::resolve(&b2Body::CreateFixture)); + b2Bodytype["DestroyFixture"] = &b2Body::DestroyFixture; + b2Bodytype["SetTransform"] = &b2Body::SetTransform; + b2Bodytype["GetTransform"] = &b2Body::GetTransform; + b2Bodytype["GetPosition"] = &b2Body::GetPosition; + b2Bodytype["GetAngle"] = &b2Body::GetAngle; + b2Bodytype["GetWorldCenter"] = &b2Body::GetWorldCenter; + b2Bodytype["GetLocalCenter"] = &b2Body::GetLocalCenter; + b2Bodytype["SetLinearVelocity"] = &b2Body::SetLinearVelocity; + b2Bodytype["GetLinearVelocity"] = &b2Body::GetLinearVelocity; + b2Bodytype["SetAngularVelocity"] = &b2Body::SetAngularVelocity; + b2Bodytype["GetAngularVelocity"] = &b2Body::GetAngularVelocity; + b2Bodytype["ApplyForce"] = &b2Body::ApplyForce; + b2Bodytype["ApplyForceToCenter"] = &b2Body::ApplyForceToCenter; + b2Bodytype["ApplyTorque"] = &b2Body::ApplyTorque; + b2Bodytype["ApplyLinearImpulse"] = &b2Body::ApplyLinearImpulse; + b2Bodytype["ApplyAngularImpulse"] = &b2Body::ApplyAngularImpulse; + b2Bodytype["GetMass"] = &b2Body::GetMass; + b2Bodytype["GetInertia"] = &b2Body::GetInertia; + b2Bodytype["GetMassData"] = &b2Body::GetMassData; + b2Bodytype["SetMassData"] = &b2Body::SetMassData; + b2Bodytype["ResetMassData"] = &b2Body::ResetMassData; + b2Bodytype["GetWorldPoint"] = &b2Body::GetWorldPoint; + b2Bodytype["GetWorldVector"] = &b2Body::GetWorldVector; + b2Bodytype["GetLocalPoint"] = &b2Body::GetLocalPoint; + b2Bodytype["GetLocalVector"] = &b2Body::GetLocalVector; + b2Bodytype["GetLinearVelocityFromWorldPoint"] = &b2Body::GetLinearVelocityFromWorldPoint; + b2Bodytype["GetLinearVelocityFromLocalPoint"] = &b2Body::GetLinearVelocityFromLocalPoint; + b2Bodytype["GetLinearDamping"] = &b2Body::GetLinearDamping; + b2Bodytype["SetLinearDamping"] = &b2Body::SetLinearDamping; + b2Bodytype["GetAngularDamping"] = &b2Body::GetAngularDamping; + b2Bodytype["SetAngularDamping"] = &b2Body::SetAngularDamping; + b2Bodytype["GetGravityScale"] = &b2Body::GetGravityScale; + b2Bodytype["SetGravityScale"] = &b2Body::SetGravityScale; + b2Bodytype["SetType"] = &b2Body::SetType; + b2Bodytype["GetType"] = &b2Body::GetType; + b2Bodytype["SetBullet"] = &b2Body::SetBullet; + b2Bodytype["IsBullet"] = &b2Body::IsBullet; + b2Bodytype["SetSleepingAllowed"] = &b2Body::SetSleepingAllowed; + b2Bodytype["IsSleepingAllowed"] = &b2Body::IsSleepingAllowed; + b2Bodytype["SetAwake"] = &b2Body::SetAwake; + b2Bodytype["IsAwake"] = &b2Body::IsAwake; + b2Bodytype["SetFixedRotation"] = &b2Body::SetFixedRotation; + b2Bodytype["IsFixedRotation"] = &b2Body::IsFixedRotation; + b2Bodytype["GetFixtureList"] = sol::overload( + sol::resolve(&b2Body::GetFixtureList), + sol::resolve(&b2Body::GetFixtureList)); + b2Bodytype["GetJointList"] = sol::overload( + sol::resolve(&b2Body::GetJointList), + sol::resolve(&b2Body::GetJointList)); + b2Bodytype["GetContactList"] = sol::overload( + sol::resolve(&b2Body::GetContactList), + sol::resolve(&b2Body::GetContactList)); + b2Bodytype["GetNext"] = sol::overload( + sol::resolve(&b2Body::GetNext), + sol::resolve(&b2Body::GetNext)); + b2Bodytype["GetUserData"] = &b2Body::GetUserData; + b2Bodytype["GetWorld"] = sol::overload( + sol::resolve(&b2Body::GetWorld), + sol::resolve(&b2Body::GetWorld)); + b2Bodytype["Dump"] = &b2Body::Dump; } } diff --git a/Lumos/Source/Lumos/Utilities/AssetManager.cpp b/Lumos/Source/Lumos/Utilities/AssetManager.cpp deleted file mode 100644 index d583843dd..000000000 --- a/Lumos/Source/Lumos/Utilities/AssetManager.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "Precompiled.h" -#include "AssetManager.h" -#include "Core/Application.h" -#include "Graphics/RHI/Texture.h" -#include - -namespace Lumos -{ - inline static std::vector> m_Futures; - - static void LoadTexture2D(Graphics::Texture2D* tex, const std::string& path) - { - LUMOS_PROFILE_FUNCTION(); - ImageLoadDesc imageLoadDesc = {}; - imageLoadDesc.filePath = path.c_str(); - imageLoadDesc.maxHeight = 256; - imageLoadDesc.maxWidth = 256; - Lumos::LoadImageFromFile(imageLoadDesc); - - Graphics::TextureDesc desc; - desc.format = imageLoadDesc.outBits / 4 == 8 ? Graphics::RHIFormat::R8G8B8A8_Unorm : Graphics::RHIFormat::R32G32B32A32_Float; - - Application::Get().SubmitToMainThread([tex, imageLoadDesc, desc]() - { tex->Load(imageLoadDesc.outWidth, imageLoadDesc.outHeight, imageLoadDesc.outPixels, desc); }); - } - - bool AssetManager::LoadTexture(const std::string& filePath, SharedPtr& texture, bool thread) - { - texture = SharedPtr(Graphics::Texture2D::Create({}, 1, 1)); - if(thread) - m_Futures.push_back(std::async(std::launch::async, &LoadTexture2D, texture.get(), filePath)); - else - LoadTexture2D(texture.get(), filePath); - - AddAsset(filePath, texture); - return true; - } - - SharedPtr AssetManager::LoadTextureAsset(const std::string& filePath, bool thread) - { - SharedPtr texture; - LoadTexture(filePath, texture, thread); - return texture; - } - - static std::mutex s_AssetRegistryMutex; - - AssetMetaData& AssetRegistry::operator[](UUID handle) - { - std::scoped_lock lock(s_AssetRegistryMutex); - return m_AssetRegistry[handle]; - } - - const AssetMetaData& AssetRegistry::Get(UUID handle) const - { - std::scoped_lock lock(s_AssetRegistryMutex); - - LUMOS_ASSERT(m_AssetRegistry.find(handle) != m_AssetRegistry.end()); - return m_AssetRegistry.at(handle); - } - - AssetMetaData& AssetRegistry::Get(UUID handle) - { - std::scoped_lock lock(s_AssetRegistryMutex); - return m_AssetRegistry[handle]; - } - - bool AssetRegistry::Contains(UUID handle) const - { - std::scoped_lock lock(s_AssetRegistryMutex); - return m_AssetRegistry.find(handle) != m_AssetRegistry.end(); - } - - size_t AssetRegistry::Remove(UUID handle) - { - std::scoped_lock lock(s_AssetRegistryMutex); - return m_AssetRegistry.erase(handle); - } - - void AssetRegistry::Clear() - { - std::scoped_lock lock(s_AssetRegistryMutex); - m_AssetRegistry.clear(); - } -} diff --git a/Lumos/Source/Lumos/Utilities/AssetManager.h b/Lumos/Source/Lumos/Utilities/AssetManager.h deleted file mode 100644 index 5f179080b..000000000 --- a/Lumos/Source/Lumos/Utilities/AssetManager.h +++ /dev/null @@ -1,278 +0,0 @@ -#pragma once -#include "Core/Engine.h" -#include "Audio/Sound.h" -#include "Graphics/RHI/Shader.h" -#include "Utilities/TSingleton.h" -#include "Utilities/LoadImage.h" -#include "Graphics/Font.h" -#include "Graphics/Model.h" -#include "Core/Asset.h" -#include "Utilities/CombineHash.h" - -namespace Lumos -{ - namespace Graphics - { - class Model; - } - - struct AssetMetaData - { - float timeSinceReload = 0.0f; - float lastAccessed = 0.0f; - SharedPtr data = nullptr; - bool onDisk = false; - bool Expire = true; - AssetType Type = AssetType::Unkown; - bool IsDataLoaded = false; - bool IsMemoryAsset = false; - uint64_t ParameterCache = 0; - }; - - class AssetRegistry - { - template - friend void save(Archive& archive, const AssetRegistry& registry); - - template - friend void load(Archive& archive, AssetRegistry& registry); - - public: - AssetMetaData& operator[](const UUID handle); - AssetMetaData& Get(const UUID handle); - const AssetMetaData& Get(const UUID handle) const; - - void Update(float elapsedSeconds) - { - static UUID keysToDelete[256]; - std::size_t keysToDeleteCount = 0; - - for(auto&& [key, value] : m_AssetRegistry) - { - if(value.Expire && value.IsDataLoaded && value.data.GetCounter()->GetReferenceCount() == 1 && m_ExpirationTime < (elapsedSeconds - value.lastAccessed)) - { - keysToDelete[keysToDeleteCount] = key; - keysToDeleteCount++; - } - } - - for(std::size_t i = 0; i < keysToDeleteCount; i++) - { - m_AssetRegistry.erase(keysToDelete[i]); - } - } - size_t Count() const { return m_AssetRegistry.size(); } - bool Contains(const UUID handle) const; - size_t Remove(const UUID handle); - void Clear(); - - auto begin() { return m_AssetRegistry.begin(); } - auto end() { return m_AssetRegistry.end(); } - auto begin() const { return m_AssetRegistry.cbegin(); } - auto end() const { return m_AssetRegistry.cend(); } - - void AddName(const std::string& name, UUID ID) - { - m_NameMap.emplace(name, ID); -#ifndef LUMOS_PRODUCTION - m_UUIDNameMap.emplace(ID, name); -#endif - } - bool GetID(const std::string& name, UUID& ID) - { - if(m_NameMap.find(name) != m_NameMap.end()) - { - ID = m_NameMap[name]; - return true; - } - - return false; - } - -#ifndef LUMOS_PRODUCTION - bool GetName(UUID ID, std::string& name) - { - if(m_UUIDNameMap.find(ID) != m_UUIDNameMap.end()) - { - name = m_UUIDNameMap[ID]; - return true; - } - - return false; - } -#endif - - private: - std::unordered_map m_AssetRegistry; - std::unordered_map m_NameMap; -#ifndef LUMOS_PRODUCTION - std::unordered_map m_UUIDNameMap; // Debug Only -#endif - - float m_ExpirationTime = 3.0f; - }; - - class AssetManager - { - public: - AssetManager() - { - m_Arena = ArenaAlloc(Megabytes(4)); - } - - ~AssetManager() - { - ArenaRelease(m_Arena); - } - - SharedPtr GetAsset(UUID ID) - { - if(m_AssetRegistry.Contains(ID)) - { - AssetMetaData& metaData = m_AssetRegistry[ID]; - metaData.lastAccessed = (float)Engine::GetTimeStep().GetElapsedSeconds(); - return metaData.data; - } - - LUMOS_LOG_WARN("Asset not found {0}", ID); - return nullptr; - } - - AssetMetaData& AddAsset(const std::string& name, SharedPtr data, bool keepUnreferenced = false) - { - UUID ID = UUID(); - m_AssetRegistry.GetID(name, ID); - - AssetMetaData& metaData = AddAsset(ID, data, keepUnreferenced); - m_AssetRegistry.AddName(name, ID); - return metaData; - } - - AssetMetaData& AddAsset(UUID name, SharedPtr data, bool keepUnreferenced = false) - { - if(m_AssetRegistry.Contains(name)) - { - AssetMetaData& metaData = m_AssetRegistry[name]; - metaData.lastAccessed = (float)Engine::GetTimeStep().GetElapsedSeconds(); - metaData.data = data; - metaData.Expire = !keepUnreferenced; - metaData.Type = data ? data->GetAssetType() : AssetType::Unkown; - metaData.IsDataLoaded = data ? true : false; - return metaData; - } - - AssetMetaData newResource; - newResource.data = data; - newResource.timeSinceReload = 0; - newResource.onDisk = true; - newResource.lastAccessed = (float)Engine::GetTimeStep().GetElapsedSeconds(); - newResource.Type = data->GetAssetType(); - newResource.Expire = !keepUnreferenced; - newResource.IsDataLoaded = data ? true : false; - - m_AssetRegistry[name] = newResource; - - return m_AssetRegistry[name]; - } - - AssetMetaData GetAsset(const std::string& name) - { - UUID ID; - if(m_AssetRegistry.GetID(name, ID)) - { - if(m_AssetRegistry[ID].IsDataLoaded) - return m_AssetRegistry[ID]; - else - { - return AssetMetaData(); - } - } - - return AssetMetaData(); - } - - SharedPtr GetAssetData(const std::string& name) - { - return GetAsset(name).data; - } - - virtual void Destroy() - { - m_AssetRegistry.Clear(); - } - - void Update(float elapsedSeconds) - { - m_AssetRegistry.Update(elapsedSeconds); - } - - bool AssetExists(const std::string& name) - { - UUID ID; - if(m_AssetRegistry.GetID(name, ID)) - return m_AssetRegistry.Contains(ID) && m_AssetRegistry[ID].IsDataLoaded; - - return false; - } - - bool AssetExists(UUID name) - { - return m_AssetRegistry.Contains(name); - } - - SharedPtr operator[](UUID name) - { - return GetAsset(name); - } - - bool LoadShader(const std::string& filePath, SharedPtr& shader, bool keepUnreferenced = true) - { - shader = SharedPtr(Graphics::Shader::CreateFromFile(filePath)); - AddAsset(filePath, shader, keepUnreferenced); - return true; - } - - bool LoadAsset(const std::string& filePath, SharedPtr& shader, bool keepUnreferenced = true) - { - shader = SharedPtr(Graphics::Shader::CreateFromFile(filePath)); - AddAsset(filePath, shader, keepUnreferenced); - return true; - } - - SharedPtr LoadTextureAsset(const std::string& filePath, bool thread); - - template - SharedPtr CreateMemoryOnlyAsset(const char* name, TArgs&&... args) - { - static_assert(std::is_base_of::value, "CreateMemoryOnlyAsset only works for types derived from Asset"); - - uint64_t hash = 0; - HashCombine(hash, std::forward(args)...); - SharedPtr asset = SharedPtr::CreateSharedPtr(std::forward(args)...); - AssetMetaData metaData = AddAsset(name, asset); - metaData.IsMemoryAsset = true; - metaData.ParameterCache = hash; - return asset; - } - - template - SharedPtr CreateMemoryOnlyAsset(const char* name, TAsset* asset) - { - static_assert(std::is_base_of::value, "CreateMemoryOnlyAsset only works for types derived from Asset"); - - uint64_t hash = 0; - SharedPtr sharedAsset = SharedPtr::SharedPtr(asset); - AssetMetaData metaData = AddAsset(name, sharedAsset); - metaData.IsMemoryAsset = true; - return asset; - } - - AssetRegistry& GetAssetRegistry() { return m_AssetRegistry; } - - protected: - bool LoadTexture(const std::string& filePath, SharedPtr& texture, bool thread); - - Arena* m_Arena; - AssetRegistry m_AssetRegistry; - }; -} diff --git a/Lumos/Source/Lumos/Utilities/Colour.cpp b/Lumos/Source/Lumos/Utilities/Colour.cpp index 776c8757e..b967a0a0d 100644 --- a/Lumos/Source/Lumos/Utilities/Colour.cpp +++ b/Lumos/Source/Lumos/Utilities/Colour.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Colour.h" #include "Maths/Random.h" diff --git a/Lumos/Source/Lumos/Utilities/ExternalBuild.cpp b/Lumos/Source/Lumos/Utilities/ExternalBuild.cpp index f883a242f..c0180db87 100644 --- a/Lumos/Source/Lumos/Utilities/ExternalBuild.cpp +++ b/Lumos/Source/Lumos/Utilities/ExternalBuild.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #pragma warning(push, 0) #if LUMOS_PROFILE diff --git a/Lumos/Source/Lumos/Utilities/Hash.cpp b/Lumos/Source/Lumos/Utilities/Hash.cpp index 43539d131..73aaaf539 100644 --- a/Lumos/Source/Lumos/Utilities/Hash.cpp +++ b/Lumos/Source/Lumos/Utilities/Hash.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #if defined(_MSC_VER) #include diff --git a/Lumos/Source/Lumos/Utilities/IniFile.cpp b/Lumos/Source/Lumos/Utilities/IniFile.cpp index adfc18a65..1ccc4aa60 100644 --- a/Lumos/Source/Lumos/Utilities/IniFile.cpp +++ b/Lumos/Source/Lumos/Utilities/IniFile.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "IniFile.h" #include "Core/OS/FileSystem.h" #include "Utilities/StringUtilities.h" diff --git a/Lumos/Source/Lumos/Utilities/LoadImage.cpp b/Lumos/Source/Lumos/Utilities/LoadImage.cpp index aab1e61f8..89d52fde3 100644 --- a/Lumos/Source/Lumos/Utilities/LoadImage.cpp +++ b/Lumos/Source/Lumos/Utilities/LoadImage.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "LoadImage.h" #include "Core/OS/FileSystem.h" diff --git a/Lumos/Source/Lumos/Utilities/StringUtilities.cpp b/Lumos/Source/Lumos/Utilities/StringUtilities.cpp index a3f2280a4..3c6ba113b 100644 --- a/Lumos/Source/Lumos/Utilities/StringUtilities.cpp +++ b/Lumos/Source/Lumos/Utilities/StringUtilities.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "StringUtilities.h" #include diff --git a/Lumos/Source/Lumos/Utilities/TimeStep.cpp b/Lumos/Source/Lumos/Utilities/TimeStep.cpp index d78a33506..861d0927a 100644 --- a/Lumos/Source/Lumos/Utilities/TimeStep.cpp +++ b/Lumos/Source/Lumos/Utilities/TimeStep.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "TimeStep.h" #include "Timer.h" diff --git a/Lumos/Source/Lumos/Utilities/Timer.cpp b/Lumos/Source/Lumos/Utilities/Timer.cpp index 9e812df55..bc290f9d5 100644 --- a/Lumos/Source/Lumos/Utilities/Timer.cpp +++ b/Lumos/Source/Lumos/Utilities/Timer.cpp @@ -1,4 +1,6 @@ +#ifndef LUMOS_PLATFORM_MACOS #include "Precompiled.h" +#endif #include "Timer.h" namespace Lumos diff --git a/Lumos/Source/Precompiled.h b/Lumos/Source/Precompiled.h index 39647a79e..4523bdc00 100644 --- a/Lumos/Source/Precompiled.h +++ b/Lumos/Source/Precompiled.h @@ -3,7 +3,6 @@ #ifdef __cplusplus #include #include -#include #include #include #include @@ -13,12 +12,9 @@ #include #include #include -#include #include #include #include -#include -#include #include #include "Core/Reference.h" diff --git a/Lumos/premake5.lua b/Lumos/premake5.lua index 403e328de..ebca719aa 100644 --- a/Lumos/premake5.lua +++ b/Lumos/premake5.lua @@ -19,7 +19,9 @@ project "Lumos" removefiles { - "Source/Lumos/Platform/**" + "Source/Lumos/Platform/**", + "Source/Precompiled.h", + "Source/Precompiled.cpp" } includedirs @@ -211,13 +213,11 @@ project "Lumos" { "-Wno-attributes", "-Wno-nullability-completeness", - "-fdiagnostics-absolute-paths" + "-fdiagnostics-absolute-paths", } - pchheader "../Lumos/Source/Precompiled.h" - pchsource "../Lumos/Source/Precompiled.cpp" - - SetRecommendedXcodeSettings() + pchheader "Source/Precompiled.h" + pchsource "Source/Precompiled.cpp" filter 'files:External/**.cpp' flags { 'NoPCH' } diff --git a/Runtime/Runtime.cpp b/Runtime/Runtime.cpp index b1309b6a5..aab070894 100644 --- a/Runtime/Runtime.cpp +++ b/Runtime/Runtime.cpp @@ -23,6 +23,12 @@ class Runtime : public Application { } + void OnUpdate(const TimeStep& dt) override + { + using namespace Lumos; + Application::OnUpdate(dt); + } + void OnEvent(Event& e) override { Application::OnEvent(e); @@ -34,8 +40,9 @@ class Runtime : public Application void Init() override { std::vector projectLocations = { - "ExampleProject/Example.lmproj", + OS::Instance()->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", diff --git a/Runtime/premake5.lua b/Runtime/premake5.lua index 262f88ac2..8820aa6a5 100644 --- a/Runtime/premake5.lua +++ b/Runtime/premake5.lua @@ -160,8 +160,6 @@ end "glfw", } - SetRecommendedXcodeSettings() - filter "system:ios" cppdialect "C++17" staticruntime "Off" @@ -269,7 +267,6 @@ end "Textures", "Example.lmproj" } - SetRecommendedXcodeSettings() filter "system:linux" cppdialect "C++17" diff --git a/premake5.lua b/premake5.lua index 30e9e6cfe..0c8dd1ba0 100644 --- a/premake5.lua +++ b/premake5.lua @@ -82,5 +82,8 @@ workspace( settings.workspace_name ) group "" include "Lumos/premake5" + SetRecommendedSettings() include "Runtime/premake5" + SetRecommendedSettings() include "Editor/premake5" + SetRecommendedSettings()