26 #if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__SWITCH__)
48 #ifndef SDL_BIG_ENDIAN
49 #error missing SDL_endian.h
67 SDL_Surface *
const tmpImage =
loadPng(rw);
68 if (tmpImage ==
nullptr)
70 logger->
log(
"Error, image load failed: %s", SDL_GetError());
79 uint32_t *pixels =
static_cast<uint32_t *
>(surf->pixels);
88 DYEPALETTEP(pal, SOGLColor)(pixels, surf->w * surf->h);
95 DYEPALETTEP(pal, AOGLColor)(pixels, surf->w * surf->h);
121 if (tmpImage ==
nullptr)
124 Image *
const img =
glLoad(tmpImage, width, height);
126 img->setAlpha(alpha);
143 if (tmpImage ==
nullptr)
149 if (realWidth < width || realHeight < height)
151 logger->
log(
"Warning: image too large, cropping to %dx%d texture!",
152 tmpImage->w, tmpImage->h);
156 SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
160 SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
164 uint32_t rmask, gmask, bmask, amask;
165 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
178 if (tmpImage->format->BitsPerPixel != 32
179 || realWidth != width || realHeight != height
180 || rmask != tmpImage->format->Rmask
181 || gmask != tmpImage->format->Gmask
182 || amask != tmpImage->format->Amask)
184 SDL_Surface *oldImage = tmpImage;
186 SDL_SetSurfaceBlendMode(oldImage, SDL_BLENDMODE_NONE);
190 32, rmask, gmask, bmask, amask);
192 if (tmpImage ==
nullptr)
194 logger->
log(
"Error, image convert failed: out of memory");
197 SDL_BlitSurface(oldImage,
nullptr, tmpImage,
nullptr);
206 if (tmpImage ==
nullptr)
210 SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
214 SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
218 uint32_t rmask, gmask, bmask, amask;
219 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
232 if (tmpImage->format->BitsPerPixel != 32
233 || rmask != tmpImage->format->Rmask
234 || gmask != tmpImage->format->Gmask
235 || amask != tmpImage->format->Amask)
237 SDL_Surface *oldImage = tmpImage;
239 SDL_SetSurfaceBlendMode(oldImage, SDL_BLENDMODE_NONE);
243 32, rmask, gmask, bmask, amask);
245 if (tmpImage ==
nullptr)
247 logger->
log(
"Error, image convert failed: out of memory");
250 SDL_BlitSurface(oldImage,
nullptr, tmpImage,
nullptr);
259 #ifdef __native_client__
270 #elif defined(ANDROID)
310 if (tmpImage ==
nullptr)
320 height = tmpImage->h;
322 SDL_Surface *oldImage = tmpImage;
324 if (tmpImage ==
nullptr)
327 const int realWidth = tmpImage->w;
328 const int realHeight = tmpImage->h;
333 if (SDL_MUSTLOCK(tmpImage))
334 SDL_LockSurface(tmpImage);
336 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
342 glTexParameteri(
mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
343 glTexParameteri(
mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
347 glTexParameteri(
mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
348 glTexParameteri(
mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
356 tmpImage->w, tmpImage->h,
357 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);
380 #ifdef DEBUG_OPENGL_LEAKS
384 if (SDL_MUSTLOCK(tmpImage))
385 SDL_UnlockSurface(tmpImage);
387 if (oldImage != tmpImage)
394 logger->
log(
"Error: Image GL import failed: %s (%u)",
395 errmsg.c_str(),
error);
399 BLOCK_END(
"SafeOpenGLImageHelper::glLoad")
400 return new Image(texture, width, height, realWidth, realHeight);
407 mglSamplerParameteri(
id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
408 mglSamplerParameteri(
id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
412 mglSamplerParameteri(
id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
413 mglSamplerParameteri(
id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
420 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
421 const uint32_t rmask = 0xff000000U;
422 const uint32_t gmask = 0x00ff0000U;
423 const uint32_t bmask = 0x0000ff00U;
424 const uint32_t amask = 0x000000ffU;
427 const uint32_t rmask = 0x000000ffU;
428 const uint32_t gmask = 0x0000ff00U;
429 const uint32_t bmask = 0x00ff0000U;
430 const uint32_t amask = 0xff000000U;
437 width, height, 32, rmask, gmask, bmask, amask);
461 logger->
log(
"invalidate: %u", textureId);
462 mglInvalidateTexImage(textureId, 0);
469 SDL_Surface *surface)
const
471 if (surface ==
nullptr || image ==
nullptr)
474 SDL_Surface *
const oldSurface = surface;
476 if (surface ==
nullptr)
481 if (mglTextureSubImage2D !=
nullptr)
483 mglTextureSubImage2D(image->mGLImage,
486 surface->w, surface->h,
487 GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
491 mglTextureSubImage2DEXT(image->mGLImage,
494 surface->w, surface->h,
495 GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
498 if (surface != oldSurface)
const DyePalette * getSPalete() const
const DyePalette * getAPalete() const
void normalOGLDye(uint32_t *pixels, const int bufSize) const
static GLenum getLastError()
static std::string errorToString(const GLenum error)
static RenderType mUseOpenGL
static SDL_Surface * convertTo32Bit(SDL_Surface *const tmpImage)
static SDL_Surface * loadPng(SDL_RWops *const rw)
void log(const char *const log_text,...)
Image * loadSurface(SDL_Surface *const tmpImage)
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)
static bool mUseTextureSampler
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)
static int mInternalTextureType
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)
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
#define MSDL_FreeSurface(surface)
#define DYEPALETTEP(palette, color)
GraphicsManager graphicsManager
#define isGLNotNull(func)
bool error(InputEvent &event) __attribute__((noreturn))
static void bindTexture(const GLenum target, const GLuint texture)
#define BLOCK_START(name)