Bitmap: make GUARD_MEGA attempt to convert Mega into non-Mega

This commit is contained in:
Splendide Imaginarius 2024-10-06 11:04:58 +00:00
parent faf17e64f2
commit f78bad83d6

View file

@ -60,9 +60,13 @@ extern "C" {
#define GUARD_MEGA \
{ \
if (p->megaSurface) \
if (p->megaSurface) { \
p->ensureNonMega(); \
if (p->megaSurface) { \
throw Exception(Exception::MKXPError, \
"Operation not supported for mega surfaces"); \
} \
} \
}
#define GUARD_ANIMATED \
@ -408,6 +412,43 @@ struct BitmapPrivate
SDL_FreeSurface(surf);
surf = surfConv;
}
void ensureNonMega()
{
if (selfHires != nullptr) {
if (selfHires->width() > glState.caps.maxTexSize || selfHires->height() > glState.caps.maxTexSize) {
return;
}
selfHires->ensureNonMega();
}
if (megaSurface->w > glState.caps.maxTexSize || megaSurface->h > glState.caps.maxTexSize)
{
return;
}
TEXFBO tex;
try
{
tex = shState->texPool().request(megaSurface->w, megaSurface->h);
}
catch (const Exception &e)
{
return;
}
gl = tex;
if (selfHires != nullptr) {
gl.selfHires = &selfHires->getGLTypes();
}
TEX::bind(gl.tex);
TEX::uploadImage(gl.width, gl.height, megaSurface->pixels, GL_RGBA);
SDL_FreeSurface(megaSurface);
megaSurface = nullptr;
}
void onModified(bool freeSurface = true)
{