-
Notifications
You must be signed in to change notification settings - Fork 6
/
Raindance.hh
107 lines (80 loc) · 2.13 KB
/
Raindance.hh
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
#pragma once
#include <raindance/Core/Headers.hh>
#include <raindance/Core/Context.hh>
#include <raindance/Core/Interface/WindowManager.hh>
class Raindance
{
public:
Raindance(int argc, char** argv)
{
GLFW::create(argc, argv);
m_Context = new Context();
m_Screenshot = false;
m_ScreenshotFactor = 1.0;
}
virtual ~Raindance()
{
GLFW::destroy();
}
virtual void add(rd::Window* window)
{
GLFW::setCallbacks(window);
auto id = m_WindowManager.add(window);
m_WindowManager.bind(id);
}
virtual void run()
{
m_WindowManager.active()->initialize(m_Context);
while (m_WindowManager.active()->state() == rd::Window::ALIVE)
{
Geometry::beginFrame();
auto window = m_WindowManager.active();
window->before(m_Context);
auto canvasWidth = window->canvas()->width();
auto canvasHeight = window->canvas()->height();
if (m_Screenshot)
{
window->onScreenshot(true);
window->onSetFramebufferSize(
static_cast<unsigned int>(canvasWidth * m_ScreenshotFactor),
static_cast<unsigned int>(canvasHeight * m_ScreenshotFactor));
}
window->canvas()->bind();
window->draw(m_Context);
window->canvas()->unbind();
window->canvas()->draw(m_Context);
if (m_Screenshot)
{
window->canvas()->dump(m_ScreenshotFilename.c_str());
window->onSetFramebufferSize(canvasWidth, canvasHeight);
m_Screenshot = false;
window->onScreenshot(false);
}
window->after(m_Context);
Geometry::endFrame();
idle();
checkGLErrors();
}
}
virtual void stop()
{
windows().active()->close();
}
virtual void idle()
{
windows().active()->idle(m_Context);
}
inline WindowManager& windows() { return m_WindowManager; }
void screenshot(const std::string& filename, float factor = 1.0)
{
m_Screenshot = true;
m_ScreenshotFilename = filename;
m_ScreenshotFactor = factor;
}
protected:
Context* m_Context;
WindowManager m_WindowManager;
bool m_Screenshot;
std::string m_ScreenshotFilename;
float m_ScreenshotFactor;
};