Skip to content
This repository was archived by the owner on Jul 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# Unfinished scripts
build.bat
build.sh
build_debug.bat
build_debug.sh
KaguEngine/assets/shaders/compile.bat
KaguEngine/assets/shaders/compile.sh

Expand All @@ -16,4 +18,5 @@ KaguEngine/assets/shaders/compile.sh
/cmake-build-minsizerel/
/cmake-build-release/
/cmake-build-relwithdebinfo/
/build/
/build/
/build_debug/
Binary file removed KaguEngine/assets/textures/dummy_texture.png
Binary file not shown.
24 changes: 13 additions & 11 deletions KaguEngine/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ void App::run() {

RenderSystem renderSystem{
m_Device,
m_Renderer.getOffscreenFormat(),
m_Renderer.getOffscreenDepthFormat(),
m_Renderer.getFormat(),
m_Renderer.getDepthFormat(),
m_GlobalSetLayout->getDescriptorSetLayout(), // set = 0 (UBO)
m_MaterialSetLayout->getDescriptorSetLayout() // set = 1 (textures)
};
PointLightSystem pointLightSystem{
m_Device,
m_Renderer.getOffscreenFormat(),
m_Renderer.getOffscreenDepthFormat(),
m_Renderer.getFormat(),
m_Renderer.getDepthFormat(),
m_GlobalSetLayout->getDescriptorSetLayout()
};
Camera camera{};
Expand All @@ -86,6 +86,12 @@ void App::run() {
KeyboardMovementController cameraController{};
glfwPollEvents();

if (m_Window.windowResized()) {
m_Renderer.recreateSwapChain();
ImGuiContext::recreateSwapChain();
m_Window.resetWindowResizedFlag();
}

auto newTime = std::chrono::high_resolution_clock::now();
float frameTime = std::chrono::duration<float, std::chrono::seconds::period>(newTime - currentTime).count();
currentTime = newTime;
Expand Down Expand Up @@ -121,13 +127,9 @@ void App::run() {
m_Renderer.endOffscreenRendering(commandBuffer);

// ImGui rendering
m_Renderer.transitionOffscreenImageForImGui(commandBuffer);
imGuiContext.render(m_Renderer);

// Present the image
m_Renderer.beginSwapChainRendering(commandBuffer);
ImGuiContext::onPresent(commandBuffer);
m_Renderer.endSwapChainRendering(commandBuffer);
m_Renderer.beginRendering(commandBuffer);
imGuiContext.render(m_Renderer, commandBuffer);
m_Renderer.endRendering(commandBuffer);

m_Renderer.endFrame();
}
Expand Down
27 changes: 12 additions & 15 deletions KaguEngine/src/ImGuiContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ ImGuiContext::~ImGuiContext() {
ImGui::DestroyContext();
}

void ImGuiContext::recreateSwapChain() {
ImGui_ImplVulkan_SetMinImageCount(3);
}

void ImGuiContext::setupConfigFlags() {
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
Expand Down Expand Up @@ -167,9 +171,9 @@ void ImGuiContext::setupContext() const {
init_info.DescriptorPool = poolRef->getDescriptorPool();
init_info.Allocator = nullptr;
init_info.Subpass = 0;
init_info.MinImageCount = SwapChain::MAX_FRAMES_IN_FLIGHT;
init_info.MSAASamples = deviceRef.getSampleCount();
init_info.ImageCount = SwapChain::MAX_FRAMES_IN_FLIGHT;
init_info.MinImageCount = 3;
init_info.ImageCount = 3;
init_info.UseDynamicRendering = true;
init_info.PipelineRenderingCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
init_info.PipelineRenderingCreateInfo.colorAttachmentCount = 1;
Expand Down Expand Up @@ -226,13 +230,12 @@ void ImGuiContext::setStyleVars() {
style.ButtonTextAlign = ImVec2(0.5f, 0.5f);
}

void ImGuiContext::recreateSwapChain() {
ImGui_ImplVulkan_SetMinImageCount(SwapChain::MAX_FRAMES_IN_FLIGHT);
}

void ImGuiContext::render(const Renderer& renderer) {
void ImGuiContext::render(const Renderer& renderer, VkCommandBuffer commandBuffer) {
beginRender();
onRender(renderer);
ImGui::Render();
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), commandBuffer);
endRender();
}

void ImGuiContext::beginRender() {
Expand Down Expand Up @@ -367,7 +370,7 @@ void ImGuiContext::render3DScene(const Renderer& renderer) const {
(viewportSpace.y - renderSize.y) * 0.5f
};
ImGui::SetCursorPos(imagePos);
ImGui::Image(reinterpret_cast<ImTextureID>(renderer.getOffscreenImGuiDescriptorSet()), renderSize);
ImGui::Image(reinterpret_cast<ImTextureID>(renderer.getSceneDescriptorSet()), renderSize);

ImGui::End();
ImGui::PopStyleVar();
Expand Down Expand Up @@ -540,7 +543,7 @@ void ImGuiContext::renderStatusBar() {
UI_Helpers::ImGui_Text(Config::compiler);

// --- Right Side: Frame Rate ---
const std::string framerate = std::to_string(static_cast<int>(ImGui::GetIO().Framerate)) + " FPS";
const std::string framerate = std::to_string(static_cast<int>(1.0f / ImGui::GetIO().DeltaTime)) + " FPS";
// Right-alignment position
constexpr float internPadding = 8.0f;
const auto align_pos = ImGui::GetWindowWidth() - ImGui::CalcTextSize(framerate.c_str()).x - ImGui::GetStyle().FramePadding.x - internPadding;
Expand All @@ -553,12 +556,6 @@ void ImGuiContext::renderStatusBar() {
}
}

void ImGuiContext::onPresent(VkCommandBuffer commandBuffer) {
ImGui::Render();
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), commandBuffer);
endRender();
}

void ImGuiContext::endRender() {
ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
Expand Down
6 changes: 2 additions & 4 deletions KaguEngine/src/ImGuiContext.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public:
);
~ImGuiContext();

static void recreateSwapChain();
void render(const Renderer& renderer);

static void onPresent(VkCommandBuffer commandBuffer);
static void recreateSwapChain() ;
void render(const Renderer& renderer, VkCommandBuffer commandBuffer);

// Specs
[[nodiscard]] float getDepth() const { return m_MaxDepth[m_CamIdx]; }
Expand Down
Loading