GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/openglimagehelper.h Lines: 0 7 0.0 %
Date: 2021-03-17 Branches: 0 8 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#ifndef RESOURCES_OPENGLIMAGEHELPER_H
25
#define RESOURCES_OPENGLIMAGEHELPER_H
26
27
#include "localconsts.h"
28
29
#ifdef USE_OPENGL
30
31
#ifndef GL_TEXTURE_RECTANGLE_ARB
32
#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
33
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
34
#endif  // GL_TEXTURE_RECTANGLE_ARB
35
36
#include "resources/imagehelper.h"
37
38
#ifdef ANDROID
39
#include <GLES/gl.h>
40
#define GL_RGBA8 GL_RGBA8_OES
41
#else  // ANDROID
42
#ifndef USE_SDL2
43
#define GL_GLEXT_PROTOTYPES 1
44
#endif  // USE_SDL2
45
#ifdef HAVE_GLEXT
46
#define NO_SDL_GLEXT
47
#endif  // HAVE_GLEXT
48
PRAGMA48(GCC diagnostic push)
49
PRAGMA48(GCC diagnostic ignored "-Wshadow")
50
// ignore -Wredundant-decls for SDL 1.2
51
PRAGMA45(GCC diagnostic push)
52
PRAGMA45(GCC diagnostic ignored "-Wredundant-decls")
53
#include <SDL_opengl.h>
54
PRAGMA45(GCC diagnostic pop)
55
PRAGMA48(GCC diagnostic pop)
56
#ifdef HAVE_GLEXT
57
PRAGMA45(GCC diagnostic push)
58
PRAGMA45(GCC diagnostic ignored "-Wredundant-decls")
59
#include <GL/glext.h>
60
PRAGMA45(GCC diagnostic pop)
61
#endif  // HAVE_GLEXT
62
#endif  // ANDROID
63
64
class Dye;
65
class Image;
66
67
/**
68
 * Defines a class for loading and storing images.
69
 */
70
class OpenGLImageHelper final : public ImageHelper
71
{
72
    friend class CompoundSprite;
73
    friend class Graphics;
74
    friend class Image;
75
76
    public:
77
        OpenGLImageHelper() :
78
            mFreeTextureIndex(0U),
79
            mTextures()
80
        {
81
        }
82
83
        A_DELETE_COPY(OpenGLImageHelper)
84
85
        ~OpenGLImageHelper() override final;
86
87
        /**
88
         * Loads an image from an SDL_RWops structure and recolors it.
89
         *
90
         * @param rw         The SDL_RWops to load the image from.
91
         * @param dye        The dye used to recolor the image.
92
         *
93
         * @return <code>NULL</code> if an error occurred, a valid pointer
94
         *         otherwise.
95
         */
96
        Image *load(SDL_RWops *const rw,
97
                    Dye const &dye) override final A_WARN_UNUSED;
98
99
        /**
100
         * Loads an image from an SDL surface.
101
         */
102
        Image *loadSurface(SDL_Surface *const tmpImage) override final
103
                           A_WARN_UNUSED;
104
105
        Image *createTextSurface(SDL_Surface *const tmpImage,
106
                                 const int width, const int height,
107
                                 const float alpha)
108
                                 override final A_WARN_UNUSED;
109
110
        // OpenGL only public functions
111
112
        static int getTextureType() noexcept2 A_WARN_UNUSED
113
        { return mTextureType; }
114
115
        static int getInternalTextureType() noexcept2 A_WARN_UNUSED
116
        { return mInternalTextureType; }
117
118
        constexpr2 static void setInternalTextureType(const int n) noexcept2
119
        { mInternalTextureType = n; }
120
121
        constexpr2 static void setBlur(const bool n) noexcept2
122
        { mBlur = n; }
123
124
        static int mTextureType;
125
126
        static int mInternalTextureType;
127
128
        static int getTextureSize() noexcept2 A_WARN_UNUSED
129
        { return mTextureSize; }
130
131
        static void initTextureSampler(const GLint id);
132
133
        constexpr2 static void setUseTextureSampler(const bool b) noexcept2
134
        { mUseTextureSampler = b; }
135
136
        static void invalidate(const GLuint textureId);
137
138
        static void bindTexture(const GLuint texture);
139
140
        SDL_Surface *create32BitSurface(int width,
141
                                        int height) const override final;
142
143
        void postInit() override final;
144
145
        void copySurfaceToImage(const Image *const image,
146
                                const int x, const int y,
147
                                SDL_Surface *surface) const override final;
148
149
    protected:
150
        /**
151
         * Returns the first power of two equal or bigger than the input.
152
         */
153
        static int powerOfTwo(const int input) A_WARN_UNUSED;
154
155
        static SDL_Surface *convertSurfaceNormalize(SDL_Surface *tmpImage,
156
                                                    int width, int height);
157
158
        static SDL_Surface *convertSurface(SDL_Surface *tmpImage,
159
                                           int width, int height);
160
161
        Image *glLoad(SDL_Surface *tmpImage,
162
                      int width = 0, int height = 0) A_WARN_UNUSED;
163
164
        GLuint getNewTexture();
165
166
        static const size_t texturesSize = 10;
167
        size_t mFreeTextureIndex;
168
        GLuint mTextures[texturesSize];
169
170
        static int mTextureSize;
171
        static bool mBlur;
172
        static bool mUseTextureSampler;
173
};
174
175
#endif  // USE_OPENGL
176
#endif  // RESOURCES_OPENGLIMAGEHELPER_H