From c30a491b6cb20f13fa472b9a7cf9623789a77c2d Mon Sep 17 00:00:00 2001 From: Webster Sheets Date: Tue, 5 Sep 2023 16:08:15 -0400 Subject: [PATCH] Editor: add MSAA to ViewportWindow --- src/editor/ViewportWindow.cpp | 27 +++++++++++++++++++-------- src/editor/ViewportWindow.h | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/editor/ViewportWindow.cpp b/src/editor/ViewportWindow.cpp index 6f83c044782..1dae2b2dc3f 100644 --- a/src/editor/ViewportWindow.cpp +++ b/src/editor/ViewportWindow.cpp @@ -6,6 +6,7 @@ #include "editor/EditorApp.h" #include "graphics/Graphics.h" #include "graphics/RenderTarget.h" +#include "graphics/Renderer.h" #include "graphics/Texture.h" #define IMGUI_DEFINE_MATH_OPERATORS @@ -55,7 +56,7 @@ void ViewportWindow::Update(float deltaTime) // Perform scene updates before rendering OnUpdate(deltaTime); - ImVec2 size = ImGui::GetContentRegionAvail(); + ImVec2 size = ImFloor(ImGui::GetContentRegionAvail()); m_viewportExtents.w = int(size.x); m_viewportExtents.h = int(size.y); @@ -68,7 +69,7 @@ void ViewportWindow::Update(float deltaTime) // Draw our render target as the window "background" // PiGui rendering happens after the contents of the texture are rendered ImGui::GetWindowDrawList()->AddImageRounded( - ImTextureID(m_renderTarget->GetColorTexture()), + ImTextureID(m_resolveTarget->GetColorTexture()), screenPos, screenPos + size, ImVec2(0, 1), ImVec2(1, 0), IM_COL32_WHITE, @@ -82,9 +83,11 @@ void ViewportWindow::Update(float deltaTime) r->SetRenderTarget(m_renderTarget.get()); r->SetViewport(m_viewportExtents); - r->ClearScreen(); // FIXME: add clear-command passing in immediate-state clear color + r->ClearScreen(Color::BLACK); OnRender(r); + + r->ResolveRenderTarget(m_renderTarget.get(), m_resolveTarget.get(), m_viewportExtents); } ImGui::BeginChild("##ViewportContainer", ImVec2(0, 0), false, @@ -144,7 +147,7 @@ void ViewportWindow::Update(float deltaTime) void ViewportWindow::CreateRenderTarget() { - bool isValid = m_renderTarget && + bool isValid = m_renderTarget && m_resolveTarget && m_renderTarget->GetDesc().width == m_viewportExtents.w && m_renderTarget->GetDesc().height == m_viewportExtents.h; @@ -152,12 +155,20 @@ void ViewportWindow::CreateRenderTarget() return; } - Graphics::RenderTargetDesc rtdesc = Graphics::RenderTargetDesc( + Graphics::RenderTargetDesc rtDesc = Graphics::RenderTargetDesc( + m_viewportExtents.w, m_viewportExtents.h, + Graphics::TextureFormat::TEXTURE_RGB_888, + Graphics::TextureFormat::TEXTURE_DEPTH, false, + GetApp()->GetGraphicsSettings().requestedSamples + ); + + m_renderTarget.reset(GetApp()->GetRenderer()->CreateRenderTarget(rtDesc)); + + Graphics::RenderTargetDesc resolveDesc = Graphics::RenderTargetDesc( m_viewportExtents.w, m_viewportExtents.h, Graphics::TextureFormat::TEXTURE_RGB_888, - Graphics::TextureFormat::TEXTURE_DEPTH, - false, 0 // FIXME: multisample resolve for MSAA! + Graphics::TextureFormat::TEXTURE_NONE, true ); - m_renderTarget.reset(GetApp()->GetRenderer()->CreateRenderTarget(rtdesc)); + m_resolveTarget.reset(GetApp()->GetRenderer()->CreateRenderTarget(resolveDesc)); } diff --git a/src/editor/ViewportWindow.h b/src/editor/ViewportWindow.h index 31b79bd4b2b..281d17ff882 100644 --- a/src/editor/ViewportWindow.h +++ b/src/editor/ViewportWindow.h @@ -48,6 +48,7 @@ namespace Editor private: std::unique_ptr m_renderTarget; + std::unique_ptr m_resolveTarget; Graphics::ViewportExtents m_viewportExtents; bool m_viewportActive;