Added images back to the editor

This commit is contained in:
antopilo
2025-01-04 03:03:17 -05:00
parent e8ad4be39d
commit 5f39899981
12 changed files with 199 additions and 99 deletions
+40 -40
View File
@@ -61,6 +61,8 @@
#include "src/Rendering/Vulkan/VulkanRenderer.h"
#include <src/Rendering/Vulkan/VkResources.h>
#include <src/Rendering/Vulkan/VulkanImage/VulkanImage.h>
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();
+6 -5
View File
@@ -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<Texture> NuakeTexture;
Ref<Texture> CloseIconTexture;
Ref<Texture> MaximizeTexture;
Ref<Texture> RestoreTexture;
Ref<Texture> MinimizeTexture;
Ref<VulkanImage> NuakeTexture;
Ref<VulkanImage> CloseIconTexture;
Ref<VulkanImage> MaximizeTexture;
Ref<VulkanImage> RestoreTexture;
Ref<VulkanImage> MinimizeTexture;
EditorInterface(CommandBuffer& commandBuffer);
static ImFont* bigIconFont;
+4 -3
View File
@@ -10,11 +10,13 @@
#include <dependencies/glfw/include/GLFW/glfw3.h>
#include <src/Rendering/Textures/TextureManager.h>
#include <src/Rendering/Vulkan/VulkanImage/VulkanImage.h>
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...");
+2 -1
View File
@@ -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<Nuake::Texture> _NuakeLogo;
Ref<Nuake::VulkanImage> _NuakeLogo;
public:
static LoadingSplash& Get()
+5 -5
View File
@@ -11,7 +11,7 @@
#include <src/Core/Logger.h>
#include <src/Rendering/Textures/TextureManager.h>
#include <src/Rendering/Textures/Texture.h>
#include <src/Rendering/Vulkan/VulkanImage/VulkanImage.h>
#include <json/json.hpp>
#include <string>
@@ -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
{
+3 -2
View File
@@ -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<Texture> ProjectIcon;
Ref<VulkanImage> 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<Texture> _NuakeLogo;
Ref<VulkanImage> _NuakeLogo;
EditorInterface* _Editor;
std::string _RecentProjectFilePath = "";
+44 -27
View File
@@ -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 <glad/glad.h>
@@ -7,6 +8,7 @@
namespace Nuake
{
std::map<std::string, Ref<Texture>> TextureManager::m_Registry;
std::map<std::string, Ref<VulkanImage>> 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<Texture>(Resources_Gizmos_bone_png, Resources_Gizmos_bone_png_len));
//m_Registry.emplace(Resources_Gizmos_camera_png_path, CreateRef<Texture>(Resources_Gizmos_camera_png, Resources_Gizmos_camera_png_len));
//m_Registry.emplace(Resources_Gizmos_light_png_path, CreateRef<Texture>(Resources_Gizmos_light_png, Resources_Gizmos_light_png_len));
//m_Registry.emplace(Resources_Gizmos_light_directional_png_path, CreateRef<Texture>(Resources_Gizmos_light_directional_png, Resources_Gizmos_light_directional_png_len));
//m_Registry.emplace(Resources_Gizmos_light_spot_png_path, CreateRef<Texture>(Resources_Gizmos_light_spot_png, Resources_Gizmos_light_spot_png_len));
//m_Registry.emplace(Resources_Gizmos_player_png_path, CreateRef<Texture>(Resources_Gizmos_player_png, Resources_Gizmos_player_png_len));
//m_Registry.emplace(Resources_Gizmos_particles_png_path, CreateRef<Texture>(Resources_Gizmos_particles_png, Resources_Gizmos_particles_png_len));
//m_Registry.emplace(Resources_Gizmos_rigidbody_png_path, CreateRef<Texture>(Resources_Gizmos_rigidbody_png, Resources_Gizmos_rigidbody_png_len));
//m_Registry.emplace(Resources_Gizmos_sound_emitter_png_path, CreateRef<Texture>(Resources_Gizmos_sound_emitter_png, Resources_Gizmos_sound_emitter_png_len));
//
//m_Registry.emplace(Resources_Images_cube_png_path, CreateRef<Texture>(Resources_Images_cube_png, Resources_Images_cube_png_len));
//m_Registry.emplace(Resources_Images_nuake_logo_png_path, CreateRef<Texture>(Resources_Images_nuake_logo_png, Resources_Images_nuake_logo_png_len));
//m_Registry.emplace(Resources_Images_logo_white_png_path, CreateRef<Texture>(Resources_Images_logo_white_png, Resources_Images_logo_white_png_len));
//m_Registry.emplace(Resources_Images_logo_png_path, CreateRef<Texture>(Resources_Images_logo_png, Resources_Images_logo_png_len));
//m_Registry.emplace(Resources_Images_file_icon_png_path, CreateRef<Texture>(Resources_Images_file_icon_png, Resources_Images_file_icon_png_len));
//m_Registry.emplace(Resources_Images_env_file_icon_png_path, CreateRef<Texture>(Resources_Images_env_file_icon_png, Resources_Images_env_file_icon_png_len));
//m_Registry.emplace(Resources_Images_scene_icon_png_path, CreateRef<Texture>(Resources_Images_scene_icon_png, Resources_Images_scene_icon_png_len));
//m_Registry.emplace(Resources_Images_project_icon_png_path, CreateRef<Texture>(Resources_Images_project_icon_png, Resources_Images_project_icon_png_len));
//m_Registry.emplace(Resources_Images_csharp_icon_png_path, CreateRef<Texture>(Resources_Images_csharp_icon_png, Resources_Images_csharp_icon_png_len));
//m_Registry.emplace(Resources_Images_sln_icon_png_path, CreateRef<Texture>(Resources_Images_sln_icon_png, Resources_Images_sln_icon_png_len));
//m_Registry.emplace(Resources_Images_trenchbroom_icon_png_path, CreateRef<Texture>(Resources_Images_trenchbroom_icon_png, Resources_Images_trenchbroom_icon_png_len));
//m_Registry.emplace(Resources_Images_editor_icon_png_path, CreateRef<Texture>(Resources_Images_editor_icon_png, Resources_Images_editor_icon_png_len));
//m_Registry.emplace(Resources_Images_close_icon_png_path, CreateRef<Texture>(Resources_Images_close_icon_png, Resources_Images_close_icon_png_len));
//m_Registry.emplace(Resources_Images_maximize_icon_png_path, CreateRef<Texture>(Resources_Images_maximize_icon_png, Resources_Images_maximize_icon_png_len));
//m_Registry.emplace(Resources_Images_minimize_icon_png_path, CreateRef<Texture>(Resources_Images_minimize_icon_png, Resources_Images_minimize_icon_png_len));
//m_Registry.emplace(Resources_Images_restore_icon_png_path, CreateRef<Texture>(Resources_Images_restore_icon_png, Resources_Images_restore_icon_png_len));
m_Registry2.emplace(Resources_Images_nuake_logo_png_path, CreateRef<VulkanImage>(Resources_Images_nuake_logo_png, Resources_Images_nuake_logo_png_len));
m_Registry2.emplace(Resources_Images_logo_white_png_path, CreateRef<VulkanImage>(Resources_Images_logo_white_png, Resources_Images_logo_white_png_len));
m_Registry2.emplace(Resources_Gizmos_bone_png_path, CreateRef<VulkanImage>(Resources_Gizmos_bone_png, Resources_Gizmos_bone_png_len));
m_Registry2.emplace(Resources_Gizmos_camera_png_path, CreateRef<VulkanImage>(Resources_Gizmos_camera_png, Resources_Gizmos_camera_png_len));
m_Registry2.emplace(Resources_Gizmos_light_png_path, CreateRef<VulkanImage>(Resources_Gizmos_light_png, Resources_Gizmos_light_png_len));
m_Registry2.emplace(Resources_Gizmos_light_directional_png_path, CreateRef<VulkanImage>(Resources_Gizmos_light_directional_png, Resources_Gizmos_light_directional_png_len));
m_Registry2.emplace(Resources_Gizmos_light_spot_png_path, CreateRef<VulkanImage>(Resources_Gizmos_light_spot_png, Resources_Gizmos_light_spot_png_len));
m_Registry2.emplace(Resources_Gizmos_player_png_path, CreateRef<VulkanImage>(Resources_Gizmos_player_png, Resources_Gizmos_player_png_len));
m_Registry2.emplace(Resources_Gizmos_particles_png_path, CreateRef<VulkanImage>(Resources_Gizmos_particles_png, Resources_Gizmos_particles_png_len));
m_Registry2.emplace(Resources_Gizmos_rigidbody_png_path, CreateRef<VulkanImage>(Resources_Gizmos_rigidbody_png, Resources_Gizmos_rigidbody_png_len));
m_Registry2.emplace(Resources_Gizmos_sound_emitter_png_path, CreateRef<VulkanImage>(Resources_Gizmos_sound_emitter_png, Resources_Gizmos_sound_emitter_png_len));
m_Registry2.emplace(Resources_Images_cube_png_path, CreateRef<VulkanImage>(Resources_Images_cube_png, Resources_Images_cube_png_len));
m_Registry2.emplace(Resources_Images_logo_white_png_path, CreateRef<VulkanImage>(Resources_Images_logo_white_png, Resources_Images_logo_white_png_len));
m_Registry2.emplace(Resources_Images_logo_png_path, CreateRef<VulkanImage>(Resources_Images_logo_png, Resources_Images_logo_png_len));
m_Registry2.emplace(Resources_Images_file_icon_png_path, CreateRef<VulkanImage>(Resources_Images_file_icon_png, Resources_Images_file_icon_png_len));
m_Registry2.emplace(Resources_Images_env_file_icon_png_path, CreateRef<VulkanImage>(Resources_Images_env_file_icon_png, Resources_Images_env_file_icon_png_len));
m_Registry2.emplace(Resources_Images_scene_icon_png_path, CreateRef<VulkanImage>(Resources_Images_scene_icon_png, Resources_Images_scene_icon_png_len));
m_Registry2.emplace(Resources_Images_project_icon_png_path, CreateRef<VulkanImage>(Resources_Images_project_icon_png, Resources_Images_project_icon_png_len));
m_Registry2.emplace(Resources_Images_csharp_icon_png_path, CreateRef<VulkanImage>(Resources_Images_csharp_icon_png, Resources_Images_csharp_icon_png_len));
m_Registry2.emplace(Resources_Images_sln_icon_png_path, CreateRef<VulkanImage>(Resources_Images_sln_icon_png, Resources_Images_sln_icon_png_len));
m_Registry2.emplace(Resources_Images_trenchbroom_icon_png_path, CreateRef<VulkanImage>(Resources_Images_trenchbroom_icon_png, Resources_Images_trenchbroom_icon_png_len));
m_Registry2.emplace(Resources_Images_editor_icon_png_path, CreateRef<VulkanImage>(Resources_Images_editor_icon_png, Resources_Images_editor_icon_png_len));
m_Registry2.emplace(Resources_Images_close_icon_png_path, CreateRef<VulkanImage>(Resources_Images_close_icon_png, Resources_Images_close_icon_png_len));
m_Registry2.emplace(Resources_Images_maximize_icon_png_path, CreateRef<VulkanImage>(Resources_Images_maximize_icon_png, Resources_Images_maximize_icon_png_len));
m_Registry2.emplace(Resources_Images_minimize_icon_png_path, CreateRef<VulkanImage>(Resources_Images_minimize_icon_png, Resources_Images_minimize_icon_png_len));
m_Registry2.emplace(Resources_Images_restore_icon_png_path, CreateRef<VulkanImage>(Resources_Images_restore_icon_png, Resources_Images_restore_icon_png_len));
m_Registry2.emplace(Resources_Images_folder_icon_png_path, CreateRef<VulkanImage>(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<Texture>(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<Texture>(Vector2(1, 1), GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, &whitePixel));
//
//m_Registry.emplace(Resources_Images_folder_icon_png_path, CreateRef<Texture>(Resources_Images_folder_icon_png, Resources_Images_folder_icon_png_len));
}
Ref<Texture> TextureManager::GetTexture(const std::string path)
@@ -64,6 +73,14 @@ namespace Nuake
return m_Registry.at(path);
}
Ref<VulkanImage> 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)
@@ -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<std::string, Ref<Texture>> m_Registry;
static std::map<std::string, Ref<VulkanImage>> m_Registry2;
bool IsTextureLoaded(const std::string path);
bool IsTextureLoaded2(const std::string path);
void LoadStaticTextures();
@@ -22,7 +25,7 @@ namespace Nuake
TextureManager();
Ref<Texture> GetTexture(const std::string path);
Ref<VulkanImage> GetTexture2(const std::string path);
};
}
@@ -11,6 +11,7 @@
using namespace Nuake;
#include "vk_mem_alloc.h"
#include <stb_image/stb_image.h>
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<const stbi_uc*>(inData), static_cast<int>(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<AllocatedBuffer> uploadBuffer = CreateRef<AllocatedBuffer>(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<uint32_t>(width),
static_cast<uint32_t>(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<VkFormat>(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<VkFormat>(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, &copyRegion);
VulkanUtil::TransitionImage(cmd, Image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
});
}
VulkanImage::~VulkanImage()
{
// TODO: deletion of image
@@ -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<int>(Extent.x); }
int GetHeight() const { return static_cast<int>(Extent.y); }
VkImageView& GetImageView() { return ImageView; }
VkImage& GetImage() { return Image; }
VkDescriptorSet& GetImGuiDescriptorSet();
+9 -9
View File
@@ -217,34 +217,34 @@ namespace Nuake
return RectOffset(rect, xy.x, xy.y);
}
void DrawButtonImage(const Ref<Texture>& imageNormal, const Ref<Texture>& imageHovered, const Ref<Texture>& imagePressed,
void DrawButtonImage(const Ref<VulkanImage>& imageNormal, const Ref<VulkanImage>& imageHovered, const Ref<VulkanImage>& 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<Texture>& imageNormal, const Ref<Texture>& imageHovered, const Ref<Texture>& imagePressed,
void DrawButtonImage(const Ref<VulkanImage>& imageNormal, const Ref<VulkanImage>& imageHovered, const Ref<VulkanImage>& imagePressed,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImRect rectangle)
{
DrawButtonImage(imageNormal, imageHovered, imagePressed, tintNormal, tintHovered, tintPressed, rectangle.Min, rectangle.Max);
};
void DrawButtonImage(const Ref<Texture>& image,
void DrawButtonImage(const Ref<VulkanImage>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 rectMin, ImVec2 rectMax)
{
DrawButtonImage(image, image, image, tintNormal, tintHovered, tintPressed, rectMin, rectMax);
};
void DrawButtonImage(const Ref<Texture>& image,
void DrawButtonImage(const Ref<VulkanImage>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImRect rectangle)
{
@@ -252,13 +252,13 @@ namespace Nuake
};
void DrawButtonImage(const Ref<Texture>& imageNormal, const Ref<Texture>& imageHovered, const Ref<Texture>& imagePressed,
void DrawButtonImage(const Ref<VulkanImage>& imageNormal, const Ref<VulkanImage>& imageHovered, const Ref<VulkanImage>& imagePressed,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed)
{
DrawButtonImage(imageNormal, imageHovered, imagePressed, tintNormal, tintHovered, tintPressed, ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
};
void DrawButtonImage(const Ref<Texture>& image,
void DrawButtonImage(const Ref<VulkanImage>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed)
{
DrawButtonImage(image, image, image, tintNormal, tintHovered, tintPressed, ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
+6 -6
View File
@@ -50,26 +50,26 @@ namespace Nuake
void Tooltip(const std::string& message);
void DrawButtonImage(const Ref<Texture>& imageNormal, const Ref<Texture>& imageHovered, const Ref<Texture>& imagePressed,
void DrawButtonImage(const Ref<VulkanImage>& imageNormal, const Ref<VulkanImage>& imageHovered, const Ref<VulkanImage>& imagePressed,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 rectMin, ImVec2 rectMax);
void DrawButtonImage(const Ref<Texture>& imageNormal, const Ref<Texture>& imageHovered, const Ref<Texture>& imagePressed,
void DrawButtonImage(const Ref<VulkanImage>& imageNormal, const Ref<VulkanImage>& imageHovered, const Ref<VulkanImage>& imagePressed,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImRect rectangle);
void DrawButtonImage(const Ref<Texture>& image,
void DrawButtonImage(const Ref<VulkanImage>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 rectMin, ImVec2 rectMax);
void DrawButtonImage(const Ref<Texture>& image,
void DrawButtonImage(const Ref<VulkanImage>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImRect rectangle);
void DrawButtonImage(const Ref<Texture>& imageNormal, const Ref<Texture>& imageHovered, const Ref<Texture>& imagePressed,
void DrawButtonImage(const Ref<VulkanImage>& imageNormal, const Ref<VulkanImage>& imageHovered, const Ref<VulkanImage>& imagePressed,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed);
void DrawButtonImage(const Ref<Texture>& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed);
void DrawButtonImage(const Ref<VulkanImage>& image, ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed);
void DrawImage(const Ref<VulkanImage> inImage);