From ea503a1c853a1100b482bbccb5704897c50943d2 Mon Sep 17 00:00:00 2001 From: antopilo Date: Thu, 6 Feb 2025 12:40:21 -0500 Subject: [PATCH] Fixed imguizmo aspect ratio --- .../SceneEditor/Widgets/ViewportWidget.cpp | 12 +++++------ .../Nuake/Rendering/Vulkan/VkResources.h | 4 ++-- .../Nuake/Rendering/Vulkan/VulkanRenderer.cpp | 20 +++++++++---------- Nuake/Source/Nuake/Window.cpp | 7 ------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/Editor/Source/Editor/Windows/SceneEditor/Widgets/ViewportWidget.cpp b/Editor/Source/Editor/Windows/SceneEditor/Widgets/ViewportWidget.cpp index 59e00278..2f6444f3 100644 --- a/Editor/Source/Editor/Windows/SceneEditor/Widgets/ViewportWidget.cpp +++ b/Editor/Source/Editor/Windows/SceneEditor/Widgets/ViewportWidget.cpp @@ -30,7 +30,7 @@ ViewportWidget::~ViewportWidget() void ViewportWidget::Update(float ts) { editorContext.GetScene()->Update(ts); - auto& editorCam = editorContext.GetScene()->m_EditorCamera; + auto editorCam = (EditorCamera*)(editorContext.GetScene()->GetCurrentCamera().get()); editorCam->Update(ts, isHoveringViewport); const Vector2 viewportSize = sceneViewport->GetViewportSize(); @@ -67,6 +67,7 @@ void ViewportWidget::Draw() VkDescriptorSet textureDesc = sceneViewport->GetRenderTarget()->GetImGuiDescriptorSet(); ImVec2 imagePos = ImGui::GetWindowPos() + ImGui::GetCursorPos(); + ImVec2 viewportMin = ImGui::GetCursorScreenPos(); // Input::SetEditorViewportSize(m_ViewportPos, viewportPanelSize); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); //m_ViewportPos = { imagePos.x, imagePos.y }; @@ -85,7 +86,7 @@ void ViewportWidget::Draw() // TODO(antopilo) drag n drop ImGuizmo::SetDrawlist(); ImGuizmo::AllowAxisFlip(true); - ImGuizmo::SetRect(imagePos.x, imagePos.y, viewportPanelSize.x, viewportPanelSize.y); + ImGuizmo::SetRect(viewportMin.x, viewportMin.y, regionAvail.x, regionAvail.y); // TODO(grid) auto selection = editorContext.GetSelection(); @@ -99,20 +100,19 @@ void ViewportWidget::Draw() { TransformComponent& tc = selection.Entity.GetComponent(); Matrix4 transform = tc.GetGlobalTransform(); - const auto& editorCam = editorContext.GetScene()->GetCurrentCamera(); + auto editorCam = editorContext.GetScene()->GetCurrentCamera(); Matrix4 cameraView = editorCam->GetTransform(); // Since imguizmo doesnt support reverse-Z, we need to create a new projection matrix // With a normal near and far plane. - Matrix4 normalZProjection = glm::perspectiveFov(glm::radians(editorCam->Fov), 9.0f * editorCam->AspectRatio, 9.0f, editorCam->Far, editorCam->Near); - + Matrix4 normalZProjection = glm::perspectiveFov(glm::radians(editorCam->Fov), 9.0f * editorCam->AspectRatio, 9.0f, editorCam->Near, editorCam->Far); static Vector3 camPreviousPos = editorContext.GetScene()->m_EditorCamera->Translation; static Vector3 camNewPos = Vector3(0, 0, 0); Vector3 camDelta = camNewPos - camPreviousPos; Vector3 previousGlobalPos = transform[3]; // Imguizmo calculates the delta from the gizmo, ImGuizmo::Manipulate( - glm::value_ptr(editorContext.GetScene()->GetCurrentCamera()->GetTransform()), + glm::value_ptr(editorCam->GetTransform()), glm::value_ptr(normalZProjection), CurrentOperation, CurrentMode, glm::value_ptr(transform), NULL, diff --git a/Nuake/Source/Nuake/Rendering/Vulkan/VkResources.h b/Nuake/Source/Nuake/Rendering/Vulkan/VkResources.h index 7a0d7e08..04d04631 100644 --- a/Nuake/Source/Nuake/Rendering/Vulkan/VkResources.h +++ b/Nuake/Source/Nuake/Rendering/Vulkan/VkResources.h @@ -47,7 +47,7 @@ namespace Nuake // This is the *whole* buffer struct MaterialData { - std::array Data; + std::array Data; }; struct LightData @@ -86,7 +86,7 @@ namespace Nuake }; constexpr uint32_t MAX_MODEL_MATRIX = 3000; - constexpr uint32_t MAX_MATERIAL = 1000; + constexpr uint32_t MAX_MATERIAL = 3000; constexpr uint32_t MAX_TEXTURES = 500; constexpr uint32_t MAX_CAMERAS = 100; constexpr uint32_t MAX_LIGHTS = 100; diff --git a/Nuake/Source/Nuake/Rendering/Vulkan/VulkanRenderer.cpp b/Nuake/Source/Nuake/Rendering/Vulkan/VulkanRenderer.cpp index 1f67b035..6e4a9c67 100644 --- a/Nuake/Source/Nuake/Rendering/Vulkan/VulkanRenderer.cpp +++ b/Nuake/Source/Nuake/Rendering/Vulkan/VulkanRenderer.cpp @@ -31,6 +31,7 @@ #include "vk_mem_alloc.h" #include +#include bool NKUseValidationLayer = true; @@ -85,7 +86,7 @@ void VkRenderer::Initialize() { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024 } }; - GlobalDescriptorAllocator.InitPool(Device, 1000, sizes); + GlobalDescriptorAllocator.InitPool(Device, 5000, sizes); InitCommands(); @@ -325,9 +326,9 @@ void VkRenderer::InitDescriptors() // create a descriptor pool std::vector frame_sizes = { - { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 3 }, - { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3 }, - { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 3 }, + { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 64 }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 64 }, + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 64 }, { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4 }, }; @@ -341,13 +342,8 @@ void VkRenderer::PrepareSceneData(RenderContext ctx) std::vector> scenes; scenes.reserve(SceneViewports.size()); - for (auto& [scene, views] : SceneViewports) + for (auto& [scene, _] : SceneViewports) { - for (auto& view : views) - { - //Viewports[view]->Resize(); - } - scenes.push_back(scene); } @@ -831,8 +827,10 @@ void DescriptorAllocator::InitPool(VkDevice device, uint32_t maxSets, std::span< ); } + + VkDescriptorPoolCreateInfo pool_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO }; - pool_info.flags = 0; + pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; pool_info.maxSets = maxSets; pool_info.poolSizeCount = (uint32_t)poolSizes.size(); pool_info.pPoolSizes = poolSizes.data(); diff --git a/Nuake/Source/Nuake/Window.cpp b/Nuake/Source/Nuake/Window.cpp index f52a843e..54331f1a 100644 --- a/Nuake/Source/Nuake/Window.cpp +++ b/Nuake/Source/Nuake/Window.cpp @@ -195,13 +195,6 @@ void Window::Draw() { return; } - - // We cannot render to a framebuffer that is smaller than 1x1. - Vector2 size = this->framebuffer->GetSize(); - size.x = std::max(size.x, 1.0f); - size.y = std::max(size.y, 1.0f); - - cam->AspectRatio = size.x / size.y; } void Window::EndDraw()