From 8e52190221eddf1f3de54a59ad26702f49a289b5 Mon Sep 17 00:00:00 2001 From: thesource Date: Mon, 15 Jul 2024 10:59:21 +0300 Subject: [PATCH 1/3] GTK: add OpenGL ES support --- desmume/src/frontend/posix/gtk/graphics.ui | 1 + desmume/src/frontend/posix/gtk/main.cpp | 22 ++++++++++++++++++---- desmume/src/frontend/posix/meson.build | 9 +++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/graphics.ui b/desmume/src/frontend/posix/gtk/graphics.ui index f8dc2976b..e71bd9a64 100644 --- a/desmume/src/frontend/posix/gtk/graphics.ui +++ b/desmume/src/frontend/posix/gtk/graphics.ui @@ -65,6 +65,7 @@ Null SoftRasterizer OpenGL + OpenGL ES diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index a9ad5b3aa..c42ca3403 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -79,6 +79,10 @@ #include "OGLRender_3_2.h" #endif +#ifdef HAVE_GLES3 + #include "OGLRender_ES3.h" +#endif + #if defined(HAVE_LIBOSMESA) #include "osmesa_3Demu.h" #else @@ -349,6 +353,9 @@ GPU3DInterface *core3DList[] = { #ifdef HAVE_OPENGL &gpu3Dgl, #endif +#ifdef HAVE_GLES3 + &gpu3Dgl_ES_3_0, +#endif }; int multisampleSizes[] = {0, 2, 4, 8, 16, 32}; @@ -2229,9 +2236,11 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g wHCInterpolate = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "hc_interpolate")); g_object_unref(builder); +#ifndef HAVE_GLES3 + gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(coreCombo), 3); +#endif #ifndef HAVE_OPENGL gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(coreCombo), 2); - gtk_grid_remove_row(wGrid, 4); #endif gtk_combo_box_set_active(coreCombo, cur3DCore); @@ -2270,7 +2279,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g // Change only if needed if (sel3DCore != cur3DCore) { - if (sel3DCore == 2) + if (sel3DCore >= 2) { #if !defined(HAVE_OPENGL) sel3DCore = RENDERID_SOFTRASTERIZER; @@ -3819,6 +3828,11 @@ common_gtk_main(GApplication *app, gpointer user_data) OGLCreateRenderer_3_2_Func = OGLCreateRenderer_3_2; #endif +#if defined(HAVE_GLES3) && defined(OGLRENDER_ES3_H) + OGLLoadEntryPoints_ES_3_0_Func = OGLLoadEntryPoints_ES_3_0; + OGLCreateRenderer_ES_3_0_Func = OGLCreateRenderer_ES_3_0; +#endif + //Set the 3D emulation to use int core = my_config->engine_3d; // setup the gdk 3D emulation; @@ -3829,7 +3843,7 @@ common_gtk_main(GApplication *app, gpointer user_data) core = config.core3D; // Check if it is valid - if (!(core >= 0 && core <= 2)) { + if (!(core >= 0 && core <= 3)) { // If it is invalid, reset it to SoftRasterizer core = 1; } @@ -3837,7 +3851,7 @@ common_gtk_main(GApplication *app, gpointer user_data) my_config->engine_3d = core; } - if (core == 2) + if (core >= 2) { #if !defined(HAVE_OPENGL) core = RENDERID_SOFTRASTERIZER; diff --git a/desmume/src/frontend/posix/meson.build b/desmume/src/frontend/posix/meson.build index 13bf45a25..f10117780 100644 --- a/desmume/src/frontend/posix/meson.build +++ b/desmume/src/frontend/posix/meson.build @@ -16,6 +16,7 @@ dep_pcap = dependency('pcap') dep_zlib = dependency('zlib') dep_threads = dependency('threads') dep_gl = dependency('gl', required: false) +dep_gles3 = dependency('glesv2', required: false) dep_openal = dependency('openal', required: get_option('openal')) dep_alsa = dependency('alsa', required: false) dep_soundtouch = dependency('soundtouch', required: false) @@ -176,6 +177,14 @@ if dep_gl.found() ] endif +if dep_gles3.found() + dependencies += dep_gles3 + add_global_arguments('-DHAVE_GLES3', language: ['c', 'cpp']) + libdesmume_src += [ + '../../OGLRender_ES3.cpp', + ] +endif + if dep_openal.found() dependencies += dep_openal libdesmume_src += [ From 9a75aabe071fd99a95b3189645ac413173e4483d Mon Sep 17 00:00:00 2001 From: thesource Date: Mon, 15 Jul 2024 11:20:11 +0300 Subject: [PATCH 2/3] Fix GLES initialization --- desmume/src/frontend/posix/gtk/main.cpp | 4 ++-- desmume/src/frontend/posix/gtk/sdl_3Demu.cpp | 17 +++++++++++++---- desmume/src/frontend/posix/gtk/sdl_3Demu.h | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index c42ca3403..a40bb2de2 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -2291,7 +2291,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g #else if (!is_sdl_initialized()) { - init_sdl_3Demu(); + init_sdl_3Demu(sel3DCore==3); } #endif } @@ -3863,7 +3863,7 @@ common_gtk_main(GApplication *app, gpointer user_data) #else if (!is_sdl_initialized()) { - init_sdl_3Demu(); + init_sdl_3Demu(core==3); } #endif } diff --git a/desmume/src/frontend/posix/gtk/sdl_3Demu.cpp b/desmume/src/frontend/posix/gtk/sdl_3Demu.cpp index 39c5d0d57..603611d8b 100644 --- a/desmume/src/frontend/posix/gtk/sdl_3Demu.cpp +++ b/desmume/src/frontend/posix/gtk/sdl_3Demu.cpp @@ -50,7 +50,7 @@ bool deinit_sdl_3Demu(void) return ret; } -bool init_sdl_3Demu(void) +bool init_sdl_3Demu(bool useES) { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); @@ -59,9 +59,18 @@ bool init_sdl_3Demu(void) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + if(useES) + { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + } + else + { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + } win = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, real_framebuffer_width, real_framebuffer_height, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN); diff --git a/desmume/src/frontend/posix/gtk/sdl_3Demu.h b/desmume/src/frontend/posix/gtk/sdl_3Demu.h index 2088263da..a369617b2 100644 --- a/desmume/src/frontend/posix/gtk/sdl_3Demu.h +++ b/desmume/src/frontend/posix/gtk/sdl_3Demu.h @@ -18,7 +18,7 @@ #ifndef SDL_3DEMU_H #define SDL_3DEMU_H -bool init_sdl_3Demu(void); +bool init_sdl_3Demu(bool useES); bool deinit_sdl_3Demu(void); bool is_sdl_initialized(void); From 3a31d0d726a5972fd68324d061de53a545226b9b Mon Sep 17 00:00:00 2001 From: thesource Date: Mon, 15 Jul 2024 12:22:59 +0300 Subject: [PATCH 3/3] Tabs/spaces and some tweaks --- desmume/src/frontend/posix/gtk/graphics.ui | 2 +- desmume/src/frontend/posix/gtk/main.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/graphics.ui b/desmume/src/frontend/posix/gtk/graphics.ui index e71bd9a64..75d2dae55 100644 --- a/desmume/src/frontend/posix/gtk/graphics.ui +++ b/desmume/src/frontend/posix/gtk/graphics.ui @@ -65,7 +65,7 @@ Null SoftRasterizer OpenGL - OpenGL ES + OpenGL ES diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index a40bb2de2..898a19b6b 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -432,6 +432,9 @@ fill_configured_features( class configured_features *config, "\t\t\t\t 1 = internal rasterizer (default)\n" #ifdef HAVE_OPENGL "\t\t\t\t 2 = opengl\n" +#endif +#ifdef HAVE_GLES3 + "\t\t\t\t 3 = gles\n" #endif ,"ENGINE"}, { "save-type", 0, 0, G_OPTION_ARG_INT, &config->savetype, "Select savetype from the following:\n" @@ -476,11 +479,17 @@ fill_configured_features( class configured_features *config, if (config->engine_3d != 0 && config->engine_3d != 1 #ifdef HAVE_OPENGL && config->engine_3d != 2 +#endif +#ifdef HAVE_GLES3 + && config->engine_3d != 3 #endif ) { g_printerr("Currently available ENGINES: 0, 1" #ifdef HAVE_OPENGL ", 2" +#endif +#ifdef HAVE_GLES3 + ", 3" #endif "\n"); goto error; @@ -2256,7 +2265,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g // 3D Texture Smoothing gtk_toggle_button_set_active(wSmoothing, CommonSettings.GFX3D_Renderer_TextureSmoothing); -#ifdef HAVE_OPENGL +#if defined(HAVE_OPENGL) || defined(HAVE_GLES3) // OpenGL Multisample int currentMultisample = CommonSettings.GFX3D_Renderer_MultisampleSize; int currentActive = 0; @@ -2351,7 +2360,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g CommonSettings.GFX3D_Renderer_TextureSmoothing = config.textureSmoothing = gtk_toggle_button_get_active(wSmoothing); CommonSettings.GFX3D_Renderer_TextureScalingFactor = config.textureUpscale = scale; CommonSettings.GFX3D_HighResolutionInterpolateColor = config.highColorInterpolation = gtk_toggle_button_get_active(wHCInterpolate); -#ifdef HAVE_OPENGL +#if defined(HAVE_OPENGL) || defined(HAVE_GLES3) int selectedMultisample = gtk_combo_box_get_active(wMultisample); config.multisamplingSize = multisampleSizes[selectedMultisample]; config.multisampling = selectedMultisample != 0;