ManaPlus
graphicsmanager.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 GRAPHICSMANAGER_H
23 #define GRAPHICSMANAGER_H
24 
25 #include "localconsts.h"
26 
27 #ifdef USE_OPENGL
28 #ifdef ANDROID
29 #include <GLES/gl.h>
30 #else // ANDROID
31 #ifndef USE_SDL2
32 #define GL_GLEXT_PROTOTYPES 1
33 #endif // USE_SDL2
34 #ifdef HAVE_GLEXT
35 #define NO_SDL_GLEXT
36 #endif // HAVE_GLEXT
37 PRAGMA48(GCC diagnostic push)
38 PRAGMA48(GCC diagnostic ignored "-Wshadow")
39 // ignore -Wredundant-decls for SDL 1.2
40 PRAGMA45(GCC diagnostic push)
41 PRAGMA45(GCC diagnostic ignored "-Wredundant-decls")
42 #include <SDL_opengl.h>
43 PRAGMA45(GCC diagnostic pop)
44 PRAGMA48(GCC diagnostic pop)
45 #ifdef HAVE_GLEXT
46 PRAGMA45(GCC diagnostic push)
47 PRAGMA45(GCC diagnostic ignored "-Wredundant-decls")
48 #include <GL/glext.h>
49 PRAGMA45(GCC diagnostic pop)
50 #endif // HAVE_GLEXT
51 // hack to hide warnings
52 #undef GL_GLEXT_VERSION
53 #undef GL_GLEXT_PROTOTYPES
54 #endif // ANDROID
55 
56 #endif // USE_OPENGL
57 
58 #include "sdlshared.h"
59 
60 #include "utils/stringvector.h"
61 
62 #include <set>
63 
64 class TestMain;
65 
66 struct FBOInfo;
67 #ifdef USE_SDL2
68 struct SDL_Renderer;
69 #endif // USE_SDL2
70 struct SDL_Window;
71 
73 {
74  public:
76 
78 
80 
81  void createRenderers();
82 
83  static void deleteRenderers();
84 
85  void initGraphics();
86 
87  static void setVideoMode();
88 
89  static SDL_Window *createWindow(const int w, const int h,
90  const int bpp, const int flags);
91 
92 #ifdef USE_SDL2
93  SDL_Renderer *createRenderer(SDL_Window *const window,
94  const int flags);
95 #endif // USE_SDL2
96 
97  bool getAllVideoModes(StringVect &modeList);
98 
99  void detectPixelSize();
100 
101  std::string getDensityString() const;
102 
103  int getDensity() const
104  { return mDensity; }
105 
106 #ifdef USE_OPENGL
108 
110 
111  bool supportExtension(const std::string &ext) const A_WARN_UNUSED;
112 
113  static void updateTextureFormat();
114 
115  void updateTextureCompressionFormat() const;
116 
117  bool checkGLVersion(const int major, const int minor)
118  const A_WARN_UNUSED;
119 
120  bool checkGLesVersion(const int major, const int minor)
121  const A_WARN_UNUSED;
122 
123  bool checkSLVersion(const int major, const int minor)
124  const A_WARN_UNUSED;
125 
126  bool checkPlatformVersion(const int major, const int minor)
127  const A_WARN_UNUSED;
128 
129  static void createFBO(const int width, const int height,
130  FBOInfo *const fbo);
131 
132  static void deleteFBO(FBOInfo *const fbo);
133 
134  void initOpenGLFunctions();
135 
136  void updateExtensions();
137 
139 
140  void initOpenGL();
141 
142  void updateLimits();
143 
145  { return mMaxVertices; }
146 
148  { return mUseAtlases; }
149 
150  void logVersion() const;
151 
152  void setGLVersion();
153 
154  static std::string getGLString(const int num) A_WARN_UNUSED;
155 
156  static void logString(const char *const format,
157  const int num) A_NONNULL(1);
158 
159  void detectVideoSettings();
160 
161  void createTextureSampler();
162 
164  { return mUseTextureSampler; }
165 
166  static GLenum getLastError();
167 
168  static std::string errorToString(const GLenum error) A_WARN_UNUSED;
169 
170  static void logError();
171 
172  void updateDebugLog() const;
173 
174  std::string getGLVersion() const
175  { return mGlVersionString; }
176 
177  static GLenum getLastErrorCached()
178  { return mLastError; }
179 
181  { mLastError = GL_NO_ERROR; }
182 #endif // USE_OPENGL
183 
184  private:
185  std::set<std::string> mExtensions;
186 
187  std::set<std::string> mPlatformExtensions;
188 
189  std::string mGlVersionString;
190 
191  std::string mGlVendor;
192 
193  std::string mGlRenderer;
194 
196 #ifdef USE_OPENGL
197  static GLenum mLastError;
198 #endif // USE_OPENGL
199 
200  int mMinor;
201 
202  int mMajor;
203 
204  int mSLMinor;
205 
206  int mSLMajor;
207 
209 
211 
213 
215 
216  uint32_t mMaxWidth;
217 
218  uint32_t mMaxHeight;
219 
220  uint32_t mWidthMM;
221 
222  uint32_t mHeightMM;
223 
224  int32_t mDensity;
225 
226 #ifdef USE_OPENGL
228 
230 
232 
234 
235  bool mGles;
236 #endif // USE_OPENGL
237 
239 };
240 
242 
243 #endif // GRAPHICSMANAGER_H
bool checkPlatformVersion(const int major, const int minor) const
static GLenum getLastError()
std::set< std::string > mPlatformExtensions
static void resetCachedError()
std::string getDensityString() const
static void deleteFBO(FBOInfo *const fbo)
std::string getGLVersion() const
static void updateTextureFormat()
static void deleteRenderers()
bool checkGLVersion(const int major, const int minor) const
static std::string getGLString(const int num)
static void createFBO(const int width, const int height, FBOInfo *const fbo)
static GLenum getLastErrorCached()
static void logString(const char *const format, const int num)
bool supportExtension(const std::string &ext) const
std::string mGlVersionString
std::string mGlVendor
void updateTextureCompressionFormat() const
static SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
static GLenum mLastError
static void logError()
void updatePlanformExtensions()
bool getAllVideoModes(StringVect &modeList)
void updateDebugLog() const
bool getUseAtlases() const
void logVersion() const
bool isUseTextureSampler() const
static void setVideoMode()
bool checkGLesVersion(const int major, const int minor) const
static std::string errorToString(const GLenum error)
std::string mGlRenderer
std::set< std::string > mExtensions
int getDensity() const
int getMaxVertices() const
TestMain * startDetection()
bool checkSLVersion(const int major, const int minor) const
std::string mGlShaderVersionString
GraphicsManager graphicsManager
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
#define constexpr2
Definition: localconsts.h:49
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define PRAGMA48(str)
Definition: localconsts.h:199
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
bool error(InputEvent &event) __attribute__((noreturn))
Definition: actions.cpp:82
#define SDL_Window
Definition: sdlshared.h:60
std::vector< std::string > StringVect
Definition: stringvector.h:29