TGUI  1.0-rc2
Loading...
Searching...
No Matches
OpenGL.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2023 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
26#ifndef TGUI_OPENGL_HPP
27#define TGUI_OPENGL_HPP
28
29#include <TGUI/Config.hpp>
30
31#if TGUI_BUILD_AS_CXX_MODULE && !defined(TGUI_BUILDING_OPENGL_MODULE)
32 import tgui.opengl;
33#endif
34
35#if defined(__GNUC__)
36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-Wold-style-cast"
38#elif defined (_MSC_VER)
39# if defined(__clang__)
40# pragma clang diagnostic push
41# pragma clang diagnostic ignored "-Wold-style-cast"
42# pragma clang diagnostic ignored "-Wlanguage-extension-token"
43# endif
44#endif
45
46#if TGUI_USE_SYSTEM_GLAD
47 #if TGUI_HAS_RENDERER_BACKEND_OPENGL3
48 #include <glad/gl.h>
49
50 #define tgui_gladLoadGL gladLoadGL
51 #define TGUI_GLAD_GL_VERSION_3_3 GLAD_GL_VERSION_3_3
52 #define TGUI_GLAD_GL_VERSION_4_0 GLAD_GL_VERSION_4_0
53 #define TGUI_GLAD_GL_VERSION_4_1 GLAD_GL_VERSION_4_1
54 #define TGUI_GLAD_GL_VERSION_4_2 GLAD_GL_VERSION_4_2
55 #define TGUI_GLAD_GL_VERSION_4_3 GLAD_GL_VERSION_4_3
56 #define TGUI_GLAD_GL_VERSION_4_4 GLAD_GL_VERSION_4_4
57 #define TGUI_GLAD_GL_VERSION_4_5 GLAD_GL_VERSION_4_5
58 #define TGUI_GLAD_GL_VERSION_4_6 GLAD_GL_VERSION_4_6
59 #endif
60
61 #if TGUI_HAS_RENDERER_BACKEND_GLES2
62 #include <glad/gles2.h>
63
64 #define tgui_gladLoadGLES2 gladLoadGLES2
65 #define TGUI_GLAD_GL_ES_VERSION_2_0 GLAD_GL_ES_VERSION_2_0
66 #define TGUI_GLAD_GL_ES_VERSION_3_0 GLAD_GL_ES_VERSION_3_0
67 #define TGUI_GLAD_GL_ES_VERSION_3_1 GLAD_GL_ES_VERSION_3_1
68 #define TGUI_GLAD_GL_ES_VERSION_3_2 GLAD_GL_ES_VERSION_3_2
69 #endif
70#else
71 // Include all functions from OpenGL 4.6 and OpenGL ES 3.2
72 #include <TGUI/extlibs/glad/gl.h>
73#endif
74
75#if defined(__GNUC__)
76# pragma GCC diagnostic pop
77#elif defined (_MSC_VER)
78# if defined(__clang__)
79# pragma clang diagnostic pop
80# endif
81#endif
82
83#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
84 #include <string>
85#endif
86
88
89#if !defined(NDEBUG)
90 #define TGUI_GL_CHECK(expr) do { expr; priv::checkAndLogErrorOpenGL(__FILE__, __LINE__, #expr); } while (false)
91#else
92 #define TGUI_GL_CHECK(expr) expr
93#endif
94
95#if !TGUI_BUILD_AS_CXX_MODULE || defined(TGUI_BUILDING_OPENGL_MODULE)
96namespace tgui
97{
98 namespace priv
99 {
100#if TGUI_BUILD_AS_CXX_MODULE
101 TGUI_MODULE_EXPORT
102#else
103 inline
104#endif
105#if !defined(NDEBUG) && !defined(TGUI_NO_RUNTIME_WARNINGS)
106 void checkAndLogErrorOpenGL(const char* file, unsigned int line, const char* expression)
107 {
108 GLenum errorCode = glGetError();
109 if (errorCode == GL_NO_ERROR)
110 return;
111
112 const char* error;
113 switch (errorCode)
114 {
115 case GL_INVALID_ENUM: error = "GL_INVALID_ENUM"; break;
116 case GL_INVALID_VALUE: error = "GL_INVALID_VALUE"; break;
117 case GL_INVALID_OPERATION: error = "GL_INVALID_OPERATION"; break;
118 case GL_STACK_OVERFLOW: error = "GL_STACK_OVERFLOW"; break;
119 case GL_STACK_UNDERFLOW: error = "GL_STACK_UNDERFLOW"; break;
120 case GL_OUT_OF_MEMORY: error = "GL_OUT_OF_MEMORY"; break;
121 default: error = "Unknown error"; break;
122 }
123
124 std::string fileStr = file;
125 TGUI_PRINT_WARNING("An internal OpenGL call failed in "
126 + fileStr.substr(fileStr.find_last_of("\\/") + 1)
127 + "(" + std::to_string(line) + ")."
128 + "\nExpression:\n " + expression + "\nError description:\n " + error + "\n");
129 }
130#else
131 void checkAndLogErrorOpenGL(const char*, unsigned int, const char*)
132 {
133 }
134#endif
135 }
136}
137#endif
138
140
141#endif // TGUI_OPENGL_HPP
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39