forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderer.cpp
More file actions
113 lines (97 loc) · 2.37 KB
/
Copy pathRenderer.cpp
File metadata and controls
113 lines (97 loc) · 2.37 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "pch.h"
#include "Renderer.h"
#include "IDrawable.h"
#include "Core/Util.h"
#include <cassert>
namespace sh::render
{
Renderer::Renderer(RenderAPI api, core::ThreadSyncManager& syncManager) :
window(nullptr), syncManager(syncManager),
apiType(api),
viewportStart(0.f), viewportEnd(100.f),
bPause(false), bDirty(false)
{
}
SH_RENDER_API void Renderer::Clean()
{
for (int thr = 0; thr < drawList.size(); ++thr)
drawList[thr].clear();
drawCalls.clear();
}
SH_RENDER_API bool Renderer::Init(sh::window::Window& win)
{
window = &win;
return true;
}
SH_RENDER_API void Renderer::PushDrawAble(IDrawable* drawable)
{
if (!core::IsValid(drawable))
return;
drawableQueue.push(drawable);
SetDirty();
}
SH_RENDER_API void Renderer::AddDrawCall(const std::function<void()>& func)
{
drawCalls.push_back(func);
}
SH_RENDER_API void Renderer::ClearDrawList()
{
drawList[core::ThreadType::Game].clear();
SetDirty();
}
SH_RENDER_API auto Renderer::GetViewportStart() const -> const glm::vec2&
{
return viewportStart;
}
SH_RENDER_API auto Renderer::GetViewportEnd() const -> const glm::vec2&
{
return viewportEnd;
}
SH_RENDER_API auto Renderer::GetWindow() -> sh::window::Window&
{
assert(window);
return *window;
}
SH_RENDER_API void Renderer::Pause(bool b)
{
bPause.store(b, std::memory_order::memory_order_release);
}
SH_RENDER_API auto Renderer::IsPause() const -> bool
{
return bPause.load(std::memory_order::memory_order_acquire);
}
SH_RENDER_API void Renderer::SetDirty()
{
if (bDirty)
return;
syncManager.PushSyncable(*this);
bDirty = true;
}
SH_RENDER_API void Renderer::Sync()
{
while (!drawableQueue.empty())
{
IDrawable* drawable = drawableQueue.front();
drawableQueue.pop();
if (!core::IsValid(drawable))
continue;
if (!drawable->CheckAssetValid())
continue;
auto it = drawList[core::ThreadType::Game].find(drawable->GetCamera());
if (it == drawList[core::ThreadType::Game].end())
{
drawList[core::ThreadType::Game].insert({ drawable->GetCamera(), core::SVector<IDrawable*>{drawable} });
}
else
{
it->second.push_back(drawable);
}
}
drawList[core::ThreadType::Render] = std::move(drawList[core::ThreadType::Game]);
bDirty = false;
}
SH_RENDER_API auto Renderer::GetThreadSyncManager() const -> core::ThreadSyncManager&
{
return syncManager;
}
}