Add mipmap scaling

Yields a substantial quality improvement when the window is much smaller
than the rendered resolution.
This commit is contained in:
Splendide Imaginarius 2024-03-18 02:02:55 +00:00
parent 8e62dfe68d
commit fcb36d22fb
5 changed files with 23 additions and 1 deletions

View file

@ -89,6 +89,13 @@
// "smoothScaling": 0,
// Apply mipmap interpolation when game screen
// is downscaled
// (default: false)
//
// "smoothScalingMipmaps": false,
// Sharpness when using Bicubic scaling.
// A good starting range is 0 to 100,
// but you may wish to go outside that range in either direction.

View file

@ -135,6 +135,7 @@ void Config::read(int argc, char *argv[]) {
{"fullscreen", false},
{"fixedAspectRatio", true},
{"smoothScaling", 0},
{"smoothScalingMipmaps", false},
{"bicubicSharpness", 100},
#ifdef MKXPZ_SSL
{"xbrzScalingFactor", 1.},
@ -269,6 +270,7 @@ try { exp } catch (...) {}
SET_OPT(fullscreen, boolean);
SET_OPT(fixedAspectRatio, boolean);
SET_OPT(smoothScaling, integer);
SET_OPT(smoothScalingMipmaps, boolean);
SET_OPT(bicubicSharpness, integer);
#ifdef MKXPZ_SSL
SET_OPT(xbrzScalingFactor, integer);

View file

@ -44,6 +44,7 @@ struct Config {
bool fullscreen;
bool fixedAspectRatio;
int smoothScaling;
bool smoothScalingMipmaps;
int bicubicSharpness;
#ifdef MKXPZ_SSL
double xbrzScalingFactor;

View file

@ -54,6 +54,8 @@ typedef void (APIENTRYP _PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint
typedef void (APIENTRYP _PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
typedef void (APIENTRYP _PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
typedef void (APIENTRYP _PFNGLACTIVETEXTUREPROC) (GLenum texture);
typedef void (APIENTRYP _PFNGLGENERATEMIPMAPPROC) (GLenum target);
typedef void (APIENTRYP _PFNGLGENERATETEXTUREMIPMAPPROC) (GLuint texture);
/* Debugging */
typedef void (APIENTRY * _GLDEBUGPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void *userParam);
@ -148,6 +150,8 @@ typedef void (APIENTRYP _PFNGLRELEASESHADERCOMPILERPROC) (void);
GL_FUN(TexSubImage2D, _PFNGLTEXSUBIMAGE2DPROC) \
GL_FUN(TexParameteri, _PFNGLTEXPARAMETERIPROC) \
GL_FUN(ActiveTexture, _PFNGLACTIVETEXTUREPROC) \
GL_FUN(GenerateMipmap, _PFNGLGENERATEMIPMAPPROC) \
GL_FUN(GenerateTextureMipmap, _PFNGLGENERATETEXTUREMIPMAPPROC) \
/* Buffer object */ \
GL_FUN(GenBuffers, _PFNGLGENBUFFERSPROC) \
GL_FUN(DeleteBuffers, _PFNGLDELETEBUFFERSPROC) \

View file

@ -24,6 +24,8 @@
#include "gl-fun.h"
#include "etc-internal.h"
#include "sharedstate.h"
#include "config.h"
/* Struct wrapping GLuint for some light type safety */
#define DEF_GL_ID \
@ -99,7 +101,13 @@ namespace TEX
static inline void setSmooth(bool mode)
{
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mode ? GL_LINEAR : GL_NEAREST);
if (mode && shState->config().smoothScalingMipmaps) {
gl.GenerateMipmap(GL_TEXTURE_2D);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
} else {
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mode ? GL_LINEAR : GL_NEAREST);
}
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mode ? GL_LINEAR : GL_NEAREST);
}
}