From 08e2244cea5f4b7ed47e2dae1c86eac391b04480 Mon Sep 17 00:00:00 2001 From: klapeto Date: Thu, 4 May 2017 22:34:59 +0300 Subject: [PATCH] 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