Skip to content

Commit

Permalink
Cleanup and fixed dumb dealloc mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
thepaladon committed Aug 16, 2024
1 parent 2aa5151 commit 40ab819
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 31 deletions.
1 change: 1 addition & 0 deletions Engine/Headers/Rendering/BEAR/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions Engine/Headers/Rendering/TextureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions Engine/Source/Rendering/BufferManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 47 additions & 1 deletion Engine/Source/Rendering/TextureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
37 changes: 10 additions & 27 deletions Engine/Source/Tools/TextureVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using namespace Ball;

bool IsFlagSetA(int flags, int flag);
void RenderMultiSelectComboA(const char* label, int& selectedFlags, const std::vector<std::string>& items);

void TextureVisualizer::Init()
Expand All @@ -30,26 +29,9 @@ void TextureVisualizer::Draw()
"Name (Descending)",
};

ImGui::Combo("Sort by", &sortOption, sortItems, IM_ARRAYSIZE(sortItems));

const std::vector<std::string> 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<std::string> comboFlags = {"NONE", "MIPMAP_GENERATE", "ALLOW_UA", "SCREENSIZE"};
RenderMultiSelectComboA("Filter", m_SelectedFlags, comboFlags);

// Copy unordered_set to vector for sorting and filtering
std::vector<Texture*> nameFilteredTextures;
Expand Down Expand Up @@ -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<Texture*> toDelete;
for (auto& Texture : flagFilteredTextures)
{
Expand All @@ -103,7 +85,6 @@ void TextureVisualizer::Draw()
if (!isSelected)
toDelete.insert(Texture);
}

index++;
}

Expand All @@ -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());
Expand Down

0 comments on commit 40ab819

Please sign in to comment.