From b460d76698e72d805bb7443e6ac2e7e011cd32b2 Mon Sep 17 00:00:00 2001 From: klapeto Date: Fri, 28 Apr 2017 15:50:23 +0300 Subject: [PATCH 1/3] Fixed segmentation faults caused by NULL assignments to std::strings --- .gitignore | 6 ++++++ desmume/src/NDSSystem.cpp | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 064cf7666..1ac096f48 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,9 @@ xcuserdata/ *.ipa *.dSYM.zip *.dSYM + +## Eclipse CDT generated files +/.autotools +/.cproject +/config.log +/.project diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 667d02744..3b8129d89 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -658,8 +658,16 @@ struct LastRom { int NDS_LoadROM(const char *filename, const char *physicalName, const char *logicalFilename) { lastRom.filename = filename; - lastRom.physicalName = physicalName; - lastRom.logicalFilename = logicalFilename; + + if (physicalName != NULL ) + { + lastRom.physicalName = physicalName; + } + + if (logicalFilename != NULL) + { + lastRom.logicalFilename = logicalFilename; + } int ret; char buf[MAX_PATH]; @@ -3137,4 +3145,4 @@ void TCommonSettings::GameHacks::apply() void TCommonSettings::GameHacks::clear() { memset(&flags,0,sizeof(flags)); -} \ No newline at end of file +} From 08e2244cea5f4b7ed47e2dae1c86eac391b04480 Mon Sep 17 00:00:00 2001 From: klapeto Date: Thu, 4 May 2017 22:34:59 +0300 Subject: [PATCH 2/3] posixGTK: Added Graphics Settings dialog and 3D core switch ui --- desmume/src/frontend/posix/gtk/config_opts.h | 1 + desmume/src/frontend/posix/gtk/glx_3Demu.cpp | 9 +- desmume/src/frontend/posix/gtk/glx_3Demu.h | 1 + desmume/src/frontend/posix/gtk/main.cpp | 116 ++++++++++++++++-- .../src/frontend/posix/gtk/osmesa_3Demu.cpp | 5 + desmume/src/frontend/posix/gtk/osmesa_3Demu.h | 1 + 6 files changed, 119 insertions(+), 14 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/config_opts.h b/desmume/src/frontend/posix/gtk/config_opts.h index 7d7d97451..730f26b23 100644 --- a/desmume/src/frontend/posix/gtk/config_opts.h +++ b/desmume/src/frontend/posix/gtk/config_opts.h @@ -56,6 +56,7 @@ OPT(autoframeskip, bool, true, Config, AudoFrameskip) OPT(frameskip, int, 0, Config, Frameskip) OPT(use_jit,bool,false,Config,JIT_Enabled) OPT(jit_max_block_size,int,100,Config,JITBlockSize) +OPT(core3D,int,1,Config,Core3D) /* Audio */ OPT(audio_enabled, bool, true, Audio, Enabled) diff --git a/desmume/src/frontend/posix/gtk/glx_3Demu.cpp b/desmume/src/frontend/posix/gtk/glx_3Demu.cpp index 897e41169..e4bee8e77 100644 --- a/desmume/src/frontend/posix/gtk/glx_3Demu.cpp +++ b/desmume/src/frontend/posix/gtk/glx_3Demu.cpp @@ -29,7 +29,7 @@ static void glx_endOpenGL(void) { } static bool glx_init(void) { return true; } static int xerror_handler(Display *dpy, XErrorEvent *ev) { return 0; } -static GLXContext ctx; +static GLXContext ctx = NULL; static GLXPbuffer pbuf; typedef GLXContext (*wtf)(Display*, GLXFBConfig, GLXContext, Bool, const int*); @@ -45,6 +45,8 @@ int deinit_glx_3Demu(void) XCloseDisplay(dpy); + ctx = NULL; + return true; } @@ -155,4 +157,9 @@ int init_glx_3Demu(void) return true; } +bool is_glx_initialized(void) +{ + return ctx != NULL; +} + #endif // HAVE_GLX diff --git a/desmume/src/frontend/posix/gtk/glx_3Demu.h b/desmume/src/frontend/posix/gtk/glx_3Demu.h index 42b070a25..b21b9376c 100644 --- a/desmume/src/frontend/posix/gtk/glx_3Demu.h +++ b/desmume/src/frontend/posix/gtk/glx_3Demu.h @@ -21,4 +21,5 @@ #ifdef HAVE_GL_GLX int init_glx_3Demu(void); int deinit_glx_3Demu(void); +bool is_glx_initialized(void); #endif diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index 44b0ef5d3..3bfe2a91b 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -163,6 +163,8 @@ static void EmulationSettingsDialog(); static void ToggleJIT(); static void JITMaxBlockSizeChanged(GtkAdjustment* adj,void *); #endif +static void GraphicsSettingsDialog(); + static const char *ui_description = "" @@ -320,6 +322,7 @@ static const char *ui_description = #ifdef HAVE_JIT " " #endif +" " " " #ifdef FAKE_MIC " " @@ -421,6 +424,7 @@ static const GtkActionEntry action_entries[] = { #ifdef HAVE_JIT { "emulationsettings",NULL,"Em_ulation Settings",NULL,NULL,EmulationSettingsDialog}, #endif + { "graphicssettings",NULL,"_Graphics Settings",NULL,NULL, GraphicsSettingsDialog}, { "SPUModeMenu", NULL, "Audio _Synchronization" }, { "SPUInterpolationMenu", NULL, "Audio _Interpolation" }, { "CheatMenu", NULL, "_Cheat" }, @@ -664,8 +668,11 @@ init_configured_features( class configured_features *config ) { if(config->render3d == COMMANDLINE_RENDER3D_GL || config->render3d == COMMANDLINE_RENDER3D_OLDGL || config->render3d == COMMANDLINE_RENDER3D_AUTOGL) config->engine_3d = 2; + else if (config->render3d == COMMANDLINE_RENDER3D_DEFAULT) + // Setting it to -1 so that common_gtk_main() will ignore it and load it from file or reconfigure it. + config->engine_3d = -1; else - config->engine_3d = 1; + config->engine_3d = 1; config->savetype = 0; @@ -727,19 +734,21 @@ fill_configured_features( class configured_features *config, goto error; } - if (config->engine_3d != 0 && config->engine_3d != 1 + // Check if the commandLine argument was actually passed + if (config->engine_3d != -1) { + if (config->engine_3d != 0 && config->engine_3d != 1 #if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) - && config->engine_3d != 2 + && config->engine_3d != 2 #endif - ) { - g_printerr("Currently available ENGINES: 0, 1" + ) { + g_printerr("Currently available ENGINES: 0, 1" #if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) - ", 2" + ", 2" #endif - "\n"); - goto error; - } - + "\n"); + goto error; + } + } #ifdef GDB_STUB if (config->arm9_gdb_port != 0 && (config->arm9_gdb_port < 1 || config->arm9_gdb_port > 65535)) { g_printerr("ARM9 GDB stub port must be in the range 1 to 65535\n"); @@ -2194,6 +2203,73 @@ static void Edit_Joystick_Controls() } +static void GraphicsSettingsDialog() +{ + GtkWidget *gsDialog; + GtkWidget *gsKey, *coreCombo; + + gsDialog = gtk_dialog_new_with_buttons("Graphics Settings", + GTK_WINDOW(pWindow), + GTK_DIALOG_MODAL, + GTK_STOCK_OK, + GTK_RESPONSE_OK, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + NULL); + + gsKey = gtk_label_new("3D Core\n"); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gsDialog)->vbox), gsKey, TRUE, FALSE, 0); + + coreCombo = gtk_combo_box_text_new(); + + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo) , 0, "Null"); + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo) , 1, "Software Raserizer"); +#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo) , 2, "OpenGL"); +#endif + + gtk_combo_box_set_active(GTK_COMBO_BOX(coreCombo), cur3DCore); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gsDialog)->vbox), coreCombo, TRUE, FALSE, 0); + + + + gtk_widget_show_all(GTK_DIALOG(gsDialog)->vbox); + + switch (gtk_dialog_run(GTK_DIALOG(gsDialog))) { + case GTK_RESPONSE_OK: + // Start: OK Response block + { + int sel3DCore = gtk_combo_box_get_active(GTK_COMBO_BOX(coreCombo)); + + // Change only if needed + if (sel3DCore != cur3DCore) { +#if defined(HAVE_LIBOSMESA) + if (sel3DCore == 2 && !is_osmesa_initialized()) { + init_osmesa_3Demu(); + } +#elif defined(HAVE_GL_GLX) + if (sel3DCore == 2 && !is_glx_initialized()) { + init_glx_3Demu(); + } +#endif + if (NDS_3D_ChangeCore(sel3DCore)) { + config.core3D = sel3DCore; + } else { + g_printerr("Failed to change the 3D Core!"); + } + } + } + // End: OK Response Block + break; + case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_NONE: + break; + } + + gtk_widget_destroy(gsDialog); + +} + static void ToggleLayerVisibility(GtkToggleAction* action, gpointer data) { guint Layer = GPOINTER_TO_UINT(data); @@ -3238,10 +3314,24 @@ common_gtk_main( class configured_features *my_config) OGLCreateRenderer_3_2_Func = OGLCreateRenderer_3_2; //Set the 3D emulation to use - unsigned core = my_config->engine_3d; + int core = my_config->engine_3d; // setup the gdk 3D emulation; + + // Check if commandLine argument was passed or not + if (core == -1) { + // If it was not passed, then get the Renderer config from the file + core = config.core3D; + + // Check if it is valid + if (!(core >= 0 && core <= 2)) { + // If it is invalid, reset it to softwareRasterizer + core = 1; + } + //Set this too for clarity + my_config->engine_3d = core; + } #if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) - if(my_config->engine_3d == 2) + if(core == 2) { #if defined(HAVE_LIBOSMESA) core = init_osmesa_3Demu() @@ -3252,7 +3342,7 @@ common_gtk_main( class configured_features *my_config) } #endif NDS_3D_ChangeCore(core); - if(my_config->engine_3d != 0 && gpu3D == &gpu3DNull) { + if(core != 0 && gpu3D == &gpu3DNull) { g_printerr("Failed to initialise openGL 3D emulation; " "removing 3D support\n"); } diff --git a/desmume/src/frontend/posix/gtk/osmesa_3Demu.cpp b/desmume/src/frontend/posix/gtk/osmesa_3Demu.cpp index 4e20fd401..51f28aa31 100644 --- a/desmume/src/frontend/posix/gtk/osmesa_3Demu.cpp +++ b/desmume/src/frontend/posix/gtk/osmesa_3Demu.cpp @@ -65,4 +65,9 @@ int init_osmesa_3Demu(void) return true; } + +bool is_osmesa_initialized(void) +{ + return ctx != NULL; +} #endif diff --git a/desmume/src/frontend/posix/gtk/osmesa_3Demu.h b/desmume/src/frontend/posix/gtk/osmesa_3Demu.h index 4e22f2028..0b3d97c47 100644 --- a/desmume/src/frontend/posix/gtk/osmesa_3Demu.h +++ b/desmume/src/frontend/posix/gtk/osmesa_3Demu.h @@ -21,4 +21,5 @@ #ifdef HAVE_LIBOSMESA int init_osmesa_3Demu(void); void deinit_osmesa_3Demu(void); +bool is_osmesa_initialized(void); #endif From a2527ef733321182100aaaad1f5f6c628584e2dd Mon Sep 17 00:00:00 2001 From: klapeto Date: Fri, 5 May 2017 21:42:51 +0300 Subject: [PATCH 3/3] posixGTK: Additional graphic options added to Graphics Dialog --- desmume/src/frontend/posix/gtk/config_opts.h | 7 +- desmume/src/frontend/posix/gtk/main.cpp | 113 +++++++++++++++++-- 2 files changed, 107 insertions(+), 13 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/config_opts.h b/desmume/src/frontend/posix/gtk/config_opts.h index 730f26b23..b2536d6e8 100644 --- a/desmume/src/frontend/posix/gtk/config_opts.h +++ b/desmume/src/frontend/posix/gtk/config_opts.h @@ -56,7 +56,12 @@ OPT(autoframeskip, bool, true, Config, AudoFrameskip) OPT(frameskip, int, 0, Config, Frameskip) OPT(use_jit,bool,false,Config,JIT_Enabled) OPT(jit_max_block_size,int,100,Config,JITBlockSize) -OPT(core3D,int,1,Config,Core3D) +OPT(core3D, int, 1, Config, Core3D) +OPT(textureDeposterize, bool, false, Config, 3DTextureDeposterization) +OPT(textureSmoothing, bool, false, Config, 3DTextureSmoothing) +OPT(textureUpscale, int, 1, Config, 3DTextureUpscaling) +OPT(highColorInterpolation, bool, true, Config, HighResolutionColorInterpolation) +OPT(multisampling, bool, false, Config, OpenGLMultisampling) /* Audio */ OPT(audio_enabled, bool, true, Audio, Enabled) diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index 3bfe2a91b..8e994aa33 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -2203,10 +2203,10 @@ static void Edit_Joystick_Controls() } -static void GraphicsSettingsDialog() -{ + +static void GraphicsSettingsDialog() { GtkWidget *gsDialog; - GtkWidget *gsKey, *coreCombo; + GtkWidget *gsKey, *coreCombo, *wTable, *wPosterize, *wScale, *wSmoothing, *wMultisample, *wHCInterpolate; gsDialog = gtk_dialog_new_with_buttons("Graphics Settings", GTK_WINDOW(pWindow), @@ -2217,20 +2217,79 @@ static void GraphicsSettingsDialog() GTK_RESPONSE_CANCEL, NULL); - gsKey = gtk_label_new("3D Core\n"); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gsDialog)->vbox), gsKey, TRUE, FALSE, 0); + + wTable = gtk_table_new(2 ,2, TRUE); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gsDialog)->vbox), wTable, TRUE, FALSE, 0); + + // 3D Core + gsKey = gtk_label_new("3D Core:"); + gtk_misc_set_alignment(GTK_MISC(gsKey), 0.0, 0.5); + gtk_table_attach(GTK_TABLE(wTable), gsKey, 0, 1, 0, 1, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 5, 0); coreCombo = gtk_combo_box_text_new(); - - gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo) , 0, "Null"); - gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo) , 1, "Software Raserizer"); + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 0, "Null"); + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 1, "Software Raserizer"); #if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) - gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo) , 2, "OpenGL"); + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 2, "OpenGL"); +#endif + gtk_combo_box_set_active(GTK_COMBO_BOX(coreCombo), cur3DCore); + gtk_table_attach(GTK_TABLE(wTable), coreCombo, 1, 2, 0, 1, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 5, 0); + + + // 3D Texture Upscaling + gsKey = gtk_label_new("3D Texture Upscaling:"); + gtk_misc_set_alignment(GTK_MISC(gsKey), 0.0, 0.5); + gtk_table_attach(GTK_TABLE(wTable), gsKey, 0, 1, 1, 2, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 5, 0); + + wScale = gtk_combo_box_text_new(); + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(wScale), 0, "x1"); + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(wScale), 1, "x2"); + gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(wScale), 2, "x4"); + + // The shift it work for scale up to 4. For scaling more than 4, a mapping function is required + gtk_combo_box_set_active(GTK_COMBO_BOX(wScale), CommonSettings.GFX3D_Renderer_TextureScalingFactor >> 1); + gtk_table_attach(GTK_TABLE(wTable), wScale, 1, 2, 1, 2, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 5, 0); + + + // 3D Texture Deposterization + wPosterize = gtk_check_button_new_with_label("3D Texture Deposterization"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wPosterize), CommonSettings.GFX3D_Renderer_TextureDeposterize); + gtk_table_attach(GTK_TABLE(wTable), wPosterize, 0, 1, 2, 3, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 0, 0); + + + // 3D Texture Smoothing + wSmoothing = gtk_check_button_new_with_label("3D Texture Smoothing"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wSmoothing), CommonSettings.GFX3D_Renderer_TextureSmoothing); + gtk_table_attach(GTK_TABLE(wTable), wSmoothing, 0, 1, 3, 4, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 0, 0); + + +#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) + // OpenGL Multisample + wMultisample = gtk_check_button_new_with_label("Multisample (OpenGL)"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wMultisample), CommonSettings.GFX3D_Renderer_Multisample); + gtk_table_attach(GTK_TABLE(wTable), wMultisample, 1, 2, 2, 3, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 10, 0); #endif - gtk_combo_box_set_active(GTK_COMBO_BOX(coreCombo), cur3DCore); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gsDialog)->vbox), coreCombo, TRUE, FALSE, 0); - + // SoftwareRasterizer High Color Interpolation + wHCInterpolate = gtk_check_button_new_with_label("High Resolution Color Interpolation (SoftwareRasterizer)"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wHCInterpolate), CommonSettings.GFX3D_HighResolutionInterpolateColor); + gtk_table_attach(GTK_TABLE(wTable), wHCInterpolate, 1, 2, 3, 4, + static_cast(GTK_EXPAND | GTK_FILL), + static_cast(GTK_EXPAND | GTK_FILL), 10, 0); gtk_widget_show_all(GTK_DIALOG(gsDialog)->vbox); @@ -2258,6 +2317,26 @@ static void GraphicsSettingsDialog() g_printerr("Failed to change the 3D Core!"); } } + + size_t scale = 1; + + switch (gtk_combo_box_get_active(GTK_COMBO_BOX(wScale))){ + case 1: + scale = 2; + break; + case 2: + scale = 4; + break; + default: + break; + } + CommonSettings.GFX3D_Renderer_TextureDeposterize = config.textureDeposterize = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wPosterize)); + CommonSettings.GFX3D_Renderer_TextureSmoothing = config.textureSmoothing = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wSmoothing)); + CommonSettings.GFX3D_Renderer_TextureScalingFactor = config.textureUpscale = scale; + CommonSettings.GFX3D_HighResolutionInterpolateColor = config.highColorInterpolation = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wHCInterpolate)); +#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) + CommonSettings.GFX3D_Renderer_Multisample = config.multisampling = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wMultisample)); +#endif } // End: OK Response Block break; @@ -3347,6 +3426,16 @@ common_gtk_main( class configured_features *my_config) "removing 3D support\n"); } + + CommonSettings.GFX3D_HighResolutionInterpolateColor = config.highColorInterpolation; + CommonSettings.GFX3D_Renderer_Multisample = config.multisampling; + CommonSettings.GFX3D_Renderer_TextureDeposterize = config.textureDeposterize; + CommonSettings.GFX3D_Renderer_TextureScalingFactor = (config.textureUpscale == 1 || + config.textureUpscale == 2 || + config.textureUpscale == 4) + ? config.textureUpscale : 1 ; + CommonSettings.GFX3D_Renderer_TextureSmoothing = config.textureSmoothing; + backup_setManualBackupType(my_config->savetype); // Command line arg