GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/openglimagehelper.h Lines: 0 7 0.0 %
Date: 2017-11-29 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-2017  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
PRAGMA48(GCC diagnostic push)
45
PRAGMA48(GCC diagnostic ignored "-Wshadow")
46
#include <SDL_opengl.h>
47
PRAGMA48(GCC diagnostic pop)
48
#endif  // ANDROID
49
50
class Dye;
51
class Image;
52
53
/**
54
 * Defines a class for loading and storing images.
55
 */
56
class OpenGLImageHelper final : public ImageHelper
57
{
58
    friend class CompoundSprite;
59
    friend class Graphics;
60
    friend class Image;
61
62
    public:
63
        OpenGLImageHelper() :
64
            mFreeTextureIndex(0U),
65
            mTextures()
66
        {
67
        }
68
69
        A_DELETE_COPY(OpenGLImageHelper)
70
71
        ~OpenGLImageHelper();
72
73
        /**
74
         * Loads an image from an SDL_RWops structure and recolors it.
75
         *
76
         * @param rw         The SDL_RWops to load the image from.
77
         * @param dye        The dye used to recolor the image.
78
         *
79
         * @return <code>NULL</code> if an error occurred, a valid pointer
80
         *         otherwise.
81
         */
82
        Image *load(SDL_RWops *const rw,
83
                    Dye const &dye) override final A_WARN_UNUSED;
84
85
        /**
86
         * Loads an image from an SDL surface.
87
         */
88
        Image *loadSurface(SDL_Surface *const tmpImage) override final
89
                           A_WARN_UNUSED;
90
91
        Image *createTextSurface(SDL_Surface *const tmpImage,
92
                                 const int width, const int height,
93
                                 const float alpha)
94
                                 override final A_WARN_UNUSED;
95
96
        // OpenGL only public functions
97
98
        static int getTextureType() noexcept2 A_WARN_UNUSED
99
        { return mTextureType; }
100
101
        static int getInternalTextureType() noexcept2 A_WARN_UNUSED
102
        { return mInternalTextureType; }
103
104
        constexpr2 static void setInternalTextureType(const int n) noexcept2
105
        { mInternalTextureType = n; }
106
107
        constexpr2 static void setBlur(const bool n) noexcept2
108
        { mBlur = n; }
109
110
        static int mTextureType;
111
112
        static int mInternalTextureType;
113
114
        static int getTextureSize() noexcept2 A_WARN_UNUSED
115
        { return mTextureSize; }
116
117
        static void initTextureSampler(const GLint id);
118
119
        constexpr2 static void setUseTextureSampler(const bool b) noexcept2
120
        { mUseTextureSampler = b; }
121
122
        static void invalidate(const GLuint textureId);
123
124
        static void bindTexture(const GLuint texture);
125
126
        SDL_Surface *create32BitSurface(int width,
127
                                        int height) const override final;
128
129
        void postInit() override final;
130
131
        void copySurfaceToImage(const Image *const image,
132
                                const int x, const int y,
133
                                SDL_Surface *surface) const override final;
134
135
    protected:
136
        /**
137
         * Returns the first power of two equal or bigger than the input.
138
         */
139
        static int powerOfTwo(const int input) A_WARN_UNUSED;
140
141
        static SDL_Surface *convertSurfaceNormalize(SDL_Surface *tmpImage,
142
                                                    int width, int height);
143
144
        static SDL_Surface *convertSurface(SDL_Surface *tmpImage,
145
                                           int width, int height);
146
147
        Image *glLoad(SDL_Surface *tmpImage,
148
                      int width = 0, int height = 0) A_WARN_UNUSED;
149
150
        GLuint getNewTexture();
151
152
        static const size_t texturesSize = 10;
153
        size_t mFreeTextureIndex;
154
        GLuint mTextures[texturesSize];
155
156
        static int mTextureSize;
157
        static bool mBlur;
158
        static bool mUseTextureSampler;
159
};
160
161
#endif  // USE_OPENGL
162
#endif  // RESOURCES_OPENGLIMAGEHELPER_H