ManaPlus
safeopenglimagehelper.h
Go to the documentation of this file.
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-2018 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_SAFEOPENGLIMAGEHELPER_H
24 #define RESOURCES_SAFEOPENGLIMAGEHELPER_H
25 
26 #include "localconsts.h"
27 
28 #if defined(USE_OPENGL) && !defined(ANDROID)
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 
57 {
58  friend class CompoundSprite;
59  friend class Graphics;
60  friend class Image;
61 
62  public:
65  mTextures()
66  {
67  }
68 
70 
71  ~SafeOpenGLImageHelper() override final;
72 
82  Image *load(SDL_RWops *const rw,
83  Dye const &dye) override final A_WARN_UNUSED;
84 
88  Image *loadSurface(SDL_Surface *const tmpImage)
89  override final 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() A_WARN_UNUSED
99  { return mTextureType; }
100 
101  static int getInternalTextureType() 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 
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:
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;
155 
156  static int mTextureSize;
157  static bool mBlur;
158  static bool mUseTextureSampler;
159 };
160 
161 #endif // defined(USE_OPENGL) && !defined(ANDROID)
162 #endif // RESOURCES_SAFEOPENGLIMAGEHELPER_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
static const size_t texturesSize
Image * loadSurface(SDL_Surface *const tmpImage)
#define constexpr2
Definition: localconsts.h:48
#define A_WARN_UNUSED
Definition: localconsts.h:172
void copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *surface) const
#define final
Definition: localconsts.h:45
Definition: dye.h:39
Image * glLoad(SDL_Surface *tmpImage, int width=0, int height=0)
SDL_Surface * create32BitSurface(int width, int height) const
Image * load(SDL_RWops *const rw, Dye const &dye)
Image * createTextSurface(SDL_Surface *const tmpImage, const int width, const int height, const float alpha)
static void setUseTextureSampler(const bool b)
static SDL_Surface * convertSurface(SDL_Surface *tmpImage, int width, int height)
#define PRAGMA48(str)
Definition: localconsts.h:214
static void setBlur(const bool n)
static void setInternalTextureType(const int n)
Definition: image.h:61
static int powerOfTwo(const int input)
static void initTextureSampler(const GLint id)
static void invalidate(const GLuint textureId)
static SDL_Surface * convertSurfaceNormalize(SDL_Surface *tmpImage, int width, int height)
#define noexcept2
Definition: localconsts.h:49
GLuint mTextures[texturesSize]
static void bindTexture(const GLuint texture)