diff --git a/driver.c b/driver.c index 083b7a86e8..c52715515c 100644 --- a/driver.c +++ b/driver.c @@ -830,6 +830,9 @@ void init_video_input(void) rarch_fail(1, "init_video_input()"); } + if (driver.video->poke_interface) + driver.video->poke_interface(driver.video_data, &driver.video_poke); + if (driver.video->set_rotation && g_extern.system.rotation) video_set_rotation_func(g_extern.system.rotation); diff --git a/driver.h b/driver.h index e81bf18df2..715c27569d 100644 --- a/driver.h +++ b/driver.h @@ -226,6 +226,15 @@ typedef struct video_overlay_interface } video_overlay_interface_t; #endif +// Optionally implemented interface to poke more deeply into video driver. +// Only used by RGUI atm. +typedef struct video_poke_interface +{ + void (*set_filtering)(void *data, unsigned index, bool smooth); + void (*set_fbo_state)(void *data, unsigned state); + void (*set_aspect_ratio)(void *data, unsigned aspectratio_index); +} video_poke_interface_t; + typedef struct video_driver { void *(*init)(const video_info_t *video, const input_driver_t **input, void **input_data); @@ -245,9 +254,6 @@ typedef struct video_driver void (*stop)(void); void (*restart)(void); #endif -#if defined(HAVE_RMENU) || defined(HAVE_RGUI) - void (*set_aspect_ratio)(void *data, unsigned aspectratio_index); -#endif void (*set_rotation)(void *data, unsigned rotation); void (*viewport_info)(void *data, struct rarch_viewport *vp); @@ -258,6 +264,7 @@ typedef struct video_driver #ifdef HAVE_OVERLAY void (*overlay_interface)(void *data, const video_overlay_interface_t **iface); #endif + void (*poke_interface)(void *data, const video_poke_interface_t **iface); } video_driver_t; enum rarch_display_type @@ -318,6 +325,9 @@ typedef struct driver input_overlay_t *overlay; uint64_t overlay_state; #endif + + // Interface for "poking". + const video_poke_interface_t *video_poke; } driver_t; void init_drivers(void); diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index 2278f27e59..67f14f0d1f 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -169,8 +169,6 @@ void gfx_scale_integer(struct rarch_viewport *vp, unsigned width, unsigned heigh vp->y = padding_y >> 1; } -#if defined(HAVE_RMENU) || defined(HAVE_RGUI) - struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = { { "1:1", 1.0f }, { "2:1", 2.0f }, @@ -206,7 +204,7 @@ char rotation_lut[ASPECT_RATIO_END][32] = void gfx_set_auto_viewport(unsigned width, unsigned height) { - if(width == 0 || height == 0) + if (width == 0 || height == 0) return; unsigned aspect_x, aspect_y, len, highest, i; @@ -222,8 +220,11 @@ void gfx_set_auto_viewport(unsigned width, unsigned height) aspect_x = width / highest; aspect_y = height / highest; - snprintf(aspectratio_lut[ASPECT_RATIO_AUTO].name, sizeof(aspectratio_lut[ASPECT_RATIO_AUTO].name), "%d:%d (Auto)", aspect_x, aspect_y); - aspectratio_lut[ASPECT_RATIO_AUTO].value = (float) aspect_x / aspect_y; + snprintf(aspectratio_lut[ASPECT_RATIO_AUTO].name, + sizeof(aspectratio_lut[ASPECT_RATIO_AUTO].name), + "%d:%d (Auto)", aspect_x, aspect_y); + + aspectratio_lut[ASPECT_RATIO_AUTO].value = (float)aspect_x / aspect_y; } void gfx_set_core_viewport(void) @@ -233,9 +234,8 @@ void gfx_set_core_viewport(void) // fallback to 1:1 pixel ratio if none provided if (g_extern.system.av_info.geometry.aspect_ratio == 0.0) - aspectratio_lut[ASPECT_RATIO_CORE].value = (float) g_extern.system.av_info.geometry.base_width / g_extern.system.av_info.geometry.base_height; + aspectratio_lut[ASPECT_RATIO_CORE].value = (float)g_extern.system.av_info.geometry.base_width / g_extern.system.av_info.geometry.base_height; else aspectratio_lut[ASPECT_RATIO_CORE].value = g_extern.system.av_info.geometry.aspect_ratio; } -#endif diff --git a/gfx/gfx_common.h b/gfx/gfx_common.h index ddf6c97a4e..f8f454c8dc 100644 --- a/gfx/gfx_common.h +++ b/gfx/gfx_common.h @@ -40,8 +40,6 @@ void gfx_set_dwm(void); void gfx_scale_integer(struct rarch_viewport *vp, unsigned win_width, unsigned win_height, float aspect_ratio, bool keep_aspect); -#if defined(HAVE_RMENU) || defined(HAVE_RGUI) - #define MIN_SCALING_FACTOR (1.0f) #if defined(__CELLOS_LV2__) @@ -90,7 +88,7 @@ enum rotation ORIENTATION_END }; -#define LAST_ORIENTATION (ORIENTATION_END-1) +#define LAST_ORIENTATION (ORIENTATION_END - 1) extern char rotation_lut[ASPECT_RATIO_END][32]; @@ -119,8 +117,6 @@ extern struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END]; extern void gfx_set_auto_viewport(unsigned width, unsigned height); extern void gfx_set_core_viewport(void); -#endif - #ifdef __cplusplus } #endif diff --git a/gfx/gl.c b/gfx/gl.c index 91bf6545b8..718353d8ed 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -2081,25 +2081,6 @@ static void gl_restart(void) } #endif -#if defined(HAVE_RGUI) || defined(HAVE_RMENU) -static void gl_set_aspect_ratio(void *data, unsigned aspectratio_index) -{ - (void)data; - gl_t *gl = driver.video_data; - - if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_AUTO) - gfx_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); - else if(g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CORE) - gfx_set_core_viewport(); - - g_settings.video.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value; - g_settings.video.force_aspect = false; - gl->keep_aspect = true; - - gl->should_resize = true; -} -#endif - #ifdef HAVE_OVERLAY static bool gl_overlay_load(void *data, const uint32_t *image, unsigned width, unsigned height) { @@ -2224,6 +2205,78 @@ static void gl_get_overlay_interface(void *data, const video_overlay_interface_t } #endif +static void gl_set_filtering(void *data, unsigned index, bool smooth) +{ + gl_t *gl = (gl_t*)data; + + GLuint filter = smooth ? GL_LINEAR : GL_NEAREST; + if (index == 1) + { + gl->tex_filter = filter; + // Apply to all PREV textures. + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + } + } + else if (index >= 2 && gl->fbo_inited) + { + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + } + + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +} + +static void gl_set_fbo_state(void *data, unsigned mode) +{ + gl_t *gl = (gl_t*)data; + + switch (mode) + { + case FBO_DEINIT: + gl_deinit_fbo(gl); + break; + case FBO_REINIT: + gl_deinit_fbo(gl); + // Fallthrough + case FBO_INIT: + gl_init_fbo(gl, gl->tex_w, gl->tex_h); + break; + } +} + +static void gl_set_aspect_ratio(void *data, unsigned aspectratio_index) +{ + gl_t *gl = (gl_t*)data; + + if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_AUTO) + gfx_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); + else if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CORE) + gfx_set_core_viewport(); + + g_settings.video.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value; + g_settings.video.force_aspect = false; + gl->keep_aspect = true; + + gl->should_resize = true; +} + +static const video_poke_interface_t gl_poke_interface = { + gl_set_filtering, + gl_set_fbo_state, + gl_set_aspect_ratio, +}; + +static void gl_get_poke_interface(void *data, const video_poke_interface_t **iface) +{ + (void)data; + *iface = &gl_poke_interface; +} + const video_driver_t video_gl = { gl_init, gl_frame, @@ -2244,9 +2297,6 @@ const video_driver_t video_gl = { gl_start, gl_stop, gl_restart, -#endif -#if defined(HAVE_RMENU) || defined(HAVE_RGUI) - gl_set_aspect_ratio, #endif gl_set_rotation, @@ -2261,6 +2311,7 @@ const video_driver_t video_gl = { #ifdef HAVE_OVERLAY gl_get_overlay_interface, #endif + gl_get_poke_interface, };