From 7411df6c73f2f6c8635bb16bcf653391b05f85ae Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sun, 13 May 2018 17:31:25 -0500 Subject: [PATCH] Make rewinding and bilinear filtering global Snes9x settings. --- gtk/src/gtk_config.cpp | 7 ++++--- gtk/src/gtk_config.h | 1 - gtk/src/gtk_control.cpp | 4 ++-- gtk/src/gtk_display_driver_gtk.cpp | 2 +- gtk/src/gtk_display_driver_opengl.cpp | 2 +- gtk/src/gtk_preferences.cpp | 4 ++-- gtk/src/gtk_s9x.cpp | 4 ++-- gtk/src/gtk_s9xwindow.cpp | 1 - gtk/src/gtk_s9xwindow.h | 1 - gtk/src/shaders/CGLCG.cpp | 4 ++-- gtk/src/shaders/glsl.cpp | 10 +++++----- gtk/src/shaders/glsl.h | 2 +- snes9x.cpp | 1 + snes9x.h | 2 ++ 14 files changed, 23 insertions(+), 22 deletions(-) diff --git a/gtk/src/gtk_config.cpp b/gtk/src/gtk_config.cpp index 53c5a34f..88d63031 100644 --- a/gtk/src/gtk_config.cpp +++ b/gtk/src/gtk_config.cpp @@ -205,7 +205,7 @@ Snes9xConfig::load_defaults (void) ntsc_setup = snes_ntsc_composite; ntsc_scanline_intensity = 1; scanline_filter_intensity = 0; - bilinear_filter = 0; + Settings.BilinearFilter = FALSE; netplay_activated = FALSE; netplay_server_up = FALSE; netplay_is_server = FALSE; @@ -221,6 +221,7 @@ Snes9xConfig::load_defaults (void) rewind_granularity = 5; rewind_buffer_size = 0; + Settings.Rewinding = FALSE; #ifdef USE_OPENGL sync_to_vblank = 1; @@ -370,7 +371,7 @@ Snes9xConfig::save_config_file (void) xml_out_int (xml, "ntsc_scanline_intensity", ntsc_scanline_intensity); xml_out_int (xml, "scanline_filter_intensity", scanline_filter_intensity); xml_out_int (xml, "hw_accel", hw_accel); - xml_out_int (xml, "bilinear_filter", bilinear_filter); + xml_out_int (xml, "bilinear_filter", Settings.BilinearFilter); xml_out_int (xml, "rewind_buffer_size", rewind_buffer_size); xml_out_int (xml, "rewind_granularity", rewind_granularity); @@ -558,7 +559,7 @@ Snes9xConfig::set_option (const char *name, const char *value) } else if (!strcasecmp (name, "bilinear_filter")) { - bilinear_filter = atoi (value); + Settings.BilinearFilter = atoi (value); } else if (!strcasecmp (name, "sync_to_vblank")) { diff --git a/gtk/src/gtk_config.h b/gtk/src/gtk_config.h index 1c7a29d0..6cf1804a 100644 --- a/gtk/src/gtk_config.h +++ b/gtk/src/gtk_config.h @@ -81,7 +81,6 @@ class Snes9xConfig float ntsc_merge_fields; unsigned int ntsc_scanline_intensity; unsigned int scanline_filter_intensity; - unsigned char bilinear_filter; unsigned char hw_accel; unsigned char allow_opengl; unsigned char allow_xv; diff --git a/gtk/src/gtk_control.cpp b/gtk/src/gtk_control.cpp index 092d61f2..f9867261 100644 --- a/gtk/src/gtk_control.cpp +++ b/gtk/src/gtk_control.cpp @@ -197,7 +197,7 @@ S9xHandlePortCommand (s9xcommand_t cmd, int16 data1, int16 data2) if (cmd.port[0] == PORT_QUIT) quit_binding_down = TRUE; else if (cmd.port[0] == PORT_REWIND) - top_level->user_rewind = TRUE; + Settings.Rewinding = TRUE; } if (data1 == FALSE) /* Release */ @@ -232,7 +232,7 @@ S9xHandlePortCommand (s9xcommand_t cmd, int16 data1, int16 data2) else if (cmd.port[0] == PORT_REWIND) { - top_level->user_rewind = FALSE; + Settings.Rewinding = FALSE; } else if (cmd.port[0] == PORT_SEEK_TO_FRAME) diff --git a/gtk/src/gtk_display_driver_gtk.cpp b/gtk/src/gtk_display_driver_gtk.cpp index 76163959..60359863 100644 --- a/gtk/src/gtk_display_driver_gtk.cpp +++ b/gtk/src/gtk_display_driver_gtk.cpp @@ -127,7 +127,7 @@ S9xGTKDisplayDriver::output (void *src, cairo_matrix_translate (&matrix, -x, -y); cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_filter (pattern, - config->bilinear_filter + Settings.BilinearFilter ? CAIRO_FILTER_BILINEAR : CAIRO_FILTER_NEAREST); } diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index d3f13a9b..8aea0bb9 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -54,7 +54,7 @@ S9xOpenGLDisplayDriver::update (int width, int height, int yoffset) glBindTexture (GL_TEXTURE_2D, texmap); } - GLint filter = config->bilinear_filter ? GL_LINEAR : GL_NEAREST; + GLint filter = Settings.BilinearFilter ? GL_LINEAR : GL_NEAREST; glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); GLint clamp = (using_shaders || !dyn_resizing) ? GL_CLAMP_TO_BORDER : GL_CLAMP_TO_EDGE; diff --git a/gtk/src/gtk_preferences.cpp b/gtk/src/gtk_preferences.cpp index 9f7b8c2b..ea11827e 100644 --- a/gtk/src/gtk_preferences.cpp +++ b/gtk/src/gtk_preferences.cpp @@ -799,7 +799,7 @@ Snes9xPreferences::move_settings_to_dialog (void) set_combo ("frameskip_combo", Settings.SkipFrames == AUTO_FRAMERATE ? 0 : Settings.SkipFrames + 1); - set_check ("bilinear_filter", config->bilinear_filter); + set_check ("bilinear_filter", Settings.BilinearFilter); #ifdef USE_OPENGL set_check ("sync_to_vblank", config->sync_to_vblank); @@ -907,7 +907,7 @@ Snes9xPreferences::get_settings_from_dialog (void) config->ntsc_scanline_intensity = get_combo ("ntsc_scanline_intensity"); config->scanline_filter_intensity = get_combo ("scanline_filter_intensity"); config->hw_accel = hw_accel_value (get_combo ("hw_accel")); - config->bilinear_filter = get_check ("bilinear_filter"); + Settings.BilinearFilter = get_check ("bilinear_filter"); config->num_threads = get_spin ("num_threads"); config->default_esc_behavior = get_combo ("default_esc_behavior"); config->prevent_screensaver = get_check ("prevent_screensaver"); diff --git a/gtk/src/gtk_s9x.cpp b/gtk/src/gtk_s9x.cpp index be14a751..a4fe27f2 100644 --- a/gtk/src/gtk_s9x.cpp +++ b/gtk/src/gtk_s9x.cpp @@ -351,8 +351,8 @@ S9xIdleFunc (gpointer data) { #endif - if(top_level->user_rewind) - top_level->user_rewind = stateMan.pop(); + if(Settings.Rewinding) + Settings.Rewinding = stateMan.pop(); else if(IPPU.TotalEmulatedFrames % gui_config->rewind_granularity == 0) stateMan.push(); diff --git a/gtk/src/gtk_s9xwindow.cpp b/gtk/src/gtk_s9xwindow.cpp index 223f2cd0..ff7c5109 100644 --- a/gtk/src/gtk_s9xwindow.cpp +++ b/gtk/src/gtk_s9xwindow.cpp @@ -593,7 +593,6 @@ Snes9xWindow::Snes9xWindow (Snes9xConfig *config) : }; user_pause = 0; - user_rewind = 0; sys_pause = 0; last_width = -1; last_height = -1; diff --git a/gtk/src/gtk_s9xwindow.h b/gtk/src/gtk_s9xwindow.h index 480b376d..58b7f18e 100644 --- a/gtk/src/gtk_s9xwindow.h +++ b/gtk/src/gtk_s9xwindow.h @@ -65,7 +65,6 @@ class Snes9xWindow : public GtkBuilderWindow Snes9xConfig *config; int user_pause, sys_pause; - int user_rewind; int last_width, last_height; int mouse_region_x, mouse_region_y; int mouse_region_width, mouse_region_height; diff --git a/gtk/src/shaders/CGLCG.cpp b/gtk/src/shaders/CGLCG.cpp index 154cd74c..0219ab9b 100644 --- a/gtk/src/shaders/CGLCG.cpp +++ b/gtk/src/shaders/CGLCG.cpp @@ -389,7 +389,7 @@ bool CGLCG::LoadShader(const char* shaderFile) */ if (pass.scaleParams.scaleTypeX == CG_SCALE_NONE && !it->filterSet) { - pass.linearFilter = gui_config->bilinear_filter; + pass.linearFilter = Settings.BilinearFilter; } else { @@ -823,7 +823,7 @@ void CGLCG::setShaderVars(int pass) shaderFrameCnt %= shaderPasses[pass].frameCounterMod; setProgram1f(pass, "IN.frame_count", (float)shaderFrameCnt); setProgram1f( - pass, "IN.frame_direction", top_level->user_rewind ? -1.0f : 1.0f); + pass, "IN.frame_direction", Settings.Rewinding ? -1.0f : 1.0f); /* ORIG parameter */ diff --git a/gtk/src/shaders/glsl.cpp b/gtk/src/shaders/glsl.cpp index b83fc170..57bbf1cf 100644 --- a/gtk/src/shaders/glsl.cpp +++ b/gtk/src/shaders/glsl.cpp @@ -645,7 +645,7 @@ void GLSLShader::render(GLuint &orig, int width, int height, int viewport_width, GLuint filter = (pass[i].filter == GLSL_UNDEFINED) ? (lastpass ? - (gui_config->bilinear_filter ? GL_LINEAR : GL_NEAREST) : GL_NEAREST + (Settings.BilinearFilter ? GL_LINEAR : GL_NEAREST) : GL_NEAREST ) : pass[i].filter; glBindTexture(GL_TEXTURE_2D, pass[i - 1].texture); @@ -813,7 +813,7 @@ void GLSLShader::register_uniforms () glUseProgram (0); } -void GLSLShader::set_shader_vars (int p) +void GLSLShader::set_shader_vars (unsigned int p) { unsigned int texunit = 0; unsigned int offset = 0; @@ -869,7 +869,7 @@ void GLSLShader::set_shader_vars (int p) if (pass[p].frame_count_mod) shaderFrameCnt %= pass[p].frame_count_mod; setUniform1i(u->FrameCount, (float) shaderFrameCnt); - setUniform1i(u->FrameDirection, top_level->user_rewind ? -1.0f : 1.0f); + setUniform1i(u->FrameDirection, Settings.Rewinding ? -1.0f : 1.0f); setTexCoords (u->TexCoord); setTexCoords (u->LUTTexCoord); @@ -920,7 +920,7 @@ void GLSLShader::set_shader_vars (int p) /* PASSX parameters, only for third pass and up */ if (p > 2) { - for (int i = 1; i < p - 1; i++) { + for (unsigned int i = 1; i < p - 1; i++) { float passSize[2] = { (float) pass[i].width, (float) pass[i].height }; setUniform2fv(u->Pass[i].InputSize, passSize); setUniform2fv(u->Pass[i].TextureSize, passSize); @@ -930,7 +930,7 @@ void GLSLShader::set_shader_vars (int p) } /* PASSPREV parameter */ - for (int i = 0; i < p; i++) + for (unsigned int i = 0; i < p; i++) { float passSize[2] = { (float) pass[i].width, (float) pass[i].height }; setUniform2fv(u->PassPrev[p - i].InputSize, passSize); diff --git a/gtk/src/shaders/glsl.h b/gtk/src/shaders/glsl.h index ed6f51f9..eb1f24c0 100644 --- a/gtk/src/shaders/glsl.h +++ b/gtk/src/shaders/glsl.h @@ -107,7 +107,7 @@ typedef struct bool load_shader (char *filename); bool load_shader_file (char *filename); void render (GLuint &orig, int width, int height, int viewport_width, int viewport_height, int viewport_x, int viewport_y); - void set_shader_vars (int pass); + void set_shader_vars (unsigned int pass); void clear_shader_vars (void); void strip_parameter_pragmas(char *buffer); GLuint compile_shader (char *program, diff --git a/snes9x.cpp b/snes9x.cpp index 265194e4..eb1173d0 100644 --- a/snes9x.cpp +++ b/snes9x.cpp @@ -437,6 +437,7 @@ void S9xLoadConfigFiles (char **argv, int argc) Settings.DisplayMovieFrame = conf.GetBool("Display::DisplayFrameCount", false); Settings.AutoDisplayMessages = conf.GetBool("Display::MessagesInImage", true); Settings.InitialInfoStringTimeout = conf.GetInt ("Display::MessageDisplayTime", 120); + Settings.BilinearFilter = conf.GetBool("Display::BilinearFilter", false); // Settings diff --git a/snes9x.h b/snes9x.h index 9e4bf06b..ee08822a 100644 --- a/snes9x.h +++ b/snes9x.h @@ -422,6 +422,7 @@ struct SSettings bool8 AutoDisplayMessages; uint32 InitialInfoStringTimeout; uint16 DisplayColor; + bool8 BilinearFilter; bool8 Multi; char CartAName[PATH_MAX + 1]; @@ -442,6 +443,7 @@ struct SSettings bool8 TurboMode; uint32 HighSpeedSeek; bool8 FrameAdvance; + bool8 Rewinding; bool8 NetPlay; bool8 NetPlayServer;