ManaPlus
mglfunctions.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef RENDER_OPENGL_MGLFUNCTIONS_H
23 #define RENDER_OPENGL_MGLFUNCTIONS_H
24 
25 #ifdef USE_OPENGL
26 
27 #include "logger.h"
28 
29 LOGGER_H
30 
31 #ifdef WIN32
32 #define getFunction(name) wglGetProcAddress(name)
33 #elif defined ANDROID
34 #define getFunction(name) eglGetProcAddress(name)
35 #elif defined __APPLE__
36 #define getFunction(name) nullptr
37 #elif defined __native_client__
38 #define getFunction(name) glGetProcAddressREGAL(name)
39 #elif defined(__SWITCH__)
40 #define getFunction(name) SDL_GL_GetProcAddress(name)
41 #else // WIN32
42 #define getFunction(name) glXGetProcAddress(\
43  reinterpret_cast<const GLubyte*>(name))
44 #endif // WIN32
45 
46 #define assignFunction(func) \
47  { \
48  m##func = reinterpret_cast<func##_t>(getFunction(#func)); \
49  if (m##func == nullptr) \
50  logger->log("function not found: " #func); \
51  else \
52  logger->log("assigned function: " #func); \
53  }
54 
55 #define assignFunction3(func, ext) \
56  { \
57  m##func = reinterpret_cast<func##_t>(getFunction(#func#ext)); \
58  if (m##func == nullptr) \
59  { \
60  logger->log("function not found: " #func#ext); \
61  m##func = reinterpret_cast<func##_t>(getFunction(#func)); \
62  if (m##func == nullptr) \
63  logger->log("function not found: " #func); \
64  else \
65  logger->log("assigned function: " #func); \
66  } \
67  else \
68  { \
69  logger->log("assigned function: " #func#ext); \
70  } \
71  }
72 
73 #define assignFunctionARB(func) assignFunction3(func, ARB)
74 
75 #define assignFunctionEXT(func) assignFunction3(func, EXT)
76 
77 #define assignFunction2(func, name) \
78  { \
79  m##func = reinterpret_cast<func##_t>(getFunction(name)); \
80  if (m##func == nullptr) \
81  logger->log(std::string("function not found: ") + name); \
82  else \
83  logger->log(std::string("assigned function: ") + name); \
84  }
85 
86 #define assignFunctionEmu2(func, name) \
87  { \
88  m##func = reinterpret_cast<func##_t>(getFunction(name)); \
89  if (m##func == nullptr) \
90  { \
91  m##func = emu##func; \
92  logger->log(std::string("emulated function: ") + name); \
93  } \
94  else \
95  { \
96  logger->log(std::string("assigned function: ") + name); \
97  } \
98  }
99 
100 #define emulateFunction(func) m##func = emu##func; \
101  logger->log("emulated function: " #func)
102 
103 #endif // USE_OPENGL
104 #endif // RENDER_OPENGL_MGLFUNCTIONS_H