From 99590da1f874196b42d4f4b976b554705ed13411 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Mon, 11 Dec 2023 19:32:28 +0100 Subject: [PATCH] Feat: Vulkan framebuffer resize --- src/atta/graphics/apis/openGL/pipeline.cpp | 2 + src/atta/graphics/apis/openGL/pipeline.h | 2 + src/atta/graphics/apis/vulkan/framebuffer.cpp | 39 ++++--- src/atta/graphics/apis/vulkan/image.cpp | 8 +- src/atta/graphics/apis/vulkan/image.h | 2 +- src/atta/graphics/apis/vulkan/pipeline.cpp | 12 +- src/atta/graphics/apis/vulkan/pipeline.h | 2 + src/atta/graphics/apis/vulkan/renderPass.cpp | 18 +-- src/atta/graphics/apis/vulkan/renderQueue.cpp | 10 +- src/atta/graphics/cameras/camera.cpp | 108 +++++++++--------- src/atta/graphics/pipeline.h | 2 + src/atta/graphics/renderers/fastRenderer.cpp | 28 +++-- src/atta/graphics/renderers/fastRenderer.h | 1 + src/atta/graphics/renderers/pbrRenderer.cpp | 2 +- src/atta/graphics/renderers/phongRenderer.cpp | 2 +- .../ui/editor/windows/viewportWindows.cpp | 12 +- src/atta/ui/manager.cpp | 9 +- src/extern/solveImgui.cmake | 5 +- src/extern/solveImguizmo.cmake | 2 +- src/extern/solveImplot.cmake | 2 +- 20 files changed, 148 insertions(+), 120 deletions(-) diff --git a/src/atta/graphics/apis/openGL/pipeline.cpp b/src/atta/graphics/apis/openGL/pipeline.cpp index 7fd4a76f..7972ec13 100644 --- a/src/atta/graphics/apis/openGL/pipeline.cpp +++ b/src/atta/graphics/apis/openGL/pipeline.cpp @@ -20,6 +20,8 @@ void Pipeline::begin(std::shared_ptr renderQueue) { _shader->bind() void Pipeline::end() { _shader->unbind(); } +void Pipeline::resize(uint32_t width, uint32_t height) { _renderPass->getFramebuffer()->resize(width, height); } + void* Pipeline::getImGuiTexture() const { return reinterpret_cast(std::static_pointer_cast(_renderPass->getFramebuffer()->getImage(0))->getImGuiImage()); } diff --git a/src/atta/graphics/apis/openGL/pipeline.h b/src/atta/graphics/apis/openGL/pipeline.h index 636cc12b..69587d4d 100644 --- a/src/atta/graphics/apis/openGL/pipeline.h +++ b/src/atta/graphics/apis/openGL/pipeline.h @@ -20,6 +20,8 @@ class Pipeline final : public gfx::Pipeline { void begin(std::shared_ptr renderQueue) override; void end() override; + void resize(uint32_t width, uint32_t height) override; + void* getImGuiTexture() const override; }; diff --git a/src/atta/graphics/apis/vulkan/framebuffer.cpp b/src/atta/graphics/apis/vulkan/framebuffer.cpp index 22619719..71b71eaa 100644 --- a/src/atta/graphics/apis/vulkan/framebuffer.cpp +++ b/src/atta/graphics/apis/vulkan/framebuffer.cpp @@ -10,6 +10,25 @@ namespace atta::graphics::vk { Framebuffer::Framebuffer(const gfx::Framebuffer::CreateInfo& info) : gfx::Framebuffer(info), _framebuffer(VK_NULL_HANDLE), _device(common::getDevice()) { + resize(_width, _height); +} + +Framebuffer::~Framebuffer() { + if (_framebuffer != VK_NULL_HANDLE) + vkDestroyFramebuffer(_device->getHandle(), _framebuffer, nullptr); +} + +void Framebuffer::bind(bool clear) { + if (_framebuffer == VK_NULL_HANDLE) { + LOG_WARN("gfx::vk::Framebuffer", "Trying to bind framebuffer [w]$0[] that was never created", _debugName); + } +} +void Framebuffer::unbind() {} + +void Framebuffer::resize(uint32_t width, uint32_t height, bool forceRecreate) { + _width = width; + _height = height; + // Create attachment images _images.clear(); for (unsigned i = 0; i < _attachments.size(); i++) { @@ -29,20 +48,6 @@ Framebuffer::Framebuffer(const gfx::Framebuffer::CreateInfo& info) } } -Framebuffer::~Framebuffer() { - if (_framebuffer != VK_NULL_HANDLE) - vkDestroyFramebuffer(_device->getHandle(), _framebuffer, nullptr); -} - -void Framebuffer::bind(bool clear) { - if (_framebuffer == VK_NULL_HANDLE) { - LOG_WARN("gfx::vk::Framebuffer", "Trying to bind framebuffer [w]$0[] that was never created", _debugName); - } -} -void Framebuffer::unbind() {} - -void Framebuffer::resize(uint32_t width, uint32_t height, bool forceRecreate) {} - int Framebuffer::readPixel(unsigned attachmentIndex, unsigned x, unsigned y) {} std::vector Framebuffer::readImage(unsigned attachmentIndex) {} @@ -53,6 +58,10 @@ std::shared_ptr Framebuffer::getRenderPass() const { return _renderP void Framebuffer::create(std::shared_ptr renderPass) { _renderPass = renderPass; + // Destroy framebuffer is necessary + if (_framebuffer != VK_NULL_HANDLE) + vkDestroyFramebuffer(_device->getHandle(), _framebuffer, nullptr); + // Get image views std::vector attachments; for (std::shared_ptr image : _images) @@ -69,7 +78,7 @@ void Framebuffer::create(std::shared_ptr renderPass) { framebufferInfo.layers = 1; if (vkCreateFramebuffer(_device->getHandle(), &framebufferInfo, nullptr, &_framebuffer) != VK_SUCCESS) - LOG_ERROR("gfx::vk::FrameBuffer", "Failed to create frame buffer!"); + LOG_ERROR("gfx::vk::Framebuffer", "Failed to create frame buffer!"); } } // namespace atta::graphics::vk diff --git a/src/atta/graphics/apis/vulkan/image.cpp b/src/atta/graphics/apis/vulkan/image.cpp index aee18d52..c28ce7ef 100644 --- a/src/atta/graphics/apis/vulkan/image.cpp +++ b/src/atta/graphics/apis/vulkan/image.cpp @@ -17,14 +17,14 @@ namespace atta::graphics::vk { Image::Image(const gfx::Image::CreateInfo& info) : gfx::Image(info), _image(VK_NULL_HANDLE), _imageView(VK_NULL_HANDLE), _sampler(VK_NULL_HANDLE), _memory(VK_NULL_HANDLE), - _device(common::getDevice()), _destroyImage(true) { + _imGuiDescriptorSet(VK_NULL_HANDLE), _device(common::getDevice()), _destroyImage(true) { _format = supportedFormat(_format); resize(_width, _height, true); } Image::Image(const gfx::Image::CreateInfo& info, std::shared_ptr device, VkImage image) - : gfx::Image(info), _image(image), _imageView(VK_NULL_HANDLE), _sampler(VK_NULL_HANDLE), _memory(VK_NULL_HANDLE), _device(device), - _destroyImage(false) { + : gfx::Image(info), _image(image), _imageView(VK_NULL_HANDLE), _sampler(VK_NULL_HANDLE), _memory(VK_NULL_HANDLE), + _imGuiDescriptorSet(VK_NULL_HANDLE), _device(device), _destroyImage(false) { _format = supportedFormat(_format); createImageView(); } @@ -277,6 +277,8 @@ void Image::allocMemory() { } void Image::destroy() { + if (_imGuiDescriptorSet != VK_NULL_HANDLE) + ImGui_ImplVulkan_RemoveTexture(_imGuiDescriptorSet); if (_imageView != VK_NULL_HANDLE) vkDestroyImageView(_device->getHandle(), _imageView, nullptr); if (_sampler != VK_NULL_HANDLE) diff --git a/src/atta/graphics/apis/vulkan/image.h b/src/atta/graphics/apis/vulkan/image.h index c4ee319e..34508c71 100644 --- a/src/atta/graphics/apis/vulkan/image.h +++ b/src/atta/graphics/apis/vulkan/image.h @@ -75,9 +75,9 @@ class Image final : public gfx::Image { VkImage _image; VkImageView _imageView; VkSampler _sampler; - VkDescriptorSet _imGuiDescriptorSet; // Used to display images in ImGui; VkDeviceMemory _memory; VkImageLayout _layout; + VkDescriptorSet _imGuiDescriptorSet; // Used to display images in ImGui; std::shared_ptr _device; bool _destroyImage; diff --git a/src/atta/graphics/apis/vulkan/pipeline.cpp b/src/atta/graphics/apis/vulkan/pipeline.cpp index 6efd512e..2f67e20d 100644 --- a/src/atta/graphics/apis/vulkan/pipeline.cpp +++ b/src/atta/graphics/apis/vulkan/pipeline.cpp @@ -149,6 +149,7 @@ Pipeline::Pipeline(const gfx::Pipeline::CreateInfo& info) : gfx::Pipeline(info), if (vkCreateGraphicsPipelines(_device->getHandle(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_pipeline) != VK_SUCCESS) LOG_ERROR("gfx::vk::Pipeline", "Failed to create pipeline!"); + LOG_DEBUG("Pipeline", "Pipeline created!"); } Pipeline::~Pipeline() { @@ -174,8 +175,8 @@ void Pipeline::begin(std::shared_ptr renderQueue) { VkViewport viewport{}; viewport.x = 0.0f; viewport.y = 0.0f; - viewport.width = _renderPass->getFramebuffer()->getWidth(); - viewport.height = _renderPass->getFramebuffer()->getHeight(); + viewport.width = _framebuffers[0]->getWidth(); + viewport.height = _framebuffers[0]->getHeight(); viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; vkCmdSetViewport(commandBuffer, 0, 1, &viewport); @@ -192,6 +193,11 @@ void Pipeline::end() { _shader->unbind(); } +void Pipeline::resize(uint32_t width, uint32_t height) { + _framebuffers[0]->resize(width, height); + _framebuffers[0]->create(std::dynamic_pointer_cast(_renderPass)); +} + void Pipeline::renderMesh(StringId meshSid) { std::shared_ptr mesh = std::dynamic_pointer_cast(Manager::getInstance().getMeshes().at(meshSid)); if (mesh) { @@ -208,7 +214,7 @@ void Pipeline::renderMesh(StringId meshSid) { } void* Pipeline::getImGuiTexture() const { - return reinterpret_cast(std::static_pointer_cast(_renderPass->getFramebuffer()->getImage(0))->getImGuiImage()); + return reinterpret_cast(std::static_pointer_cast(_framebuffers[0]->getImage(0))->getImGuiImage()); } VkPipeline Pipeline::getHandle() const { return _pipeline; } diff --git a/src/atta/graphics/apis/vulkan/pipeline.h b/src/atta/graphics/apis/vulkan/pipeline.h index c56f26af..97f86fcc 100644 --- a/src/atta/graphics/apis/vulkan/pipeline.h +++ b/src/atta/graphics/apis/vulkan/pipeline.h @@ -29,6 +29,8 @@ class Pipeline final : public gfx::Pipeline { void begin(std::shared_ptr renderQueue) override; void end() override; + void resize(uint32_t width, uint32_t height) override; + void renderMesh(StringId meshSid) override; void* getImGuiTexture() const override; diff --git a/src/atta/graphics/apis/vulkan/renderPass.cpp b/src/atta/graphics/apis/vulkan/renderPass.cpp index 31be627c..06a83371 100644 --- a/src/atta/graphics/apis/vulkan/renderPass.cpp +++ b/src/atta/graphics/apis/vulkan/renderPass.cpp @@ -104,12 +104,12 @@ void RenderPass::end() { } void RenderPass::begin(VkCommandBuffer commandBuffer) { - VkRenderPassBeginInfo renderPassInfo{}; - renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - renderPassInfo.renderPass = _renderPass; - renderPassInfo.framebuffer = std::dynamic_pointer_cast(_framebuffer)->getHandle(); - renderPassInfo.renderArea.offset = {0, 0}; - renderPassInfo.renderArea.extent = {_framebuffer->getWidth(), _framebuffer->getHeight()}; + VkRenderPassBeginInfo renderPassBeginInfo{}; + renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + renderPassBeginInfo.renderPass = _renderPass; + renderPassBeginInfo.framebuffer = std::dynamic_pointer_cast(_framebuffer)->getHandle(); + renderPassBeginInfo.renderArea.offset = {0, 0}; + renderPassBeginInfo.renderArea.extent = {_framebuffer->getWidth(), _framebuffer->getHeight()}; // LOG_DEBUG("RenderPass", "Frame buf is $2 -> $0 $1", _framebuffer->getWidth(), _framebuffer->getHeight(), _framebuffer->getDebugName()); std::vector clearValues{}; @@ -124,10 +124,10 @@ void RenderPass::begin(VkCommandBuffer commandBuffer) { clearValues.push_back(clearDepth); } } - renderPassInfo.clearValueCount = clearValues.size(); - renderPassInfo.pClearValues = clearValues.data(); + renderPassBeginInfo.clearValueCount = clearValues.size(); + renderPassBeginInfo.pClearValues = clearValues.data(); - vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); + vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); } void RenderPass::end(VkCommandBuffer commandBuffer) { vkCmdEndRenderPass(commandBuffer); } diff --git a/src/atta/graphics/apis/vulkan/renderQueue.cpp b/src/atta/graphics/apis/vulkan/renderQueue.cpp index f98050c1..4610a84c 100644 --- a/src/atta/graphics/apis/vulkan/renderQueue.cpp +++ b/src/atta/graphics/apis/vulkan/renderQueue.cpp @@ -23,11 +23,7 @@ RenderQueue::~RenderQueue() { _commandPool.reset(); } -void RenderQueue::begin() { - _fence->wait(); - _fence->reset(); - _commandBuffers->begin(0); -} +void RenderQueue::begin() { _commandBuffers->begin(0); } void RenderQueue::end() { _commandBuffers->end(0); @@ -39,6 +35,10 @@ void RenderQueue::end() { submitInfo.pCommandBuffers = &cmdBuf; if (vkQueueSubmit(_device->getGraphicsQueue(), 1, &submitInfo, _fence->getHandle()) != VK_SUCCESS) LOG_ERROR("gfx::vk::RenderQueue", "Failed to submit render queue!"); + + // Wait commands to complete + _fence->wait(); + _fence->reset(); } VkCommandBuffer RenderQueue::getCommandBuffer() { return _commandBuffers->getHandles()[0]; } diff --git a/src/atta/graphics/cameras/camera.cpp b/src/atta/graphics/cameras/camera.cpp index 6b7a27a4..935751a0 100644 --- a/src/atta/graphics/cameras/camera.cpp +++ b/src/atta/graphics/cameras/camera.cpp @@ -20,19 +20,19 @@ void Camera::update() { void Camera::move() { switch (_control) { - case Control::PLANAR: - movePlanar(); - break; - case Control::FIRST_PERSON: - moveFirstPerson(); - break; - default: - break; + case Control::PLANAR: + movePlanar(); + break; + case Control::FIRST_PERSON: + moveFirstPerson(); + break; + default: + break; } } void Camera::movePlanar() { - if (!ImGui::IsMouseDown(2)) // Move only if middle button is pressed + if (!ImGui::IsMouseDown(ImGuiMouseButton_Middle)) // Move only if middle button is pressed return; ImGuiIO& io = ImGui::GetIO(); @@ -44,7 +44,7 @@ void Camera::movePlanar() { } void Camera::moveFirstPerson() { - if (!ImGui::IsMouseDown(2)) // Move only if middle button is pressed + if (!ImGui::IsMouseDown(ImGuiMouseButton_Middle)) // Move only if middle button is pressed return; static float lastTimeFront = 0; @@ -63,71 +63,71 @@ void Camera::moveFirstPerson() { _up = vec3(0, 0, 1); // Move front/back - if (ImGui::IsKeyDown('W') || ImGui::IsKeyDown('S')) { + if (ImGui::IsKeyDown(ImGuiKey_W) || ImGui::IsKeyDown(ImGuiKey_S)) { int key = 0; - if (ImGui::GetKeyData('W')->DownDuration > 0 && ImGui::GetKeyData('S')->DownDuration > 0) - if (ImGui::GetKeyData('W')->DownDuration < ImGui::GetKeyData('S')->DownDuration) - key = 'W'; + if (io.KeysData[ImGuiKey_W].DownDuration > 0 && io.KeysData[ImGuiKey_S].DownDuration > 0) + if (io.KeysData[ImGuiKey_W].DownDuration < io.KeysData[ImGuiKey_S].DownDuration) + key = ImGuiKey_W; else - key = 'S'; - else if (ImGui::GetKeyData('W')->DownDuration > 0) - key = 'W'; - else if (ImGui::GetKeyData('S')->DownDuration > 0) - key = 'S'; + key = ImGuiKey_S; + else if (io.KeysData[ImGuiKey_W].DownDuration > 0) + key = ImGuiKey_W; + else if (io.KeysData[ImGuiKey_S].DownDuration > 0) + key = ImGuiKey_S; if (key) { - if (ImGui::GetKeyData(key)->DownDuration < lastTimeFront) + if (io.KeysData[key].DownDuration < lastTimeFront) lastTimeFront = 0; - float delta = (ImGui::GetKeyData(key)->DownDuration - lastTimeFront) * (key == 'W' ? 1 : -1) * _speed; - lastTimeFront = ImGui::GetKeyData(key)->DownDuration; + float delta = (io.KeysData[key].DownDuration - lastTimeFront) * (key == ImGuiKey_W ? 1 : -1) * _speed; + lastTimeFront = io.KeysData[key].DownDuration; _position += _front * delta; } } // Move left/right - if (ImGui::IsKeyDown('A') || ImGui::IsKeyDown('D')) { + if (ImGui::IsKeyDown(ImGuiKey_A) || ImGui::IsKeyDown(ImGuiKey_D)) { int key = 0; - if (ImGui::GetKeyData('A')->DownDuration > 0 && ImGui::GetKeyData('D')->DownDuration > 0) - if (ImGui::GetKeyData('A')->DownDuration < ImGui::GetKeyData('D')->DownDuration) - key = 'A'; + if (io.KeysData[ImGuiKey_A].DownDuration > 0 && io.KeysData[ImGuiKey_D].DownDuration > 0) + if (io.KeysData[ImGuiKey_A].DownDuration < io.KeysData[ImGuiKey_D].DownDuration) + key = ImGuiKey_A; else - key = 'D'; - else if (ImGui::GetKeyData('A')->DownDuration > 0) - key = 'A'; - else if (ImGui::GetKeyData('D')->DownDuration > 0) - key = 'D'; + key = ImGuiKey_D; + else if (io.KeysData[ImGuiKey_A].DownDuration > 0) + key = ImGuiKey_A; + else if (io.KeysData[ImGuiKey_D].DownDuration > 0) + key = ImGuiKey_D; if (key) { - if (ImGui::GetKeyData(key)->DownDuration < lastTimeLeft) + if (io.KeysData[key].DownDuration < lastTimeLeft) lastTimeLeft = 0; - float delta = (ImGui::GetKeyData(key)->DownDuration - lastTimeLeft) * (key == 'A' ? 1 : -1) * _speed; - lastTimeLeft = ImGui::GetKeyData(key)->DownDuration; + float delta = (io.KeysData[key].DownDuration - lastTimeLeft) * (key == ImGuiKey_A ? 1 : -1) * _speed; + lastTimeLeft = io.KeysData[key].DownDuration; _position += _left * delta; } } // Move up/down - if (ImGui::IsKeyDown('E') || ImGui::IsKeyDown('Q')) { + if (ImGui::IsKeyDown(ImGuiKey_E) || ImGui::IsKeyDown(ImGuiKey_Q)) { int key = 0; - if (ImGui::GetKeyData('E')->DownDuration > 0 && ImGui::GetKeyData('Q')->DownDuration > 0) - if (ImGui::GetKeyData('E')->DownDuration < ImGui::GetKeyData('Q')->DownDuration) - key = 'E'; + if (io.KeysData[ImGuiKey_E].DownDuration > 0 && io.KeysData[ImGuiKey_Q].DownDuration > 0) + if (io.KeysData[ImGuiKey_E].DownDuration < io.KeysData[ImGuiKey_Q].DownDuration) + key = ImGuiKey_E; else - key = 'Q'; - else if (ImGui::GetKeyData('E')->DownDuration > 0) - key = 'E'; - else if (ImGui::GetKeyData('Q')->DownDuration > 0) - key = 'Q'; + key = ImGuiKey_Q; + else if (io.KeysData[ImGuiKey_E].DownDuration > 0) + key = ImGuiKey_E; + else if (io.KeysData[ImGuiKey_Q].DownDuration > 0) + key = ImGuiKey_Q; if (key) { - if (ImGui::GetKeyData(key)->DownDuration < lastTimeUp) + if (io.KeysData[key].DownDuration < lastTimeUp) lastTimeUp = 0; - float delta = (ImGui::GetKeyData(key)->DownDuration - lastTimeUp) * (key == 'E' ? 1 : -1) * _speed; - lastTimeUp = ImGui::GetKeyData(key)->DownDuration; + float delta = (io.KeysData[key].DownDuration - lastTimeUp) * (key == ImGuiKey_E ? 1 : -1) * _speed; + lastTimeUp = io.KeysData[key].DownDuration; _position += _up * delta; } } @@ -146,14 +146,14 @@ void Camera::renderUI() { for (size_t j = 0; j < controls.size(); j++) { if (ImGui::Selectable(controls[j], comboValue == j)) { switch (j) { - case 0: - if (comboValue != 0) - _control = Control::PLANAR; - break; - case 1: - if (comboValue != 1) - _control = Control::FIRST_PERSON; - break; + case 0: + if (comboValue != 0) + _control = Control::PLANAR; + break; + case 1: + if (comboValue != 1) + _control = Control::FIRST_PERSON; + break; } } if (comboValue == j) diff --git a/src/atta/graphics/pipeline.h b/src/atta/graphics/pipeline.h index 5bd72335..4929b058 100644 --- a/src/atta/graphics/pipeline.h +++ b/src/atta/graphics/pipeline.h @@ -35,6 +35,8 @@ class Pipeline { virtual void begin(std::shared_ptr renderQueue) = 0; virtual void end() = 0; + virtual void resize(uint32_t width, uint32_t height) = 0; + virtual void* getImGuiTexture() const = 0; void setBool(const char* name, bool b); diff --git a/src/atta/graphics/renderers/fastRenderer.cpp b/src/atta/graphics/renderers/fastRenderer.cpp index 438f52cc..c47fcfbe 100644 --- a/src/atta/graphics/renderers/fastRenderer.cpp +++ b/src/atta/graphics/renderers/fastRenderer.cpp @@ -21,8 +21,10 @@ namespace atta::graphics { -FastRenderer::FastRenderer() : Renderer("FastRenderer") { - //---------- Create geometry pipeline ----------// +FastRenderer::FastRenderer() : Renderer("FastRenderer"), _wasResized(false) { + // Render Queue + _renderQueue = graphics::create(); + // Framebuffer Framebuffer::CreateInfo framebufferInfo{}; framebufferInfo.attachments.push_back({Image::Format::RGBA}); @@ -33,22 +35,17 @@ FastRenderer::FastRenderer() : Renderer("FastRenderer") { framebufferInfo.debugName = StringId("FastRenderer Framebuffer"); std::shared_ptr framebuffer = graphics::create(framebufferInfo); - // Shader - std::shared_ptr shader = graphics::create("shaders/fastRenderer/fastRenderer.asl"); - - // Render Queue - _renderQueue = graphics::create(); - // Render Pass RenderPass::CreateInfo renderPassInfo{}; renderPassInfo.framebuffer = framebuffer; - renderPassInfo.debugName = StringId("FastRenderer Render Pass"); + renderPassInfo.debugName = StringId("FastRenderer RenderPass"); _renderPass = graphics::create(renderPassInfo); - // Pipeline + //---------- Create geometry pipeline ----------// Pipeline::CreateInfo pipelineInfo{}; - pipelineInfo.shader = shader; + pipelineInfo.shader = graphics::create("shaders/fastRenderer/fastRenderer.asl"); pipelineInfo.renderPass = _renderPass; + pipelineInfo.debugName = StringId("FastRenderer Pipeline"); _geometryPipeline = graphics::create(pipelineInfo); //---------- Common pipelines ----------// @@ -59,6 +56,13 @@ FastRenderer::FastRenderer() : Renderer("FastRenderer") { FastRenderer::~FastRenderer() {} void FastRenderer::render(std::shared_ptr camera) { + // Handle resize (ensure that last framebuffer command finished) + if (_wasResized) { + _geometryPipeline->resize(_width, _height); + _wasResized = false; + } + + // Render _renderQueue->begin(); { _renderPass->begin(_renderQueue); @@ -110,7 +114,7 @@ void FastRenderer::render(std::shared_ptr camera) { void FastRenderer::resize(uint32_t width, uint32_t height) { if (width != _width || height != _height) { - _geometryPipeline->getRenderPass()->getFramebuffer()->resize(width, height); + _wasResized = true; _width = width; _height = height; } diff --git a/src/atta/graphics/renderers/fastRenderer.h b/src/atta/graphics/renderers/fastRenderer.h index 8fc4aa5b..41ee6ae1 100644 --- a/src/atta/graphics/renderers/fastRenderer.h +++ b/src/atta/graphics/renderers/fastRenderer.h @@ -34,6 +34,7 @@ class FastRenderer final : public Renderer { std::shared_ptr _geometryPipeline; std::unique_ptr _selectedPipeline; std::unique_ptr _drawerPipeline; + bool _wasResized; }; } // namespace atta::graphics diff --git a/src/atta/graphics/renderers/pbrRenderer.cpp b/src/atta/graphics/renderers/pbrRenderer.cpp index 9ee6bbfd..eb3ea486 100644 --- a/src/atta/graphics/renderers/pbrRenderer.cpp +++ b/src/atta/graphics/renderers/pbrRenderer.cpp @@ -171,7 +171,7 @@ void PbrRenderer::render(std::shared_ptr camera) { void PbrRenderer::resize(uint32_t width, uint32_t height) { if (width != _width || height != _height) { - _geometryPipeline->getRenderPass()->getFramebuffer()->resize(width, height); + _geometryPipeline->resize(width, height); _width = width; _height = height; } diff --git a/src/atta/graphics/renderers/phongRenderer.cpp b/src/atta/graphics/renderers/phongRenderer.cpp index 07f5e597..b33cea24 100644 --- a/src/atta/graphics/renderers/phongRenderer.cpp +++ b/src/atta/graphics/renderers/phongRenderer.cpp @@ -161,7 +161,7 @@ void PhongRenderer::render(std::shared_ptr camera) { void PhongRenderer::resize(uint32_t width, uint32_t height) { if (width != _width || height != _height) { - _geometryPipeline->getRenderPass()->getFramebuffer()->resize(width, height); + _geometryPipeline->resize(width, height); _width = width; _height = height; } diff --git a/src/atta/ui/editor/windows/viewportWindows.cpp b/src/atta/ui/editor/windows/viewportWindows.cpp index 4c34f5f5..6de1eb0a 100644 --- a/src/atta/ui/editor/windows/viewportWindows.cpp +++ b/src/atta/ui/editor/windows/viewportWindows.cpp @@ -81,22 +81,22 @@ void ViewportWindows::render() { if (ImGui::IsWindowHovered()) { snap = false; ImGuiIO& io = ImGui::GetIO(); - if (ImGui::IsKeyPressed('T') && io.KeyCtrl) { + if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { mouseOperation = ImGuizmo::OPERATION::TRANSLATE; mouseMode = ImGuizmo::MODE::LOCAL; - } else if (ImGui::IsKeyPressed('T') && io.KeyShift) { + } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { mouseOperation = ImGuizmo::OPERATION::TRANSLATE; mouseMode = ImGuizmo::MODE::WORLD; - } else if (ImGui::IsKeyPressed('S') && io.KeyCtrl) { + } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { mouseOperation = ImGuizmo::OPERATION::SCALE; mouseMode = ImGuizmo::MODE::LOCAL; - } else if (ImGui::IsKeyPressed('S') && io.KeyShift) { + } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { mouseOperation = ImGuizmo::OPERATION::SCALE; mouseMode = ImGuizmo::MODE::WORLD; - } else if (ImGui::IsKeyPressed('R') && io.KeyCtrl) { + } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { mouseOperation = ImGuizmo::OPERATION::ROTATE; mouseMode = ImGuizmo::MODE::LOCAL; - } else if (ImGui::IsKeyPressed('R') && io.KeyShift) { + } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { mouseOperation = ImGuizmo::OPERATION::ROTATE; mouseMode = ImGuizmo::MODE::WORLD; } else if (io.KeyCtrl) diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 331e8516..76d2198b 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -129,13 +129,8 @@ void Manager::initVulkan() { ImGui_ImplVulkan_Init(&info, vulkanAPI->getRenderPass()->getHandle()); // Upload Fonts - { - std::shared_ptr commandPool = vulkanAPI->getCommandPool(); - VkCommandBuffer commandBuffer = commandPool->beginSingleTimeCommands(); - ImGui_ImplVulkan_CreateFontsTexture(commandBuffer); - commandPool->endSingleTimeCommands(commandBuffer); - } - ImGui_ImplVulkan_DestroyFontUploadObjects(); + if (!ImGui_ImplVulkan_CreateFontsTexture()) + LOG_WARN("ui::Manager", "Failed to created ImGui font texture"); } void Manager::render() { diff --git a/src/extern/solveImgui.cmake b/src/extern/solveImgui.cmake index 05470b1f..9bd9b147 100644 --- a/src/extern/solveImgui.cmake +++ b/src/extern/solveImgui.cmake @@ -3,7 +3,10 @@ set(ATTA_IMGUI_TARGETS "") FetchContent_Declare( imgui - URL "http://storage.googleapis.com/atta-deps/imgui-ff1567e2406797cbd1a3ef3d716888d6c3a66bd7.zip" + GIT_REPOSITORY "https://github.com/ocornut/imgui" + GIT_TAG "v1.90-docking" + GIT_PROGRESS TRUE + GIT_SHALLOW TRUE ) atta_log(Info Extern "Fetching ImGui...") diff --git a/src/extern/solveImguizmo.cmake b/src/extern/solveImguizmo.cmake index 61495461..c6300774 100644 --- a/src/extern/solveImguizmo.cmake +++ b/src/extern/solveImguizmo.cmake @@ -4,7 +4,7 @@ set(ATTA_IMGUIZMO_TARGETS "") FetchContent_Declare( imguizmo GIT_REPOSITORY "https://github.com/CedricGuillemet/ImGuizmo.git" - GIT_TAG "1.83" + GIT_TAG "ba662b1" GIT_PROGRESS TRUE GIT_SHALLOW TRUE ) diff --git a/src/extern/solveImplot.cmake b/src/extern/solveImplot.cmake index fabe6ce3..c630b1d2 100644 --- a/src/extern/solveImplot.cmake +++ b/src/extern/solveImplot.cmake @@ -4,7 +4,7 @@ set(ATTA_IMPLOT_TARGETS "") FetchContent_Declare( implot GIT_REPOSITORY "https://github.com/epezent/implot" - GIT_TAG "v0.13" + GIT_TAG "v0.16" GIT_PROGRESS TRUE GIT_SHALLOW TRUE )