[GTK3] Make rgb_encode() big endian compatible

This commit is contained in:
Maximilian Mader 2019-09-23 18:38:16 +02:00
parent 56308f8b73
commit 557bfd117e
Signed by: Max
GPG Key ID: F71D56A3151C4FB3

View File

@ -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]);