GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/graphicsmanager.h Lines: 0 6 0.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
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
72
class GraphicsManager final
73
{
74
    public:
75
        GraphicsManager();
76
77
        A_DELETE_COPY(GraphicsManager)
78
79
        ~GraphicsManager();
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
107
        TestMain *startDetection() A_WARN_UNUSED;
108
109
        int detectGraphics() A_WARN_UNUSED;
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
138
        void updatePlanformExtensions();
139
140
        void initOpenGL();
141
142
        void updateLimits();
143
144
        int getMaxVertices() const noexcept2 A_WARN_UNUSED
145
        { return mMaxVertices; }
146
147
        bool getUseAtlases() const noexcept2 A_WARN_UNUSED
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
163
        bool isUseTextureSampler() const noexcept2 A_WARN_UNUSED
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
180
        constexpr2 static void resetCachedError() noexcept2
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
195
        std::string mGlShaderVersionString;
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
208
        int mPlatformMinor;
209
210
        int mPlatformMajor;
211
212
        int mMaxVertices;
213
214
        int mMaxFboSize;
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
227
        bool mUseTextureSampler;
228
229
        GLuint mTextureSampler;
230
231
        int mSupportDebug;
232
233
        bool mSupportModernOpengl;
234
235
        bool mGles;
236
#endif  // USE_OPENGL
237
238
        bool mUseAtlases;
239
};
240
241
extern GraphicsManager graphicsManager;
242
243
#endif  // GRAPHICSMANAGER_H