GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/graphicsmanager.h Lines: 0 6 0.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  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
PRAGMA48(GCC diagnostic push)
34
PRAGMA48(GCC diagnostic ignored "-Wshadow")
35
#include <SDL_opengl.h>
36
PRAGMA48(GCC diagnostic pop)
37
// hack to hide warnings
38
#undef GL_GLEXT_VERSION
39
#undef GL_GLEXT_PROTOTYPES
40
#endif  // ANDROID
41
42
#endif  // USE_OPENGL
43
44
#include "sdlshared.h"
45
46
#include "utils/stringvector.h"
47
48
#include <set>
49
50
class TestMain;
51
52
struct FBOInfo;
53
#ifdef USE_SDL2
54
struct SDL_Renderer;
55
#endif  // USE_SDL2
56
struct SDL_Window;
57
58
class GraphicsManager final
59
{
60
    public:
61
        GraphicsManager();
62
63
        A_DELETE_COPY(GraphicsManager)
64
65
        ~GraphicsManager();
66
67
        void createRenderers();
68
69
        static void deleteRenderers();
70
71
        void initGraphics();
72
73
        static void setVideoMode();
74
75
        SDL_Window *createWindow(const int w, const int h,
76
                                 const int bpp, const int flags);
77
78
#ifdef USE_SDL2
79
        SDL_Renderer *createRenderer(SDL_Window *const window,
80
                                     const int flags);
81
#endif  // USE_SDL2
82
83
        bool getAllVideoModes(StringVect &modeList);
84
85
        void detectPixelSize();
86
87
        std::string getDensityString() const;
88
89
        int getDensity() const
90
        { return mDensity; }
91
92
#ifdef USE_OPENGL
93
        TestMain *startDetection() A_WARN_UNUSED;
94
95
        int detectGraphics() A_WARN_UNUSED;
96
97
        bool supportExtension(const std::string &ext) const A_WARN_UNUSED;
98
99
        static void updateTextureFormat();
100
101
        void updateTextureCompressionFormat() const;
102
103
        bool checkGLVersion(const int major, const int minor)
104
                            const A_WARN_UNUSED;
105
106
        bool checkGLesVersion(const int major, const int minor)
107
                              const A_WARN_UNUSED;
108
109
        bool checkSLVersion(const int major, const int minor)
110
                            const A_WARN_UNUSED;
111
112
        bool checkPlatformVersion(const int major, const int minor)
113
                                  const A_WARN_UNUSED;
114
115
        static void createFBO(const int width, const int height,
116
                              FBOInfo *const fbo);
117
118
        static void deleteFBO(FBOInfo *const fbo);
119
120
        void initOpenGLFunctions();
121
122
        void updateExtensions();
123
124
        void updatePlanformExtensions();
125
126
        void initOpenGL();
127
128
        void updateLimits();
129
130
        int getMaxVertices() const noexcept2 A_WARN_UNUSED
131
        { return mMaxVertices; }
132
133
        bool getUseAtlases() const noexcept2 A_WARN_UNUSED
134
        { return mUseAtlases; }
135
136
        void logVersion() const;
137
138
        void setGLVersion();
139
140
        static std::string getGLString(const int num) A_WARN_UNUSED;
141
142
        static void logString(const char *const format,
143
                              const int num) A_NONNULL(1);
144
145
        void detectVideoSettings();
146
147
        void createTextureSampler();
148
149
        bool isUseTextureSampler() const noexcept2 A_WARN_UNUSED
150
        { return mUseTextureSampler; }
151
152
        static GLenum getLastError();
153
154
        static std::string errorToString(const GLenum error) A_WARN_UNUSED;
155
156
        static void logError();
157
158
        void updateDebugLog() const;
159
160
        std::string getGLVersion() const
161
        { return mGlVersionString; }
162
163
        static GLenum getLastErrorCached()
164
        { return mLastError; }
165
166
        constexpr2 static void resetCachedError() noexcept2
167
        { mLastError = GL_NO_ERROR; }
168
#endif  // USE_OPENGL
169
170
    private:
171
        std::set<std::string> mExtensions;
172
173
        std::set<std::string> mPlatformExtensions;
174
175
        std::string mGlVersionString;
176
177
        std::string mGlVendor;
178
179
        std::string mGlRenderer;
180
181
        std::string mGlShaderVersionString;
182
#ifdef USE_OPENGL
183
        static GLenum mLastError;
184
#endif  // USE_OPENGL
185
186
        int mMinor;
187
188
        int mMajor;
189
190
        int mSLMinor;
191
192
        int mSLMajor;
193
194
        int mPlatformMinor;
195
196
        int mPlatformMajor;
197
198
        int mMaxVertices;
199
200
        int mMaxFboSize;
201
202
        uint32_t mMaxWidth;
203
204
        uint32_t mMaxHeight;
205
206
        uint32_t mWidthMM;
207
208
        uint32_t mHeightMM;
209
210
        int32_t mDensity;
211
212
#ifdef USE_OPENGL
213
        bool mUseTextureSampler;
214
215
        GLuint mTextureSampler;
216
217
        int mSupportDebug;
218
219
        bool mSupportModernOpengl;
220
221
        bool mGles;
222
#endif  // USE_OPENGL
223
224
        bool mUseAtlases;
225
};
226
227
extern GraphicsManager graphicsManager;
228
229
#endif  // GRAPHICSMANAGER_H