ManaPlus
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
SafeOpenGLImageHelper Class Reference

#include <safeopenglimagehelper.h>

Inheritance diagram for SafeOpenGLImageHelper:
ImageHelper

Public Member Functions

 SafeOpenGLImageHelper ()
 
 ~SafeOpenGLImageHelper ()
 
Imageload (SDL_RWops *const rw, Dye const &dye)
 
ImageloadSurface (SDL_Surface *const tmpImage)
 
ImagecreateTextSurface (SDL_Surface *const tmpImage, const int width, const int height, const float alpha)
 
SDL_Surface * create32BitSurface (int width, int height) const
 
void postInit ()
 
void copySurfaceToImage (const Image *const image, const int x, const int y, SDL_Surface *surface) const
 
- Public Member Functions inherited from ImageHelper
virtual ~ImageHelper ()
 
Imageload (SDL_RWops *const rw)
 
virtual ImagecreateTextSurface (SDL_Surface *const tmpImage, const int width, const int height, const float alpha) const
 
virtual RenderType useOpenGL () const
 

Static Public Member Functions

static int getTextureType ()
 
static int getInternalTextureType ()
 
static void setInternalTextureType (const int n)
 
static void setBlur (const bool n)
 
static int getTextureSize ()
 
static void initTextureSampler (const GLint id)
 
static void setUseTextureSampler (const bool b)
 
static void invalidate (const GLuint textureId)
 
static void bindTexture (const GLuint texture)
 
- Static Public Member Functions inherited from ImageHelper
static SDL_Surface * convertTo32Bit (SDL_Surface *const tmpImage)
 
static void dumpSurfaceFormat (const SDL_Surface *const image)
 
static void setEnableAlpha (const bool n)
 
static SDL_Surface * loadPng (SDL_RWops *const rw)
 
static void setOpenGlMode (const RenderType useOpenGL)
 

Static Public Attributes

static int mTextureType = 0
 
static int mInternalTextureType = 0x8058
 

Protected Member Functions

ImageglLoad (SDL_Surface *tmpImage, int width=0, int height=0)
 
GLuint getNewTexture ()
 
- Protected Member Functions inherited from ImageHelper
 ImageHelper ()
 

Static Protected Member Functions

static int powerOfTwo (const int input)
 
static SDL_Surface * convertSurfaceNormalize (SDL_Surface *tmpImage, int width, int height)
 
static SDL_Surface * convertSurface (SDL_Surface *tmpImage, int width, int height)
 

Protected Attributes

size_t mFreeTextureIndex
 
GLuint mTextures [texturesSize]
 

Static Protected Attributes

static const size_t texturesSize = 10
 
static int mTextureSize = 0
 
static bool mBlur = true
 
static bool mUseTextureSampler = false
 
- Static Protected Attributes inherited from ImageHelper
static bool mEnableAlpha = true
 
static RenderType mUseOpenGL = RENDER_SOFTWARE
 

Friends

class CompoundSprite
 
class Graphics
 
class Image
 

Detailed Description

Defines a class for loading and storing images.

Definition at line 56 of file safeopenglimagehelper.h.

Constructor & Destructor Documentation

◆ SafeOpenGLImageHelper()

SafeOpenGLImageHelper::SafeOpenGLImageHelper ( )
inline

◆ ~SafeOpenGLImageHelper()

SafeOpenGLImageHelper::~SafeOpenGLImageHelper ( )

Definition at line 57 of file safeopenglimagehelper.cpp.

References mFreeTextureIndex, mTextures, and texturesSize.

Referenced by SafeOpenGLImageHelper().

