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 5, 2023
1 parent 9106467 commit aa0f6c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 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 @@ -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 @@ -85,6 +86,8 @@ void ViewportWindow::Update(float deltaTime)
r->ClearScreen(); // FIXME: add clear-command passing in immediate-state clear color

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 aa0f6c9

Please sign in to comment.