context.hpp 2.42 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
21
22
		class Asset_manager;
		class AID;
	}

23
	namespace graphic {
24

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

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

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


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

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

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

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

61
			auto create_window(std::string name, int width = -1, int height = -1) -> Window_ptr;
62

63
			auto list_windows() -> auto& { return util::Registration<Context, Window>::children(); }
64

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

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

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

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

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