TGUI 1.13
Loading...
Searching...
No Matches
OpenGL.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_OPENGL_HPP
26#define TGUI_OPENGL_HPP
27
28#include <TGUI/Config.hpp>
29
30#if defined(__GNUC__)
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wold-style-cast"
33#elif defined(_MSC_VER)
34 #if defined(__clang__)
35 #pragma clang diagnostic push
36 #pragma clang diagnostic ignored "-Wold-style-cast"
37 #pragma clang diagnostic ignored "-Wlanguage-extension-token"
38 #endif
39#endif
40
41#if TGUI_USE_SYSTEM_GLAD
42 #if TGUI_HAS_RENDERER_BACKEND_OPENGL3
43 #include <glad/gl.h>
44
45 #define tgui_gladLoadGL gladLoadGL
46 #define TGUI_GLAD_GL_VERSION_3_3 GLAD_GL_VERSION_3_3
47 #define TGUI_GLAD_GL_VERSION_4_0 GLAD_GL_VERSION_4_0
48 #define TGUI_GLAD_GL_VERSION_4_1 GLAD_GL_VERSION_4_1
49 #define TGUI_GLAD_GL_VERSION_4_2 GLAD_GL_VERSION_4_2
50 #define TGUI_GLAD_GL_VERSION_4_3 GLAD_GL_VERSION_4_3
51 #define TGUI_GLAD_GL_VERSION_4_4 GLAD_GL_VERSION_4_4
52 #define TGUI_GLAD_GL_VERSION_4_5 GLAD_GL_VERSION_4_5
53 #define TGUI_GLAD_GL_VERSION_4_6 GLAD_GL_VERSION_4_6
54 #endif
55
56 #if TGUI_HAS_RENDERER_BACKEND_GLES2
57 #include <glad/gles2.h>
58
59 #define tgui_gladLoadGLES2 gladLoadGLES2
60 #define TGUI_GLAD_GL_ES_VERSION_2_0 GLAD_GL_ES_VERSION_2_0
61 #define TGUI_GLAD_GL_ES_VERSION_3_0 GLAD_GL_ES_VERSION_3_0
62 #define TGUI_GLAD_GL_ES_VERSION_3_1 GLAD_GL_ES_VERSION_3_1
63 #define TGUI_GLAD_GL_ES_VERSION_3_2 GLAD_GL_ES_VERSION_3_2
64 #endif
65#else
66 // Include all functions from OpenGL 4.6 and OpenGL ES 3.2
67 #include <TGUI/extlibs/glad/gl.h>
68#endif
69
70#if defined(__GNUC__)
71 #pragma GCC diagnostic pop
72#elif defined(_MSC_VER)
73 #if defined(__clang__)
74 #pragma clang diagnostic pop
75 #endif
76#endif
77
78#include <string>
79
81
82#if !defined(NDEBUG)
83 #define TGUI_GL_CHECK(expr) \
84 do \
85 { \
86 expr; \
87 priv::checkAndLogErrorOpenGL(__FILE__, __LINE__, #expr); \
88 } while (false)
89#else
90 #define TGUI_GL_CHECK(expr) expr
91#endif
92
93namespace tgui::priv
94{
95#if !defined(NDEBUG) && !defined(TGUI_NO_RUNTIME_WARNINGS)
96 inline void checkAndLogErrorOpenGL(const char* file, unsigned int line, const char* expression)
97 {
98 const GLenum errorCode = glGetError();
99 if (errorCode == GL_NO_ERROR)
100 return;
101
102 const char* error;
103 switch (errorCode)
104 {
105 case GL_INVALID_ENUM:
106 error = "GL_INVALID_ENUM";
107 break;
108 case GL_INVALID_VALUE:
109 error = "GL_INVALID_VALUE";
110 break;
111 case GL_INVALID_OPERATION:
112 error = "GL_INVALID_OPERATION";
113 break;
114 case GL_STACK_OVERFLOW:
115 error = "GL_STACK_OVERFLOW";
116 break;
117 case GL_STACK_UNDERFLOW:
118 error = "GL_STACK_UNDERFLOW";
119 break;
120 case GL_OUT_OF_MEMORY:
121 error = "GL_OUT_OF_MEMORY";
122 break;
123 default:
124 error = "Unknown error";
125 break;
126 }
127
128 const std::string fileStr = file;
129 TGUI_PRINT_WARNING(
130 "An internal OpenGL call failed in " + fileStr.substr(fileStr.find_last_of("\\/") + 1) + "(" + std::to_string(line)
131 + ")." + "\nExpression:\n " + expression + "\nError description:\n " + error + "\n");
132 }
133#else
134 inline void checkAndLogErrorOpenGL(const char*, unsigned int, const char*)
135 {
136 }
137#endif
138} // namespace tgui::priv
139
140#endif // TGUI_OPENGL_HPP