From 2ac1d818e16164d707b018500cdfad2ef8726c29 Mon Sep 17 00:00:00 2001 From: Hjalte Sorgenfrei Mac Dalland Date: Wed, 12 Oct 2022 14:35:11 +0200 Subject: [PATCH] Stop recreating swapchain twice, remove unused field --- README.md | 7 +++++++ src/Application.cpp | 6 ------ src/Renderer.cpp | 8 -------- src/Renderer.h | 3 --- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ccbc600..3bf2afc 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,13 @@ Some ideas were also taken from [Zeux's blog](https://zeux.io/2020/02/27/writing - [ ] Create handles for materials and uploaded models, currently its just returned as an object. - The handles could be `uint64_t`. - This would also remove the shared ptr, which is weird to use anyway as the lifetime of the object is more than the data. +- [ ] Smooth resize + - [ ] Use old_swapchain when creating a new swapchain + - [ ] Never resize in the drawing thread, only call resize in the OS 'resize callback/event' + - [ ] In the OS 'resize callback/even', repaint the scene. + - [ ] Never delete resources (images, views, framebuffers) in the resize. Instead put it in a delayed-deletion-queue. This will delete it when its no longer being used in a couple of frames + - [x] Use dynamic viewport/scissor, use imageless framebuffer, and re-record command buffers every frame + - [ ] If the items in 4 and 5 are implemented, the resize function will not need to call vkDeviceWaitIdle() ### Descriptor Layout Idea diff --git a/src/Application.cpp b/src/Application.cpp index 50e2190..47c63f9 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -23,18 +23,12 @@ void App::run() { void App::setupCallBacks() { glfwSetWindowUserPointer(window->getGLFWwindow(), this); - glfwSetFramebufferSizeCallback(window->getGLFWwindow(), framebufferResizeCallback); glfwSetCursorPosCallback(window->getGLFWwindow(), cursorPosCallback); glfwSetCursorEnterCallback(window->getGLFWwindow(), cursorEnterCallback); glfwSetMouseButtonCallback(window->getGLFWwindow(), mouseButtonCallback); glfwSetKeyCallback(window->getGLFWwindow(), keyCallback); } -void App::framebufferResizeCallback(GLFWwindow* window, int width, int height) { - auto* const app = static_cast(glfwGetWindowUserPointer(window)); - app->renderer->frameBufferResized(); -} - void App::cursorPosCallback(GLFWwindow* window, double xPosIn, double yPosIn) { auto* const app = static_cast(glfwGetWindowUserPointer(window)); if (app->mouseCaptured) { diff --git a/src/Renderer.cpp b/src/Renderer.cpp index cc9b1fd..20371d8 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -60,10 +60,6 @@ Renderer::~Renderer() { cleanup(); } -void Renderer::frameBufferResized() { - frameBufferResizePending = true; -} - Material Renderer::createMaterial(std::vector& texturePaths) { std::vector> textures; std::map> uploadedTextures; @@ -1047,10 +1043,6 @@ void Renderer::drawFrame(FrameInfo& frameInfo) { try { switch (device->presentQueue().presentKHR(presentInfo)) { case vk::Result::eSuccess: - if (frameBufferResizePending) { - recreateSwapchain(); - frameBufferResizePending = false; - } break; case vk::Result::eSuboptimalKHR: case vk::Result::eErrorOutOfDateKHR: // What we would like to do :) But it's actually an exception diff --git a/src/Renderer.h b/src/Renderer.h index 417fe23..20c48e3 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -38,7 +38,6 @@ class Renderer { void drawFrame(FrameInfo& frameInfo); void uploadMeshes(const std::vector>& objects); - void frameBufferResized(); Material createMaterial(std::vector& texturePaths); RendererMode rendererMode = RendererMode::NORMAL; @@ -97,8 +96,6 @@ class Renderer { size_t currentFrame = 0; - bool frameBufferResizePending = false; - void initImgui(); void createSwapChain();