Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Context.h
Go to the documentation of this file.
1/**
2 * @file Context.h
3 * @brief Vulkan instance + physical/logical device + queue selection.
4 *
5 * This is a *preview* scaffold. It is not wired into the engine's GL render
6 * path; it exists so we can iterate on a Vulkan backend in parallel without
7 * disturbing the working OpenGL pipeline. See engine/source/graphics/vulkan/
8 * README considerations in CMakeLists (MONAD_VULKAN_PREVIEW option).
9 */
10
11#pragma once
12
13#include <vector>
14
15#include <vulkan/vulkan.h>
16
17struct GLFWwindow;
18
19namespace mnd::vk
20{
21
23{
24 uint32_t graphics = UINT32_MAX;
25 uint32_t present = UINT32_MAX;
26
27 [[nodiscard]] bool IsComplete() const { return graphics != UINT32_MAX && present != UINT32_MAX; }
28};
29
30/**
31 * @brief Owns the Vulkan instance, surface (tied to a GLFW window),
32 * physical + logical device, and graphics/present queues.
33 *
34 * Construction order matches typical Vulkan boot:
35 * 1. CreateInstance (+ optional debug messenger when validation layers requested)
36 * 2. CreateSurface (via glfwCreateWindowSurface)
37 * 3. PickPhysicalDevice (scores by queue family + swapchain support)
38 * 4. CreateLogicalDevice (one queue from each unique family)
39 */
41{
42 public:
43 /// @param window Required — used to create a VkSurfaceKHR via GLFW.
44 /// @param enableValidation Toggle VK_LAYER_KHRONOS_validation + debug messenger.
45 Context(GLFWwindow *window, bool enableValidation);
46 ~Context();
47
48 Context(const Context &) = delete;
49 Context &operator=(const Context &) = delete;
50
51 [[nodiscard]] VkInstance GetInstance() const { return m_instance; }
52
53 [[nodiscard]] VkSurfaceKHR GetSurface() const { return m_surface; }
54
55 [[nodiscard]] VkPhysicalDevice GetPhysicalDevice() const { return m_physicalDevice; }
56
57 [[nodiscard]] VkDevice GetDevice() const { return m_device; }
58
59 [[nodiscard]] VkQueue GetGraphicsQueue() const { return m_graphicsQueue; }
60
61 [[nodiscard]] VkQueue GetPresentQueue() const { return m_presentQueue; }
62
63 [[nodiscard]] QueueFamilies GetQueueFamilies() const { return m_queueFamilies; }
64
65 private:
66 void CreateInstance();
67 void CreateDebugMessenger();
68 void CreateSurface(GLFWwindow *window);
69 void PickPhysicalDevice();
70 void CreateLogicalDevice();
71
72 bool m_enableValidation = false;
73 VkInstance m_instance = VK_NULL_HANDLE;
74 VkDebugUtilsMessengerEXT m_debugMessenger = VK_NULL_HANDLE;
75 VkSurfaceKHR m_surface = VK_NULL_HANDLE;
76 VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
77 VkDevice m_device = VK_NULL_HANDLE;
78 VkQueue m_graphicsQueue = VK_NULL_HANDLE;
79 VkQueue m_presentQueue = VK_NULL_HANDLE;
80 QueueFamilies m_queueFamilies;
81};
82
83} // namespace mnd::vk
Owns the Vulkan instance, surface (tied to a GLFW window), physical + logical device,...
Definition Context.h:41
VkPhysicalDevice GetPhysicalDevice() const
Definition Context.h:55
VkInstance GetInstance() const
Definition Context.h:51
VkQueue GetGraphicsQueue() const
Definition Context.h:59
Context(const Context &)=delete
QueueFamilies GetQueueFamilies() const
Definition Context.h:63
Context & operator=(const Context &)=delete
VkDevice GetDevice() const
Definition Context.h:57
VkSurfaceKHR GetSurface() const
Definition Context.h:53
VkQueue GetPresentQueue() const
Definition Context.h:61
bool IsComplete() const
Definition Context.h:27