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-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_SAFEOPENGLIMAGEHELPER_H
25 #define RESOURCES_SAFEOPENGLIMAGEHELPER_H
26 
27 #include "localconsts.h"
28 
29 #if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__SWITCH__)
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 
71 {
72  friend class CompoundSprite;
73  friend class Graphics;
74  friend class Image;
75 
76  public:
79  mTextures()
80  {
81  }
82 
84 
86 
96  Image *load(SDL_RWops *const rw,
97  Dye const &dye) override final A_WARN_UNUSED;
98 
102  Image *loadSurface(SDL_Surface *const tmpImage)
104 
105  Image *createTextSurface(SDL_Surface *const tmpImage,
106  const int width, const int height,
107  const float alpha)
109 
110  // OpenGL only public functions
111 
113  { return mTextureType; }
114 
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 
127 
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:
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;
169 
170  static int mTextureSize;
171  static bool mBlur;
172  static bool mUseTextureSampler;
173 };
174 
175 #endif // defined(USE_OPENGL) && !defined(ANDROID)
176 #endif // RESOURCES_SAFEOPENGLIMAGEHELPER_H
Definition: dye.h:41
static void setBlur(const bool n)
Image * loadSurface(SDL_Surface *const tmpImage)
static void setUseTextureSampler(const bool b)
Image * glLoad(SDL_Surface *tmpImage, int width=0, int height=0)
static const size_t texturesSize
static void bindTexture(const GLuint texture)
static void invalidate(const GLuint textureId)
Image * load(SDL_RWops *const rw, Dye const &dye)
Image * createTextSurface(SDL_Surface *const tmpImage, const int width, const int height, const float alpha)
GLuint mTextures[texturesSize]
void copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *surface) const
static SDL_Surface * convertSurfaceNormalize(SDL_Surface *tmpImage, int width, int height)
static int powerOfTwo(const int input)
SDL_Surface * create32BitSurface(int width, int height) const
static SDL_Surface * convertSurface(SDL_Surface *tmpImage, int width, int height)
static void initTextureSampler(const GLint id)
static void setInternalTextureType(const int n)
#define constexpr2
Definition: localconsts.h:49
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define PRAGMA48(str)
Definition: localconsts.h:199
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class Dye