context.hpp 3.06 KB
Newer Older
1
2
3
4
#pragma once

#include <mirrage/graphic/settings.hpp>

5
6
#include <mirrage/asset/asset_manager.hpp>

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

#include <vulkan/vulkan.hpp>

#include <memory>
#include <string>
16
#include <vector>
17
18


19
namespace mirrage {
20
	namespace asset {
21
22
		class Asset_manager;
		class AID;
23
	} // namespace asset
24

25
	namespace graphic {
26

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

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

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


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

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

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

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

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

64
			auto list_windows() -> auto& { return _windows; }
65

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

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

70
71
72
73
			void vkCmdBeginDebugUtilsLabelEXT(VkCommandBuffer             commandBuffer,
			                                  const VkDebugUtilsLabelEXT* pLabelInfo);
			void vkCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer);

74
		  private:
75
			bool                          _debug;
76
77
78
79
			asset::Asset_manager&         _assets;
			std::string                   _name;
			asset::Ptr<Graphics_settings> _settings;
			std::vector<const char*>      _enabled_layers;
80

81
			vk::UniqueInstance               _instance;
82
			vk::UniqueDebugUtilsMessengerEXT _debug_callback;
83

84
85
			std::unordered_map<std::string, Window_ptr> _windows;

86
87
			PFN_vkCmdBeginDebugUtilsLabelEXT _vkCmdBeginDebugUtilsLabelEXT = nullptr;
			PFN_vkCmdEndDebugUtilsLabelEXT   _vkCmdEndDebugUtilsLabelEXT   = nullptr;
88

89
			auto _find_window_settings(const std::string& name, int width, int height) -> Window_settings;
90
		};
91
92
93
94
95
96
97
98
99
100
101

		class Queue_debug_label {
		  public:
			Queue_debug_label(Context&, vk::CommandBuffer, const char* name);
			~Queue_debug_label();

		  private:
			Context*          _ctx;
			vk::CommandBuffer _cmds;
		};

102
103
	} // namespace graphic
} // namespace mirrage