From 5476f45eb87a781dace7bef64ea46981e0ca1868 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Mon, 30 Sep 2019 17:18:58 +0200 Subject: [PATCH] [GTK3] Use logical ARGB byte order for image buffers --- gtk3/main.c | 26 ++------------------------ gtk3/main.h | 1 - gtk3/shader.c | 4 ++-- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index 9479cf6..474c41f 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -830,29 +830,7 @@ G_MODULE_EXPORT void on_use_integer_scaling_changed(GtkWidget *w, gpointer user_ } static uint32_t rgb_encode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b) { - // We use GL_RGBA and GL_UNSIGNED_BYTE for our texture upload, - // so OpenGL expects pixel data in RGBA order in memory. -#ifdef GB_LITTLE_ENDIAN - // ABGR - uint32_t color = 0xFF000000 | (b << 16) | (g << 8) | r; -#else - // RGBA - uint32_t color = (r << 24) | (g << 16) | (b << 8) | 0xFF; -#endif - - return color; -} - -static uint32_t rgb_encode_fallback(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b) { -#ifdef GB_LITTLE_ENDIAN - // ARGB - uint32_t color = 0xFF000000 | (r << 16) | (g << 8) | b; -#else - // BGRA - uint32_t color = (b << 24) | (g << 16) | (r << 8) | 0xFF; -#endif - - return color; + return 0xFF000000 | (r << 16) | (g << 8) | b; } static void render_texture(void *pixels, void *previous) { @@ -992,7 +970,7 @@ static void run(GApplication *app, UserData *user_data) { GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank); GB_set_pixels_output(&gb, get_current_buffer()); - GB_set_rgb_encode_callback(&gb, fallback_canvas? rgb_encode_fallback : rgb_encode); + GB_set_rgb_encode_callback(&gb, rgb_encode); // GB_set_sample_rate(&gb, have_aspec.freq); GB_set_color_correction_mode(&gb, get_color_correction_mode()); GB_set_highpass_filter_mode(&gb, get_highpass_mode()); diff --git a/gtk3/main.h b/gtk3/main.h index f2eb600..b5e2a40 100644 --- a/gtk3/main.h +++ b/gtk3/main.h @@ -103,7 +103,6 @@ G_MODULE_EXPORT void on_sgb_model_changed(GtkWidget *w, gpointer user_data_gptr) G_MODULE_EXPORT void on_use_integer_scaling_changed(GtkWidget *w, gpointer user_data_gptr); static uint32_t rgb_encode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b); -static uint32_t rgb_encode_fallback(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b); static void render_texture(void *pixels, void *previous); static void update_viewport(void); static void update_window_geometry(); diff --git a/gtk3/shader.c b/gtk3/shader.c index 402e5b9..a247c4b 100644 --- a/gtk3/shader.c +++ b/gtk3/shader.c @@ -178,13 +178,13 @@ void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous, glUniform2f(shader->resolution_uniform, w, h); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, shader->texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap); + 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); if (previous) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, shader->previous_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, previous); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, source_width, source_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, previous); glUniform1i(shader->previous_texture_uniform, 1); } glBindFragDataLocation(shader->program, 0, "frag_color");