Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
glfwdebug.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2025 Conquer Space
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <fmt/format.h>
20#include <glad/glad.h>
21
22#include <string>
23
24#include "engine/enginelogger.h"
25
26#define LogGlError(x) \
27 do { \
28 GLenum error = glGetError(); \
29 while ((error = glGetError()) != GL_NO_ERROR) { \
30 if (error != GL_NO_ERROR) { \
31 SPDLOG_ERROR("{} {}", x, engine::GetGlError(error)); \
32 } \
33 } \
34 } while (0)
35
36namespace cqsp::engine {
37const inline char* ParseType(GLenum type) {
38 switch (type) {
39 case GL_DEBUG_TYPE_ERROR:
40 return ("Error");
41 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
42 return ("Deprecated Behaviour");
43 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
44 return ("Undefined Behaviour");
45 case GL_DEBUG_TYPE_PORTABILITY:
46 return ("Portability");
47 case GL_DEBUG_TYPE_PERFORMANCE:
48 return ("Performance");
49 case GL_DEBUG_TYPE_MARKER:
50 return ("Marker");
51 case GL_DEBUG_TYPE_PUSH_GROUP:
52 return ("Push Group");
53 case GL_DEBUG_TYPE_POP_GROUP:
54 return ("Pop Group");
55 case GL_DEBUG_TYPE_OTHER:
56 default:
57 return ("Other");
58 }
59}
60
61const inline char* ParseSeverity(GLenum severity) {
62 switch (severity) {
63 case GL_DEBUG_SEVERITY_HIGH:
64 return ("high");
65 case GL_DEBUG_SEVERITY_MEDIUM:
66 return ("medium");
67 case GL_DEBUG_SEVERITY_LOW:
68 return ("low");
69 case GL_DEBUG_SEVERITY_NOTIFICATION:
70 default:
71 return ("notification");
72 }
73}
74
75const inline char* ParseSource(GLenum source) {
76 switch (source) {
77 case GL_DEBUG_SOURCE_API:
78 return ("API");
79 case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
80 return ("Window System");
81 case GL_DEBUG_SOURCE_SHADER_COMPILER:
82 return ("Shader Compiler");
83 case GL_DEBUG_SOURCE_THIRD_PARTY:
84 return ("Third Party");
85 case GL_DEBUG_SOURCE_APPLICATION:
86 return ("Application");
87 case GL_DEBUG_SOURCE_OTHER:
88 default:
89 return ("Other");
90 }
91}
92
93const inline std::string GetGlError(GLenum error) {
94 switch (error) {
95 case GL_NO_ERROR:
96 return "No Error";
97 case GL_INVALID_ENUM:
98 return "Invalid Enum";
99 case GL_INVALID_VALUE:
100 return "Invalid Value";
101 case GL_INVALID_OPERATION:
102 return "Invalid Operation";
103 case GL_INVALID_FRAMEBUFFER_OPERATION:
104 return "Invalid Framebuffer Operation";
105 case GL_OUT_OF_MEMORY:
106 return "Out of Memory";
107 case GL_STACK_UNDERFLOW:
108 return "Stack Underflow";
109 case GL_STACK_OVERFLOW:
110 return "Stack Overflow";
111 default:
112 return fmt::format("Unknown error 0x{:x}", error);
113 }
114}
115
116void inline APIENTRY glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length,
117 const char* message, const void* userParam) {
118 if (id == 131169 || id == 131185 || id == 131218 || id == 131204)
119 return; // ignore these non-significant error codes
120
121 ENGINE_LOG_INFO("{} message from {} ({}:{}): {}", ParseType(type), ParseSource(source), ParseSeverity(severity), id,
122 message);
123}
124} // namespace cqsp::engine
#define ENGINE_LOG_INFO(...)
Definition: enginelogger.h:29
Definition: application.cpp:55
void APIENTRY glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char *message, const void *userParam)
Definition: glfwdebug.h:116
const char * ParseType(GLenum type)
Definition: glfwdebug.h:37
const char * ParseSeverity(GLenum severity)
Definition: glfwdebug.h:61
const std::string GetGlError(GLenum error)
Definition: glfwdebug.h:93
const char * ParseSource(GLenum source)
Definition: glfwdebug.h:75