Disabled framebuffer caching by physical device
Swapchain is now capable of being recreated in a partially automatic manner (some effort is still required on the developer's side still) Windows are now allowed to be resizeable Updated main program to support resizable windows
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "vulkan/basalt_command_buffer.h"
|
||||
#include "vulkan/basalt_swapchain.h"
|
||||
|
||||
void framebuffer_resized(GLFWwindow* window, int width, int height);
|
||||
|
||||
void application()
|
||||
{
|
||||
basalt::Context ctx("Basic",
|
||||
@@ -11,7 +13,10 @@ void application()
|
||||
VK_EXT_DEBUG_UTILS_EXTENSION_NAME
|
||||
}, MEMORY_TAG_CLASS_ARRAY | MEMORY_TAG_ZONE_APPLICATION | MEMORY_TAG_ALIGN_ANY)
|
||||
);
|
||||
basalt::Window window(ctx, 640, 480, "Hello Vulkan!");;
|
||||
basalt::Window window(ctx, 640, 480, "Hello Vulkan!");
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_resized);
|
||||
glfwSetWindowUserPointer(window, nullptr);
|
||||
|
||||
basalt::PhysicalDevice phy_dev = basalt::PhysicalDeviceSelector(ctx, window)
|
||||
.prefer_types(VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, 2.0f, 0.0f)
|
||||
.prefer_types(VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, 1.0f, 0.0f)
|
||||
@@ -32,6 +37,8 @@ void application()
|
||||
{ {VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR} },
|
||||
{ VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_FIFO_KHR }
|
||||
);
|
||||
glfwSetWindowUserPointer(window, &swapchain);
|
||||
|
||||
basalt::RenderPass pass = basalt::RenderPassBuilder(dev)
|
||||
.add_attachment({
|
||||
.format = swapchain.details.cached_format.format,
|
||||
@@ -104,9 +111,14 @@ void application()
|
||||
while (!window.should_close())
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
swapchain.wait_and_reset();
|
||||
u32 image_index = swapchain.acquire_next_image();
|
||||
|
||||
u32 image_index = swapchain.wait_acquire_reset();
|
||||
if (image_index == -1 || !swapchain.framebuffers_created)
|
||||
{
|
||||
swapchain.create_framebuffers(pass.render_pass);
|
||||
swapchain.current_frame = (swapchain.current_frame + 1) % swapchain.max_frames_in_flight;
|
||||
continue;
|
||||
}
|
||||
|
||||
cmdbufs[swapchain.current_frame].reset();
|
||||
cmdbufs[swapchain.current_frame].start(pass, swapchain.framebuffers[image_index], render_area);
|
||||
@@ -138,10 +150,17 @@ void application()
|
||||
present_info.pSwapchains = &swapchain.swapchain;
|
||||
present_info.pImageIndices = &image_index;
|
||||
|
||||
VK_ASSERT(vkQueuePresentKHR(dev.queues[1].queue, &present_info), "Failed to queue presentation of rendered frame\n\tAt %s:%d\n\tError %s\n");
|
||||
VkResult err = vkQueuePresentKHR(dev.queues[1].queue, &present_info);
|
||||
if (err == VK_ERROR_OUT_OF_DATE_KHR)
|
||||
{
|
||||
swapchain.framebuffers_created = false;
|
||||
swapchain.current_frame = (swapchain.current_frame + 1) % swapchain.max_frames_in_flight;
|
||||
continue;
|
||||
}
|
||||
|
||||
VK_ASSERT(err, "Failed to queue presentation of rendered frame\n\tAt %s:%d\n\tError %s\n");
|
||||
swapchain.current_frame = (swapchain.current_frame + 1) % swapchain.max_frames_in_flight;
|
||||
}
|
||||
cmdbufs.resize(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -165,4 +184,11 @@ int main()
|
||||
terminate_logger();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void framebuffer_resized(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
basalt::Swapchain* swapchain = (basalt::Swapchain*)glfwGetWindowUserPointer(window);
|
||||
if (swapchain == nullptr)
|
||||
return;
|
||||
swapchain->framebuffers_created = false;
|
||||
}
|
||||
Reference in New Issue
Block a user