Added Deconstructor for Mesh

This commit is contained in:
OusmBlueNinja 2024-12-31 16:35:06 -06:00
parent b6aa69210f
commit dbd23a30fc
5 changed files with 106 additions and 63 deletions

View File

@ -1,6 +1,6 @@
[Window][DockSpace]
Pos=0,0
Size=1280,720
Size=1920,1177
Collapsed=0
[Window][Debug##Default]
@ -68,26 +68,26 @@ Size=1920,1177
Collapsed=0
[Window][Inspector##InspectorWindow]
Pos=896,27
Size=376,685
Pos=1536,27
Size=376,1142
Collapsed=0
DockId=0x00000016,0
[Window][Editor##EditorWindow]
Pos=332,27
Size=562,319
Size=1202,776
Collapsed=0
DockId=0x00000017,0
[Window][Performance##performance]
Pos=8,468
Size=322,244
Pos=8,761
Size=322,408
Collapsed=0
DockId=0x0000001C,0
[Window][Logger##logger]
Pos=332,348
Size=562,364
Pos=332,805
Size=1202,364
Collapsed=0
DockId=0x00000019,0
@ -105,7 +105,7 @@ DockId=0x0000000F,0
[Window][Scene Window##SceneWindow]
Pos=8,27
Size=322,439
Size=322,732
Collapsed=0
DockId=0x0000001B,0
@ -134,7 +134,7 @@ Column 2 Weight=0.6474
Column 3 Weight=1.0088
[Docking][Data]
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=42,84 Size=1264,685 Split=X Selected=0xF7365A5A
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,50 Size=1904,1142 Split=X Selected=0xF7365A5A
DockNode ID=0x00000013 Parent=0x14621557 SizeRef=322,1142 Split=Y Selected=0x818D04BB
DockNode ID=0x0000001B Parent=0x00000013 SizeRef=264,456 HiddenTabBar=1 Selected=0x1D5D92B6
DockNode ID=0x0000001C Parent=0x00000013 SizeRef=264,254 HiddenTabBar=1 Selected=0x818D04BB

View File

@ -16,6 +16,47 @@ MeshComponent::MeshComponent()
{
}
MeshComponent::~MeshComponent()
{
for (auto &submesh : submeshes)
{
// Delete OpenGL buffers associated with the submesh
if (submesh.vbo != 0)
{
glDeleteBuffers(1, &submesh.vbo);
submesh.vbo = 0;
}
if (submesh.ebo != 0)
{
glDeleteBuffers(1, &submesh.ebo);
submesh.ebo = 0;
}
if (submesh.vao != 0)
{
glDeleteVertexArrays(1, &submesh.vao);
submesh.vao = 0;
}
// Clear textures associated with the submesh
for (const auto &texture : submesh.textures)
{
if (texture.id != 0)
{
glDeleteTextures(1, &texture.id);
}
}
// Clear submesh data
submesh.textures.clear();
submesh.vertices.clear();
submesh.indices.clear();
}
// Clear the submesh container
submeshes.clear();
}
const std::string &MeshComponent::GetName() const
{
return name;
@ -26,6 +67,7 @@ const std::string &MeshComponent::GetStaticName()
return name;
}
void MeshComponent::Update(float deltaTime)
{
(void)deltaTime;

View File

@ -23,6 +23,8 @@ public:
MeshComponent();
~MeshComponent();
virtual const std::string& GetName() const override;
static const std::string& GetStaticName();

View File

@ -194,23 +194,23 @@ public:
std::string key = generateKey(type, path);
// 2) Check if its already loaded
auto it = m_AssetMap.find(key);
if (it != m_AssetMap.end())
{
// Debug: Log the variant type
if (std::holds_alternative<std::shared_ptr<T>>(it->second))
{
#ifdef DEBUG
DebugAssetMap();
#endif
std::cout << "[AssetManager] Retrieved asset from cache: " << key << std::endl;
return std::get<std::shared_ptr<T>>(it->second);
}
else
{
throw std::runtime_error("Asset type mismatch for key: " + key);
}
}
// auto it = m_AssetMap.find(key);
// if (it != m_AssetMap.end())
//{
// // Debug: Log the variant type
// if (std::holds_alternative<std::shared_ptr<T>>(it->second))
// {
// #ifdef DEBUG
// DebugAssetMap();
// #endif
// std::cout << "[AssetManager] Retrieved asset from cache: " << key << std::endl;
// return std::get<std::shared_ptr<T>>(it->second);
// }
// else
// {
// throw std::runtime_error("Asset type mismatch for key: " + key);
// }
//}
// 3) Not loaded yet
AssetVariant assetData = loadAssetFromDisk(type, path);

View File

@ -27,11 +27,8 @@ extern std::vector<std::shared_ptr<GameObject>> g_GameObjects;
// Extern reference to our global (or extern) asset manager
extern AssetManager g_AssetManager;
extern std::shared_ptr<CameraComponent> g_RuntimeCameraObject;
extern int g_GPU_Triangles_drawn_to_screen;
// Example cube data (position + UVs)
@ -185,16 +182,12 @@ static unsigned int g_CubeIndices[] =
// Bottom
20, 21, 22, 22, 23, 20};
bool PlayPauseButton(const char* label, bool* isPlaying)
bool PlayPauseButton(const char *label, bool *isPlaying, ImVec2 Size)
{
// Define button size
ImVec2 buttonSize = ImVec2(50, 50); // Adjust size as needed
// Begin the button
if (ImGui::Button(label, buttonSize))
if (ImGui::Button(label, Size))
{
// Toggle the state
*isPlaying = !(*isPlaying);
@ -216,7 +209,7 @@ bool PlayPauseButton(const char* label, bool* isPlaying)
ImVec2 center = ImVec2(button_pos.x + button_size.x * 0.5f, button_pos.y + button_size.y * 0.5f);
// Define icon size
float icon_size = 20.0f;
float icon_size = 0.4f * Size.x;
float half_icon_size = icon_size / 2.0f;
// Define colors
@ -226,7 +219,7 @@ bool PlayPauseButton(const char* label, bool* isPlaying)
{
// Draw Pause Icon (two vertical bars)
float bar_width = 4.0f;
float spacing = 6.0f;
float spacing = 0.1f * Size.x;
// Left bar
ImVec2 left_bar_p1 = ImVec2(center.x - spacing - bar_width, center.y - half_icon_size);
@ -252,37 +245,28 @@ bool PlayPauseButton(const char* label, bool* isPlaying)
void RenderWindow::Show(bool *GameRunning)
{
ImGui::Begin("Editor##EditorWindow");
ImVec2 size = ImGui::GetContentRegionAvail();
int w = static_cast<int>(size.x);
int h = static_cast<int>(size.y);
if (!m_Initialized)
{
InitGLResources();
m_Initialized = true;
}
// Center the button
ImGui::SetCursorPosX((ImGui::GetWindowWidth() - 60) * 0.5f);
// Render the Play/Pause button
// Render the Play/Pause button
PlayPauseButton("##PlayPauseButton", GameRunning);
ImVec2 size = ImGui::GetContentRegionAvail();
int w = static_cast<int>(size.x);
int h = static_cast<int>(size.y);
// If there's space, render to the FBO, then show it as an ImGui image
if (w > 0 && h > 0)
{
if (w != m_LastWidth || h != m_LastHeight)
{
m_FBO.Create(w, h);
m_LastWidth = w;
m_LastHeight = h;
@ -290,18 +274,39 @@ void RenderWindow::Show(bool *GameRunning)
RenderSceneToFBO(GameRunning);
// Render the image first
ImGui::Image(m_FBO.GetTextureID(), size, ImVec2(0, 0), ImVec2(1, 1));
// Calculate button position to place it slightly right and down from the top-left of the image
ImVec2 imagePos = ImGui::GetItemRectMin();
// Add an offset to position the button
ImVec2 buttonOffset(10.0f, 10.0f); // Adjust these values as needed for the desired offset
ImVec2 buttonPos = ImVec2(imagePos.x + buttonOffset.x, imagePos.y + buttonOffset.y);
// Set cursor position for the button
ImGui::SetCursorScreenPos(buttonPos);
// Dynamically calculate button size based on window size
float buttonWidth = size.x * 0.03f; // 5% of the window width
ImVec2 buttonSize = ImVec2(buttonWidth, buttonWidth);
// Render the Play/Pause button with the calculated size
PlayPauseButton("##PlayPauseButton", GameRunning, buttonSize);
}
else
{
ImGui::Text("No space to render.");
}
ImGui::End();
}
void RenderWindow::InitGLResources()
{
// ----------------------------------------------------
@ -365,7 +370,6 @@ void RenderWindow::InitGLResources()
// ----------------------------------------------------
}
void CheckOpenGLError(const std::string &location)
{
GLenum err;
@ -381,11 +385,6 @@ void CheckOpenGLError(const std::string &location)
}
}
#include <glm/gtc/type_ptr.hpp> // For glm::value_ptr
#include <algorithm> // Ensure <algorithm> is included