Compare commits

...

2 Commits

Author SHA1 Message Date
Amaryllis Kulla bfe889f00a Add lastMileScaling, fix bugs, and expose options to MRI 2021-10-27 19:20:34 +02:00
Ancurio fb16c8e6d0 Graphics: PoC integer scaling 2021-10-10 10:07:27 +02:00
7 changed files with 237 additions and 10 deletions

View File

@ -203,6 +203,9 @@ DEF_GRA_PROP_B(Fullscreen)
DEF_GRA_PROP_B(ShowCursor)
DEF_GRA_PROP_B(FixedAspectRatio)
DEF_GRA_PROP_B(SmoothScaling)
DEF_GRA_PROP_B(IntegerScaling)
DEF_GRA_PROP_B(LastMileScaling)
#define INIT_GRA_PROP_BIND(PropName, prop_name_s) \
{ \
@ -225,6 +228,9 @@ void graphicsBindingInit()
INIT_GRA_PROP_BIND( FrameCount, "frame_count" );
INIT_GRA_PROP_BIND( FixedAspectRatio, "fixed_aspect_ratio" );
INIT_GRA_PROP_BIND( SmoothScaling, "smooth_scaling" );
INIT_GRA_PROP_BIND( IntegerScaling, "integer_scaling" );
INIT_GRA_PROP_BIND( LastMileScaling, "last_mile_scaling" );
if (rgssVer >= 2)
{

View File

@ -150,6 +150,30 @@
# maxTextureSize=0
# Scale up the game screen by an integer amount,
# as large as the current window size allows, before
# doing any last additional scalings to fill part or
# all of the remaining window space (or none at all
# if lastMileScaling is disabled).
# If fixedAspectRatio is disabled, the integer scale
# factors in horizontal and vertical direction can differ
# depending on how much space is available, otherwise
# they are forced to the smaller of the two.
# (default: disabled)
#
# integerScaling.active = false
# When integer scaling is enabled, this option controls
# whether the scaled game screen is further scaled
# (with linear interpolation when smoothScaling is enabled)
# to fill the rest of the game window.
# Note that this option still respects fixedAspectRatio.
# (default: enabled)
#
# integerScaling.lastMileScaling = true
# Set the base path of the game to '/path/to/game'
# (default: executable directory)
#

View File

@ -170,6 +170,8 @@ void Config::read(int argc, char *argv[])
PO_DESC(subImageFix, bool, false) \
PO_DESC(enableBlitting, bool, true) \
PO_DESC(maxTextureSize, int, 0) \
PO_DESC(integerScaling.active, bool, false) \
PO_DESC(integerScaling.lastMileScaling, bool, true) \
PO_DESC(gameFolder, std::string, ".") \
PO_DESC(anyAltToggleFS, bool, false) \
PO_DESC(enableReset, bool, true) \

View File

@ -59,6 +59,12 @@ struct Config
bool enableBlitting;
int maxTextureSize;
struct
{
bool active;
bool lastMileScaling;
} integerScaling;
std::string gameFolder;
bool anyAltToggleFS;
bool enableReset;

View File

@ -477,6 +477,11 @@ struct GraphicsPrivate
TEXFBO frozenScene;
Quad screenQuad;
Vec2i integerScaleFactor;
TEXFBO integerScaleBuffer;
bool integerScaleActive;
bool integerLastMileScaling;
/* Global list of all live Disposables
* (disposed on reset) */
IntruList<Disposable> dispList;
@ -492,9 +497,18 @@ struct GraphicsPrivate
frameCount(0),
brightness(255),
fpsLimiter(frameRate),
frozen(false)
frozen(false),
integerScaleFactor(0, 0),
integerScaleActive(rtData->config.integerScaling.active),
integerLastMileScaling(rtData->config.integerScaling.lastMileScaling)
{
recalculateScreenSize(rtData);
if (integerScaleActive)
{
integerScaleFactor = Vec2i(1, 1);
rebuildIntegerScaleBuffer();
}
recalculateScreenSize(rtData->config.fixedAspectRatio);
updateScreenResoRatio(rtData);
TEXFBO::init(frozenScene);
@ -510,6 +524,7 @@ struct GraphicsPrivate
~GraphicsPrivate()
{
TEXFBO::fini(frozenScene);
TEXFBO::fini(integerScaleBuffer);
}
void updateScreenResoRatio(RGSSThreadData *rtData)
@ -522,16 +537,28 @@ struct GraphicsPrivate
}
/* Enforces fixed aspect ratio, if desired */
void recalculateScreenSize(RGSSThreadData *rtData)
void recalculateScreenSize(bool fixedAspectRatio)
{
scSize = winSize;
if (!rtData->config.fixedAspectRatio)
if (!fixedAspectRatio && integerLastMileScaling)
{
scOffset = Vec2i(0, 0);
return;
}
/* Last mile scaling disabled: just center the integer scale buffer
* inside the window space */
if (integerScaleActive && !integerLastMileScaling)
{
scOffset.x = (winSize.x - scRes.x * integerScaleFactor.x) / 2;
scOffset.y = (winSize.y - scRes.y * integerScaleFactor.y) / 2;
scSize = Vec2i(scRes.x * integerScaleFactor.x, scRes.y * integerScaleFactor.y);
Debug() << scOffset.x << scOffset.y << winSize.x << winSize.y << integerScaleFactor.x << integerScaleFactor.y;
return;
}
float resRatio = (float) scRes.x / scRes.y;
float winRatio = (float) winSize.x / winSize.y;
@ -544,10 +571,70 @@ struct GraphicsPrivate
scOffset.y = (winSize.y - scSize.y) / 2.f;
}
static int findHighestFittingScale(int base, int target)
{
int scale = 1;
while (base * scale <= target)
scale += 1;
Debug() << base << target << scale - 1;
return scale - 1;
}
/* Returns whether a new scale was found */
bool findHighestIntegerScale()
{
Vec2i newScale(findHighestFittingScale(scRes.x, winSize.x),
findHighestFittingScale(scRes.y, winSize.y));
if (threadData->config.fixedAspectRatio)
{
/* Limit both factors to the smaller of the two */
newScale.x = newScale.y = std::min(newScale.x, newScale.y);
}
if (newScale == integerScaleFactor)
return false;
integerScaleFactor = newScale;
return true;
}
void rebuildIntegerScaleBuffer()
{
TEXFBO::fini(integerScaleBuffer);
TEXFBO::init(integerScaleBuffer);
TEXFBO::allocEmpty(integerScaleBuffer, scRes.x * integerScaleFactor.x,
scRes.y * integerScaleFactor.y);
TEXFBO::linkFBO(integerScaleBuffer);
}
bool integerScaleStepApplicable() const
{
if (!integerScaleActive)
return false;
if (integerScaleFactor.x < 1 || integerScaleFactor.y < 1) // XXX should be < 2, this is for testing only
return false;
return true;
}
void checkResize()
{
if (threadData->windowSizeMsg.poll(winSize))
{
/* Query the acutal size in pixels, not units */
SDL_GL_GetDrawableSize(threadData->window, &winSize.x, &winSize.y);
/* Make sure integer buffers are rebuilt before screen offsets are
* calculated so we have the final allocated buffer size ready */
if (integerScaleActive)
if (findHighestIntegerScale())
rebuildIntegerScaleBuffer();
/* some GL drivers change the viewport on window resize */
glState.viewport.refresh();
recalculateScreenSize(threadData);
@ -600,20 +687,64 @@ struct GraphicsPrivate
void metaBlitBufferFlippedScaled()
{
GLMeta::blitRectangle(IntRect(0, 0, scRes.x, scRes.y),
metaBlitBufferFlippedScaled(scRes);
}
void metaBlitBufferFlippedScaled(const Vec2i &sourceSize, bool forceNearestNeighbour = false)
{
GLMeta::blitRectangle(IntRect(0, 0, sourceSize.x, sourceSize.y),
IntRect(scOffset.x, scSize.y+scOffset.y, scSize.x, -scSize.y),
threadData->config.smoothScaling);
!forceNearestNeighbour && threadData->config.smoothScaling);
}
void redrawScreen()
{
screen.composite();
// maybe unspaghetti this later
if (integerScaleStepApplicable() && !integerLastMileScaling)
{
GLMeta::blitBeginScreen(winSize);
GLMeta::blitSource(screen.getPP().frontBuffer());
FBO::clear();
metaBlitBufferFlippedScaled();
metaBlitBufferFlippedScaled(scRes, true);
GLMeta::blitEnd();
swapGLBuffer();
return;
}
if (integerScaleStepApplicable())
{
assert(integerScaleBuffer.tex != TEX::ID(0));
GLMeta::blitBegin(integerScaleBuffer);
GLMeta::blitSource(screen.getPP().frontBuffer());
GLMeta::blitRectangle(IntRect(0, 0, scRes.x, scRes.y),
IntRect(0, 0, integerScaleBuffer.width, integerScaleBuffer.height),
false);
GLMeta::blitEnd();
}
GLMeta::blitBeginScreen(winSize);
Vec2i sourceSize;
if (integerScaleActive)
{
GLMeta::blitSource(integerScaleBuffer);
sourceSize = Vec2i(integerScaleBuffer.width, integerScaleBuffer.height);
}
else
{
GLMeta::blitSource(screen.getPP().frontBuffer());
sourceSize = scRes;
}
FBO::clear();
metaBlitBufferFlippedScaled(sourceSize);
GLMeta::blitEnd();
@ -1026,7 +1157,48 @@ bool Graphics::getFixedAspectRatio() const
void Graphics::setFixedAspectRatio(bool value)
{
shState->config().fixedAspectRatio = value;
p->recalculateScreenSize(p->threadData);
p->findHighestIntegerScale();
p->recalculateScreenSize(p->threadData->config.fixedAspectRatio);
p->updateScreenResoRatio(p->threadData);
}
bool Graphics::getSmoothScaling() const
{
// Same deal as with fixed aspect ratio
return shState->config().smoothScaling;
}
void Graphics::setSmoothScaling(bool value)
{
shState->config().smoothScaling = value;
}
bool Graphics::getIntegerScaling() const
{
return p->integerScaleActive;
}
void Graphics::setIntegerScaling(bool value)
{
p->integerScaleActive = value;
p->findHighestIntegerScale();
p->rebuildIntegerScaleBuffer();
p->recalculateScreenSize(p->threadData->config.fixedAspectRatio);
p->updateScreenResoRatio(p->threadData);
}
bool Graphics::getLastMileScaling() const
{
return p->integerLastMileScaling;
}
void Graphics::setLastMileScaling(bool value)
{
p->integerLastMileScaling = value;
p->recalculateScreenSize(p->threadData->config.fixedAspectRatio);
p->updateScreenResoRatio(p->threadData);
}

View File

@ -63,6 +63,9 @@ public:
DECL_ATTR( ShowCursor, bool )
DECL_ATTR( FixedAspectRatio, bool )
DECL_ATTR( SmoothScaling, bool )
DECL_ATTR( IntegerScaling, bool )
DECL_ATTR( LastMileScaling, bool )
/* <internal> */
Scene *getScreen() const;

View File

@ -41,6 +41,10 @@
#include "binding.h"
#ifdef __WINDOWS__
#include <windows.h>
#include <shellscalingapi.h>
#include <comdef.h>
#include "resource.h"
// Try to force dedicated GPU
@ -204,6 +208,16 @@ int main(int argc, char *argv[])
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
// SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
#ifdef __WINDOWS__
SetProcessDPIAware();
// HRESULT hr = SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
// if (FAILED(hr))
// {
// _com_error err(hr);
// fwprintf(stderr, L"SetProcessDpiAwareness: %s\n", err.ErrorMessage());
// }
#endif
/* initialize SDL first */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
{
@ -276,7 +290,7 @@ int main(int argc, char *argv[])
}
SDL_Window *win;
Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS;
Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_ALLOW_HIGHDPI;
if (conf.winResizable)
winFlags |= SDL_WINDOW_RESIZABLE;