Skip to content

Commit

Permalink
Stop recreating swapchain twice, remove unused field
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjaltesorgenfrei committed Oct 12, 2022
1 parent 57280ae commit 2ac1d81
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<App*>(glfwGetWindowUserPointer(window));
app->renderer->frameBufferResized();
}

void App::cursorPosCallback(GLFWwindow* window, double xPosIn, double yPosIn) {
auto* const app = static_cast<App*>(glfwGetWindowUserPointer(window));
if (app->mouseCaptured) {
Expand Down
8 changes: 0 additions & 8 deletions src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ Renderer::~Renderer() {
cleanup();
}

void Renderer::frameBufferResized() {
frameBufferResizePending = true;
}

Material Renderer::createMaterial(std::vector<std::string>& texturePaths) {
std::vector<std::shared_ptr<UploadedTexture>> textures;
std::map<std::string, std::shared_ptr<UploadedTexture>> uploadedTextures;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Renderer {

void drawFrame(FrameInfo& frameInfo);
void uploadMeshes(const std::vector<std::shared_ptr<RenderObject>>& objects);
void frameBufferResized();
Material createMaterial(std::vector<std::string>& texturePaths);
RendererMode rendererMode = RendererMode::NORMAL;

Expand Down Expand Up @@ -97,8 +96,6 @@ class Renderer {

size_t currentFrame = 0;

bool frameBufferResizePending = false;

void initImgui();

void createSwapChain();
Expand Down

0 comments on commit 2ac1d81

Please sign in to comment.