From 5f39899981f58a675f518f3209b7440f948f15db Mon Sep 17 00:00:00 2001 From: antopilo Date: Sat, 4 Jan 2025 03:03:17 -0500 Subject: [PATCH] Added images back to the editor --- Editor/src/Windows/EditorInterface.cpp | 80 +++++++++---------- Editor/src/Windows/EditorInterface.h | 11 +-- Editor/src/Windows/LoadingSplash.cpp | 7 +- Editor/src/Windows/LoadingSplash.h | 3 +- Editor/src/Windows/WelcomeWindow.cpp | 10 +-- Editor/src/Windows/WelcomeWindow.h | 5 +- .../src/Rendering/Textures/TextureManager.cpp | 71 +++++++++------- Nuake/src/Rendering/Textures/TextureManager.h | 5 +- .../Vulkan/VulkanImage/VulkanImage.cpp | 71 ++++++++++++++++ .../Vulkan/VulkanImage/VulkanImage.h | 5 ++ Nuake/src/UI/ImUI.cpp | 18 ++--- Nuake/src/UI/ImUI.h | 12 +-- 12 files changed, 199 insertions(+), 99 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 5e2a9291..5ac99d4b 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -61,6 +61,8 @@ #include "src/Rendering/Vulkan/VulkanRenderer.h" #include +#include + namespace Nuake { @@ -112,11 +114,11 @@ namespace Nuake { mCommandBuffer = &commandBuffer; // Load textures - NuakeTexture = Nuake::TextureManager::Get()->GetTexture("Resources/Images/editor-icon.png"); - CloseIconTexture = Nuake::TextureManager::Get()->GetTexture("Resources/Images/close-icon.png"); - MaximizeTexture = Nuake::TextureManager::Get()->GetTexture("Resources/Images/maximize-icon.png"); - RestoreTexture = Nuake::TextureManager::Get()->GetTexture("Resources/Images/restore-icon.png"); - MinimizeTexture = Nuake::TextureManager::Get()->GetTexture("Resources/Images/minimize-icon.png"); + NuakeTexture = Nuake::TextureManager::Get()->GetTexture2("Resources/Images/editor-icon.png"); + CloseIconTexture = Nuake::TextureManager::Get()->GetTexture2("Resources/Images/close-icon.png"); + MaximizeTexture = Nuake::TextureManager::Get()->GetTexture2("Resources/Images/maximize-icon.png"); + RestoreTexture = Nuake::TextureManager::Get()->GetTexture2("Resources/Images/restore-icon.png"); + MinimizeTexture = Nuake::TextureManager::Get()->GetTexture2("Resources/Images/minimize-icon.png"); Logger::Log("Creating editor windows", "window", VERBOSE); filesystem = new FileSystemUI(this); @@ -167,7 +169,7 @@ namespace Nuake { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 2.0f + windowPadding.x); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (5.0f + windowPadding.y + titlebarVerticalOffset) / 2.0); - //ImGui::Image((ImTextureID)NuakeTexture->GetID(), ImVec2(logoWidth, logoHeight), ImVec2(0, 1), ImVec2(1, 0)); + ImGui::Image((ImTextureID)NuakeTexture->GetImGuiDescriptorSet(), ImVec2(logoWidth, logoHeight)); } const float w = ImGui::GetContentRegionAvail().x; @@ -231,16 +233,14 @@ namespace Nuake { int iconWidth = std::max(MinimizeTexture->GetWidth(), 24); int iconHeight = std::max(MinimizeTexture->GetHeight(), 24); - - - //const float padY = (buttonHeight - (float)iconHeight) / 2.0f; - //if (ImGui::InvisibleButton("Minimize", ImVec2(iconWidth, iconHeight))) - //{ - // glfwIconifyWindow(Window::Get()->GetHandle()); - //} - // - //auto rect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); - //UI::DrawButtonImage(MinimizeTexture, buttonColN, buttonColH, buttonColP); + const float padY = (buttonHeight - (float)iconHeight) / 2.0f; + if (ImGui::InvisibleButton("Minimize", ImVec2(iconWidth, iconHeight))) + { + glfwIconifyWindow(Window::Get()->GetHandle()); + } + + auto rect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + UI::DrawButtonImage(MinimizeTexture, buttonColN, buttonColH, buttonColP, rect); } ImGui::SameLine(); @@ -252,33 +252,33 @@ namespace Nuake { const bool isMaximized = Window::Get()->IsMaximized(); - //if (ImGui::InvisibleButton("Maximize", ImVec2(buttonWidth, buttonHeight))) - //{ - // const auto window = Window::Get()->GetHandle(); - // if (isMaximized) - // { - // glfwRestoreWindow(window); - // } - // else - // { - // glfwMaximizeWindow(window); - // } - //} - //auto rect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); - //UI::DrawButtonImage(isMaximized ? RestoreTexture : MaximizeTexture, buttonColN, buttonColH, buttonColP); + if (ImGui::InvisibleButton("Maximize", ImVec2(buttonWidth, buttonHeight))) + { + const auto window = Window::Get()->GetHandle(); + if (isMaximized) + { + glfwRestoreWindow(window); + } + else + { + glfwMaximizeWindow(window); + } + } + auto rect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + UI::DrawButtonImage(isMaximized ? RestoreTexture : MaximizeTexture, buttonColN, buttonColH, buttonColP); } // Close Button ImGui::SameLine(); { - int iconWidth = std::max(CloseIconTexture ->GetWidth(), 24); + int iconWidth = std::max(CloseIconTexture->GetWidth(), 24); int iconHeight = std::max(CloseIconTexture->GetHeight(), 24); - //if (ImGui::InvisibleButton("Close", ImVec2(buttonWidth, buttonHeight))) - //{ - // glfwSetWindowShouldClose(Window::Get()->GetHandle(), true); - //} - // - //UI::DrawButtonImage(CloseIconTexture, UI::TextCol, UI::TextCol, buttonColP); + if (ImGui::InvisibleButton("Close", ImVec2(buttonWidth, buttonHeight))) + { + glfwSetWindowShouldClose(Window::Get()->GetHandle(), true); + } + + UI::DrawButtonImage(CloseIconTexture, UI::TextCol, UI::TextCol, buttonColP); } // Second bar with play stop pause etc @@ -656,7 +656,7 @@ namespace Nuake { Input::SetEditorViewportSize(m_ViewportPos, viewportPanelSize); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); m_ViewportPos = { imagePos.x, imagePos.y }; - ImGui::Image(VkRenderer::Get().GetDrawImage()->GetImGuiDescriptorSet(), regionAvail, { 0, 1 }, { 1, 0 }); + ImGui::Image(VkRenderer::Get().GetDrawImage()->GetImGuiDescriptorSet(), regionAvail, {0, 1}, {1, 0}); ImGui::PopStyleVar(); const Vector2& mousePos = Input::GetMousePosition(); @@ -930,7 +930,7 @@ namespace Nuake { ImGui::SameLine(); const float remainingWidth = ImGui::GetContentRegionAvail().x; - auto nuakeLogoTexture = TextureManager::Get()->GetTexture("Resources/Images/logo_white.png"); + auto nuakeLogoTexture = TextureManager::Get()->GetTexture2("Resources/Images/logo_white.png"); auto nuakeSize = nuakeLogoTexture->GetSize(); float sizeDiff = height / nuakeSize.y; float scale = 0.5f; @@ -948,7 +948,7 @@ namespace Nuake { ImGui::SameLine(); ImGui::SetCursorPosY(height / 4.0 ); - //ImGui::Image((ImTextureID)(nuakeLogoTexture->GetID()), ImVec2(logoWidth, height) * scale, ImVec2{0, 1}, ImVec2{1, 0}); + ImGui::Image((ImTextureID)(nuakeLogoTexture->GetImGuiDescriptorSet()), ImVec2(logoWidth, height) * scale); ImGui::EndMenuBar(); } ImGui::End(); diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index b70afca0..4cfa0ccc 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -27,6 +27,7 @@ namespace Nuake { class Material; class FileSystemUI; + class VulkanImage; class EditorInterface { @@ -83,11 +84,11 @@ namespace Nuake MapImporterWindow m_MapImporter; ProjectSettingsWindow* m_ProjectSettingsWindow; - Ref NuakeTexture; - Ref CloseIconTexture; - Ref MaximizeTexture; - Ref RestoreTexture; - Ref MinimizeTexture; + Ref NuakeTexture; + Ref CloseIconTexture; + Ref MaximizeTexture; + Ref RestoreTexture; + Ref MinimizeTexture; EditorInterface(CommandBuffer& commandBuffer); static ImFont* bigIconFont; diff --git a/Editor/src/Windows/LoadingSplash.cpp b/Editor/src/Windows/LoadingSplash.cpp index 6c636c54..63664a96 100644 --- a/Editor/src/Windows/LoadingSplash.cpp +++ b/Editor/src/Windows/LoadingSplash.cpp @@ -10,11 +10,13 @@ #include #include +#include +using namespace Nuake; LoadingSplash::LoadingSplash() { - _NuakeLogo = Nuake::TextureManager::Get()->GetTexture(NUAKE_LOGO_PATH); + _NuakeLogo = Nuake::TextureManager::Get()->GetTexture2(NUAKE_LOGO_PATH); Nuake::Window::Get()->SetDecorated(false); Nuake::Window::Get()->SetSize({ 640, 480 }); @@ -23,7 +25,6 @@ LoadingSplash::LoadingSplash() void LoadingSplash::Draw() { - using namespace Nuake; // Make viewport fullscreen ImGuiViewport* viewport = ImGui::GetMainViewport(); @@ -39,7 +40,7 @@ void LoadingSplash::Draw() { const Vector2 logoSize = _NuakeLogo->GetSize(); const ImVec2 imguiSize = ImVec2(logoSize.x, logoSize.y); - //ImGui::Image((ImTextureID)_NuakeLogo->GetID(), imguiSize, ImVec2(0, 1), ImVec2(1, 0)); + ImGui::Image((ImTextureID)_NuakeLogo->GetImGuiDescriptorSet(), imguiSize); } ImGui::Text("LOADING SCENE..."); diff --git a/Editor/src/Windows/LoadingSplash.h b/Editor/src/Windows/LoadingSplash.h index deb0124a..64364d5c 100644 --- a/Editor/src/Windows/LoadingSplash.h +++ b/Editor/src/Windows/LoadingSplash.h @@ -7,13 +7,14 @@ namespace Nuake { class Texture; + class VulkanImage; } class LoadingSplash { private: const std::string NUAKE_LOGO_PATH = "Resources/Images/logo_white.png"; - Ref _NuakeLogo; + Ref _NuakeLogo; public: static LoadingSplash& Get() diff --git a/Editor/src/Windows/WelcomeWindow.cpp b/Editor/src/Windows/WelcomeWindow.cpp index 3996f3c1..7377b6fe 100644 --- a/Editor/src/Windows/WelcomeWindow.cpp +++ b/Editor/src/Windows/WelcomeWindow.cpp @@ -11,7 +11,7 @@ #include #include #include - +#include #include #include @@ -46,7 +46,7 @@ namespace Nuake } else { - //ProjectIcon = TextureManager::Get()->GetTexture("Resources/Images/nuake-logo.png"); + ProjectIcon = TextureManager::Get()->GetTexture2("Resources/Images/nuake-logo.png"); } } else @@ -87,7 +87,7 @@ namespace Nuake } // Load Nuake logo - _NuakeLogo = TextureManager::Get()->GetTexture(NUAKE_LOGO_PATH); + _NuakeLogo = TextureManager::Get()->GetTexture2(NUAKE_LOGO_PATH); } void WelcomeWindow::LoadQueuedProject() @@ -164,7 +164,7 @@ namespace Nuake { const Vector2 logoSize = _NuakeLogo->GetSize(); const ImVec2 imguiSize = ImVec2(logoSize.x, logoSize.y); - //ImGui::Image((ImTextureID)_NuakeLogo->GetID(), imguiSize, ImVec2(0, 1), ImVec2(1, 0)); + ImGui::Image((ImTextureID)_NuakeLogo->GetImGuiDescriptorSet(), imguiSize); } //ImGui::SameLine(); @@ -312,7 +312,7 @@ namespace Nuake if (project.ProjectIcon) { - //ImGui::Image((ImTextureID)project.ProjectIcon->GetID(), iconSize, ImVec2(0, 1), ImVec2(1, 0)); + ImGui::Image((ImTextureID)project.ProjectIcon->GetImGuiDescriptorSet(), iconSize); } else { diff --git a/Editor/src/Windows/WelcomeWindow.h b/Editor/src/Windows/WelcomeWindow.h index 478559a4..3324964d 100644 --- a/Editor/src/Windows/WelcomeWindow.h +++ b/Editor/src/Windows/WelcomeWindow.h @@ -8,6 +8,7 @@ namespace Nuake { class Texture; + class VulkanImage; class ProjectPreview : ISerializable { public: @@ -15,7 +16,7 @@ namespace Nuake std::string Path; std::string Description; - Ref ProjectIcon; + Ref ProjectIcon; ProjectPreview(const std::string& path); ProjectPreview() = default; @@ -33,7 +34,7 @@ namespace Nuake { private: const std::string NUAKE_LOGO_PATH = "Resources/Images/logo_white.png"; - Ref _NuakeLogo; + Ref _NuakeLogo; EditorInterface* _Editor; std::string _RecentProjectFilePath = ""; diff --git a/Nuake/src/Rendering/Textures/TextureManager.cpp b/Nuake/src/Rendering/Textures/TextureManager.cpp index 8cb0a8c1..6a67b07b 100644 --- a/Nuake/src/Rendering/Textures/TextureManager.cpp +++ b/Nuake/src/Rendering/Textures/TextureManager.cpp @@ -1,5 +1,6 @@ #include "TextureManager.h" #include "src/Rendering/Textures/Texture.h" +#include "src/Rendering/Vulkan/VulkanImage/VulkanImage.h" #include "src/Resource/StaticResources.h" #include @@ -7,6 +8,7 @@ namespace Nuake { std::map> TextureManager::m_Registry; + std::map> TextureManager::m_Registry2; bool m_StaticTextureLoaded = false; TextureManager* TextureManager::s_Instance = nullptr; @@ -16,35 +18,43 @@ namespace Nuake return m_Registry.find(path) != m_Registry.end(); } + bool TextureManager::IsTextureLoaded2(const std::string path) + { + return m_Registry2.find(path) != m_Registry2.end(); + } + void TextureManager::LoadStaticTextures() { using namespace StaticResources; - //m_Registry.emplace(Resources_Gizmos_bone_png_path, CreateRef(Resources_Gizmos_bone_png, Resources_Gizmos_bone_png_len)); - //m_Registry.emplace(Resources_Gizmos_camera_png_path, CreateRef(Resources_Gizmos_camera_png, Resources_Gizmos_camera_png_len)); - //m_Registry.emplace(Resources_Gizmos_light_png_path, CreateRef(Resources_Gizmos_light_png, Resources_Gizmos_light_png_len)); - //m_Registry.emplace(Resources_Gizmos_light_directional_png_path, CreateRef(Resources_Gizmos_light_directional_png, Resources_Gizmos_light_directional_png_len)); - //m_Registry.emplace(Resources_Gizmos_light_spot_png_path, CreateRef(Resources_Gizmos_light_spot_png, Resources_Gizmos_light_spot_png_len)); - //m_Registry.emplace(Resources_Gizmos_player_png_path, CreateRef(Resources_Gizmos_player_png, Resources_Gizmos_player_png_len)); - //m_Registry.emplace(Resources_Gizmos_particles_png_path, CreateRef(Resources_Gizmos_particles_png, Resources_Gizmos_particles_png_len)); - //m_Registry.emplace(Resources_Gizmos_rigidbody_png_path, CreateRef(Resources_Gizmos_rigidbody_png, Resources_Gizmos_rigidbody_png_len)); - //m_Registry.emplace(Resources_Gizmos_sound_emitter_png_path, CreateRef(Resources_Gizmos_sound_emitter_png, Resources_Gizmos_sound_emitter_png_len)); - // - //m_Registry.emplace(Resources_Images_cube_png_path, CreateRef(Resources_Images_cube_png, Resources_Images_cube_png_len)); - //m_Registry.emplace(Resources_Images_nuake_logo_png_path, CreateRef(Resources_Images_nuake_logo_png, Resources_Images_nuake_logo_png_len)); - //m_Registry.emplace(Resources_Images_logo_white_png_path, CreateRef(Resources_Images_logo_white_png, Resources_Images_logo_white_png_len)); - //m_Registry.emplace(Resources_Images_logo_png_path, CreateRef(Resources_Images_logo_png, Resources_Images_logo_png_len)); - //m_Registry.emplace(Resources_Images_file_icon_png_path, CreateRef(Resources_Images_file_icon_png, Resources_Images_file_icon_png_len)); - //m_Registry.emplace(Resources_Images_env_file_icon_png_path, CreateRef(Resources_Images_env_file_icon_png, Resources_Images_env_file_icon_png_len)); - //m_Registry.emplace(Resources_Images_scene_icon_png_path, CreateRef(Resources_Images_scene_icon_png, Resources_Images_scene_icon_png_len)); - //m_Registry.emplace(Resources_Images_project_icon_png_path, CreateRef(Resources_Images_project_icon_png, Resources_Images_project_icon_png_len)); - //m_Registry.emplace(Resources_Images_csharp_icon_png_path, CreateRef(Resources_Images_csharp_icon_png, Resources_Images_csharp_icon_png_len)); - //m_Registry.emplace(Resources_Images_sln_icon_png_path, CreateRef(Resources_Images_sln_icon_png, Resources_Images_sln_icon_png_len)); - //m_Registry.emplace(Resources_Images_trenchbroom_icon_png_path, CreateRef(Resources_Images_trenchbroom_icon_png, Resources_Images_trenchbroom_icon_png_len)); - //m_Registry.emplace(Resources_Images_editor_icon_png_path, CreateRef(Resources_Images_editor_icon_png, Resources_Images_editor_icon_png_len)); - //m_Registry.emplace(Resources_Images_close_icon_png_path, CreateRef(Resources_Images_close_icon_png, Resources_Images_close_icon_png_len)); - //m_Registry.emplace(Resources_Images_maximize_icon_png_path, CreateRef(Resources_Images_maximize_icon_png, Resources_Images_maximize_icon_png_len)); - //m_Registry.emplace(Resources_Images_minimize_icon_png_path, CreateRef(Resources_Images_minimize_icon_png, Resources_Images_minimize_icon_png_len)); - //m_Registry.emplace(Resources_Images_restore_icon_png_path, CreateRef(Resources_Images_restore_icon_png, Resources_Images_restore_icon_png_len)); + m_Registry2.emplace(Resources_Images_nuake_logo_png_path, CreateRef(Resources_Images_nuake_logo_png, Resources_Images_nuake_logo_png_len)); + m_Registry2.emplace(Resources_Images_logo_white_png_path, CreateRef(Resources_Images_logo_white_png, Resources_Images_logo_white_png_len)); + m_Registry2.emplace(Resources_Gizmos_bone_png_path, CreateRef(Resources_Gizmos_bone_png, Resources_Gizmos_bone_png_len)); + m_Registry2.emplace(Resources_Gizmos_camera_png_path, CreateRef(Resources_Gizmos_camera_png, Resources_Gizmos_camera_png_len)); + m_Registry2.emplace(Resources_Gizmos_light_png_path, CreateRef(Resources_Gizmos_light_png, Resources_Gizmos_light_png_len)); + m_Registry2.emplace(Resources_Gizmos_light_directional_png_path, CreateRef(Resources_Gizmos_light_directional_png, Resources_Gizmos_light_directional_png_len)); + m_Registry2.emplace(Resources_Gizmos_light_spot_png_path, CreateRef(Resources_Gizmos_light_spot_png, Resources_Gizmos_light_spot_png_len)); + m_Registry2.emplace(Resources_Gizmos_player_png_path, CreateRef(Resources_Gizmos_player_png, Resources_Gizmos_player_png_len)); + m_Registry2.emplace(Resources_Gizmos_particles_png_path, CreateRef(Resources_Gizmos_particles_png, Resources_Gizmos_particles_png_len)); + m_Registry2.emplace(Resources_Gizmos_rigidbody_png_path, CreateRef(Resources_Gizmos_rigidbody_png, Resources_Gizmos_rigidbody_png_len)); + m_Registry2.emplace(Resources_Gizmos_sound_emitter_png_path, CreateRef(Resources_Gizmos_sound_emitter_png, Resources_Gizmos_sound_emitter_png_len)); + + m_Registry2.emplace(Resources_Images_cube_png_path, CreateRef(Resources_Images_cube_png, Resources_Images_cube_png_len)); + m_Registry2.emplace(Resources_Images_logo_white_png_path, CreateRef(Resources_Images_logo_white_png, Resources_Images_logo_white_png_len)); + m_Registry2.emplace(Resources_Images_logo_png_path, CreateRef(Resources_Images_logo_png, Resources_Images_logo_png_len)); + m_Registry2.emplace(Resources_Images_file_icon_png_path, CreateRef(Resources_Images_file_icon_png, Resources_Images_file_icon_png_len)); + m_Registry2.emplace(Resources_Images_env_file_icon_png_path, CreateRef(Resources_Images_env_file_icon_png, Resources_Images_env_file_icon_png_len)); + m_Registry2.emplace(Resources_Images_scene_icon_png_path, CreateRef(Resources_Images_scene_icon_png, Resources_Images_scene_icon_png_len)); + m_Registry2.emplace(Resources_Images_project_icon_png_path, CreateRef(Resources_Images_project_icon_png, Resources_Images_project_icon_png_len)); + m_Registry2.emplace(Resources_Images_csharp_icon_png_path, CreateRef(Resources_Images_csharp_icon_png, Resources_Images_csharp_icon_png_len)); + m_Registry2.emplace(Resources_Images_sln_icon_png_path, CreateRef(Resources_Images_sln_icon_png, Resources_Images_sln_icon_png_len)); + m_Registry2.emplace(Resources_Images_trenchbroom_icon_png_path, CreateRef(Resources_Images_trenchbroom_icon_png, Resources_Images_trenchbroom_icon_png_len)); + m_Registry2.emplace(Resources_Images_editor_icon_png_path, CreateRef(Resources_Images_editor_icon_png, Resources_Images_editor_icon_png_len)); + m_Registry2.emplace(Resources_Images_close_icon_png_path, CreateRef(Resources_Images_close_icon_png, Resources_Images_close_icon_png_len)); + m_Registry2.emplace(Resources_Images_maximize_icon_png_path, CreateRef(Resources_Images_maximize_icon_png, Resources_Images_maximize_icon_png_len)); + m_Registry2.emplace(Resources_Images_minimize_icon_png_path, CreateRef(Resources_Images_minimize_icon_png, Resources_Images_minimize_icon_png_len)); + m_Registry2.emplace(Resources_Images_restore_icon_png_path, CreateRef(Resources_Images_restore_icon_png, Resources_Images_restore_icon_png_len)); + m_Registry2.emplace(Resources_Images_folder_icon_png_path, CreateRef(Resources_Images_folder_icon_png, Resources_Images_folder_icon_png_len)); + // //unsigned char whitePixel[] = { 255, 255, 255, 255 }; //m_Registry.emplace("Resources/Textures/Default.png", CreateRef(Vector2( 1, 1 ), GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, &whitePixel)); @@ -53,7 +63,6 @@ namespace Nuake //unsigned char normalPixel[] = { 128, 128, 255, 255 }; //m_Registry.emplace("Resources/Textures/DefaultNormal.png", CreateRef(Vector2(1, 1), GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, &whitePixel)); // - //m_Registry.emplace(Resources_Images_folder_icon_png_path, CreateRef(Resources_Images_folder_icon_png, Resources_Images_folder_icon_png_len)); } Ref TextureManager::GetTexture(const std::string path) @@ -64,6 +73,14 @@ namespace Nuake return m_Registry.at(path); } + Ref TextureManager::GetTexture2(const std::string path) + { + //if (!IsTextureLoaded2(path)) + //m_Registry2.emplace(path, new VulkanImage(path)); + + return m_Registry2.at(path); + } + TextureManager* TextureManager::Get() { if (!m_StaticTextureLoaded) diff --git a/Nuake/src/Rendering/Textures/TextureManager.h b/Nuake/src/Rendering/Textures/TextureManager.h index af7f37bc..8038bc70 100644 --- a/Nuake/src/Rendering/Textures/TextureManager.h +++ b/Nuake/src/Rendering/Textures/TextureManager.h @@ -4,6 +4,7 @@ namespace Nuake { class Texture; + class VulkanImage; // Todo: SHOULD probably be static too. class TextureManager @@ -12,7 +13,9 @@ namespace Nuake static TextureManager* s_Instance; static std::map> m_Registry; + static std::map> m_Registry2; bool IsTextureLoaded(const std::string path); + bool IsTextureLoaded2(const std::string path); void LoadStaticTextures(); @@ -22,7 +25,7 @@ namespace Nuake TextureManager(); Ref GetTexture(const std::string path); - + Ref GetTexture2(const std::string path); }; } diff --git a/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.cpp b/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.cpp index beaf13af..e0a9ed90 100644 --- a/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.cpp +++ b/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.cpp @@ -11,6 +11,7 @@ using namespace Nuake; #include "vk_mem_alloc.h" +#include VulkanImage::VulkanImage(ImageFormat inFormat, Vector2 inSize, ImageUsage usage) : Format(inFormat), @@ -126,6 +127,76 @@ VulkanImage::VulkanImage(void* inData, ImageFormat inFormat, Vector2 inSize) : V // TODO: Clean up temporary buffer! we leak memory here } +VulkanImage::VulkanImage(void* inData, size_t inSize) : + Format(ImageFormat::RGBA8), + ImGuiDescriptorSetGenerated(false) +{ + int channels = 0; + int width = 0; + int height = 0; + void* imageData = stbi_load_from_memory(static_cast(inData), static_cast(inSize), &width, &height, &channels, 4); + + if (!imageData) + { + throw std::runtime_error("Failed to load image data using stb_image!"); + } + + // Use the loaded image data with the existing VulkanImage constructor logic + size_t data_size = width * height * 4; // 4 for RGBA + + Ref uploadBuffer = CreateRef(data_size, BufferUsage::TRANSFER_SRC, MemoryUsage::CPU_TO_GPU); + void* mappedData; + vmaMapMemory(VulkanAllocator::Get().GetAllocator(), uploadBuffer->GetAllocation(), &mappedData); + + std::memcpy(mappedData, imageData, data_size); + + // Free the image data as we no longer need it + stbi_image_free(imageData); + + VkExtent3D vkExtent = { + static_cast(width), + static_cast(height), + 1 // We don't support 3D images yet + }; + + Extent = { width, height, 1 }; + + VkImageUsageFlags drawImageUsages = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; + + VkImageCreateInfo imgCreateInfo = VulkanInit::ImageCreateInfo(static_cast(Format), drawImageUsages, vkExtent); + + VmaAllocationCreateInfo imgAllocInfo = {}; + imgAllocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; + imgAllocInfo.requiredFlags = VkMemoryPropertyFlags(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + + vmaCreateImage(VulkanAllocator::Get().GetAllocator(), &imgCreateInfo, &imgAllocInfo, &Image, &Allocation, nullptr); + + VkImageViewCreateInfo imageViewCreateInfo = VulkanInit::ImageviewCreateInfo(static_cast(Format), Image, VK_IMAGE_ASPECT_COLOR_BIT); + + VK_CALL(vkCreateImageView(VkRenderer::Get().GetDevice(), &imageViewCreateInfo, nullptr, &ImageView)); + + // Transition image and copy data to GPU + VkRenderer::Get().ImmediateSubmit([&](VkCommandBuffer cmd) + { + VulkanUtil::TransitionImage(cmd, Image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + + VkBufferImageCopy copyRegion = {}; + copyRegion.bufferOffset = 0; + copyRegion.bufferRowLength = 0; + copyRegion.bufferImageHeight = 0; + + copyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + copyRegion.imageSubresource.mipLevel = 0; + copyRegion.imageSubresource.baseArrayLayer = 0; + copyRegion.imageSubresource.layerCount = 1; + copyRegion.imageExtent = vkExtent; + + vkCmdCopyBufferToImage(cmd, uploadBuffer->GetBuffer(), Image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©Region); + + VulkanUtil::TransitionImage(cmd, Image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + }); +} + VulkanImage::~VulkanImage() { // TODO: deletion of image diff --git a/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.h b/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.h index e73cbe51..1918adf0 100644 --- a/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.h +++ b/Nuake/src/Rendering/Vulkan/VulkanImage/VulkanImage.h @@ -47,9 +47,14 @@ namespace Nuake public: VulkanImage(ImageFormat format, Vector2 size, ImageUsage usage = ImageUsage::Default); VulkanImage(void* data, ImageFormat format, Vector2 size); + VulkanImage(void* data, size_t size); // This one is for embedded files. Ignore. + ~VulkanImage(); Vector2 GetSize() const { return Vector2(Extent.x, Extent.y); } + int GetWidth() const { return static_cast(Extent.x); } + int GetHeight() const { return static_cast(Extent.y); } + VkImageView& GetImageView() { return ImageView; } VkImage& GetImage() { return Image; } VkDescriptorSet& GetImGuiDescriptorSet(); diff --git a/Nuake/src/UI/ImUI.cpp b/Nuake/src/UI/ImUI.cpp index cab1c0ac..ac942e1f 100644 --- a/Nuake/src/UI/ImUI.cpp +++ b/Nuake/src/UI/ImUI.cpp @@ -217,34 +217,34 @@ namespace Nuake return RectOffset(rect, xy.x, xy.y); } - void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, + void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImVec2 rectMin, ImVec2 rectMax) { auto* drawList = ImGui::GetForegroundDrawList(); if (ImGui::IsItemActive()) - drawList->AddImage((ImTextureID)imagePressed->GetID(), rectMin, rectMax, ImVec2(0, 1), ImVec2(1, 0), tintPressed); + drawList->AddImage((ImTextureID)imagePressed->GetImGuiDescriptorSet(), rectMin, rectMax, ImVec2(0, 0), ImVec2(1, 1), tintPressed); else if (ImGui::IsItemHovered()) - drawList->AddImage((ImTextureID)imagePressed->GetID(), rectMin, rectMax, ImVec2(0, 1), ImVec2(1, 0), tintHovered); + drawList->AddImage((ImTextureID)imagePressed->GetImGuiDescriptorSet(), rectMin, rectMax, ImVec2(0, 0), ImVec2(1, 1), tintHovered); else - drawList->AddImage((ImTextureID)imagePressed->GetID(), rectMin, rectMax, ImVec2(0, 1), ImVec2(1, 0), tintNormal); + drawList->AddImage((ImTextureID)imagePressed->GetImGuiDescriptorSet(), rectMin, rectMax, ImVec2(0, 0), ImVec2(1, 1), tintNormal); }; - void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, + void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImRect rectangle) { DrawButtonImage(imageNormal, imageHovered, imagePressed, tintNormal, tintHovered, tintPressed, rectangle.Min, rectangle.Max); }; - void DrawButtonImage(const Ref& image, + void DrawButtonImage(const Ref& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImVec2 rectMin, ImVec2 rectMax) { DrawButtonImage(image, image, image, tintNormal, tintHovered, tintPressed, rectMin, rectMax); }; - void DrawButtonImage(const Ref& image, + void DrawButtonImage(const Ref& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImRect rectangle) { @@ -252,13 +252,13 @@ namespace Nuake }; - void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, + void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed) { DrawButtonImage(imageNormal, imageHovered, imagePressed, tintNormal, tintHovered, tintPressed, ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); }; - void DrawButtonImage(const Ref& image, + void DrawButtonImage(const Ref& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed) { DrawButtonImage(image, image, image, tintNormal, tintHovered, tintPressed, ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); diff --git a/Nuake/src/UI/ImUI.h b/Nuake/src/UI/ImUI.h index 2e615ef2..c9aed303 100644 --- a/Nuake/src/UI/ImUI.h +++ b/Nuake/src/UI/ImUI.h @@ -50,26 +50,26 @@ namespace Nuake void Tooltip(const std::string& message); - void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, + void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImVec2 rectMin, ImVec2 rectMax); - void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, + void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImRect rectangle); - void DrawButtonImage(const Ref& image, + void DrawButtonImage(const Ref& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImVec2 rectMin, ImVec2 rectMax); - void DrawButtonImage(const Ref& image, + void DrawButtonImage(const Ref& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed, ImRect rectangle); - void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, + void DrawButtonImage(const Ref& imageNormal, const Ref& imageHovered, const Ref& imagePressed, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed); - void DrawButtonImage(const Ref& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed); + void DrawButtonImage(const Ref& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed); void DrawImage(const Ref inImage);