[GTK3] Use logical ARGB byte order for image buffers

This commit is contained in:
Maximilian Mader 2019-09-30 17:18:58 +02:00
parent 8d0526fd1f
commit 8e8e576460
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
3 changed files with 4 additions and 27 deletions

View File

@ -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) { 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, return 0xFF000000 | (r << 16) | (g << 8) | b;
// 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;
} }
static void render_texture(void *pixels, void *previous) { 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_vblank_callback(&gb, (GB_vblank_callback_t) vblank);
GB_set_pixels_output(&gb, get_current_buffer()); 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_sample_rate(&gb, have_aspec.freq);
GB_set_color_correction_mode(&gb, get_color_correction_mode()); GB_set_color_correction_mode(&gb, get_color_correction_mode());
GB_set_highpass_filter_mode(&gb, get_highpass_mode()); GB_set_highpass_filter_mode(&gb, get_highpass_mode());

View File

@ -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); 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(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 render_texture(void *pixels, void *previous);
static void update_viewport(void); static void update_viewport(void);
static void update_window_geometry(); static void update_window_geometry();

View File

@ -178,13 +178,13 @@ void render_bitmap_with_shader(shader_t *shader, void *bitmap, void *previous,
glUniform2f(shader->resolution_uniform, w, h); glUniform2f(shader->resolution_uniform, w, h);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, shader->texture); 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->texture_uniform, 0);
glUniform1i(shader->mix_previous_uniform, previous != NULL); glUniform1i(shader->mix_previous_uniform, previous != NULL);
if (previous) { if (previous) {
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, shader->previous_texture); 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); glUniform1i(shader->previous_texture_uniform, 1);
} }
glBindFragDataLocation(shader->program, 0, "frag_color"); glBindFragDataLocation(shader->program, 0, "frag_color");