Nameless Engine
Loading...
Searching...
No Matches
GLFW.hpp
1#pragma once
2
3// Standard.
4#include <stdexcept>
5#include <string>
6
7// Custom.
8#include "misc/Error.h"
9#include "io/Logger.h"
10
11// External.
12#define GLFW_INCLUDE_NONE
13#include "GLFW/glfw3.h"
14#undef MessageBox
15#undef IGNORE
16
17namespace ne {
18 inline void glfwErrorCallback(int iErrorCode, const char* pDescription) {
19 const auto sMessage = "GLFW error (" + std::to_string(iErrorCode) + "): " + std::string(pDescription);
20
21 if (iErrorCode == GLFW_FEATURE_UNAVAILABLE) {
22 // Just log an error, this is probably some platform-specific limitation like window icons.
23 Logger::get().error(sMessage);
24 return;
25 }
26
27 const Error error(sMessage);
28 error.showError();
29 throw std::runtime_error(error.getFullErrorMessage());
30 }
31
33 class GLFW {
34 public:
35 GLFW(const GLFW&) = delete;
36 GLFW& operator=(const GLFW&) = delete;
37
39 ~GLFW() { glfwTerminate(); }
40
46 static GLFW& get() {
47 static GLFW glfw;
48 return glfw;
49 }
50
51 private:
53 GLFW() {
54 glfwSetErrorCallback(ne::glfwErrorCallback);
55
56 if (glfwInit() != GLFW_TRUE) {
57 const Error error("failed to initialize GLFW");
58 error.showError();
59 throw std::runtime_error(error.getFullErrorMessage());
60 }
61 }
62 };
63} // namespace ne
Definition: Error.h:27
std::string getFullErrorMessage() const
Definition: Error.cpp:84
void showError() const
Definition: Error.cpp:102
Definition: GLFW.hpp:33
~GLFW()
Definition: GLFW.hpp:39
GLFW()
Definition: GLFW.hpp:53
static GLFW & get()
Definition: GLFW.hpp:46
void error(std::string_view sText, const std::source_location location=std::source_location::current()) const
Definition: Logger.cpp:75
static Logger & get()
Definition: Logger.cpp:41