Fix some bitmap and gl-meta bugs in libretro builds

This commit is contained in:
刘皓 2025-02-19 21:49:59 -05:00
parent 20c8f6d463
commit 071be23d74
No known key found for this signature in database
GPG key ID: 7901753DB465B711
3 changed files with 55 additions and 20 deletions

View file

@ -423,6 +423,7 @@ struct BitmapPrivate
FBO::clear();
glState.clearColor.pop();
glState.scissorBox.pop();
glState.scissorTest.pop();
}
@ -443,7 +444,9 @@ struct BitmapPrivate
{
if (surface && freeSurface)
{
#ifndef MKXPZ_RETRO
#ifdef MKXPZ_RETRO
delete surface;
#else
SDL_FreeSurface(surface);
#endif // MKXPZ_RETRO
surface = 0;
@ -570,9 +573,7 @@ Bitmap::Bitmap(const char *filename)
handler.gif->width, handler.gif->height, glState.caps.maxTexSize, glState.caps.maxTexSize);
}
#endif // MKXPZ_RETRO
p = new BitmapPrivate(this);
#ifndef MKXPZ_RETRO
p->selfHires = hiresBitmap;
@ -667,9 +668,15 @@ Bitmap::Bitmap(const char *filename)
}
SDL_Surface *imgSurf = handler.surface;
initFromSurface(imgSurf, hiresBitmap, false);
#endif // MKXPZ_RETRO
#ifdef MKXPZ_RETRO
SDL_Surface *imgSurf = new SDL_Surface;
// TODO: use actual image dimensions
imgSurf->w = 64;
imgSurf->h = 64;
#endif // MKXPZ_RETRO
initFromSurface(imgSurf, hiresBitmap, false);
}
Bitmap::Bitmap(int width, int height, bool isHires)
@ -732,24 +739,30 @@ Bitmap::Bitmap(void *pixeldata, int width, int height)
}
else
{
#endif // MKXPZ_RETRO
TEXFBO tex;
try
{
#ifdef MKXPZ_RETRO
tex = shState->texPool().request(64, 64); // TODO: use actual image dimensions
#else
tex = shState->texPool().request(surface->w, surface->h);
#endif // MKXPZ_RETRO
}
catch (const Exception &e)
{
#ifndef MKXPZ_RETRO
SDL_FreeSurface(surface);
#endif // MKXPZ_RETRO
throw e;
}
#endif // MKXPZ_RETRO
p = new BitmapPrivate(this);
#ifndef MKXPZ_RETRO
p->gl = tex;
TEX::bind(p->gl.tex);
#ifndef MKXPZ_RETRO
TEX::uploadImage(p->gl.width, p->gl.height, surface->pixels, GL_RGBA);
SDL_FreeSurface(surface);
@ -909,7 +922,9 @@ void Bitmap::initFromSurface(SDL_Surface *imgSurf, Bitmap *hiresBitmap, bool for
{
if (hiresBitmap)
delete hiresBitmap;
#ifndef MKXPZ_RETRO
#ifdef MKXPZ_RETRO
delete imgSurf;
#else
SDL_FreeSurface(imgSurf);
#endif // MKXPZ_RETRO
throw e;
@ -923,9 +938,13 @@ void Bitmap::initFromSurface(SDL_Surface *imgSurf, Bitmap *hiresBitmap, bool for
}
TEX::bind(p->gl.tex);
TEX::uploadImage(p->gl.width, p->gl.height, imgSurf->pixels, GL_RGBA);
#ifndef MKXPZ_RETRO
TEX::uploadImage(p->gl.width, p->gl.height, imgSurf->pixels, GL_RGBA);
#endif // MKXPZ_RETRO
#ifdef MKXPZ_RETRO
delete imgSurf;
#else
SDL_FreeSurface(imgSurf);
#endif // MKXPZ_RETRO
}
@ -2504,8 +2523,10 @@ int Bitmap::addFrame(Bitmap &source, int position)
p->animation.frames.push_back(p->gl);
#ifndef MKXPZ_RETRO
if (p->surface)
#ifdef MKXPZ_RETRO
delete p->surface;
#else
SDL_FreeSurface(p->surface);
#endif // MKXPZ_RETRO
p->gl = TEXFBO();
@ -2514,7 +2535,9 @@ int Bitmap::addFrame(Bitmap &source, int position)
if (source.surface()) {
TEX::bind(newframe.tex);
TEX::uploadImage(source.width(), source.height(), source.surface()->pixels, GL_RGBA);
#ifndef MKXPZ_RETRO
#ifdef MKXPZ_RETRO
delete p->surface;
#else
SDL_FreeSurface(p->surface);
#endif // MKXPZ_RETRO
p->surface = 0;
@ -2714,12 +2737,13 @@ void Bitmap::releaseResources()
delete p->selfHires;
}
#ifndef MKXPZ_RETRO
if (p->megaSurface)
#ifdef MKXPZ_RETRO
delete p->megaSurface;
#else
SDL_FreeSurface(p->megaSurface);
else
#endif // MKXPZ_RETRO
if (p->animation.enabled) {
else if (p->animation.enabled) {
p->animation.enabled = false;
p->animation.playing = false;
for (TEXFBO &tex : p->animation.frames)

View file

@ -211,10 +211,21 @@ int smoothScalingMethod(int scaleIsSpecial)
static void _blitBegin(FBO::ID fbo, const Vec2i &size, int scaleIsSpecial)
{
FBO::bind(fbo);
if (!HAVE_NATIVE_BLIT)
if (HAVE_NATIVE_BLIT)
{
FBO::boundFramebufferID = fbo;
gl.BindFramebuffer(
GL_DRAW_FRAMEBUFFER,
#ifdef MKXPZ_RETRO
fbo.gl != 0 ? fbo.gl : mkxp_retro::hw_render.get_current_framebuffer()
#else
fbo.gl
#endif // MKXPZ_RETRO
);
}
else
{
FBO::bind(fbo);
glState.viewport.pushSet(IntRect(0, 0, size.x, size.y));
switch (smoothScalingMethod(scaleIsSpecial))
@ -320,7 +331,7 @@ void blitSource(TEXFBO &source, int scaleIsSpecial)
gl.BindFramebuffer(
GL_READ_FRAMEBUFFER,
#ifdef MKXPZ_RETRO
source.fbo.gl || mkxp_retro::hw_render.get_current_framebuffer()
source.fbo.gl != 0 ? source.fbo.gl : mkxp_retro::hw_render.get_current_framebuffer()
#else
source.fbo.gl
#endif // MKXPZ_RETRO

View file

@ -145,7 +145,7 @@ namespace FBO
gl.BindFramebuffer(
GL_FRAMEBUFFER,
#ifdef MKXPZ_RETRO
id.gl || mkxp_retro::hw_render.get_current_framebuffer()
id.gl != 0 ? id.gl : mkxp_retro::hw_render.get_current_framebuffer()
#else
id.gl
#endif // MKXPZ_RETRO