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

#include <openglimagehelper.h>

Inheritance diagram for OpenGLImageHelper:
ImageHelper

Public Member Functions

 OpenGLImageHelper ()
 
 ~OpenGLImageHelper ()
 
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 openglimagehelper.h.

Constructor & Destructor Documentation

◆ OpenGLImageHelper()

OpenGLImageHelper::OpenGLImageHelper ( )
inline

Definition at line 63 of file openglimagehelper.h.

References A_DELETE_COPY, A_WARN_UNUSED, createTextSurface(), ServerCommandType::dye, load(), loadSurface(), and ~OpenGLImageHelper().

63  :
65  mTextures()
66  {
67  }
GLuint mTextures[texturesSize]

◆ ~OpenGLImageHelper()

OpenGLImageHelper::~OpenGLImageHelper ( )

Definition at line 61 of file openglimagehelper.cpp.

References mFreeTextureIndex, mTextures, and texturesSize.

Referenced by OpenGLImageHelper().

62 {
63  glDeleteTextures(static_cast<GLsizei>(texturesSize - mFreeTextureIndex),
65 }
static const size_t texturesSize
GLuint mTextures[texturesSize]

Member Function Documentation

◆ bindTexture()

void OpenGLImageHelper::bindTexture ( const GLuint  texture)
static

Definition at line 253 of file openglimagehelper.cpp.

References MobileOpenGLGraphics::bindTexture(), SafeOpenGLGraphics::bindTexture(), MobileOpenGL2Graphics::bindTexture(), NormalOpenGLGraphics::bindTexture(), ModernOpenGLGraphics::bindTexture(), 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, RENDER_SOFTWARE, and reportAlways.

Referenced by emuglTextureSubImage2DEXT(), glLoad(), and setUseTextureSampler().

254 {
255  switch (mUseOpenGL)
256  {
257 #ifdef ANDROID
259  case RENDER_SAFE_OPENGL:
261  case RENDER_GLES2_OPENGL:
262  break;
263  case RENDER_GLES_OPENGL:
265  break;
266 #elif defined(__native_client__)
269  case RENDER_GLES_OPENGL:
270  break;
271  case RENDER_SAFE_OPENGL:
273  break;
274  case RENDER_GLES2_OPENGL:
276  break;
277 #else // ANDROID
278 
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 // ANDROID
295 
296  case RENDER_SOFTWARE:
297  case RENDER_SDL2_DEFAULT:
298  case RENDER_NULL:
299  case RENDER_LAST:
300  default:
301  reportAlways("Unknown OpenGL backend: %d", mUseOpenGL);
302  break;
303  }
304 }
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
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)
#define reportAlways(...)
Definition: checkutils.h:252

◆ convertSurface()

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

< Surface is in system memory

Definition at line 201 of file openglimagehelper.cpp.

References MSDL_CreateRGBSurface, and reportAlways.

Referenced by copySurfaceToImage(), and setUseTextureSampler().

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

◆ convertSurfaceNormalize()

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

< Surface is in system memory

Definition at line 139 of file openglimagehelper.cpp.

References MSDL_CreateRGBSurface, powerOfTwo(), and reportAlways.

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  reportAlways("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  reportAlways("Error, image convert failed: out of memory");
194  return nullptr;
195  }
196  SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr);
197  }
198  return tmpImage;
199 }
static int powerOfTwo(const int input)
#define reportAlways(...)
Definition: checkutils.h:252
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:54

◆ copySurfaceToImage()

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

Reimplemented from ImageHelper.

Definition at line 490 of file openglimagehelper.cpp.

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

Referenced by setUseTextureSampler().

