context.hpp 2.45 KB
Newer Older
1
2
3
4
5
6
#pragma once

#include <mirrage/graphic/settings.hpp>

#include <mirrage/utils/maybe.hpp>
#include <mirrage/utils/str_id.hpp>
7
#include <mirrage/utils/template_utils.hpp>
8
9
10
11
12
13
#include <mirrage/utils/units.hpp>

#include <vulkan/vulkan.hpp>

#include <memory>
#include <string>
14
#include <vector>
15
16


17
namespace mirrage {
18
	namespace asset {
19
20
		class Asset_manager;
		class AID;
21
	} // namespace asset
22

23
	namespace graphic {
24

25
26
27
28
		struct Queue_create_info {
			std::uint32_t family_id;
			float         priority = 1.f;
		};
29

30
31
		struct Device_create_info {
			std::unordered_map<util::Str_id, Queue_create_info> queue_families;
32
			vk::PhysicalDeviceFeatures                          features;
33
		};
34

35
36
		using Device_selector = std::function<int(vk::PhysicalDevice, util::maybe<std::uint32_t>)>;
		using Device_factory  = std::function<Device_create_info(
37
                vk::PhysicalDevice, util::maybe<std::uint32_t> graphic_queue_family)>;
38
39


40
		class Context : public util::Registration<Context, Device> {
41
42
43
44
45
46
47
		  public:
			Context(const std::string&    appName,
			        uint32_t              appVersion,
			        const std::string&    engineName,
			        uint32_t              engineVersion,
			        bool                  debug,
			        asset::Asset_manager& assets);
48
49
			~Context();

50
			auto settings() const noexcept -> const Graphics_settings& { return *_settings; }
51
52
			bool settings(Graphics_settings);

53
			auto app_name() const noexcept -> const std::string& { return _name; }
54

55
56
57
			auto instantiate_device(Device_selector,
			                        Device_factory,
			                        const std::vector<Window*>& can_present_to = {},
58
			                        bool                        srgb = false) -> Device_ptr;
59

60
			auto find_window(std::string name) -> util::maybe<Window&>;
61

62
			auto list_windows() -> auto& { return _windows; }
63

64
			auto instance() -> auto& { return *_instance; }
65

66
			auto asset_manager() -> auto& { return _assets; }
67

68
		  private:
69
70
71
72
73
			asset::Asset_manager&                       _assets;
			std::string                                 _name;
			std::shared_ptr<const Graphics_settings>    _settings;
			std::vector<const char*>                    _enabled_layers;
			std::unordered_map<std::string, Window_ptr> _windows;
74

75
			vk::UniqueInstance               _instance;
76
77
			vk::UniqueDebugReportCallbackEXT _debug_callback;

78
79
			auto _find_window_settings(const std::string& name, int width, int height)
			        -> Window_settings;
80
		};
81
82
	} // namespace graphic
} // namespace mirrage