Skip to content

Commit

Permalink
Added integer scaling option
Browse files Browse the repository at this point in the history
Might help with #81
  • Loading branch information
ata4 committed Jan 3, 2021
1 parent 0d6235a commit 3744ec7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/core/n64video.h
Expand Up @@ -100,6 +100,7 @@ struct n64video_config
bool hide_overscan; // crop to visible area if true
bool vsync; // enable vsync if true
bool exclusive; // run in exclusive mode when in fullscreen if true
bool integer_scaling; // one native pixel is displayed as a multiple of a screen pixel if true
} vi;
struct {
enum dp_compat_profile compat; // multithreading compatibility mode
Expand Down
48 changes: 35 additions & 13 deletions src/output/vdac.c
Expand Up @@ -19,6 +19,7 @@

static bool m_fbo_enabled;
static GLuint m_fbo;
static bool m_integer_scaling;

static GLuint m_fbtex;
static uint32_t m_fbtex_width;
Expand Down Expand Up @@ -278,6 +279,9 @@ void vdac_init(struct n64video_config* config)
// read with exact FB size in non-filtered modes
m_rawtex_read = config->vi.mode != VI_MODE_NORMAL;

// save integer scaling flag, will be used later
m_integer_scaling = config->vi.integer_scaling;

// check if there was an error when using any of the commands above
gl_check_errors();
}
Expand Down Expand Up @@ -393,19 +397,37 @@ void vdac_sync(bool valid)
return;
}

int32_t hw = m_fbtex_height * win_width;
int32_t wh = m_fbtex_width * win_height;

