Filebrowser icons done

This commit is contained in:
antopilo
2025-01-04 03:31:27 -05:00
parent 3e10ee032c
commit 97ba783644
5 changed files with 102 additions and 34 deletions

View File

@@ -106,7 +106,7 @@ namespace Nuake
ImGui::SetCursorPos(prevCursor);
//ImGui::Image((ImTextureID)TextureManager::Get()->GetTexture("Resources/Images/folder_icon.png")->GetID(), ImVec2(100, 100), ImVec2(0, 1), ImVec2(1, 0));
ImGui::Image((ImTextureID)TextureManager::Get()->GetTexture2("Resources/Images/folder_icon.png")->GetImGuiDescriptorSet(), ImVec2(100, 100));
auto imguiStyle = ImGui::GetStyle();
@@ -344,74 +344,74 @@ namespace Nuake
}
Ref<Texture> textureImage = TextureManager::Get()->GetTexture("Resources/Images/file_icon.png");
Ref<VulkanImage> textureImage = TextureManager::Get()->GetTexture2("Resources/Images/file_icon.png");
const auto textureMgr = TextureManager::Get();
const auto fileType = file->GetFileType();
if (fileType == FileType::Material)
{
auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath());
if (image)
{
textureImage = image;
}
//auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath());
//if (image)
//{
// textureImage = image;
//}
}
else if (fileType == FileType::Image)
{
const std::string path = file->GetAbsolutePath();
textureImage = textureMgr->GetTexture(path);
textureImage = textureMgr->GetTexture2(path);
}
else if (fileType == FileType::Project)
{
textureImage = textureMgr->GetTexture("Resources/Images/project_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/project_icon.png");
}
else if (fileType == FileType::NetScript)
{
textureImage = textureMgr->GetTexture("Resources/Images/csharp_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/csharp_icon.png");
}
else if (fileType == FileType::Scene)
{
textureImage = textureMgr->GetTexture("Resources/Images/scene_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/scene_icon.png");
}
else if (fileType == FileType::Script)
{
textureImage = textureMgr->GetTexture("Resources/Images/script_file_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/script_file_icon.png");
}
else if (fileType == FileType::Audio)
{
textureImage = textureMgr->GetTexture("Resources/Images/Audio_file_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/Audio_file_icon.png");
}
else if (fileType == FileType::Prefab)
{
auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath());
if (image)
{
textureImage = image;
}
//auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath());
//if (image)
//{
// textureImage = image;
//}
}
else if (fileType == FileType::Mesh)
{
auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath());
if (image)
{
textureImage = image;
}
//auto image = ThumbnailManager::Get().GetThumbnail(file->GetRelativePath());
//if (image)
//{
// textureImage = image;
//}
}
else if (fileType == FileType::Solution)
{
textureImage = textureMgr->GetTexture("Resources/Images/sln_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/sln_icon.png");
}
else if (fileType == FileType::Map)
{
textureImage = textureMgr->GetTexture("Resources/Images/trenchbroom_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/trenchbroom_icon.png");
}
else if (fileType == FileType::Env)
{
textureImage = textureMgr->GetTexture("Resources/Images/env_file_icon.png");
textureImage = textureMgr->GetTexture2("Resources/Images/env_file_icon.png");
}
ImGui::SetCursorPos(prevCursor);
//ImGui::Image(reinterpret_cast<ImTextureID>(textureImage->GetID()), ImVec2(100, 100), ImVec2(0, 1), ImVec2(1, 0));
ImGui::Image(reinterpret_cast<ImTextureID>(textureImage->GetImGuiDescriptorSet()), ImVec2(100, 100));
ImGui::PopStyleVar();
auto& imguiStyle = ImGui::GetStyle();

View File

@@ -42,7 +42,7 @@ namespace Nuake
const std::string projectIconPath = Path + "/../icon.png";
if (FileSystem::FileExists(projectIconPath, true))
{
//ProjectIcon = TextureManager::Get()->GetTexture(projectIconPath);
ProjectIcon = TextureManager::Get()->GetTexture2(projectIconPath);
}
else
{
@@ -314,10 +314,6 @@ namespace Nuake
{
ImGui::Image((ImTextureID)project.ProjectIcon->GetImGuiDescriptorSet(), iconSize);
}
else
{
//ImGui::Image((void*)Nuake::TextureManager::Get()->GetTexture("Resources/Images/cube.png")->GetID(), iconSize, ImVec2(0, 1), ImVec2(1, 0));
}
ImGui::SameLine();
ImGui::SetCursorPosX(padding.x + iconSize.x);

View File

@@ -75,8 +75,8 @@ namespace Nuake
Ref<VulkanImage> TextureManager::GetTexture2(const std::string path)
{
//if (!IsTextureLoaded2(path))
//m_Registry2.emplace(path, new VulkanImage(path));
if (!IsTextureLoaded2(path))
m_Registry2.emplace(path, new VulkanImage(path));
return m_Registry2.at(path);
}

View File

@@ -13,6 +13,76 @@ using namespace Nuake;
#include "vk_mem_alloc.h"
#include <stb_image/stb_image.h>
VulkanImage::VulkanImage(const std::string & path) :
ImGuiDescriptorSetGenerated(false),
Format(ImageFormat::RGBA8)
{
int channels = 0;
int width = 0;
int height = 0;
void* imageData = stbi_load(path.c_str(), &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(ImageFormat inFormat, Vector2 inSize, ImageUsage usage) :
Format(inFormat),
Extent(inSize, 1),

View File

@@ -5,6 +5,7 @@
#include "volk/volk.h"
#include "vk_mem_alloc.h"
#include <string>
namespace Nuake
{
@@ -45,6 +46,7 @@ namespace Nuake
VkDescriptorSet ImGuiDescriptorSet;
public:
VulkanImage(const std::string& path);
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.