cli: add scaling

the new command line parameter --scale allows to scale the window by
a floating point factor. SDL2 stretches it in hardware to the desired
size, which makes the scaled window run at almost identical speed to
1x scale.
This commit is contained in:
rofl0r 2021-10-25 03:21:34 +00:00
parent b685818413
commit 90326ea1f9
4 changed files with 18 additions and 11 deletions

View File

@ -81,6 +81,7 @@ CommandLine::CommandLine()
, disable_limiter(0)
, windowed_fullscreen(0)
, frameskip(0)
, scale(1.0)
, _rtc_day(-1)
, _rtc_hour(-1)
{
@ -123,6 +124,7 @@ static const char* help_string = \
" --windowed-fullscreen" ENDL
" Launches in windowed fullscreen (same as alt+enter)" ENDL
#else
" --scale N scale factor for window; default 1.0" ENDL
" --nojoy Disables joystick support" ENDL
#endif
" --disable-sound Disables the sound output" ENDL
@ -198,6 +200,7 @@ ENDL
#define OPT_3D_TEXTURE_UPSCALE 81
#define OPT_GPU_RESOLUTION_MULTIPLIER 82
#define OPT_FRAMESKIP 83
#define OPT_SCALE 84
#define OPT_JIT_SIZE 100
#define OPT_CONSOLE_TYPE 200
@ -261,6 +264,7 @@ bool CommandLine::parse(int argc,char **argv)
{ "windowed-fullscreen", no_argument, &windowed_fullscreen, 1 },
#else
{ "nojoy", no_argument, &_commandline_linux_nojoy, 1},
{ "scale", required_argument, NULL, OPT_SCALE},
#endif
{ "frameskip", required_argument, NULL, OPT_FRAMESKIP},
{ "disable-sound", no_argument, &disable_sound, 1},
@ -339,6 +343,7 @@ bool CommandLine::parse(int argc,char **argv)
case OPT_3D_RENDER: _render3d = optarg; break;
case OPT_3D_TEXTURE_UPSCALE: texture_upscale = atoi(optarg); break;
case OPT_GPU_RESOLUTION_MULTIPLIER: gpu_resolution_multiplier = atoi(optarg); break;
case OPT_SCALE: scale = atof(optarg); break;
case OPT_FRAMESKIP: frameskip = atoi(optarg); break;
//RTC settings

View File

@ -49,6 +49,7 @@ public:
int texture_upscale;
int gpu_resolution_multiplier;
int language;
float scale;
std::string nds_file;
std::string play_movie_file;
std::string record_movie_file;

View File

@ -262,17 +262,17 @@ static void
resizeWindow_stub (u16 width, u16 height, void *screen_texture) {
}
static void
Draw( void) {
static void Draw(class configured_features *cfg) {
const float scale = cfg->scale;
const unsigned w = GPU_FRAMEBUFFER_NATIVE_WIDTH, h = GPU_FRAMEBUFFER_NATIVE_HEIGHT;
const int ws = w * scale, hs = h * scale;
const NDSDisplayInfo &displayInfo = GPU->GetDisplayInfo();
const size_t pixCount = GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT;
const size_t pixCount = w * h;
ColorspaceApplyIntensityToBuffer16<false, false>(displayInfo.nativeBuffer16[NDSDisplayID_Main], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Main]);
ColorspaceApplyIntensityToBuffer16<false, false>(displayInfo.nativeBuffer16[NDSDisplayID_Touch], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Touch]);
static const SDL_Rect destrect[2] = {
{ 0,0,
GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT},
{ 0, GPU_FRAMEBUFFER_NATIVE_HEIGHT,
GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT},
SDL_Rect destrect[2] = {
{ 0, 0 , ws, hs},
{ 0, hs, ws, hs},
};
unsigned i, off = 0, n = pixCount*2;
for(i = 0; i < 2; ++i) {
@ -481,9 +481,10 @@ int main(int argc, char ** argv) {
return 1;
}
nds_screen_size_ratio = my_config.scale;
sdl_videoFlags |= SDL_WINDOW_OPENGL;
window = SDL_CreateWindow( "Desmume SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
256, 384, sdl_videoFlags );
256*my_config.scale, 384*my_config.scale, sdl_videoFlags );
if ( !window ) {
fprintf( stderr, "Window creation failed: %s\n", SDL_GetError( ) );
@ -541,7 +542,7 @@ int main(int argc, char ** argv) {
DrawHUD();
#endif
Draw();
Draw(&my_config);
#ifdef HAVE_LIBAGG
osd->clear();

View File

@ -259,7 +259,7 @@ u16 get_set_joy_key(int index) {
static signed long
screen_to_touch_range( signed long scr, float size_ratio) {
return (signed long)((float)scr * size_ratio);
return (signed long)((float)scr / size_ratio);
}
/* Set mouse coordinates */