493 {
494  if (surface == nullptr || image == nullptr)
495  return;
496 
497  SDL_Surface *const oldSurface = surface;
498  surface = convertSurface(surface, surface->w, surface->h);
499  if (surface == nullptr)
500  return;
501 
502  // +++ probably need combine
503  // mglTextureSubImage2D and mglTextureSubImage2DEXT
504  if (mglTextureSubImage2D != nullptr)
505  {
506  mglTextureSubImage2D(image->mGLImage,
507  0,
508  x, y,
509  surface->w, surface->h,
510  GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
511  }
512  else
513  {
514  mglTextureSubImage2DEXT(image->mGLImage,
515  mTextureType, 0,
516  x, y,
517  surface->w, surface->h,
518  GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
519  }
520 #ifdef OPENGLERRORS
522 #endif // OPENGLERRORS
523 
524  if (surface != oldSurface)
525  MSDL_FreeSurface(surface);
526 }
#define MSDL_FreeSurface(surface)
Definition: debug.h:53
GLuint mGLImage
Definition: image.h:182
static void logError()
static SDL_Surface * convertSurface(SDL_Surface *tmpImage, int width, int height)
GraphicsManager graphicsManager

◆ create32BitSurface()

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

< Surface is in system memory

Reimplemented from ImageHelper.

Definition at line 441 of file openglimagehelper.cpp.

References MSDL_CreateRGBSurface, and powerOfTwo().

Referenced by setUseTextureSampler().

443 {
444 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
445  const int rmask = 0xff000000;
446  const int gmask = 0x00ff0000;
447  const int bmask = 0x0000ff00;
448  const int amask = 0x000000ff;
449 #else // SDL_BYTEORDER == SDL_BIG_ENDIAN
450 
451  const int rmask = 0x000000ff;
452  const int gmask = 0x0000ff00;
453  const int bmask = 0x00ff0000;
454  const int amask = 0xff000000;
455 #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
456 
457  width = powerOfTwo(width);
458  height = powerOfTwo(height);
459 
460  return MSDL_CreateRGBSurface(SDL_SWSURFACE,
461  width, height, 32, rmask, gmask, bmask, amask);
462 }
static int powerOfTwo(const int input)
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:54

◆ createTextSurface()

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

Definition at line 118 of file openglimagehelper.cpp.

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

Referenced by OpenGLImageHelper().

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

◆ getInternalTextureType()

static int OpenGLImageHelper::getInternalTextureType ( )
inlinestatic

Definition at line 101 of file openglimagehelper.h.

References mInternalTextureType.

Referenced by Graphics::setOpenGLMode().

102  { return mInternalTextureType; }
static int mInternalTextureType

◆ getNewTexture()

GLuint OpenGLImageHelper::getNewTexture ( )
protected

Definition at line 464 of file openglimagehelper.cpp.

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

Referenced by glLoad(), and setUseTextureSampler().

465 {
466  GLuint texture = mTextures[mFreeTextureIndex];
469  {
470  mFreeTextureIndex = 0;
471  postInit();
472  }
473  return texture;
474 }
static const size_t texturesSize
GLuint mTextures[texturesSize]

◆ getTextureSize()

static int OpenGLImageHelper::getTextureSize ( )
inlinestatic

Definition at line 114 of file openglimagehelper.h.

References initTextureSampler(), and mTextureSize.

Referenced by AtlasManager::loadTextureAtlas(), and TestLauncher::testTextures().

115  { return mTextureSize; }

◆ getTextureType()

static int OpenGLImageHelper::getTextureType ( )
inlinestatic

Definition at line 98 of file openglimagehelper.h.

References mTextureType.

99  { return mTextureType; }

◆ glLoad()

Image * OpenGLImageHelper::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 306 of file openglimagehelper.cpp.

References bindTexture(), BLOCK_END, BLOCK_START, convertSurfaceNormalize(), Actions::error(), GraphicsManager::errorToString(), GraphicsManager::getLastError(), getNewTexture(), graphicsManager, Image, GraphicsManager::logError(), mBlur, mglTexImage2D, mglTexParameteri, mInternalTextureType, MSDL_FreeSurface, mTextureType, ImageHelper::mUseOpenGL, mUseTextureSampler, RENDER_GLES2_OPENGL, RENDER_GLES_OPENGL, RENDER_MODERN_OPENGL, reportAlways, and textures_count.

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

308 {
309  if (tmpImage == nullptr)
310  return nullptr;
311 
312  BLOCK_START("OpenGLImageHelper::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 
338  {
339  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
340 #ifdef OPENGLERRORS
342 #endif // OPENGLERRORS
343  }
344 
345  if (!mUseTextureSampler)
346  {
347  if (mBlur)
348  {
349  mglTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
350 #ifdef OPENGLERRORS
352 #endif // OPENGLERRORS
353 
354  mglTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
355 #ifdef OPENGLERRORS
357 #endif // OPENGLERRORS
358  }
359  else
360  {
361  mglTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
362 #ifdef OPENGLERRORS
364 #endif // OPENGLERRORS
365 
366  mglTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
367 #ifdef OPENGLERRORS
369 #endif // OPENGLERRORS
370  }
371  }
372 #if !defined(ANDROID) && !defined(__native_client__)
373  mglTexParameteri(mTextureType, GL_TEXTURE_MAX_LEVEL, 0);
374 #endif // !defined(ANDROID) && !defined(__native_client__)
375 
377  tmpImage->w, tmpImage->h,
378  0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);
379 #ifdef OPENGLERRORS
381 #endif // OPENGLERRORS
382 
383 #ifdef DEBUG_OPENGL
384 /*
385  disabled for now, because debugger can't show it
386  if (isGLNotNull(mglLabelObject))
387  {
388  const char *const text = "image text";
389  mglLabelObject(GL_TEXTURE, texture, strlen(text), text);
390  }
391 */
392 #endif // DEBUG_OPENGL
393 
394 /*
395  GLint compressed;
396  glGetTexLevelParameteriv(mTextureType, 0,
397  GL_TEXTURE_COMPRESSED_ARB, &compressed);
398  if (compressed)
399  logger->log("image compressed");
400  else
401  logger->log("image not compressed");
402 */
403 
404 #ifdef DEBUG_OPENGL_LEAKS
405  textures_count ++;
406 #endif // DEBUG_OPENGL_LEAKS
407 
408  if (SDL_MUSTLOCK(tmpImage))
409  SDL_UnlockSurface(tmpImage);
410 
411  if (oldImage != tmpImage)
412  MSDL_FreeSurface(tmpImage);
413 
415  if (error != 0u)
416  {
417  std::string errmsg = GraphicsManager::errorToString(error);
418  reportAlways("Error: Image GL import failed: %s (%u)",
419  errmsg.c_str(), error);
420 // return nullptr;
421  }
422 
423  BLOCK_END("OpenGLImageHelper::glLoad")
424  return new Image(texture, width, height, realWidth, realHeight);
425 }
int textures_count
Definition: client.cpp:125
#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
static RenderType mUseOpenGL
Definition: imagehelper.h:117
#define mglTexParameteri(...)
Definition: mgl.hpp:100
#define new
Definition: debug_new.h:147
#define mglTexImage2D(...)
Definition: mgl.hpp:102
static bool mUseTextureSampler
static void bindTexture(const GLuint texture)
static SDL_Surface * convertSurfaceNormalize(SDL_Surface *tmpImage, int width, int height)
static int mInternalTextureType
static void logError()
Definition: image.h:61
bool error(InputEvent &event) __attribute__((noreturn))
Definition: actions.cpp:81
static GLenum getLastError()
static std::string errorToString(const GLenum error)
#define reportAlways(...)
Definition: checkutils.h:252
GraphicsManager graphicsManager

◆ initTextureSampler()

void OpenGLImageHelper::initTextureSampler ( const GLint  id)
static

Definition at line 427 of file openglimagehelper.cpp.

References mBlur.

Referenced by GraphicsManager::createTextureSampler(), and getTextureSize().

428 {
429  if (mBlur)
430  {
431  mglSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
432  mglSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
433  }
434  else
435  {
436  mglSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
437  mglSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
438  }
439 }

◆ invalidate()

void OpenGLImageHelper::invalidate ( const GLuint  textureId)
static

Definition at line 481 of file openglimagehelper.cpp.

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

Referenced by Image::decRef(), and setUseTextureSampler().

482 {
483  if (isGLNotNull(mglInvalidateTexImage))
484  {
485  logger->log("invalidate: %u", textureId);
486  mglInvalidateTexImage(textureId, 0);
487  }
488 }
#define isGLNotNull(func)
Definition: mglcheck.h:27
Logger * logger
Definition: logger.cpp:95
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ load()

Image * OpenGLImageHelper::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 67 of file openglimagehelper.cpp.

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

Referenced by OpenGLImageHelper().

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

◆ loadSurface()

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

Loads an image from an SDL surface.

Reimplemented from ImageHelper.

Definition at line 113 of file openglimagehelper.cpp.

References glLoad().

Referenced by load(), and OpenGLImageHelper().

114 {
115  return glLoad(tmpImage);
116 }
Image * glLoad(SDL_Surface *tmpImage, int width=0, int height=0)

◆ postInit()

void OpenGLImageHelper::postInit ( )
virtual

Reimplemented from ImageHelper.

Definition at line 476 of file openglimagehelper.cpp.

References mFreeTextureIndex, mglGenTextures, mTextures, and texturesSize.

Referenced by getNewTexture(), and setUseTextureSampler().

477 {
479 }
static const size_t texturesSize
#define mglGenTextures(...)
Definition: mgl.hpp:104
GLuint mTextures[texturesSize]

◆ powerOfTwo()

int OpenGLImageHelper::powerOfTwo ( const int  input)
staticprotected

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

Definition at line 131 of file openglimagehelper.cpp.

References mTextureSize.

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

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

◆ setBlur()

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

Definition at line 107 of file openglimagehelper.h.

References mBlur.

Referenced by GraphicsManager::initGraphics().

108  { mBlur = n; }

◆ setInternalTextureType()

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

Definition at line 104 of file openglimagehelper.h.

References mInternalTextureType.

Referenced by GraphicsManager::updateTextureFormat().

105  { mInternalTextureType = n; }
static int mInternalTextureType

◆ setUseTextureSampler()

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

Friends And Related Function Documentation

◆ CompoundSprite

friend class CompoundSprite
friend

Definition at line 58 of file openglimagehelper.h.

◆ Graphics

friend class Graphics
friend

Definition at line 59 of file openglimagehelper.h.

◆ Image

friend class Image
friend

Definition at line 60 of file openglimagehelper.h.

Referenced by glLoad().

Field Documentation

◆ mBlur

bool OpenGLImageHelper::mBlur = true
staticprotected

Definition at line 157 of file openglimagehelper.h.

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

◆ mFreeTextureIndex

size_t OpenGLImageHelper::mFreeTextureIndex
protected

Definition at line 153 of file openglimagehelper.h.

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

◆ mInternalTextureType

int OpenGLImageHelper::mInternalTextureType = 0x8058
static

Definition at line 112 of file openglimagehelper.h.

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

◆ mTextures

GLuint OpenGLImageHelper::mTextures[texturesSize]
protected

Definition at line 154 of file openglimagehelper.h.

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

◆ mTextureSize

int OpenGLImageHelper::mTextureSize = 0
staticprotected

Definition at line 156 of file openglimagehelper.h.

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

◆ mTextureType

int OpenGLImageHelper::mTextureType = 0
static

Definition at line 110 of file openglimagehelper.h.

Referenced by bindTexture(), NormalOpenGLGraphics::calcPatternInline(), NullOpenGLGraphics::calcPatternInline(), NullOpenGLGraphics::calcTileVertexesInline(), NormalOpenGLGraphics::calcTileVertexesInline(), NormalOpenGLGraphics::completeCache(), MobileOpenGLGraphics::completeCache(), copySurfaceToImage(), GraphicsManager::createFBO(), NormalOpenGLGraphics::disableTexturingAndBlending(), MobileOpenGLGraphics::disableTexturingAndBlending(), NormalOpenGLGraphics::drawImageCached(), NormalOpenGLGraphics::drawImageInline(), NullOpenGLGraphics::drawImageInline(), MobileOpenGLGraphics::drawImageInline(), NormalOpenGLGraphics::drawPatternCached(), NullOpenGLGraphics::drawPatternInline(), MobileOpenGLGraphics::drawPatternInline(), NormalOpenGLGraphics::drawPatternInline(), ModernOpenGLGraphics::drawPatternInline(), drawQuad(), NullOpenGLGraphics::drawRescaledImage(), MobileOpenGLGraphics::drawRescaledImage(), NormalOpenGLGraphics::drawRescaledImage(), ModernOpenGLGraphics::drawRescaledImage(), NullOpenGLGraphics::drawRescaledPattern(), NormalOpenGLGraphics::drawRescaledPattern(), MobileOpenGLGraphics::drawRescaledPattern(), ModernOpenGLGraphics::drawRescaledPattern(), drawRescaledQuad(), MobileOpenGLGraphics::drawTileCollection(), NullOpenGLGraphics::drawTileCollection(), NormalOpenGLGraphics::drawTileCollection(), ModernOpenGLGraphics::drawTileCollection(), NormalOpenGLGraphics::drawTileVertexes(), MobileOpenGLGraphics::drawTileVertexes(), NullOpenGLGraphics::drawTileVertexes(), ModernOpenGLGraphics::drawTileVertexes(), NormalOpenGLGraphics::drawVertexes(), NullOpenGLGraphics::drawVertexes(), MobileOpenGLGraphics::enableTexturingAndBlending(), NormalOpenGLGraphics::enableTexturingAndBlending(), getTextureType(), glLoad(), Graphics::setOpenGLMode(), and NormalOpenGLGraphics::testDraw().

◆ mUseTextureSampler

bool OpenGLImageHelper::mUseTextureSampler = false
staticprotected

Definition at line 158 of file openglimagehelper.h.

Referenced by glLoad(), and setUseTextureSampler().

◆ texturesSize

const size_t OpenGLImageHelper::texturesSize = 10
staticprotected

Definition at line 152 of file openglimagehelper.h.

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


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