Add menu option for filter method to use when scaling video.

This commit is contained in:
ts-korhonen
2021-05-01 20:49:23 +03:00
parent 6b2e544306
commit dd65a80b19
10 changed files with 81 additions and 12 deletions

View File

@@ -83,6 +83,11 @@ BEGIN
MENUITEM "1.&5x", IDM_VID_SCALE_3X
MENUITEM "&2x", IDM_VID_SCALE_4X
END
POPUP "Filter method"
BEGIN
MENUITEM "&Nearest", IDM_VID_FILTER_NEAREST
MENUITEM "&Linear", IDM_VID_FILTER_LINEAR
END
MENUITEM "Hi&DPI scaling", IDM_VID_HIDPI
MENUITEM SEPARATOR
MENUITEM "&Fullscreen\tCtrl+Alt+PageUP", IDM_VID_FULLSCREEN

View File

@@ -101,9 +101,9 @@ static const struct {
void (*set_fs)(int fs);
void (*reload)(void);
} vid_apis[RENDERERS_NUM] = {
{ "SDL_Software", 1, (int(*)(void*))sdl_inits, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs, NULL },
{ "SDL_Hardware", 1, (int(*)(void*))sdl_inith, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs, NULL },
{ "SDL_OpenGL", 1, (int(*)(void*))sdl_initho, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs, NULL }
{ "SDL_Software", 1, (int(*)(void*))sdl_inits, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs, sdl_reload },
{ "SDL_Hardware", 1, (int(*)(void*))sdl_inith, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs, sdl_reload },
{ "SDL_OpenGL", 1, (int(*)(void*))sdl_initho, sdl_close, NULL, sdl_pause, sdl_enable, sdl_set_fs, sdl_reload }
#if defined(DEV_BRANCH) && defined(USE_OPENGL)
,{ "OpenGL_Core", 1, (int(*)(void*))opengl_init, opengl_close, opengl_resize, opengl_pause, NULL, opengl_set_fs, opengl_reload}
#else

View File

@@ -140,6 +140,8 @@ static struct
int frametime; /* Frametime in microseconds, or -1 to sync with blitter */
char shaderfile[512]; /* Shader file path. Match the length of openfilestring in win_dialog.c */
int shaderfile_changed; /* Has shader file path changed. To prevent unnecessary shader recompilation. */
int filter; /* 0 = Nearest, 1 = Linear */
int filter_changed; /* Has filter changed. */
mutex_t* mutex;
} options = { 0 };
@@ -353,8 +355,8 @@ static int initialize_glcontext(gl_identifiers* gl)
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options.filter ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options.filter ? GL_LINEAR : GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, INIT_WIDTH, INIT_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
@@ -751,6 +753,14 @@ static void opengl_main(void* param)
options.shaderfile_changed = 0;
}
if (options.filter_changed)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options.filter ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options.filter ? GL_LINEAR : GL_NEAREST);
options.filter_changed = 0;
}
thread_release_mutex(options.mutex);
}
@@ -836,6 +846,9 @@ int opengl_init(HWND hwnd)
options.vsync = video_vsync;
options.frametime = framerate_to_frametime(video_framerate);
strcpy_s(options.shaderfile, sizeof(options.shaderfile), video_shader);
options.shaderfile_changed = 0;
options.filter = video_filter_method;
options.filter_changed = 0;
options.mutex = thread_create_mutex();
blit_info = (blit_info_t*)malloc(BUFFERCOUNT * sizeof(blit_info_t));
@@ -933,6 +946,12 @@ void opengl_reload(void)
options.shaderfile_changed = 1;
}
if (video_filter_method != options.filter)
{
options.filter = video_filter_method;
options.filter_changed = 1;
}
thread_release_mutex(options.mutex);
SetEvent(sync_objects.reload);

View File

@@ -347,7 +347,7 @@ sdl_reinit_texture(void)
if (sdl_flags & RENDERER_HARDWARE) {
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
} else
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE);
@@ -552,3 +552,17 @@ sdl_enable(int enable)
SDL_UnlockMutex(sdl_mutex);
}
void
sdl_reload(void)
{
if (sdl_flags & RENDERER_HARDWARE)
{
SDL_LockMutex(sdl_mutex);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
sdl_reinit_texture();
SDL_UnlockMutex(sdl_mutex);
}
}

View File

@@ -178,7 +178,8 @@ video_toggle_option(HMENU h, int *val, int id)
}
/* Recursively finds and deletes target submenu */
int delete_submenu(HMENU parent, HMENU target)
static int
delete_submenu(HMENU parent, HMENU target)
{
for (int i = 0; i < GetMenuItemCount(parent); i++)
{
@@ -243,6 +244,14 @@ show_render_options_menu()
#endif
}
static void
video_set_filter_menu(HMENU menu)
{
CheckMenuItem(menu, IDM_VID_FILTER_NEAREST, vid_api == 0 || video_filter_method == 0 ? MF_CHECKED : MF_UNCHECKED);
CheckMenuItem(menu, IDM_VID_FILTER_LINEAR, vid_api != 0 && video_filter_method == 1 ? MF_CHECKED : MF_UNCHECKED);
EnableMenuItem(menu, IDM_VID_FILTER_NEAREST, vid_api == 0 ? MF_GRAYED : MF_ENABLED);
EnableMenuItem(menu, IDM_VID_FILTER_LINEAR, vid_api == 0 ? MF_GRAYED : MF_ENABLED);
}
static void
ResetAllMenus(void)
@@ -362,6 +371,8 @@ ResetAllMenus(void)
CheckMenuItem(menuMain, IDM_VID_GRAYCT_601+video_graytype, MF_CHECKED);
CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+video_grayscale, MF_CHECKED);
video_set_filter_menu(menuMain);
#ifdef USE_DISCORD
if (discord_loaded)
CheckMenuItem(menuMain, IDM_DISCORD, enable_discord ? MF_CHECKED : MF_UNCHECKED);
@@ -748,6 +759,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
CheckMenuItem(hmenu, IDM_VID_SDL_SW + vid_api, MF_UNCHECKED);
plat_setvid(LOWORD(wParam) - IDM_VID_SDL_SW);
CheckMenuItem(hmenu, IDM_VID_SDL_SW + vid_api, MF_CHECKED);
video_set_filter_menu(hmenu);
config_save();
show_render_options_menu();
break;
@@ -823,6 +835,14 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
config_save();
break;
case IDM_VID_FILTER_NEAREST:
case IDM_VID_FILTER_LINEAR:
video_filter_method = LOWORD(wParam) - IDM_VID_FILTER_NEAREST;
video_set_filter_menu(hmenu);
plat_vid_reload_options();
config_save();
break;
case IDM_VID_HIDPI:
dpi_scale = !dpi_scale;
CheckMenuItem(hmenu, IDM_VID_HIDPI, dpi_scale ? MF_CHECKED : MF_UNCHECKED);