SDEngine
Game Engine
Loading...
Searching...
No Matches
GlfwContext.hpp
Go to the documentation of this file.
1// TODO(docs): Add file-level Doxygen header
2// - @file GlfwContext.hpp
3// - @brief RAII wrapper for GLFW initialization
4// - Error callback setup
5// - Vulkan extension query
6#pragma once
7
8#include <GLFW/glfw3.h>
9
10#include "SD/core/base.hpp"
11#include "SD/core/logging.hpp"
12
13namespace sd {
14using glfw_error_callback = std::function<void(int, const char*)>;
15
16// TODO(docs): Document GlfwContext class
17// - Purpose: RAII wrapper for GLFW lifecycle
18// - Initialization and termination guarantees
19// - Error callback customization
20// - GetRequiredInstanceExtensions for Vulkan
21// - Example: Usage in Application
27 // Set GLFW error callback
28 m_error_callback = [](int error_code, const char* description) {
29 log::engine::error("Glfw: ERROR:{} \n{}", error_code, description);
30 };
31 glfwSetErrorCallback(&GlfwContext::glfw_error_callback_trampoline);
32
33
34 if (glfwInit() == false) {
35 log::engine::critical("Failed to initialise GLFW");
36 }
37 }
38
39 GlfwContext(const GlfwContext&) = delete;
43
45 log::engine::info("Shutting down Glfw");
46
48 }
49
55 m_error_callback = callback;
56 }
57
58 // tODO: remove
59 static std::pair<const char**, uint32_t> get_required_instance_extensions() {
60 uint32_t count = 0;
61 const char** glfw_exts = glfwGetRequiredInstanceExtensions(&count);
62 return {glfw_exts, count};
63 }
64
65
67
69 m_error_callback(error_code, description);
70 }
71};
72} // namespace sd
Definition Application.hpp:22
std::function< void(int, const char *)> glfw_error_callback
Definition GlfwContext.hpp:14
RAII wrapper for initializing and terminating Glfw. Also sets a glfwErrorCallback.
Definition GlfwContext.hpp:25
static std::pair< const char **, uint32_t > get_required_instance_extensions()
Definition GlfwContext.hpp:59
GlfwContext()
Definition GlfwContext.hpp:26
GlfwContext & operator=(GlfwContext &&)=delete
GlfwContext(GlfwContext &&)=delete
~GlfwContext()
Definition GlfwContext.hpp:44
static glfw_error_callback m_error_callback
Definition GlfwContext.hpp:66
GlfwContext & operator=(const GlfwContext &)=delete
GlfwContext(const GlfwContext &)=delete
static void set_error_callback(const glfw_error_callback &callback)
Definition GlfwContext.hpp:54
static void glfw_error_callback_trampoline(int error_code, const char *description)
Definition GlfwContext.hpp:68
consteval U64 type_id_of()
Definition type_id.hpp:6