Update triangle and box examples to separate swapchain.

This commit is contained in:
Anish Bhobe 2025-02-02 17:51:36 +01:00
parent 0462dc33f0
commit 91010a448e
2 changed files with 12 additions and 10 deletions

View File

@ -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<f32>(swapchain.m_Extent.height);
viewport.width = Cast<f32>(swapchain.m_Extent.width);
viewport.height = -Cast<f32>(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<f32>(swapchain.m_Extent.height);
viewport.width = Cast<f32>(swapchain.m_Extent.width);
viewport.height = -Cast<f32>(swapchain.m_Extent.height);

View File

@ -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<f32>(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();