GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/graphicsmanager.h Lines: 0 6 0.0 %
Date: 2019-08-19 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2019  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#ifndef GRAPHICSMANAGER_H
22
#define GRAPHICSMANAGER_H
23
24
#include "localconsts.h"
25
26
#ifdef USE_OPENGL
27
#ifdef ANDROID
28
#include <GLES/gl.h>
29
#else  // ANDROID
30
#ifndef USE_SDL2
31
#define GL_GLEXT_PROTOTYPES 1
32
#endif  // USE_SDL2
33
#ifdef HAVE_GLEXT
34
#define NO_SDL_GLEXT
35
#endif  // HAVE_GLEXT
36
PRAGMA48(GCC diagnostic push)
37
PRAGMA48(GCC diagnostic ignored "-Wshadow")
38
#include <SDL_opengl.h>
39
PRAGMA48(GCC diagnostic pop)
40
#ifdef HAVE_GLEXT
41
#include <GL/glext.h>
42
#endif  // HAVE_GLEXT
43
// hack to hide warnings
44
#undef GL_GLEXT_VERSION
45
#undef GL_GLEXT_PROTOTYPES
46
#endif  // ANDROID
47
48
#endif  // USE_OPENGL
49
50
#include "sdlshared.h"
51
52
#include "utils/stringvector.h"
53
54
#include <set>
55
56
class TestMain;
57
58
struct FBOInfo;
59
#ifdef USE_SDL2
60
struct SDL_Renderer;
61
#endif  // USE_SDL2
62
struct SDL_Window;
63
64
class GraphicsManager final
65
{
66
    public:
67
        GraphicsManager();
68
69
        A_DELETE_COPY(GraphicsManager)
70
71
        ~GraphicsManager();
72
73
        void createRenderers();
74
75
        static void deleteRenderers();
76
77
        void initGraphics();
78
79
        static void setVideoMode();
80
81
        SDL_Window *createWindow(const int w, const int h,
82
                                 const int bpp, const int flags);
83
84
#ifdef USE_SDL2
85
        SDL_Renderer *createRenderer(SDL_Window *const window,
86
                                     const int flags);
87
#endif  // USE_SDL2
88
89
        bool getAllVideoModes(StringVect &modeList);
90
91
        void detectPixelSize();
92
93
        std::string getDensityString() const;
94
95
        int getDensity() const
96
        { return mDensity; }
97
98
#ifdef USE_OPENGL
99
        TestMain *startDetection() A_WARN_UNUSED;
100
101
        int detectGraphics() A_WARN_UNUSED;
102
103
        bool supportExtension(const std::string &ext) const A_WARN_UNUSED;
104
105
        static void updateTextureFormat();
106
107
        void updateTextureCompressionFormat() const;
108
109
        bool checkGLVersion(const int major, const int minor)
110
                            const A_WARN_UNUSED;
111
112
        bool checkGLesVersion(const int major, const int minor)
113
                              const A_WARN_UNUSED;
114
115
        bool checkSLVersion(const int major, const int minor)
116
                            const A_WARN_UNUSED;
117
118
        bool checkPlatformVersion(const int major, const int minor)
119
                                  const A_WARN_UNUSED;
120
121
        static void createFBO(const int width, const int height,
122
                              FBOInfo *const fbo);
123
124
        static void deleteFBO(FBOInfo *const fbo);
125
126
        void initOpenGLFunctions();
127
128
        void updateExtensions();
129
130
        void updatePlanformExtensions();
131
132
        void initOpenGL();
133
134
        void updateLimits();
135
136
        int getMaxVertices() const noexcept2 A_WARN_UNUSED
137
        { return mMaxVertices; }
138
139
        bool getUseAtlases() const noexcept2 A_WARN_UNUSED
140
        { return mUseAtlases; }
141
142
        void logVersion() const;
143
144
        void setGLVersion();
145
146
        static std::string getGLString(const int num) A_WARN_UNUSED;
147
148
        static void logString(const char *const format,
149
                              const int num) A_NONNULL(1);
150
151
        void detectVideoSettings();
152
153
        void createTextureSampler();
154
155
        bool isUseTextureSampler() const noexcept2 A_WARN_UNUSED
156
        { return mUseTextureSampler; }
157
158
        static GLenum getLastError();
159
160
        static std::string errorToString(const GLenum error) A_WARN_UNUSED;
161
162
        static void logError();
163
164
        void updateDebugLog() const;
165
166
        std::string getGLVersion() const
167
        { return mGlVersionString; }
168
169
        static GLenum getLastErrorCached()
170
        { return mLastError; }
171
172
        constexpr2 static void resetCachedError() noexcept2
173
        { mLastError = GL_NO_ERROR; }
174
#endif  // USE_OPENGL
175
176
    private:
177
        std::set<std::string> mExtensions;
178
179
        std::set<std::string> mPlatformExtensions;
180
181
        std::string mGlVersionString;
182
183
        std::string mGlVendor;
184
185
        std::string mGlRenderer;
186
187
        std::string mGlShaderVersionString;
188
#ifdef USE_OPENGL
189
        static GLenum mLastError;
190
#endif  // USE_OPENGL
191
192
        int mMinor;
193
194
        int mMajor;
195
196
        int mSLMinor;
197
198
        int mSLMajor;
199
200
        int mPlatformMinor;
201
202
        int mPlatformMajor;
203
204
        int mMaxVertices;
205
206
        int mMaxFboSize;
207
208
        uint32_t mMaxWidth;
209
210
        uint32_t mMaxHeight;
211
212
        uint32_t mWidthMM;
213
214
        uint32_t mHeightMM;
215
216
        int32_t mDensity;
217
218
#ifdef USE_OPENGL
219
        bool mUseTextureSampler;
220
221
        GLuint mTextureSampler;
222
223
        int mSupportDebug;
224
225
        bool mSupportModernOpengl;
226
227
        bool mGles;
228
#endif  // USE_OPENGL
229
230
        bool mUseAtlases;
231
};
232
233
extern GraphicsManager graphicsManager;
234
235
#endif  // GRAPHICSMANAGER_H