Skip to content

Commit

Permalink
Editor: add MSAA to ViewportWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
sturnclaw committed Sep 6, 2023
1 parent b31d192 commit c30a491
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/editor/ViewportWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -144,20 +147,28 @@ 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;

if (isValid) {
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));
}
1 change: 1 addition & 0 deletions src/editor/ViewportWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace Editor
private:

std::unique_ptr<Graphics::RenderTarget> m_renderTarget;
std::unique_ptr<Graphics::RenderTarget> m_resolveTarget;
Graphics::ViewportExtents m_viewportExtents;

bool m_viewportActive;
Expand Down

0 comments on commit c30a491

Please sign in to comment.