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