[GTK3] Add "no-gl" CLI option

This commit is contained in:
Maximilian Mader 2020-05-05 21:38:56 +02:00
parent f46d35528b
commit f7beeb9c98
Signed by: Max
GPG Key ID: F71D56A3151C4FB3

View File

@ -49,6 +49,7 @@ typedef struct GuiData {
gchar *prefix; gchar *prefix;
gboolean fullscreen; gboolean fullscreen;
GB_model_t model; GB_model_t model;
gboolean force_software_renderer;
} cli_options; } cli_options;
GFile *file; GFile *file;
@ -332,10 +333,6 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (g_variant_dict_lookup(options, "fullscreen", "b", &count)) {
gui_data.cli_options.fullscreen = true;
}
// Handle model override // Handle model override
GVariant *model_name_var = g_variant_dict_lookup_value(options, "model", G_VARIANT_TYPE_STRING); GVariant *model_name_var = g_variant_dict_lookup_value(options, "model", G_VARIANT_TYPE_STRING);
if (model_name_var != NULL) { if (model_name_var != NULL) {
@ -1958,14 +1955,19 @@ static void startup(GApplication *app, gpointer null_ptr) {
g_debug("GTK version %u.%u.%u", gtk_get_major_version(), gtk_get_minor_version(), gtk_get_micro_version()); g_debug("GTK version %u.%u.%u", gtk_get_major_version(), gtk_get_minor_version(), gtk_get_micro_version());
// Very ugly workaround for GtkGlArea! if (gui_data.cli_options.force_software_renderer) {
// When a GtkGlArea is realized and it creates a legacy GL 1.4 context g_message("Forcing fallback renderer!");
// it tries to use GL 2.0 functions to render the window which leads to the application crashing. }
// So we initialize GTK, create a dummy GtkWindow object, attach a `realize` callback and else {
// in this callback create a GdkGLContext on this window. But instead of running the GTK main loop // Very ugly workaround for GtkGlArea!
// we just realize and destroy the dummy window and compare the contexts version in the realize callback. // When a GtkGlArea is realized and it creates a legacy GL 1.4 context
gui_data.supports_gl = test_gl_support(); // it tries to use GL 2.0 functions to render the window which leads to the application crashing.
g_debug("OpenGL supported: %s", gui_data.supports_gl? "Yes" : "No"); // So we initialize GTK, create a dummy GtkWindow object, attach a `realize` callback and
// in this callback create a GdkGLContext on this window. But instead of running the GTK main loop
// we just realize and destroy the dummy window and compare the contexts version in the realize callback.
gui_data.supports_gl = test_gl_support();
g_debug("OpenGL supported: %s", gui_data.supports_gl? "Yes" : "No");
}
gui_data.builder = gtk_builder_new_from_resource(RESOURCE_PREFIX "ui/window.ui"); gui_data.builder = gtk_builder_new_from_resource(RESOURCE_PREFIX "ui/window.ui");
gtk_builder_connect_signals(gui_data.builder, NULL); gtk_builder_connect_signals(gui_data.builder, NULL);
@ -2676,10 +2678,11 @@ int main(int argc, char *argv[]) {
// Define our command line parameters // Define our command line parameters
GOptionEntry entries[] = { GOptionEntry entries[] = {
{ "version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "Show the application version", NULL }, { "version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "Show the application version", NULL },
{ "fullscreen", 'f', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, "Start in fullscreen mode", NULL }, { "fullscreen", 'f', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &gui_data.cli_options.fullscreen, "Start in fullscreen mode", NULL },
{ "bootrom", 'b', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &gui_data.cli_options.boot_rom_path, "Path to the boot ROM to use", "<file path>" }, { "bootrom", 'b', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &gui_data.cli_options.boot_rom_path, "Path to the boot ROM to use", "<file path>" },
{ "model", 'm', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, NULL, "Override the model type to emulate", "<model type>" }, { "model", 'm', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, NULL, "Override the model type to emulate", "<model type>" },
{ "config", 'c', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &gui_data.cli_options.config_path, "Override the path of the configuration file", "<file path>" }, { "config", 'c', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &gui_data.cli_options.config_path, "Override the path of the configuration file", "<file path>" },
{ "no-gl", 's', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &gui_data.cli_options.force_software_renderer, "Do not use OpenGL for rendering", NULL },
{ NULL } { NULL }
}; };
// Setup our command line information // Setup our command line information