From 91010a448e8da5fa285e9be652132ece61a51b5d Mon Sep 17 00:00:00 2001 From: Anish Bhobe Date: Sun, 2 Feb 2025 17:51:36 +0100 Subject: [PATCH] Update triangle and box examples to separate swapchain. --- samples/01_triangle/triangle.cpp | 11 ++++++----- samples/02_box/box.cpp | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/samples/01_triangle/triangle.cpp b/samples/01_triangle/triangle.cpp index 980a5e5..e921e65 100644 --- a/samples/01_triangle/triangle.cpp +++ b/samples/01_triangle/triangle.cpp @@ -75,9 +75,10 @@ main(int, char **) MIN_LOG_LEVEL(Logger::LogType::eInfo); Context context = {"Triangle", VERSION}; - Window window = {"Triangle (Aster)", &context, {640, 480}}; + Window window = {"Triangle (Aster)", {640, 480}}; + Surface surface = {&context, &window, "Primary"}; - PhysicalDevices physicalDevices = {&window, &context}; + PhysicalDevices physicalDevices = {&surface, &context}; PhysicalDevice deviceToUse = FindSuitableDevice(physicalDevices); INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data()); @@ -86,7 +87,7 @@ main(int, char **) QueueAllocation queueAllocation = FindAppropriateQueueAllocation(&deviceToUse); Device device = {&context, &deviceToUse, &enabledDeviceFeatures, {queueAllocation}, "Primary Device"}; vk::Queue commandQueue = device.GetQueue(queueAllocation.m_Family, 0); - Swapchain swapchain = {&window, &device, "Primary Chain"}; + Swapchain swapchain = {&surface, &device, window.GetSize(), "Primary Chain"}; Pipeline pipeline = CreatePipeline(&device, &swapchain); vk::CommandPool copyPool; @@ -217,7 +218,7 @@ main(int, char **) case vk::Result::eErrorOutOfDateKHR: case vk::Result::eSuboptimalKHR: INFO("Recreating Swapchain. Cause: {}", result); - swapchain.Create(&window); + swapchain.Create(&surface, window.GetSize()); viewport.y = Cast(swapchain.m_Extent.height); viewport.width = Cast(swapchain.m_Extent.width); viewport.height = -Cast(swapchain.m_Extent.height); @@ -317,7 +318,7 @@ main(int, char **) case vk::Result::eErrorOutOfDateKHR: case vk::Result::eSuboptimalKHR: INFO("Recreating Swapchain. Cause: {}", result); - swapchain.Create(&window); + swapchain.Create(&surface, window.GetSize()); viewport.y = Cast(swapchain.m_Extent.height); viewport.width = Cast(swapchain.m_Extent.width); viewport.height = -Cast(swapchain.m_Extent.height); diff --git a/samples/02_box/box.cpp b/samples/02_box/box.cpp index 93e1d1e..6442ff6 100644 --- a/samples/02_box/box.cpp +++ b/samples/02_box/box.cpp @@ -116,9 +116,10 @@ main(int, char **) MIN_LOG_LEVEL(Logger::LogType::eInfo); Context context = {"Box", VERSION}; - Window window = {"Box (Aster)", &context, {640, 480}}; + Window window = {"Box (Aster)", {640, 480}}; + Surface surface = {&context, &window, "Primary"}; - PhysicalDevices physicalDevices = {&window, &context}; + PhysicalDevices physicalDevices = {&surface, &context}; PhysicalDevice deviceToUse = FindSuitableDevice(physicalDevices); INFO("Using {} as the primary device.", deviceToUse.m_DeviceProperties.deviceName.data()); @@ -130,7 +131,7 @@ main(int, char **) QueueAllocation queueAllocation = FindAppropriateQueueAllocation(&deviceToUse); Device device = {&context, &deviceToUse, &enabledDeviceFeatures, {queueAllocation}, "Primary Device"}; vk::Queue commandQueue = device.GetQueue(queueAllocation.m_Family, 0); - Swapchain swapchain = {&window, &device, "Primary Chain"}; + Swapchain swapchain = {&surface, &device, window.GetSize(), "Primary Chain"}; Pipeline pipeline = CreatePipeline(&device, &swapchain); Camera camera = { @@ -453,7 +454,7 @@ main(int, char **) camera.m_Model *= rotate(mat4{1.0f}, Cast(45.0_deg * Time::m_Delta), vec3(0.0f, 1.0f, 0.0f)); ubo.Write(&device, 0, sizeof camera, &camera); - Frame *currentFrame = frameManager.GetNextFrame(&swapchain, &window); + Frame *currentFrame = frameManager.GetNextFrame(&swapchain, &surface, window.GetSize()); u32 imageIndex = currentFrame->m_ImageIdx; vk::ImageView currentImageView = swapchain.m_ImageViews[imageIndex]; @@ -528,7 +529,7 @@ main(int, char **) }; AbortIfFailed(commandQueue.submit(1, &submitInfo, currentFrame->m_FrameAvailableFence)); - currentFrame->Present(commandQueue, &swapchain, TODO, TODO); + currentFrame->Present(commandQueue, &swapchain, &surface, window.GetSize()); } device.WaitIdle();