-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameRenderer.cpp
More file actions
89 lines (73 loc) · 2.35 KB
/
FrameRenderer.cpp
File metadata and controls
89 lines (73 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Core/Graphics/Rendering/FrameRenderer.h"
#include "Core/Graphics/GraphicsDevice.h"
#include "Core/Graphics/Rendering/Deferred/ColorRenderTarget2D.h"
#include "Core/Graphics/Rendering/Deferred/GBufferResources.h"
#include <stdexcept>
void FrameRenderer::Initialize(GraphicsDevice &graphics) noexcept
{
m_graphics = &graphics;
}
void FrameRenderer::BeginFrame(const Color &clearColor)
{
if (m_graphics == nullptr)
{
throw std::logic_error("FrameRenderer::BeginFrame called before Initialize.");
}
m_activePass = RenderPassKind::None;
m_graphics->BeginFrame(clearColor);
}
void FrameRenderer::EndFrame(const bool vSync) const
{
if (m_graphics == nullptr)
{
throw std::logic_error("FrameRenderer::EndFrame called before Initialize.");
}
m_graphics->EndFrame(vSync);
}
void FrameRenderer::BindMainPassTargets() const
{
if (m_graphics == nullptr)
{
throw std::logic_error("FrameRenderer::BindMainPassTargets called before Initialize.");
}
m_graphics->BindMainRenderTargets();
m_graphics->SetMainViewport();
}
void FrameRenderer::BindDeferredGeometryPass(GBufferResources &gBufferResources)
{
if (m_graphics == nullptr)
{
throw std::logic_error("FrameRenderer::BindDeferredGeometryPass called before Initialize.");
}
EnterPass(RenderPassKind::DeferredGeometry);
gBufferResources.BindGeometryPassTargets(*m_graphics);
m_graphics->SetViewportPixels(
static_cast<float>(gBufferResources.GetWidth()),
static_cast<float>(gBufferResources.GetHeight())
);
}
void FrameRenderer::BindDeferredLightingAccumulation(ColorRenderTarget2D &lightAccumulation)
{
if (m_graphics == nullptr)
{
throw std::logic_error("FrameRenderer::BindDeferredLightingAccumulation called before Initialize.");
}
EnterPass(RenderPassKind::DeferredLighting);
lightAccumulation.BindAsSingleRenderTarget(*m_graphics);
m_graphics->SetViewportPixels(
static_cast<float>(lightAccumulation.GetWidth()),
static_cast<float>(lightAccumulation.GetHeight())
);
}
void FrameRenderer::EnterPass(const RenderPassKind passKind) noexcept
{
m_activePass = passKind;
}
void FrameRenderer::LeavePass() noexcept
{
m_activePass = RenderPassKind::None;
}
RenderPassKind FrameRenderer::GetActivePass() const noexcept
{
return m_activePass;
}