58 {
59  glDeleteTextures(static_cast<GLsizei>(texturesSize - mFreeTextureIndex),
61 }
static const size_t texturesSize
GLuint mTextures[texturesSize]

Member Function Documentation

◆ bindTexture()

void SafeOpenGLImageHelper::bindTexture ( const GLuint  texture)
static

Definition at line 254 of file safeopenglimagehelper.cpp.

References SafeOpenGLGraphics::bindTexture(), MobileOpenGL2Graphics::bindTexture(), MobileOpenGLGraphics::bindTexture(), NormalOpenGLGraphics::bindTexture(), ModernOpenGLGraphics::bindTexture(), Logger::log(), logger, mTextureType, ImageHelper::mUseOpenGL, RENDER_GLES2_OPENGL, RENDER_GLES_OPENGL, RENDER_LAST, RENDER_MODERN_OPENGL, RENDER_NORMAL_OPENGL, RENDER_NULL, RENDER_SAFE_OPENGL, RENDER_SDL2_DEFAULT, and RENDER_SOFTWARE.

Referenced by glLoad(), and setUseTextureSampler().

255 {
256  switch (mUseOpenGL)
257  {
258 #ifdef __native_client__
261  case RENDER_GLES_OPENGL:
262  break;
263  case RENDER_SAFE_OPENGL:
265  break;
266  case RENDER_GLES2_OPENGL:
268  break;
269 #elif defined(ANDROID)
272  case RENDER_SAFE_OPENGL:
273  case RENDER_GLES2_OPENGL:
274  break;
275  case RENDER_GLES_OPENGL:
277  break;
278 #else // __native_client__
281  break;
284  break;
285  case RENDER_SAFE_OPENGL:
287  break;
288  case RENDER_GLES_OPENGL:
290  break;
291  case RENDER_GLES2_OPENGL:
293  break;
294 #endif // __native_client__
295  case RENDER_SOFTWARE:
296  case RENDER_SDL2_DEFAULT:
297  case RENDER_NULL:
298  case RENDER_LAST:
299  default:
300  logger->log("Unknown OpenGL backend: %d", mUseOpenGL);
301  break;
302  }
303 }
static void bindTexture(const GLenum target, const GLuint texture)
static void bindTexture(const GLenum target, const GLuint texture)
static RenderType mUseOpenGL
Definition: imagehelper.h:117
Logger * logger
Definition: logger.cpp:88
static void bindTexture(const GLenum target, const GLuint texture)
static void bindTexture(const GLenum target, const GLuint texture)
static void bindTexture(const GLenum target, const GLuint texture)
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ convertSurface()

SDL_Surface * SafeOpenGLImageHelper::convertSurface ( SDL_Surface *  tmpImage,
int  width,
int  height 
)
staticprotected

< Surface is in system memory

Definition at line 201 of file safeopenglimagehelper.cpp.

References Logger::log(), logger, and MSDL_CreateRGBSurface.

Referenced by copySurfaceToImage(), and setUseTextureSampler().

204 {
205  if (tmpImage == nullptr)
206  return nullptr;
207 
208 #ifdef USE_SDL2
209  SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
210 #else // USE_SDL2
211 
212  // Make sure the alpha channel is not used, but copied to destination
213  SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
214 #endif // USE_SDL2
215 
216  // Determine 32-bit masks based on byte order
217  uint32_t rmask, gmask, bmask, amask;
218 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
219  rmask = 0xff000000;
220  gmask = 0x00ff0000;
221  bmask = 0x0000ff00;
222  amask = 0x000000ff;
223 #else // SDL_BYTEORDER == SDL_BIG_ENDIAN
224 
225  rmask = 0x000000ff;
226  gmask = 0x0000ff00;
227  bmask = 0x00ff0000;
228  amask = 0xff000000;
229 #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
230 
231  if (tmpImage->format->BitsPerPixel != 32
232  || rmask != tmpImage->format->Rmask
233  || gmask != tmpImage->format->Gmask
234  || amask != tmpImage->format->Amask)
235  {
236  SDL_Surface *oldImage = tmpImage;
237 #ifdef USE_SDL2
238  SDL_SetSurfaceBlendMode(oldImage, SDL_BLENDMODE_NONE);
239 #endif // USE_SDL2
240 
241  tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
242  32, rmask, gmask, bmask, amask);
243 
244  if (tmpImage == nullptr)
245  {
246  logger->log("Error, image convert failed: out of memory");
247  return nullptr;
248  }
249  SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr);
250  }
251  return tmpImage;
252 }
Logger * logger
Definition: logger.cpp:88
void log(const char *const log_text,...)
Definition: logger.cpp:264
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:54

