-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.cpp
More file actions
66 lines (54 loc) · 1.6 KB
/
application.cpp
File metadata and controls
66 lines (54 loc) · 1.6 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
#include "application.h"
#include "window.h"
#include "device-vk.h"
#include "device-dx12.h"
#include <windows.h>
#include <chrono>
int ApplicationBase::Run()
{
ApplicationConfig config;
Init(config);
m_window = CreateWnd(config.window_width, config.window_height, config.window_title);
m_device = CreateDevice(config.api, config.features, *m_window);
m_swapchain = m_device->CreateSwapchain();
Start();
MSG msg;
auto start = std::chrono::high_resolution_clock::now();
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
{
break;
}
}
auto now = std::chrono::high_resolution_clock::now();
float dt = std::chrono::duration_cast<std::chrono::duration<float>>(now - start).count();
start = now;
Update(dt);
}
Terminate();
m_device = nullptr;
m_window = nullptr;
return EXIT_SUCCESS;
}
std::shared_ptr<Device> ApplicationBase::CreateDevice(DeviceAPI api, const DeviceFeatures& features, const Window& window) const
{
switch (api)
{
case DeviceAPI::Direct3D_12:
return std::make_shared<DeviceDX12>(features, window);
break;
case DeviceAPI::Vulkan:
return std::make_shared<DeviceVK>(features, window);
case DeviceAPI::Metal:
break;
}
return nullptr;
}
std::shared_ptr<Window> ApplicationBase::CreateWnd(int width, int height, const std::wstring& title) const
{
return std::make_shared<Window>(width, height, title);
}