diff --git a/Engine/Headers/Rendering/BEAR/Texture.h b/Engine/Headers/Rendering/BEAR/Texture.h index e5495bd..93bf183 100644 --- a/Engine/Headers/Rendering/BEAR/Texture.h +++ b/Engine/Headers/Rendering/BEAR/Texture.h @@ -99,6 +99,7 @@ namespace Ball return uint32_t(fmax(1.0, log2(fmax(float(m_Spec.m_Width), float(m_Spec.m_Height))) + 1.f)); } + // Note: Should be private, but because of MT Model Loading it's not - [ Angel 16/08/24 ] void GenerateMips(); private: diff --git a/Engine/Headers/Rendering/TextureManager.h b/Engine/Headers/Rendering/TextureManager.h index 5ecd2fe..77cc455 100644 --- a/Engine/Headers/Rendering/TextureManager.h +++ b/Engine/Headers/Rendering/TextureManager.h @@ -18,6 +18,12 @@ namespace Ball static size_t GetCount() { return m_TextureCount; } + // Function to get TextureFormat as string + static std::string GetFormatAsString(const TextureFormat format); + + // Function to get TextureType as string + static std::string GetTypeAsString(const TextureType type); + private: TextureManager() = delete; TextureManager(const TextureManager&) = delete; diff --git a/Engine/Source/Rendering/BufferManager.cpp b/Engine/Source/Rendering/BufferManager.cpp index 48739d8..46dfce8 100644 --- a/Engine/Source/Rendering/BufferManager.cpp +++ b/Engine/Source/Rendering/BufferManager.cpp @@ -20,9 +20,11 @@ namespace Ball void BufferManager::DestroyAll() { - for (auto& buf : m_Buffers) - { + m_BufferCount = 0; + + for (const auto& buf : m_Buffers) delete buf; - } + + m_Buffers.clear(); } } // namespace Ball diff --git a/Engine/Source/Rendering/TextureManager.cpp b/Engine/Source/Rendering/TextureManager.cpp index ebb5964..ff75010 100644 --- a/Engine/Source/Rendering/TextureManager.cpp +++ b/Engine/Source/Rendering/TextureManager.cpp @@ -39,10 +39,56 @@ Texture* TextureManager::CreateFromFilepath(const std::string& path, TextureSpec return texture; } -void TextureManager::Destroy(Texture* buffer) +void TextureManager::Destroy(Texture* texture) { + m_Textures.remove(texture); + delete texture; + m_TextureCount--; } void TextureManager::DestroyAll() { + m_TextureCount = 0; + + for (auto& tex : m_Textures) + delete tex; + + m_Textures.clear(); +} + +std::string TextureManager::GetFormatAsString(const TextureFormat format) +{ + switch (format) + { + case TextureFormat::R8G8B8A8_UNORM: + return "R8G8B8A8_UNORM"; + case TextureFormat::R8G8B8A8_SNORM: + return "R8G8B8A8_SNORM"; + case TextureFormat::R16G16B16A16_UNORM: + return "R16G16B16A16_UNORM"; + case TextureFormat::R32_FLOAT: + return "R32_FLOAT"; + case TextureFormat::R32_G32_FLOAT: + return "R32_G32_FLOAT"; + case TextureFormat::R32_G32_B32_A32_FLOAT: + return "R32_G32_B32_A32_FLOAT"; + default: + ASSERT_MSG(LOG_GRAPHICS, false, "Unknown Format of Texture"); + return "Unknown Format"; + } +} +std::string TextureManager::GetTypeAsString(const TextureType type) +{ + switch (type) + { + case TextureType::RENDER_TARGET: + return "RENDER_TARGET"; + case TextureType::R_TEXTURE: + return "R_TEXTURE"; + case TextureType::RW_TEXTURE: + return "RW_TEXTURE"; + default: + ASSERT_MSG(LOG_GRAPHICS, false, "Unknown Type of Texture"); + return "Unknown Type"; + } } diff --git a/Engine/Source/Tools/TextureVisualizer.cpp b/Engine/Source/Tools/TextureVisualizer.cpp index 21946e8..4b12227 100644 --- a/Engine/Source/Tools/TextureVisualizer.cpp +++ b/Engine/Source/Tools/TextureVisualizer.cpp @@ -5,7 +5,6 @@ using namespace Ball; -bool IsFlagSetA(int flags, int flag); void RenderMultiSelectComboA(const char* label, int& selectedFlags, const std::vector& items); void TextureVisualizer::Init() @@ -30,26 +29,9 @@ void TextureVisualizer::Draw() "Name (Descending)", }; - ImGui::Combo("Sort by", &sortOption, sortItems, IM_ARRAYSIZE(sortItems)); - - const std::vector items = { - "NONE", "CBV", "SRV", "UAV", "ALLOW_UA", "DEFAULT_HEAP", "UPLOAD_HEAP", "VERTEX_Texture", "SCREENSIZE"}; - - if (ImGui::BeginCombo("Filter", "Select...")) - { - for (int i = 0; i < items.size(); ++i) - { - bool isSelected = IsFlagSetA(m_SelectedFlags, 1 << i); - if (ImGui::Checkbox(items[i].c_str(), &isSelected)) - { - if (isSelected) - m_SelectedFlags |= (1 << i); // Set the flag - else - m_SelectedFlags &= ~(1 << i); // Clear the flag - } - } - ImGui::EndCombo(); - } + ImGui::Combo("Sort by Flags", &sortOption, sortItems, IM_ARRAYSIZE(sortItems)); + const std::vector comboFlags = {"NONE", "MIPMAP_GENERATE", "ALLOW_UA", "SCREENSIZE"}; + RenderMultiSelectComboA("Filter", m_SelectedFlags, comboFlags); // Copy unordered_set to vector for sorting and filtering std::vector nameFilteredTextures; @@ -88,8 +70,8 @@ void TextureVisualizer::Draw() [](Texture* a, Texture* b) { return a->GetName() > b->GetName(); }); } + // List all Textures as selectable items int index = 0; - std::unordered_set toDelete; for (auto& Texture : flagFilteredTextures) { @@ -103,7 +85,6 @@ void TextureVisualizer::Draw() if (!isSelected) toDelete.insert(Texture); } - index++; } @@ -114,11 +95,13 @@ void TextureVisualizer::Draw() bool open = true; ImGui::Begin(name.c_str(), &open); ImGui::Text("%s", name.c_str()); - ImGui::Text("Width: %u Bytes", selectedTexture->GetWidth()); - ImGui::Text("Height: %u Bytes", selectedTexture->GetHeight()); - ImGui::Text("Aligned Width: %u Bytes", selectedTexture->GetAlignedWidth()); + ImGui::Text("Type: %s", TextureManager::GetTypeAsString(selectedTexture->GetType()).c_str()); + ImGui::Text("Format: %s", TextureManager::GetFormatAsString(selectedTexture->GetFormat()).c_str()); + ImGui::Text("Width: %u", selectedTexture->GetWidth()); + ImGui::Text("Height: %u", selectedTexture->GetHeight()); + ImGui::Text("Aligned Width: %u", selectedTexture->GetAlignedWidth()); ImGui::Text("Number of Channels: %u", selectedTexture->GetNumChannels()); - ImGui::Text("Bytes per Channel: %u Bytes", selectedTexture->GetBytesPerChannel()); + ImGui::Text("Bytes per Channel: %u", selectedTexture->GetBytesPerChannel()); ImGui::Text("Size: %u Bytes", selectedTexture->GetAlignedWidth() * selectedTexture->GetHeight() * selectedTexture->GetBytesPerChannel() * selectedTexture->GetNumChannels());