◆ convertSurfaceNormalize()

SDL_Surface * SafeOpenGLImageHelper::convertSurfaceNormalize ( SDL_Surface *  tmpImage,
int  width,
int  height 
)
staticprotected

< Surface is in system memory

Definition at line 137 of file safeopenglimagehelper.cpp.

References Logger::log(), logger, MSDL_CreateRGBSurface, and powerOfTwo().

Referenced by glLoad(), and setUseTextureSampler().

141 {
142  if (tmpImage == nullptr)
143  return nullptr;
144 
145  int realWidth = powerOfTwo(width);
146  int realHeight = powerOfTwo(height);
147 
148  if (realWidth < width || realHeight < height)
149  {
150  logger->log("Warning: image too large, cropping to %dx%d texture!",
151  tmpImage->w, tmpImage->h);
152  }
153 
154 #ifdef USE_SDL2
155  SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
156 #else // USE_SDL2
157 
158  // Make sure the alpha channel is not used, but copied to destination
159  SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
160 #endif // USE_SDL2
161 
162  // Determine 32-bit masks based on byte order
163  uint32_t rmask, gmask, bmask, amask;
164 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
165  rmask = 0xff000000;
166  gmask = 0x00ff0000;
167  bmask = 0x0000ff00;
168  amask = 0x000000ff;
169 #else // SDL_BYTEORDER == SDL_BIG_ENDIAN
170 
171  rmask = 0x000000ff;
172  gmask = 0x0000ff00;
173  bmask = 0x00ff0000;
174  amask = 0xff000000;
175 #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
176 
177  if (tmpImage->format->BitsPerPixel != 32
178  || realWidth != width || realHeight != height
179  || rmask != tmpImage->format->Rmask
180  || gmask != tmpImage->format->Gmask
181  || amask != tmpImage->format->Amask)
182  {
183  SDL_Surface *oldImage = tmpImage;
184 #ifdef USE_SDL2
185  SDL_SetSurfaceBlendMode(oldImage, SDL_BLENDMODE_NONE);
186 #endif // USE_SDL2
187 
188  tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight,
189  32, rmask, gmask, bmask, amask);
190 
191  if (tmpImage == nullptr)
192  {
193  logger->log("Error, image convert failed: out of memory");
194  return nullptr;
195  }
196  SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr);
197  }
198  return tmpImage;
199 }
Logger * logger
Definition: logger.cpp:88
static int powerOfTwo(const int input)
void log(const char *const log_text,...)
Definition: logger.cpp:264
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:54

◆ copySurfaceToImage()

void SafeOpenGLImageHelper::copySurfaceToImage ( const Image *const  image,
const int  x,
const int  y,
SDL_Surface *  surface 
) const
virtual

Reimplemented from ImageHelper.

Definition at line 465 of file safeopenglimagehelper.cpp.

References convertSurface(), Image::mGLImage, MSDL_FreeSurface, and mTextureType.

Referenced by setUseTextureSampler().

