From 0212567d75f9b588a4ee25e4e7343831d861a4bc Mon Sep 17 00:00:00 2001 From: driver1998 Date: Tue, 1 Oct 2019 05:59:31 +0800 Subject: [PATCH 1/3] Support GLDirect (D3D9 to OGL1.1 wrapper) in gl1 driver --- gfx/drivers/gl1.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index 4ecf6631f8..3f178eab5a 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -564,9 +564,31 @@ static void draw_tex(gl1_t *gl1, int pot_width, int pot_height, int width, int h glPixelStorei(GL_UNPACK_ROW_LENGTH, pot_width); glBindTexture(GL_TEXTURE_2D, tex); - /* TODO: We could implement red/blue swap if client GL does not support BGRA... but even MS GDI Generic supports it */ - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, pot_width, pot_height, 0, format, type, NULL); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, frame_to_copy); + /* For whatever reason you can't send NULL in GLDirect, + so we send the frame as dummy data */ + glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, pot_width, pot_height, 0, format, type, frame_to_copy); + + if (!gl1->supports_bgra) { + uint8_t* frame_rgba = malloc(pot_width * pot_height * 4); + uint8_t* frame_bgra = frame_to_copy; + for (int y = 0; y < pot_height; y++) { + for (int x = 0; x < pot_width; x++) { + int index = (y * pot_width + x) * 4; + frame_rgba[index + 2] = frame_bgra[index + 0]; + frame_rgba[index + 1] = frame_bgra[index + 1]; + frame_rgba[index + 0] = frame_bgra[index + 2]; + frame_rgba[index + 3] = 255; + } + } + + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, type, frame_rgba); + free(frame_rgba); + } + else { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, frame_to_copy); + } + + if (tex == gl1->tex) { From 897488862ebb9235ecaa4f621a194a8bfa7bcb48 Mon Sep 17 00:00:00 2001 From: GH Cao Date: Tue, 1 Oct 2019 06:24:06 +0800 Subject: [PATCH 2/3] gl1: adapt C89 --- gfx/drivers/gl1.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index 3f178eab5a..54dd130e50 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -571,8 +571,9 @@ static void draw_tex(gl1_t *gl1, int pot_width, int pot_height, int width, int h if (!gl1->supports_bgra) { uint8_t* frame_rgba = malloc(pot_width * pot_height * 4); uint8_t* frame_bgra = frame_to_copy; - for (int y = 0; y < pot_height; y++) { - for (int x = 0; x < pot_width; x++) { + int x, y; + for (y = 0; y < pot_height; y++) { + for (x = 0; x < pot_width; x++) { int index = (y * pot_width + x) * 4; frame_rgba[index + 2] = frame_bgra[index + 0]; frame_rgba[index + 1] = frame_bgra[index + 1]; From 27d28771063197ea8a813159620a594c8f08e839 Mon Sep 17 00:00:00 2001 From: GH Cao Date: Tue, 1 Oct 2019 06:51:29 +0800 Subject: [PATCH 3/3] gl1: take care of const --- gfx/drivers/gl1.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index 54dd130e50..8ae8ddc231 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -568,28 +568,27 @@ static void draw_tex(gl1_t *gl1, int pot_width, int pot_height, int width, int h so we send the frame as dummy data */ glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, pot_width, pot_height, 0, format, type, frame_to_copy); + uint8_t *frame = (uint8_t*)frame_to_copy; + uint8_t *frame_rgba = NULL; if (!gl1->supports_bgra) { - uint8_t* frame_rgba = malloc(pot_width * pot_height * 4); - uint8_t* frame_bgra = frame_to_copy; - int x, y; - for (y = 0; y < pot_height; y++) { - for (x = 0; x < pot_width; x++) { - int index = (y * pot_width + x) * 4; - frame_rgba[index + 2] = frame_bgra[index + 0]; - frame_rgba[index + 1] = frame_bgra[index + 1]; - frame_rgba[index + 0] = frame_bgra[index + 2]; - frame_rgba[index + 3] = 255; + frame_rgba = (uint8_t*)malloc(pot_width * pot_height * 4); + if (frame_rgba) { + int x, y; + for (y = 0; y < pot_height; y++) { + for (x = 0; x < pot_width; x++) { + int index = (y * pot_width + x) * 4; + frame_rgba[index + 2] = frame[index + 0]; + frame_rgba[index + 1] = frame[index + 1]; + frame_rgba[index + 0] = frame[index + 2]; + frame_rgba[index + 3] = frame[index + 3]; + } } + frame = frame_rgba; } - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, type, frame_rgba); - free(frame_rgba); - } - else { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, frame_to_copy); } - + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, frame); + free(frame_rgba); if (tex == gl1->tex) {