From b976938be8cff5f8717f8c34adba7801bd74864b Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Mon, 23 Sep 2019 18:38:16 +0200 Subject: [PATCH] [GTK3] Make rgb_encode() big endian compatible --- gtk3/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gtk3/main.c b/gtk3/main.c index 86c9596..165af4e 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -372,7 +372,16 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin } static uint32_t rgb_encode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b) { - uint32_t color = 0xFF000000 | (b << 16) | (g << 8) | r; // abgr + // 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; } @@ -394,6 +403,7 @@ static void update_window_geometry() { GB_get_screen_height(&gb) * 2 ); + // Setup our image buffers if (image_buffers[0]) free(image_buffers[0]); if (image_buffers[1]) free(image_buffers[1]); if (image_buffers[2]) free(image_buffers[2]);