33 #ifdef __native_client__
52 #ifndef SDL_BIG_ENDIAN
53 #error missing SDL_endian.h
70 SDL_Surface *
const tmpImage =
loadPng(rw);
71 if (tmpImage ==
nullptr)
73 reportAlways(
"Error, image load failed: %s", SDL_GetError())
82 uint32_t *pixels =
static_cast<uint32_t *
>(surf->pixels);
91 DYEPALETTEP(pal, SOGLColor)(pixels, surf->w * surf->h);
98 DYEPALETTEP(pal, AOGLColor)(pixels, surf->w * surf->h);
120 const int width,
const int height,
123 if (tmpImage ==
nullptr)
126 Image *
const img =
glLoad(tmpImage, width, height);
128 img->setAlpha(alpha);
141 int width,
int height)
143 if (tmpImage ==
nullptr)
149 if (realWidth < width || realHeight < height)
151 reportAlways(
"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 reportAlways(
"Error, image convert failed: out of memory")
197 SDL_BlitSurface(oldImage,
nullptr, tmpImage,
nullptr);
203 int width,
int height)
205 if (tmpImage ==
nullptr)
209 SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
213 SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
217 uint32_t rmask, gmask, bmask, amask;
218 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
231 if (tmpImage->format->BitsPerPixel != 32
232 || rmask != tmpImage->format->Rmask
233 || gmask != tmpImage->format->Gmask
234 || amask != tmpImage->format->Amask)
236 SDL_Surface *oldImage = tmpImage;
238 SDL_SetSurfaceBlendMode(oldImage, SDL_BLENDMODE_NONE);
242 32, rmask, gmask, bmask, amask);
244 if (tmpImage ==
nullptr)
246 reportAlways(
"Error, image convert failed: out of memory")
249 SDL_BlitSurface(oldImage,
nullptr, tmpImage,
nullptr);
267 #elif defined(__native_client__) || defined(__SWITCH__)
310 int width,
int height)
312 if (tmpImage ==
nullptr)
322 height = tmpImage->h;
324 SDL_Surface *oldImage = tmpImage;
326 if (tmpImage ==
nullptr)
329 const int realWidth = tmpImage->w;
330 const int realHeight = tmpImage->h;
335 if (SDL_MUSTLOCK(tmpImage))
336 SDL_LockSurface(tmpImage);
343 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
377 #if !defined(ANDROID) && !defined(__native_client__)
382 tmpImage->w, tmpImage->h,
383 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);
409 #ifdef DEBUG_OPENGL_LEAKS
413 if (SDL_MUSTLOCK(tmpImage))
414 SDL_UnlockSurface(tmpImage);
416 if (oldImage != tmpImage)
424 errmsg.c_str(),
error)
429 return new Image(texture, width, height, realWidth, realHeight);
436 mglSamplerParameteri(
id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
437 mglSamplerParameteri(
id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
441 mglSamplerParameteri(
id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
442 mglSamplerParameteri(
id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
449 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
450 const uint32_t rmask = 0xff000000U;
451 const uint32_t gmask = 0x00ff0000U;
452 const uint32_t bmask = 0x0000ff00U;
453 const uint32_t amask = 0x000000ffU;
456 const uint32_t rmask = 0x000000ffU;
457 const uint32_t gmask = 0x0000ff00U;
458 const uint32_t bmask = 0x00ff0000U;
459 const uint32_t amask = 0xff000000U;
466 width, height, 32, rmask, gmask, bmask, amask);
490 logger->
log(
"invalidate: %u", textureId);
491 mglInvalidateTexImage(textureId, 0);
496 const int x,
const int y,
497 SDL_Surface *surface)
const
499 if (surface ==
nullptr || image ==
nullptr)
502 SDL_Surface *
const oldSurface = surface;
504 if (surface ==
nullptr)
509 if (mglTextureSubImage2D !=
nullptr)
511 mglTextureSubImage2D(image->mGLImage,
514 surface->w, surface->h,
515 GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
519 mglTextureSubImage2DEXT(image->mGLImage,
522 surface->w, surface->h,
523 GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
529 if (surface != oldSurface)
#define reportAlways(...)
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)
static void initTextureSampler(const GLint id)
static SDL_Surface * convertSurfaceNormalize(SDL_Surface *tmpImage, int width, int height)
static void invalidate(const GLuint textureId)
static SDL_Surface * convertSurface(SDL_Surface *tmpImage, int width, int height)
GLuint mTextures[texturesSize]
SDL_Surface * create32BitSurface(int width, int height) const
Image * glLoad(SDL_Surface *tmpImage, int width=0, int height=0)
Image * createTextSurface(SDL_Surface *const tmpImage, const int width, const int height, const float alpha)
static void bindTexture(const GLuint texture)
static int mInternalTextureType
static bool mUseTextureSampler
static int powerOfTwo(const int input)
Image * load(SDL_RWops *const rw, Dye const &dye)
void copySurfaceToImage(const Image *const image, const int x, const int y, SDL_Surface *surface) const
static const size_t texturesSize
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
#define MSDL_FreeSurface(surface)
#define DYEPALETTEP(palette, color)
GraphicsManager graphicsManager
#define mglTexParameteri(...)
#define mglGenTextures(...)
#define mglTexImage2D(...)
#define isGLNotNull(func)
bool error(InputEvent &event) __attribute__((noreturn))
static void bindTexture(const GLenum target, const GLuint texture)
#define BLOCK_START(name)