Skip to content

Commit e3f6fc6

Browse files
committed
everything runs and can close without validation warnings other than the semaphore. resizing still doesn't work. Next step is to get the parts of the engine to demonstrate things.
1 parent e6b8583 commit e3f6fc6

File tree

5 files changed

+60
-17
lines changed

5 files changed

+60
-17
lines changed

attachments/simple_engine/engine.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ void Engine::HandleResize(int width, int height) {
299299
if (activeCamera) {
300300
activeCamera->SetAspectRatio(static_cast<float>(width) / static_cast<float>(height));
301301
}
302+
303+
// Notify the renderer that the framebuffer has been resized
304+
if (renderer) {
305+
renderer->SetFramebufferResized();
306+
}
307+
308+
// Notify ImGui system about the resize
309+
if (imguiSystem) {
310+
imguiSystem->HandleResize(static_cast<uint32_t>(width), static_cast<uint32_t>(height));
311+
}
302312
}
303313

304314
#if PLATFORM_ANDROID

attachments/simple_engine/imgui_system.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,6 @@ void ImGuiSystem::Cleanup() {
6363
if (renderer) {
6464
renderer->WaitIdle();
6565
}
66-
67-
// Clean up Vulkan resources - using RAII, these will be automatically destroyed
68-
pipeline = nullptr;
69-
pipelineLayout = nullptr;
70-
descriptorSetLayout = nullptr;
71-
fontSampler = nullptr;
72-
fontView = nullptr;
73-
fontImage = nullptr;
74-
fontMemory = nullptr;
75-
vertexBuffer = nullptr;
76-
vertexBufferMemory = nullptr;
77-
indexBuffer = nullptr;
78-
indexBufferMemory = nullptr;
79-
descriptorPool = nullptr;
80-
8166
// Destroy ImGui context
8267
if (context) {
8368
ImGui::DestroyContext(context);
@@ -612,11 +597,13 @@ bool ImGuiSystem::createPipeline() {
612597
dynamicState.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size());
613598
dynamicState.pDynamicStates = dynamicStates.data();
614599

600+
vk::Format depthFormat = renderer->findDepthFormat();
615601
// Create the graphics pipeline with dynamic rendering
616602
vk::PipelineRenderingCreateInfo renderingInfo;
617603
renderingInfo.colorAttachmentCount = 1;
618604
vk::Format colorFormat = renderer->GetSwapChainImageFormat(); // Get the actual swapchain format
619605
renderingInfo.pColorAttachmentFormats = &colorFormat;
606+
renderingInfo.depthAttachmentFormat = depthFormat;
620607

621608
vk::GraphicsPipelineCreateInfo pipelineInfo;
622609
pipelineInfo.stageCount = static_cast<uint32_t>(shaderStages.size());

attachments/simple_engine/renderer.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class Renderer {
215215
return swapChainImageFormat;
216216
}
217217

218+
/**
219+
* @brief Set the framebuffer resized flag.
220+
* This should be called when the window is resized to trigger swap chain recreation.
221+
*/
222+
void SetFramebufferResized() {
223+
framebufferResized = true;
224+
}
225+
vk::Format findDepthFormat();
226+
218227
private:
219228
// Platform
220229
Platform* platform = nullptr;
@@ -415,7 +424,6 @@ class Renderer {
415424

416425
vk::raii::ImageView createImageView(vk::raii::Image& image, vk::Format format, vk::ImageAspectFlags aspectFlags);
417426
vk::Format findSupportedFormat(const std::vector<vk::Format>& candidates, vk::ImageTiling tiling, vk::FormatFeatureFlags features);
418-
vk::Format findDepthFormat();
419427
bool hasStencilComponent(vk::Format format);
420428

421429
std::vector<char> readFile(const std::string& filename);

attachments/simple_engine/renderer_core.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <iostream>
44
#include <set>
55
#include <cstring>
6+
#include <ranges>
67

78
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE; // In a .cpp file
89

@@ -173,6 +174,14 @@ void Renderer::Cleanup() {
173174

174175
// Wait for the device to be idle before cleaning up
175176
device.waitIdle();
177+
for (auto& resources : entityResources | std::views::values) {
178+
for (auto& memory : resources.uniformBuffersMemory) {
179+
memory.unmapMemory();
180+
}
181+
resources.descriptorSets.clear();
182+
resources.uniformBuffers.clear();
183+
resources.uniformBuffersMemory.clear();
184+
}
176185
std::cout << "Renderer cleanup completed." << std::endl;
177186
initialized = false;
178187
}

attachments/simple_engine/renderer_rendering.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "renderer.h"
22
#include "imgui_system.h"
3+
#include "imgui/imgui.h"
34
#include <fstream>
45
#include <stdexcept>
56
#include <array>
@@ -246,6 +247,23 @@ void Renderer::cleanupSwapChain() {
246247
// Clean up swap chain image views
247248
swapChainImageViews.clear();
248249

250+
// Clean up descriptor pool (this will automatically clean up descriptor sets)
251+
descriptorPool = nullptr;
252+
253+
// Clean up pipelines
254+
graphicsPipeline = nullptr;
255+
pbrGraphicsPipeline = nullptr;
256+
lightingPipeline = nullptr;
257+
258+
// Clean up pipeline layouts
259+
pipelineLayout = nullptr;
260+
pbrPipelineLayout = nullptr;
261+
lightingPipelineLayout = nullptr;
262+
263+
// Clean up sync objects (they need to be recreated with new swap chain image count)
264+
imageAvailableSemaphores.clear();
265+
renderFinishedSemaphores.clear();
266+
249267
// Clean up swap chain
250268
swapChain = nullptr;
251269
}
@@ -258,10 +276,15 @@ void Renderer::recreateSwapChain() {
258276
// Clean up old swap chain resources
259277
cleanupSwapChain();
260278

261-
// Recreate swap chain
279+
// Recreate swap chain and related resources
262280
createSwapChain();
263281
createImageViews();
264282
createDepthResources();
283+
284+
// Recreate sync objects with correct sizing for new swap chain
285+
createSyncObjects();
286+
287+
// Recreate descriptor pool and pipelines
265288
createDescriptorPool();
266289
createGraphicsPipeline();
267290
createPBRPipeline();
@@ -314,6 +337,12 @@ void Renderer::Render(const std::vector<Entity*>& entities, CameraComponent* cam
314337
// Check if the swap chain needs to be recreated
315338
if (result.first == vk::Result::eErrorOutOfDateKHR || result.first == vk::Result::eSuboptimalKHR || framebufferResized) {
316339
framebufferResized = false;
340+
341+
// If ImGui has started a frame, we need to end it properly before returning
342+
if (imguiSystem) {
343+
ImGui::EndFrame();
344+
}
345+
317346
recreateSwapChain();
318347
return;
319348
} else if (result.first != vk::Result::eSuccess) {

0 commit comments

Comments
 (0)