From 9224b3f2acf3e8ae8e099eeceb97736f28bf721a Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 10 Apr 2020 04:07:01 +0200 Subject: [PATCH] [GTK3] Convert to structured logging --- Makefile | 2 +- gtk3/main.c | 85 +++++++++++++++++++++++-------------- gtk3/main.h | 2 + gtk3/resources/ui/window.ui | 1 + gtk3/settings.c | 75 +++++++++++++++++++++++++------- gtk3/settings.h | 5 +++ gtk3/shader.c | 15 ++++--- gtk3/shader.h | 15 +++++-- 8 files changed, 139 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 513bda3..281c57c 100644 --- a/Makefile +++ b/Makefile @@ -120,7 +120,7 @@ ifneq ($(findstring gtk3,$(MAKECMDGOALS)),) $(error The gtk3 target requires pkg-config) endif else -GTK3_CFLAGS := $(shell $(PKG_CONFIG) --cflags gio-2.0 gtk+-3.0 epoxy sdl2) -DGTK_DISABLE_DEPRECATED=1 -DG_DISABLE_DEPRECATED=1 -DRESOURCE_PREFIX=\"/io/github/sameboy/\" -DAPP_ID=\"io.github.sameboy\" +GTK3_CFLAGS := $(shell $(PKG_CONFIG) --cflags gio-2.0 gtk+-3.0 epoxy sdl2) -DGTK_DISABLE_DEPRECATED=1 -DG_DISABLE_DEPRECATED=1 -DG_LOG_DOMAIN=\"SameBoy\" -DRESOURCE_PREFIX=\"/io/github/sameboy/\" -DAPP_ID=\"io.github.sameboy\" GTK3_LDFLAGS := $(shell $(PKG_CONFIG) --libs gio-2.0 gtk+-3.0 epoxy sdl2) # TODO: REMOVE DISABLE UNUSED WARNINGS diff --git a/gtk3/main.c b/gtk3/main.c index 2b15f24..8632553 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -133,7 +133,7 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin guint32 count; if (g_variant_dict_lookup(options, "version", "b", &count)) { - g_print("SameBoy v" xstr(VERSION) "\n"); + g_message("SameBoy v" xstr(VERSION)); return EXIT_SUCCESS; } @@ -153,7 +153,7 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin } else { gui_data->cli_options.model = GB_MODEL_DMG_B; - g_printerr("Unsupported revision: %s\nFalling back to DMG-B", model_name); + g_warning("Unsupported revision: %s\nFalling back to DMG-B", model_name); } } else if (g_str_has_prefix(model_name, "SGB")) { @@ -168,7 +168,7 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin } else { gui_data->cli_options.model = GB_MODEL_SGB2; - g_printerr("Unsupported revision: %s\nFalling back to SGB2", model_name); + g_warning("Unsupported revision: %s\nFalling back to SGB2", model_name); } } else if (g_str_has_prefix(model_name, "CGB")) { @@ -180,14 +180,14 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin } else { gui_data->cli_options.model = GB_MODEL_CGB_E; - g_printerr("Unsupported revision: %s\nFalling back to CGB-E", model_name); + g_warning("Unsupported revision: %s\nFalling back to CGB-E", model_name); } } else if (g_str_has_prefix(model_name, "AGB")) { gui_data->cli_options.model = GB_MODEL_AGB; } else { - g_printerr("Unknown model: %s\n", model_name); + g_warning("Unknown model: %s", model_name); exit(EXIT_FAILURE); } } @@ -220,7 +220,7 @@ void gl_check_realize(GtkWidget *w, gpointer user_data_gptr) { GdkGLContext *context = gdk_window_create_gl_context(gdk_window, &error); if (error != NULL) { - g_printerr("Failed to create context: %s\n", error->message); + g_warning("Failed to create context: %s", error->message); g_error_free(error); *result = FALSE; } @@ -234,7 +234,7 @@ void gl_check_realize(GtkWidget *w, gpointer user_data_gptr) { gdk_gl_context_clear_current(); - g_print("OpenGL version: %d\n", version); + g_debug("OpenGL version: %d", version); *result = version >= 32; } @@ -242,7 +242,7 @@ void gl_check_realize(GtkWidget *w, gpointer user_data_gptr) { static gboolean init_controllers() { if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) < 0) { - g_print("Failed to initialize game controller support: %s\n", SDL_GetError()); + g_warning("Failed to initialize game controller support: %s", SDL_GetError()); return FALSE; } @@ -258,7 +258,7 @@ static gboolean init_controllers() { const gint val = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem((void *)db_data, db_data_size), 1); if (val < 0) { - g_warning("Failed to load controller mappings: %s\n", SDL_GetError()); + g_warning("Failed to load controller mappings: %s", SDL_GetError()); } g_bytes_unref(db_f); @@ -274,7 +274,7 @@ static gboolean init_controllers() { break; } else { - g_warning("Could not open gamecontroller %i: %s\n", i, SDL_GetError()); + g_warning("Could not open gamecontroller %i: %s", i, SDL_GetError()); } } } @@ -289,7 +289,7 @@ static gboolean init_audio() { SDL_QuitSubSystem(SDL_INIT_AUDIO); if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { - g_print("Failed to initialize audio: %s\n", SDL_GetError()); + g_warning("Failed to initialize audio: %s", SDL_GetError()); return FALSE; } @@ -319,7 +319,7 @@ static gboolean init_audio() { device_id = SDL_OpenAudioDevice(0, 0, &want_aspec, &have_aspec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_SAMPLES_CHANGE); - g_print("Requested Sample Rate: %d Hz\nUsed Sample Rate: %d Hz\n", want_aspec.freq, have_aspec.freq); + g_debug("Requested Sample Rate: %d Hz\nUsed Sample Rate: %d Hz", want_aspec.freq, have_aspec.freq); SDL_PauseAudioDevice(device_id, audio_playing? 0 : 1); GB_set_sample_rate(&gb, have_aspec.freq); @@ -491,7 +491,7 @@ static void setup_menu(GApplication *app) { if (desktop == NULL || g_str_equal(desktop, "")) desktop = (gchar *)gdm_session; if (desktop == NULL || g_str_equal(desktop, "")) desktop = (gchar *)desktop_session; - g_print("XDG_CURRENT_DESKTOP: %s\nGDMSESSION: %s\nDESKTOP_SESSION: %s\nChosen value: %s\nShow menu in shell: %d\n", xdg_current_desktop, gdm_session, desktop_session, desktop, show_in_shell); + g_debug("XDG_CURRENT_DESKTOP: %s\nGDMSESSION: %s\nDESKTOP_SESSION: %s\nChosen value: %s\nShow menu in shell: %d", xdg_current_desktop, gdm_session, desktop_session, desktop, show_in_shell); if (desktop != NULL && show_in_shell) { menubar_type = MENUBAR_SHOW_IN_SHELL; @@ -514,23 +514,23 @@ static void setup_menu(GApplication *app) { switch (menubar_type) { case MENUBAR_AUTO: - g_error("Unreachable\n"); + g_warning("Unreachable"); break; case MENUBAR_SHOW_IN_SHELL: - g_print("Showing menu in the shell\n"); + g_debug("Showing menu in the shell"); gtk_application_set_menubar(GTK_APPLICATION(app), menubar_model); break; case MENUBAR_SHOW_IN_WINDOW: { - g_print("Showing menu in the window\n"); + g_debug("Showing menu in the window"); GtkMenuBar *menubar = GTK_MENU_BAR(gtk_menu_bar_new_from_model(menubar_model)); gtk_box_pack_start(GTK_BOX(main_window_container), GTK_WIDGET(menubar), FALSE, FALSE, 0); break; } case MENUBAR_SHOW_HAMBURGER: { - g_print("Showing hamburger\n"); + g_debug("Showing hamburger"); // Attach a custom title bar GtkWidget *titlebar = builder_get(GTK_WIDGET, "main_header_bar"); gtk_header_bar_set_title(GTK_HEADER_BAR(titlebar), gtk_window_get_title(GTK_WINDOW(main_window))); @@ -626,7 +626,7 @@ static void startup(GApplication *app, gpointer gui_data_gptr) { // 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 context’s version in the realize callback. supports_gl = test_gl_support(); - g_print("OpenGL supported: %s\n", supports_gl? "Yes" : "No"); + g_debug("OpenGL supported: %s", supports_gl? "Yes" : "No"); builder = gtk_builder_new_from_resource(RESOURCE_PREFIX "ui/window.ui"); gtk_builder_connect_signals(builder, NULL); @@ -792,7 +792,7 @@ static void activate(GApplication *app, gpointer gui_data_gptr) { // This function gets called when the application is closed. static void shutdown(GApplication *app, GFile **files, gint n_files, const gchar *hint, gpointer gui_data_gptr) { - g_print("SHUTDOWN\n"); + g_debug("SHUTDOWN"); stop(&gui_data); while (stopping); @@ -818,7 +818,7 @@ static void open(GApplication *app, GFile **files, gint n_files, const gchar *hi GuiData *gui_data = gui_data_gptr; if (n_files > 1) { - g_printerr("More than one file specified\n"); + g_warning("More than one file specified"); exit(EXIT_FAILURE); } @@ -932,7 +932,7 @@ static void activate_open(GSimpleAction *action, GVariant *parameter, gpointer a if (res == GTK_RESPONSE_ACCEPT) { // TODO: Emit an event for our emulation loop - g_print("%s\n", gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native))); + g_message("%s", gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native))); } g_object_unref(native); @@ -1026,10 +1026,10 @@ static void on_quit(GtkWidget *w, gpointer app) { static void gl_init(GtkWidget *w) { GtkGLArea *gl_area = GTK_GL_AREA(w); - g_print("GL_INIT\n"); + g_debug("GL_INIT"); const char *renderer; - g_print("GL Context: %p\n", gtk_gl_area_get_context(gl_area)); + g_debug("GL Context: %p", gtk_gl_area_get_context(gl_area)); gtk_gl_area_make_current(gl_area); @@ -1038,7 +1038,7 @@ static void gl_init(GtkWidget *w) { } renderer = (char *)glGetString(GL_RENDERER); - g_print("GtkGLArea on %s\n", renderer ? renderer : "Unknown"); + g_debug("GtkGLArea on %s", renderer ? renderer : "Unknown"); if (config.shader == NULL || (!init_shader_with_name(&shader, config.shader) && !init_shader_with_name(&shader, "NearestNeighbor"))) { GError *error = g_error_new_literal(g_quark_from_string("sameboy-gl-error"), 1, "Failed to initialize shaders"); @@ -1053,7 +1053,7 @@ static void gl_init(GtkWidget *w) { error: if (gtk_gl_area_get_error(gl_area) != NULL) { - g_printerr("GtkGLArea: %s\n", gtk_gl_area_get_error(gl_area)->message); + g_warning("GtkGLArea: %s", gtk_gl_area_get_error(gl_area)->message); } create_fallback_canvas(); @@ -1458,7 +1458,25 @@ static void render_texture(void *pixels, void *previous) { glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); - render_bitmap_with_shader(&shader, _pixels, previous, GB_get_screen_width(&gb), GB_get_screen_height(&gb), viewport.x, viewport.y, viewport.w, viewport.h); + GB_frame_blending_mode_t mode = get_frame_blending_mode(); + if (!previous) { + mode = GB_FRAME_BLENDING_MODE_DISABLED; + } + else if (mode == GB_FRAME_BLENDING_MODE_ACCURATE) { + if (GB_is_sgb(&gb)) { + mode = GB_FRAME_BLENDING_MODE_SIMPLE; + } + else { + mode = GB_is_odd_frame(&gb)? GB_FRAME_BLENDING_MODE_ACCURATE_ODD : GB_FRAME_BLENDING_MODE_ACCURATE_EVEN; + } + } + + render_bitmap_with_shader( + &shader, _pixels, previous, + GB_get_screen_width(&gb), GB_get_screen_height(&gb), + viewport.x, viewport.y, viewport.w, viewport.h, + mode + ); } static void update_viewport(void) { @@ -1858,9 +1876,9 @@ static void load_boot_rom(GuiData *gui_data) { gsize boot_rom_size; if (gui_data->cli_options.boot_rom_path != NULL) { - g_print("Trying to load boot ROM from %s\n", gui_data->cli_options.boot_rom_path); + g_message("Trying to load boot ROM from %s", gui_data->cli_options.boot_rom_path); if (GB_load_boot_rom(&gb, gui_data->cli_options.boot_rom_path)) { - g_printerr("Falling back to boot ROM from config\n"); + g_warning("Falling back to boot ROM from config"); goto config_boot_rom; } } @@ -1874,6 +1892,7 @@ static void load_boot_rom(GuiData *gui_data) { case GB_MODEL_SGB: case GB_MODEL_SGB_PAL: case GB_MODEL_SGB_NO_SFC: + case GB_MODEL_SGB_PAL_NO_SFC: boot_rom_name = "sgb_boot.bin"; break; @@ -1894,11 +1913,11 @@ static void load_boot_rom(GuiData *gui_data) { if (config.boot_rom_path != NULL && g_strcmp0(config.boot_rom_path, "other") != 0 && g_strcmp0(config.boot_rom_path, "auto") != 0) { boot_rom_path = g_build_filename(config.boot_rom_path, boot_rom_name, NULL); - g_print("Trying to load boot ROM from %s\n", boot_rom_path); + g_message("Trying to load boot ROM from %s", boot_rom_path); if (GB_load_boot_rom(&gb, boot_rom_path)) { g_free(boot_rom_path); - g_printerr("Falling back to internal boot ROM\n"); + g_warning("Falling back to internal boot ROM"); goto internal_boot_rom; } @@ -1910,7 +1929,7 @@ static void load_boot_rom(GuiData *gui_data) { g_free(boot_rom_path); if (boot_rom_f == NULL) { - g_printerr("Failed to load internal boot ROM: %s\n", boot_rom_path); + g_warning("Failed to load internal boot ROM: %s", boot_rom_path); g_error_free(error); exit(EXIT_FAILURE); } @@ -1942,7 +1961,7 @@ static void stop(GuiData *gui_data) { } static void reset(GuiData *gui_data) { - g_print("Reset: %d == %d\n", get_model(), gui_data->prev_model); + g_debug("Reset: %d == %d", get_model(), gui_data->prev_model); GB_model_t current_model = get_model(); if (gui_data->prev_model == -1 || gui_data->prev_model == current_model) { @@ -1968,7 +1987,7 @@ static void reset(GuiData *gui_data) { char *path = g_file_get_path(gui_data->file); if (GB_load_rom(&gb, path) != 0) { - g_print("Failed to load ROM: %s", path); + g_warning("Failed to load ROM: %s", path); } g_free(path); diff --git a/gtk3/main.h b/gtk3/main.h index 80ef074..1fadb01 100644 --- a/gtk3/main.h +++ b/gtk3/main.h @@ -4,6 +4,8 @@ // used for audio and game controllers #include "SDL.h" +#define G_LOG_USE_STRUCTURED + #include #include #include diff --git a/gtk3/resources/ui/window.ui b/gtk3/resources/ui/window.ui index c02b8bb..59d0c32 100644 --- a/gtk3/resources/ui/window.ui +++ b/gtk3/resources/ui/window.ui @@ -646,6 +646,7 @@ Maximilian Mader https://github.com/max-m Correct Color Curves Emulate Hardware Preserve Brightness + Reduce contrast diff --git a/gtk3/settings.c b/gtk3/settings.c index c0a7123..b68a078 100644 --- a/gtk3/settings.c +++ b/gtk3/settings.c @@ -4,17 +4,17 @@ static void print_config_error(GError *error) { if (error == NULL) return; if (!g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) && !g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { - g_printerr("Config error: %s\n", error->message); + g_warning("Config error: %s", error->message); } } -void print_config(config_t *config) { +void _print_config(config_t *config, GLogLevelFlags log_level) { #define EXPAND_GROUP(group_name, members) \ - g_print("[%s]\n", #group_name); \ + g_log(G_LOG_DOMAIN, log_level, "[%s]", #group_name); \ members #define EXPAND_GROUP_MEMBER(member, key_type, default_value) \ - g_print("%s="FORMAT_FOR_KEY_TYPE(key_type)"\n", #member, config->member); + g_log(G_LOG_DOMAIN, log_level, "%s="FORMAT_FOR_KEY_TYPE(key_type)"", #member, config->member); EXPAND_CONFIG @@ -23,7 +23,7 @@ void print_config(config_t *config) { } void load_config_from_key_file(config_t *config, GKeyFile *key_file) { - g_print("Loading config from key file\n"); + g_message("Loading config from key file"); GError *error = NULL; gchar *group_name; @@ -42,15 +42,19 @@ void load_config_from_key_file(config_t *config, GKeyFile *key_file) { EXPAND_CONFIG if (config->rewind_duration > 600) { - g_warning("Setting Emulation.rewind_duration too high might affect performance.\n"); + g_warning("Setting Emulation.rewind_duration too high might affect performance."); } #undef EXPAND_GROUP #undef EXPAND_GROUP_MEMBER } +void print_config(config_t *config) { + _print_config(config, G_LOG_LEVEL_MESSAGE); +} + void save_config_to_key_file(config_t *config, GKeyFile *key_file) { - g_print("Saving config to key file\n"); + g_message("Saving config to key file"); GError *error = NULL; gchar *group_name; @@ -67,12 +71,12 @@ void save_config_to_key_file(config_t *config, GKeyFile *key_file) { } \ else if (g_key_file_has_key(key_file, group_name, #member, &error)) { \ if (error != NULL) { \ - g_printerr("%s\n", error->message); \ + g_warning("%s", error->message); \ g_clear_error(&error); \ } \ g_key_file_remove_key(key_file, group_name, #member, &error); \ if (error != NULL) { \ - g_printerr("%s\n", error->message); \ + g_warning("%s", error->message); \ g_clear_error(&error); \ } \ } @@ -136,7 +140,7 @@ void init_settings(gchar *path, GtkWindow *preferences) { int load_settings(void) { GError *error = NULL; - g_print("Trying to load settings from %s\n", settings_file_path); + g_message("Trying to load settings from %s", settings_file_path); if (!g_key_file_load_from_file(key_file, settings_file_path, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) { if (error->domain == G_FILE_ERROR) { @@ -150,7 +154,7 @@ int load_settings(void) { } load_config_from_key_file(&config, key_file); - print_config(&config); + _print_config(&config, G_LOG_LEVEL_DEBUG); return 0; } @@ -158,7 +162,7 @@ int load_settings(void) { void save_settings(void) { GError *error = NULL; - g_print("Trying to save settings to %s\n", settings_file_path); + g_message("Trying to save settings to %s", settings_file_path); save_config_to_key_file(&config, key_file); @@ -208,7 +212,7 @@ enum menubar_type_t get_show_menubar(void) { } // This should not happen - g_warning("Unknown menubar setting: %s\nFalling back to “Auto”\n", config.menubar_override); + g_warning("Unknown menubar setting: %s\nFalling back to “Auto”", config.menubar_override); default_value: return MENUBAR_AUTO; } @@ -244,9 +248,12 @@ GB_color_correction_mode_t get_color_correction_mode(void) { else if (g_strcmp0(config.color_correction_id, "preserve_brightness") == 0) { return GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS; } + else if (g_strcmp0(config.color_correction_id, "reduce_contrast") == 0) { + return GB_COLOR_CORRECTION_REDUCE_CONTRAST; + } // This should not happen - g_warning("Unknown color correction mode: %s\nFalling back to “Emulate Hardware”\n", config.color_correction_id); + g_warning("Unknown color correction mode: %s\nFalling back to “Emulate Hardware”", config.color_correction_id); default_value: return GB_COLOR_CORRECTION_EMULATE_HARDWARE; } @@ -264,6 +271,42 @@ void set_color_correction_mode(GB_color_correction_mode_t mode) { case GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS: config.color_correction_id = "preserve_brightness"; break; + case GB_COLOR_CORRECTION_REDUCE_CONTRAST: + config.color_correction_id = "reduce_contrast"; + break; + } +} + +GB_frame_blending_mode_t get_frame_blending_mode(void) { + if (config.frame_blending_mode == NULL) goto default_value; + + if (g_strcmp0(config.frame_blending_mode, "disabled") == 0) { + return GB_FRAME_BLENDING_MODE_DISABLED; + } + else if (g_strcmp0(config.frame_blending_mode, "simple") == 0) { + return GB_FRAME_BLENDING_MODE_SIMPLE; + } + else if (g_strcmp0(config.frame_blending_mode, "accurate") == 0) { + return GB_FRAME_BLENDING_MODE_ACCURATE; + } + + // This should not happen + g_warning("Unknown frame blending mode: %s\nFalling back to “Disabled”", config.frame_blending_mode); + default_value: return GB_FRAME_BLENDING_MODE_DISABLED; +} + +void set_frame_blending_mode(GB_frame_blending_mode_t mode) { + switch (mode) { + case GB_FRAME_BLENDING_MODE_DISABLED: + config.frame_blending_mode = "disabled"; + break; + case GB_FRAME_BLENDING_MODE_SIMPLE: + config.frame_blending_mode = "simple"; + break; + case GB_FRAME_BLENDING_MODE_ACCURATE: + case GB_FRAME_BLENDING_MODE_ACCURATE_ODD: + config.frame_blending_mode = "accurate"; + break; } } @@ -281,7 +324,7 @@ GB_highpass_mode_t get_highpass_mode(void) { } // This should not happen - g_warning("Unknown highpass mode: %s\nFalling back to “Accurate”\n", config.high_pass_filter_id); + g_warning("Unknown highpass mode: %s\nFalling back to “Accurate”", config.high_pass_filter_id); default_value: return GB_HIGHPASS_ACCURATE; } @@ -291,7 +334,7 @@ void set_highpass_mode(GB_highpass_mode_t mode) { config.high_pass_filter_id = "disabled"; break; case GB_HIGHPASS_MAX: - g_warning("GB_HIGHPASS_MAX is not a valid highpass mode, falling back to “Accurate”.\n"); + g_warning("GB_HIGHPASS_MAX is not a valid highpass mode, falling back to “Accurate”."); case GB_HIGHPASS_ACCURATE: config.high_pass_filter_id = "emulate_hardware"; break; diff --git a/gtk3/settings.h b/gtk3/settings.h index 50415c4..862905c 100644 --- a/gtk3/settings.h +++ b/gtk3/settings.h @@ -4,6 +4,7 @@ #include #include #include "macros.h" +#include "shader.h" #define SETTINGS_FILE "sameboy-gtk3-settings.ini" @@ -39,6 +40,7 @@ EXPAND_GROUP(Video, \ EXPAND_GROUP_MEMBER(shader, string, "NearestNeighbor") \ EXPAND_GROUP_MEMBER(color_correction_id, string, "emulate_hardware") \ + EXPAND_GROUP_MEMBER(frame_blending_mode, string, "disabled") \ EXPAND_GROUP_MEMBER(keep_aspect_ratio, boolean, true) \ EXPAND_GROUP_MEMBER(use_integer_scaling, boolean, true) \ EXPAND_GROUP_MEMBER(menubar_override, string, "auto") \ @@ -88,6 +90,9 @@ void set_show_menubar(enum menubar_type_t); GB_color_correction_mode_t get_color_correction_mode(void); void set_color_correction_mode(GB_color_correction_mode_t); +GB_frame_blending_mode_t get_frame_blending_mode(void); +void set_frame_blending_mode(GB_frame_blending_mode_t); + GB_highpass_mode_t get_highpass_mode(void); void set_highpass_mode(GB_highpass_mode_t); diff --git a/gtk3/shader.c b/gtk3/shader.c index 88a1aa8..b8cfb17 100644 --- a/gtk3/shader.c +++ b/gtk3/shader.c @@ -26,7 +26,7 @@ static GLuint create_shader(const char *source, GLenum type) if (status == GL_FALSE) { GLchar messages[1024]; glGetShaderInfoLog(shader, sizeof(messages), 0, &messages[0]); - g_printerr("GLSL Shader Error: %s", messages); + g_warning("GLSL Shader Error: %s", messages); } return shader; } @@ -53,7 +53,7 @@ static GLuint create_program(const char *vsh, const char *fsh) if (status == GL_FALSE) { GLchar messages[1024]; glGetProgramInfoLog(program, sizeof(messages), 0, &messages[0]); - g_printerr("GLSL Program Error: %s", messages); + g_warning("GLSL Program Error: %s", messages); } // Delete shaders @@ -78,7 +78,7 @@ bool init_shader_with_name(shader_t *shader, const char *name) master_shader_code = g_bytes_get_data(master_shader_f, &master_shader_code_size); if (!master_shader_f) { - g_printerr("Failed to load master shader: %s", error->message); + g_warning("Failed to load master shader: %s", error->message); g_error_free(error); return false; } @@ -96,7 +96,7 @@ bool init_shader_with_name(shader_t *shader, const char *name) GBytes *shader_f = g_resources_lookup_data(shader_path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); if (!shader_f) { - g_printerr("Failed to load shader \"%s\": %s", shader_path, error->message); + g_warning("Failed to load shader \"%s\": %s", shader_path, error->message); g_error_free(error); return false; } @@ -138,7 +138,7 @@ bool init_shader_with_name(shader_t *shader, const char *name) glBindTexture(GL_TEXTURE_2D, 0); shader->previous_texture_uniform = glGetUniformLocation(shader->program, "previous_image"); - shader->mix_previous_uniform = glGetUniformLocation(shader->program, "mix_previous"); + shader->blending_mode_uniform = glGetUniformLocation(shader->program, "frame_blending_mode"); // Program @@ -170,7 +170,8 @@ bool init_shader_with_name(shader_t *shader, const char *name) void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous, unsigned source_width, unsigned source_height, - unsigned x, unsigned y, unsigned w, unsigned h) + unsigned x, unsigned y, unsigned w, unsigned h, + GB_frame_blending_mode_t blending_mode) { glUseProgram(shader->program); glUniform2f(shader->origin_uniform, x, y); @@ -179,7 +180,7 @@ void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous, glBindTexture(GL_TEXTURE_2D, shader->texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, source_width, source_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, bitmap); glUniform1i(shader->texture_uniform, 0); - glUniform1i(shader->mix_previous_uniform, previous != NULL); + glUniform1i(shader->blending_mode_uniform, previous? blending_mode : GB_FRAME_BLENDING_MODE_DISABLED); if (previous) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, shader->previous_texture); diff --git a/gtk3/shader.h b/gtk3/shader.h index 033f4ff..19b397c 100644 --- a/gtk3/shader.h +++ b/gtk3/shader.h @@ -11,20 +11,27 @@ typedef struct shader_s { GLuint origin_uniform; GLuint texture_uniform; GLuint previous_texture_uniform; - GLuint mix_previous_uniform; + GLuint blending_mode_uniform; GLuint position_attribute; GLuint texture; GLuint previous_texture; GLuint program; - - bool compat_mode; } shader_t; +typedef enum { + GB_FRAME_BLENDING_MODE_DISABLED, + GB_FRAME_BLENDING_MODE_SIMPLE, + GB_FRAME_BLENDING_MODE_ACCURATE, + GB_FRAME_BLENDING_MODE_ACCURATE_EVEN = GB_FRAME_BLENDING_MODE_ACCURATE, + GB_FRAME_BLENDING_MODE_ACCURATE_ODD, +} GB_frame_blending_mode_t; + bool init_shader_with_name(shader_t *shader, const char *name); void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous, unsigned source_width, unsigned source_height, - unsigned x, unsigned y, unsigned w, unsigned h); + unsigned x, unsigned y, unsigned w, unsigned h, + GB_frame_blending_mode_t blending_mode); void free_shader(struct shader_s *shader); void free_master_shader(void);