// add letterboxes or pillarboxes if the window has a different aspect ratio
// than the current display mode
if (hw > wh) {
int32_t w_max = wh / m_fbtex_height;
win_x += (win_width - w_max) / 2;
win_width = w_max;
} else if (hw < wh) {
int32_t h_max = hw / m_fbtex_width;
win_y += (win_height - h_max) / 2;
win_height = h_max;
if (m_integer_scaling) {
// get smallest integer scale that is at least 1
uint32_t scale_x = (uint32_t)win_width < m_fbtex_width ? 1 : (uint32_t)win_width / m_fbtex_width;
uint32_t scale_y = (uint32_t)win_height < m_fbtex_height ? 1 : (uint32_t)win_height / m_fbtex_height;
uint32_t scale = scale_x > scale_y ? scale_x : scale_y;

// get new window size (or rather viewport size in this context)
int32_t win_width_new = m_fbtex_width * scale;
int32_t win_height_new = m_fbtex_height * scale;

// apply new size and offset
win_x = (win_width - win_width_new) / 2;
win_y = (win_height - win_height_new) / 2;

win_width = win_width_new;
win_height = win_height_new;
} else {
int32_t hw = m_fbtex_height * win_width;
int32_t wh = m_fbtex_width * win_height;

// add letterboxes or pillarboxes if the window has a different aspect ratio
// than the current display mode
if (hw > wh) {
int32_t w_max = wh / m_fbtex_height;
win_x += (win_width - w_max) / 2;
win_width = w_max;
} else if (hw < wh) {
int32_t h_max = hw / m_fbtex_width;
win_y += (win_height - h_max) / 2;
win_height = h_max;
}
}

if (m_fbo_enabled) {
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/mupen64plus/gfx_m64p.c
Expand Up @@ -33,6 +33,7 @@
#define KEY_VI_INTERP "ViInterpolation"
#define KEY_VI_WIDESCREEN "ViWidescreen"
#define KEY_VI_HIDE_OVERSCAN "ViHideOverscan"
#define KEY_VI_INTEGER_SCALING "ViIntegerScaling"

#define KEY_DP_COMPAT "DpCompat"

Expand Down Expand Up @@ -117,6 +118,7 @@ EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle _CoreLibHandle, void *Co
ConfigSetDefaultInt(configVideoAngrylionPlus, KEY_VI_INTERP, config.vi.interp, "Scaling interpolation type (0=NN, 1=Linear)");
ConfigSetDefaultBool(configVideoAngrylionPlus, KEY_VI_WIDESCREEN, config.vi.widescreen, "Use anamorphic 16:9 output mode if True");
ConfigSetDefaultBool(configVideoAngrylionPlus, KEY_VI_HIDE_OVERSCAN, config.vi.hide_overscan, "Hide overscan area in filteded mode if True");
ConfigSetDefaultBool(configVideoAngrylionPlus, KEY_VI_INTEGER_SCALING, config.vi.integer_scaling, "Display upscaled pixels as groups of 1x1, 2x2, 3x3, etc. if True");
ConfigSetDefaultInt(configVideoAngrylionPlus, KEY_DP_COMPAT, config.dp.compat, "Compatibility mode (0=Fast 1=Moderate 2=Slow");

ConfigSaveSection("Video-General");
Expand Down Expand Up @@ -204,6 +206,7 @@ EXPORT int CALL RomOpen (void)
config.vi.interp = ConfigGetParamInt(configVideoAngrylionPlus, KEY_VI_INTERP);
config.vi.widescreen = ConfigGetParamBool(configVideoAngrylionPlus, KEY_VI_WIDESCREEN);
config.vi.hide_overscan = ConfigGetParamBool(configVideoAngrylionPlus, KEY_VI_HIDE_OVERSCAN);
config.vi.integer_scaling = ConfigGetParamBool(configVideoAngrylionPlus, KEY_VI_INTEGER_SCALING);

config.dp.compat = ConfigGetParamInt(configVideoAngrylionPlus, KEY_DP_COMPAT);

Expand Down
3 changes: 3 additions & 0 deletions src/plugin/zilmar/config.c
Expand Up @@ -49,6 +49,7 @@ static HWND dlg_check_vi_widescreen;
static HWND dlg_check_vi_overscan;
static HWND dlg_check_vi_exclusive;
static HWND dlg_check_vi_vsync;
static HWND dlg_check_vi_integer_scaling;
static HWND dlg_combo_dp_compat;
static HWND dlg_spin_workers;
static HWND dlg_edit_workers;
Expand Down Expand Up @@ -119,6 +120,7 @@ INT_PTR CALLBACK config_dialog_proc(HWND hwnd, UINT iMessage, WPARAM wParam, LPA
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_OVERSCAN, dlg_check_vi_overscan, config.vi.hide_overscan);
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_EXCLUSIVE, dlg_check_vi_exclusive, config.vi.exclusive);
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_VSYNC, dlg_check_vi_vsync, config.vi.vsync);
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_INTEGER_SCALING, dlg_check_vi_integer_scaling, config.vi.integer_scaling);

dlg_edit_workers = GetDlgItem(hwnd, IDC_EDIT_WORKERS);
SetDlgItemInt(hwnd, IDC_EDIT_WORKERS, config.num_workers, FALSE);
Expand Down Expand Up @@ -159,6 +161,7 @@ INT_PTR CALLBACK config_dialog_proc(HWND hwnd, UINT iMessage, WPARAM wParam, LPA
config.vi.hide_overscan = SendMessage(dlg_check_vi_overscan, BM_GETCHECK, 0, 0);
config.vi.exclusive = SendMessage(dlg_check_vi_exclusive, BM_GETCHECK, 0, 0);
config.vi.vsync = SendMessage(dlg_check_vi_vsync, BM_GETCHECK, 0, 0);
config.vi.integer_scaling = SendMessage(dlg_check_vi_integer_scaling, BM_GETCHECK, 0, 0);
config.dp.compat = SendMessage(dlg_combo_dp_compat, CB_GETCURSEL, 0, 0);
config.parallel = SendMessage(dlg_check_multithread, BM_GETCHECK, 0, 0);
config.num_workers = GetDlgItemInt(hwnd, IDC_EDIT_WORKERS, FALSE, FALSE);
Expand Down
Binary file modified src/plugin/zilmar/config.rc
Binary file not shown.
Binary file modified src/plugin/zilmar/resource.h
Binary file not shown.

0 comments on commit 3744ec7

Please sign in to comment.