From 3c1a805770fe8b3289a35b46ad471f1c38162be6 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 23 Dec 2017 17:41:47 +0200 Subject: [PATCH] Frame blending --- SDL/gui.c | 18 +++++++++++++++--- SDL/gui.h | 1 + SDL/main.c | 17 ++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/SDL/gui.c b/SDL/gui.c index bbee0d8..3076ddd 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -47,7 +47,7 @@ void render_texture(void *pixels, void *previous) configuration_t configuration = { - { SDL_SCANCODE_RIGHT, + .keys = { SDL_SCANCODE_RIGHT, SDL_SCANCODE_LEFT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, @@ -57,8 +57,9 @@ configuration_t configuration = SDL_SCANCODE_RETURN, SDL_SCANCODE_SPACE }, - GB_COLOR_CORRECTION_EMULATE_HARDWARE, - GB_SDL_SCALING_INTEGER_FACTOR, + .color_correction_mode = GB_COLOR_CORRECTION_EMULATE_HARDWARE, + .scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR, + .blend_frames = true }; @@ -383,10 +384,21 @@ static void return_to_root_menu(unsigned index) current_selection = 0; } +static void toggle_blend_frames(unsigned index) +{ + configuration.blend_frames ^= true; +} + +const char *blend_frames_string(unsigned index) +{ + return configuration.blend_frames? "Enabled" : "Disabled"; +} + static const struct menu_item graphics_menu[] = { {"Scaling Mode:", cycle_scaling, current_scaling_mode, cycle_scaling_backwards}, {"Scaling Filter:", cycle_filter, current_filter_name, cycle_filter_backwards}, {"Color Correction:", cycle_color_correction, current_color_correction_mode, cycle_color_correction_backwards}, + {"Blend Frames:", toggle_blend_frames, blend_frames_string, toggle_blend_frames}, {"Back", return_to_root_menu}, {NULL,} }; diff --git a/SDL/gui.h b/SDL/gui.h index 5a7e94a..41ac374 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -35,6 +35,7 @@ typedef struct { SDL_Scancode keys[9]; GB_color_correction_mode_t color_correction_mode; enum scaling_mode scaling_mode; + bool blend_frames; bool div_joystick; bool flip_joystick_bit_1; diff --git a/SDL/main.c b/SDL/main.c index bac5936..9df3e43 100755 --- a/SDL/main.c +++ b/SDL/main.c @@ -16,7 +16,9 @@ GB_gameboy_t gb; static bool dmg = false; static bool paused = false; -static uint32_t pixels[160*144]; +static uint32_t pixel_buffer_1[160*144], pixel_buffer_2[160*144]; +static uint32_t *active_pixel_buffer = pixel_buffer_1, *previous_pixel_buffer = pixel_buffer_2; + static char *filename = NULL; static bool should_free_filename = false; @@ -213,7 +215,16 @@ static void handle_events(GB_gameboy_t *gb) static void vblank(GB_gameboy_t *gb) { - render_texture(pixels, NULL); + if (configuration.blend_frames) { + render_texture(active_pixel_buffer, previous_pixel_buffer); + uint32_t *temp = active_pixel_buffer; + active_pixel_buffer = previous_pixel_buffer; + previous_pixel_buffer = temp; + GB_set_pixels_output(gb, active_pixel_buffer); + } + else { + render_texture(active_pixel_buffer, NULL); + } handle_events(gb); } @@ -303,7 +314,7 @@ restart: } GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank); - GB_set_pixels_output(&gb, pixels); + GB_set_pixels_output(&gb, active_pixel_buffer); GB_set_rgb_encode_callback(&gb, rgb_encode); GB_set_sample_rate(&gb, have_aspec.freq); GB_set_color_correction_mode(&gb, configuration.color_correction_mode);