469 {
470  if (surface == nullptr || image == nullptr)
471  return;
472 
473  SDL_Surface *const oldSurface = surface;
474  surface = convertSurface(surface, surface->w, surface->h);
475  if (surface == nullptr)
476  return;
477 
478  // +++ probably need combine
479  // mglTextureSubImage2D and mglTextureSubImage2DEXT
480  if (mglTextureSubImage2D != nullptr)
481  {
482  mglTextureSubImage2D(image->mGLImage,
483  0,
484  x, y,
485  surface->w, surface->h,
486  GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
487  }
488  else
489  {
490  mglTextureSubImage2DEXT(image->mGLImage,
491  mTextureType, 0,
492  x, y,
493  surface->w, surface->h,
494  GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
495  }
496 
497  if (surface != oldSurface)
498  MSDL_FreeSurface(surface);
499 }
#define MSDL_FreeSurface(surface)
Definition: debug.h:53
static SDL_Surface * convertSurface(SDL_Surface *tmpImage, int width, int height)
GLuint mGLImage
Definition: image.h:182

◆ create32BitSurface()

SDL_Surface * SafeOpenGLImageHelper::create32BitSurface ( int  width,
int  height 
) const
virtual

< Surface is in system memory

Reimplemented from ImageHelper.

Definition at line 416 of file safeopenglimagehelper.cpp.

References MSDL_CreateRGBSurface, and powerOfTwo().

Referenced by setUseTextureSampler().

418 {
419 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
420  const int rmask = 0xff000000;
421  const int gmask = 0x00ff0000;
422  const int bmask = 0x0000ff00;
423  const int amask = 0x000000ff;
424 #else // SDL_BYTEORDER == SDL_BIG_ENDIAN
425 
426  const int rmask = 0x000000ff;
427  const int gmask = 0x0000ff00;
428  const int bmask = 0x00ff0000;
429  const int amask = 0xff000000;
430 #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
431 
432  width = powerOfTwo(width);
433  height = powerOfTwo(height);
434 
435  return MSDL_CreateRGBSurface(SDL_SWSURFACE,
436  width, height, 32, rmask, gmask, bmask, amask);
437 }
static int powerOfTwo(const int input)
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:54

◆ createTextSurface()

Image * SafeOpenGLImageHelper::createTextSurface ( SDL_Surface *const  tmpImage,
const int  width,
const int  height,
const float  alpha 
)

Definition at line 115 of file safeopenglimagehelper.cpp.

References glLoad(), and Image::setAlpha().

Referenced by SafeOpenGLImageHelper().

119 {
120  if (tmpImage == nullptr)
121  return nullptr;
122 
123  Image *const img = glLoad(tmpImage, width, height);
124  if (img != nullptr)
125  img->setAlpha(alpha);
126  return img;
127 }
Image * glLoad(SDL_Surface *tmpImage, int width=0, int height=0)
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
Definition: image.h:61

◆ getInternalTextureType()

static int SafeOpenGLImageHelper::getInternalTextureType ( )
inlinestatic

Definition at line 101 of file safeopenglimagehelper.h.

References mInternalTextureType.

102  { return mInternalTextureType; }

◆ getNewTexture()

GLuint SafeOpenGLImageHelper::getNewTexture ( )
protected

Definition at line 439 of file safeopenglimagehelper.cpp.

References mFreeTextureIndex, mTextures, postInit(), and texturesSize.

Referenced by glLoad(), and setUseTextureSampler().

440 {
441  GLuint texture = mTextures[mFreeTextureIndex];
444  {
445  mFreeTextureIndex = 0;
446  postInit();
447  }
448  return texture;
449 }
static const size_t texturesSize
GLuint mTextures[texturesSize]

◆ getTextureSize()

static int SafeOpenGLImageHelper::getTextureSize ( )
inlinestatic

Definition at line 114 of file safeopenglimagehelper.h.

References initTextureSampler(), and mTextureSize.

115  { return mTextureSize; }

◆ getTextureType()

static int SafeOpenGLImageHelper::getTextureType ( )
inlinestatic

Definition at line 98 of file safeopenglimagehelper.h.

References mTextureType.

99  { return mTextureType; }

◆ glLoad()

Image * SafeOpenGLImageHelper::glLoad ( SDL_Surface *  tmpImage,
int  width = 0,
int  height = 0 
)
protected

< Surface is in video memory

< Use asynchronous blits if possible

< Surface is RLE encoded

< Surface is in video memory

< Use asynchronous blits if possible

< Surface is RLE encoded

Definition at line 305 of file safeopenglimagehelper.cpp.

References bindTexture(), BLOCK_END, BLOCK_START, convertSurfaceNormalize(), Actions::error(), GraphicsManager::errorToString(), GraphicsManager::getLastError(), getNewTexture(), graphicsManager, Image, Logger::log(), logger, mBlur, mInternalTextureType, MSDL_FreeSurface, mTextureType, mUseTextureSampler, and textures_count.

Referenced by createTextSurface(), loadSurface(), and setUseTextureSampler().

308 {
309  if (tmpImage == nullptr)
310  return nullptr;
311 
312  BLOCK_START("SafeOpenGLImageHelper::glLoad")
313  // Flush current error flag.
314  graphicsManager.getLastError();
315 
316  if (width == 0)
317  width = tmpImage->w;
318  if (height == 0)
319  height = tmpImage->h;
320 
321  SDL_Surface *oldImage = tmpImage;
322  tmpImage = convertSurfaceNormalize(tmpImage, width, height);
323  if (tmpImage == nullptr)
324  return nullptr;
325 
326  const int realWidth = tmpImage->w;
327  const int realHeight = tmpImage->h;
328 
329  const GLuint texture = getNewTexture();
330  bindTexture(texture);
331 
332  if (SDL_MUSTLOCK(tmpImage))
333  SDL_LockSurface(tmpImage);
334 
335  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
336 
338  {
339  if (mBlur)
340  {
341  glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
342  glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
343  }
344  else
345  {
346  glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
347  glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
348  }
349  }
350 #ifndef ANDROID
351  glTexParameteri(mTextureType, GL_TEXTURE_MAX_LEVEL, 0);
352 #endif // ANDROID
353 
354  glTexImage2D(mTextureType, 0, mInternalTextureType,
355  tmpImage->w, tmpImage->h,
356  0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);
357 
358 #ifdef DEBUG_OPENGL
359 /*
360  disabled for now, because debugger can't show it
361  if (isGLNotNull(mglLabelObject))
362  {
363  const char *const text = "image text";
364  mglLabelObject(GL_TEXTURE, texture, strlen(text), text);
365  }
366 */
367 #endif // DEBUG_OPENGL
368 
369 /*
370  GLint compressed;
371  glGetTexLevelParameteriv(mTextureType, 0,
372  GL_TEXTURE_COMPRESSED_ARB, &compressed);
373  if (compressed)
374  logger->log("image compressed");
375  else
376  logger->log("image not compressed");
377 */
378 
379 #ifdef DEBUG_OPENGL_LEAKS
380  textures_count ++;
381 #endif // DEBUG_OPENGL_LEAKS
382 
383  if (SDL_MUSTLOCK(tmpImage))
384  SDL_UnlockSurface(tmpImage);
385 
386  if (oldImage != tmpImage)
387  MSDL_FreeSurface(tmpImage);
388 
390  if (error != 0u)
391  {
392  std::string errmsg = GraphicsManager::errorToString(error);
393  logger->log("Error: Image GL import failed: %s (%u)",
394  errmsg.c_str(), error);
395 // return nullptr;
396  }
397 
398  BLOCK_END("SafeOpenGLImageHelper::glLoad")
399  return new Image(texture, width, height, realWidth, realHeight);
400 }
int textures_count
Definition: client.cpp:136
#define MSDL_FreeSurface(surface)
Definition: debug.h:53
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Logger * logger
Definition: logger.cpp:88
#define new
Definition: debug_new.h:147
Definition: image.h:61
bool error(InputEvent &event) __attribute__((noreturn))
Definition: actions.cpp:81
static GLenum getLastError()
void log(const char *const log_text,...)
Definition: logger.cpp:264
static std::string errorToString(const GLenum error)
GraphicsManager graphicsManager
static SDL_Surface * convertSurfaceNormalize(SDL_Surface *tmpImage, int width, int height)
static void bindTexture(const GLuint texture)

◆ initTextureSampler()

void SafeOpenGLImageHelper::initTextureSampler ( const GLint  id)
static

Definition at line 402 of file safeopenglimagehelper.cpp.

References mBlur.

Referenced by getTextureSize().

403 {
404  if (mBlur)
405  {
406  mglSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
407  mglSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
408  }
409  else
410  {
411  mglSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
412  mglSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
413  }
414 }

◆ invalidate()

void SafeOpenGLImageHelper::invalidate ( const GLuint  textureId)
static

Definition at line 456 of file safeopenglimagehelper.cpp.

References isGLNotNull, Logger::log(), and logger.

Referenced by setUseTextureSampler().

457 {
458  if (isGLNotNull(mglInvalidateTexImage))
459  {
460  logger->log("invalidate: %u", textureId);
461  mglInvalidateTexImage(textureId, 0);
462  }
463 }
#define isGLNotNull(func)
Definition: mglcheck.h:27
Logger * logger
Definition: logger.cpp:88
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ load()

Image * SafeOpenGLImageHelper::load ( SDL_RWops *const  rw,
Dye const &  dye 
)
virtual

Loads an image from an SDL_RWops structure and recolors it.

Parameters
rwThe SDL_RWops to load the image from.
dyeThe dye used to recolor the image.
Returns
NULL if an error occurred, a valid pointer otherwise.

Reimplemented from ImageHelper.

Definition at line 63 of file safeopenglimagehelper.cpp.

References ImageHelper::convertTo32Bit(), DYEPALETTEP, Dye::getAPalete(), Dye::getSPalete(), Dye::getType(), ImageHelper::loadPng(), loadSurface(), Logger::log(), logger, MSDL_FreeSurface, and Dye::normalOGLDye().

Referenced by SafeOpenGLImageHelper().

65 {
66  SDL_Surface *const tmpImage = loadPng(rw);
67  if (tmpImage == nullptr)
68  {
69  logger->log("Error, image load failed: %s", SDL_GetError());
70  return nullptr;
71  }
72 
73  SDL_Surface *const surf = convertTo32Bit(tmpImage);
74  MSDL_FreeSurface(tmpImage);
75  if (surf == nullptr)
76  return nullptr;
77 
78  uint32_t *pixels = static_cast<uint32_t *>(surf->pixels);
79  const int type = dye.getType();
80 
81  switch (type)
82  {
83  case 1:
84  {
85  const DyePalette *const pal = dye.getSPalete();
86  if (pal != nullptr)
87  DYEPALETTEP(pal, SOGLColor)(pixels, surf->w * surf->h);
88  break;
89  }
90  case 2:
91  {
92  const DyePalette *const pal = dye.getAPalete();
93  if (pal != nullptr)
94  DYEPALETTEP(pal, AOGLColor)(pixels, surf->w * surf->h);
95  break;
96  }
97  case 0:
98  default:
99  {
100  dye.normalOGLDye(pixels, surf->w * surf->h);
101  break;
102  }
103  }
104 
105  Image *const image = loadSurface(surf);
106  MSDL_FreeSurface(surf);
107  return image;
108 }
Image * loadSurface(SDL_Surface *const tmpImage)
static SDL_Surface * loadPng(SDL_RWops *const rw)
#define MSDL_FreeSurface(surface)
Definition: debug.h:53
static SDL_Surface * convertTo32Bit(SDL_Surface *const tmpImage)
Logger * logger
Definition: logger.cpp:88
#define DYEPALETTEP(palette, color)
Definition: dyepalette.h:39
Definition: image.h:61
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ loadSurface()

Image * SafeOpenGLImageHelper::loadSurface ( SDL_Surface *const  tmpImage)
virtual

Loads an image from an SDL surface.

Reimplemented from ImageHelper.

Definition at line 110 of file safeopenglimagehelper.cpp.

References glLoad().

Referenced by load(), and SafeOpenGLImageHelper().

111 {
112  return glLoad(tmpImage);
113 }
Image * glLoad(SDL_Surface *tmpImage, int width=0, int height=0)

◆ postInit()

void SafeOpenGLImageHelper::postInit ( )
virtual

Reimplemented from ImageHelper.

Definition at line 451 of file safeopenglimagehelper.cpp.

References mFreeTextureIndex, mTextures, and texturesSize.

Referenced by getNewTexture(), and setUseTextureSampler().

452 {
453  glGenTextures(texturesSize, &mTextures[mFreeTextureIndex]);
454 }
static const size_t texturesSize
GLuint mTextures[texturesSize]

◆ powerOfTwo()

int SafeOpenGLImageHelper::powerOfTwo ( const int  input)
staticprotected

Returns the first power of two equal or bigger than the input.

Definition at line 129 of file safeopenglimagehelper.cpp.

References mTextureSize.

Referenced by convertSurfaceNormalize(), create32BitSurface(), and setUseTextureSampler().

130 {
131  int value = 1;
132  while (value < input && value < mTextureSize)
133  value <<= 1;
134  return value >= mTextureSize ? mTextureSize : value;
135 }

◆ setBlur()

static void SafeOpenGLImageHelper::setBlur ( const bool  n)
inlinestatic

Definition at line 107 of file safeopenglimagehelper.h.

References mBlur.

Referenced by GraphicsManager::initGraphics().

108  { mBlur = n; }

◆ setInternalTextureType()

static void SafeOpenGLImageHelper::setInternalTextureType ( const int  n)
inlinestatic

Definition at line 104 of file safeopenglimagehelper.h.

References mInternalTextureType.

Referenced by GraphicsManager::updateTextureFormat().

105  { mInternalTextureType = n; }

◆ setUseTextureSampler()

static void SafeOpenGLImageHelper::setUseTextureSampler ( const bool  b)
inlinestatic

Friends And Related Function Documentation

◆ CompoundSprite

friend class CompoundSprite
friend

Definition at line 58 of file safeopenglimagehelper.h.

◆ Graphics

friend class Graphics
friend

Definition at line 59 of file safeopenglimagehelper.h.

◆ Image

friend class Image
friend

Definition at line 60 of file safeopenglimagehelper.h.

Referenced by glLoad().

Field Documentation

◆ mBlur

bool SafeOpenGLImageHelper::mBlur = true
staticprotected

Definition at line 157 of file safeopenglimagehelper.h.

Referenced by glLoad(), initTextureSampler(), and setBlur().

◆ mFreeTextureIndex

size_t SafeOpenGLImageHelper::mFreeTextureIndex
protected

Definition at line 153 of file safeopenglimagehelper.h.

Referenced by getNewTexture(), postInit(), and ~SafeOpenGLImageHelper().

◆ mInternalTextureType

int SafeOpenGLImageHelper::mInternalTextureType = 0x8058
static

Definition at line 112 of file safeopenglimagehelper.h.

Referenced by getInternalTextureType(), glLoad(), and setInternalTextureType().

◆ mTextures

GLuint SafeOpenGLImageHelper::mTextures[texturesSize]
protected

Definition at line 154 of file safeopenglimagehelper.h.

Referenced by getNewTexture(), postInit(), and ~SafeOpenGLImageHelper().

◆ mTextureSize

int SafeOpenGLImageHelper::mTextureSize = 0
staticprotected

Definition at line 156 of file safeopenglimagehelper.h.

Referenced by getTextureSize(), powerOfTwo(), and Graphics::setOpenGLMode().

◆ mTextureType

int SafeOpenGLImageHelper::mTextureType = 0
static

◆ mUseTextureSampler

bool SafeOpenGLImageHelper::mUseTextureSampler = false
staticprotected

Definition at line 158 of file safeopenglimagehelper.h.

Referenced by glLoad(), and setUseTextureSampler().

◆ texturesSize

const size_t SafeOpenGLImageHelper::texturesSize = 10
staticprotected

Definition at line 152 of file safeopenglimagehelper.h.

Referenced by getNewTexture(), postInit(), and ~SafeOpenGLImageHelper().


The documentation for this class was generated from the following files: