Fixed uneeded copies of TriangleVertices

This commit is contained in:
2026-02-18 13:09:50 -05:00
parent 5c7b030dc8
commit 7cf88ee70d
89 changed files with 24785 additions and 128 deletions

View File

@@ -1,6 +1,10 @@
#include <GLFW/glfw3.h>
#include <cstdint>
#include <vulkan/vulkan_core.h>
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_vulkan.h"
#include "utilities/Logger.h"
#include "GlfwWindowManager.h"
@@ -40,10 +44,42 @@ private:
GlfwWindowManager WindowManager;
VulkanContext VkContext;
bool bShowImGui = true;
bool bShowDemo = false;
static void KeyCallback(GLFWwindow* Window, int Key, int Scancode, int Action, int Mods)
{
auto App = reinterpret_cast<HelloTriangleApplication*>(glfwGetWindowUserPointer(Window));
if (Action == GLFW_PRESS || Action == GLFW_REPEAT)
{
App->OnKey(Key);
}
}
void OnKey(int Key)
{
switch (Key)
{
case GLFW_KEY_O:
bShowImGui = !bShowImGui;
Log::Info("ImGui visibility toggled: " + std::string(bShowImGui ? "ON" : "OFF"));
break;
case GLFW_KEY_L:
bShowDemo = !bShowDemo;
Log::Info("Demo window toggled: " + std::string(bShowDemo ? "ON" : "OFF"));
break;
}
}
void Initialization()
{
InitGlfw();
InitVulkan();
IMGUI_CHECKVERSION();
ImGui::CreateContext();
VkContext.InitImGui();
}
void InitVulkan()
@@ -52,9 +88,8 @@ private:
Settings.bValidationEnabled,
Settings.bVerboseLogging,
WindowManager.GetWindow(),
TriangleVertices
};
VkContext.Initialize(Config);
VkContext.Initialize(Config, TriangleVertices);
}
void InitGlfw()
@@ -70,6 +105,8 @@ private:
glfwSetWindowUserPointer(WindowManager.GetWindow(), this);
glfwSetFramebufferSizeCallback(WindowManager.GetWindow(), FramebufferResizeCallback);
WindowManager.SetKeyCallback(KeyCallback);
}
static void FramebufferResizeCallback(GLFWwindow* Window, int Width, int Height)
@@ -78,25 +115,43 @@ private:
App->VkContext.SetFramebufferResized(true);
}
void DrawFrame()
{
VkContext.DrawFrame();
}
void MainLoop()
{
VkPhysicalDeviceProperties Properties{};
vkGetPhysicalDeviceProperties(VkContext.DeviceManager.GetPhysicalDevice(), &Properties);
while (!WindowManager.ShouldClose())
{
WindowManager.PollEvents();
DrawFrame();
if (bShowImGui)
{
ImGui_ImplVulkan_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
if (bShowDemo)
{
ImGui::ShowDemoWindow();
}
else
{
ImGui::Begin(Properties.deviceName);
ImGui::Text("Application average %.1f FPS", ImGui::GetIO().Framerate);
ImGui::End();
}
}
VkContext.DrawFrame(bShowImGui, TriangleVertices.size());
}
}
void Cleanup()
{
Log::Info("Cleaning up...");
VkContext.Cleanup();
WindowManager.Cleanup();
ImGui::DestroyContext();
}
};