From b2cf64c117b89bb65997ade66f8c35825f3f2b29 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 3 Jun 2023 15:05:55 -0500 Subject: [PATCH] GUI: GL render backend now supports ES --- CMakeLists.txt | 13 +++++++++++++ src/gui/render/renderGL.cpp | 14 ++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75cd110e4..536ec434f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,12 @@ else() set(WITH_RENDER_OPENGL_DEFAULT ON) endif() +if (ANDROID) + set(USE_GLES_DEFAULT ON) +else() + set(USE_GLES_DEFAULT OFF) +endif() + option(BUILD_GUI "Build the tracker (disable to build only a headless player)" ${BUILD_GUI_DEFAULT}) option(USE_RTMIDI "Build with MIDI support using RtMidi." ${USE_RTMIDI_DEFAULT}) option(USE_SDL2 "Build with SDL2. Required to build with GUI." ${USE_SDL2_DEFAULT}) @@ -69,6 +75,7 @@ option(USE_BACKWARD "Use backward-cpp to print a backtrace on crash/abort." ${US option(WITH_JACK "Whether to build with JACK support. Auto-detects if JACK is available" ${WITH_JACK_DEFAULT}) option(WITH_RENDER_SDL "Whether to build with the SDL_Renderer render backend." ${WITH_RENDER_SDL_DEFAULT}) option(WITH_RENDER_OPENGL "Whether to build with the OpenGL render backend." ${WITH_RENDER_OPENGL_DEFAULT}) +option(USE_GLES "Use OpenGL ES for the OpenGL render backend." ${USE_GLES_DEFAULT}) option(SYSTEM_FFTW "Use a system-installed version of FFTW instead of the vendored one" OFF) option(SYSTEM_FMT "Use a system-installed version of fmt instead of the vendored one" OFF) option(SYSTEM_LIBSNDFILE "Use a system-installed version of libsndfile instead of the vendored one" OFF) @@ -704,8 +711,14 @@ if (WITH_RENDER_OPENGL) list(APPEND GUI_SOURCES src/gui/render/renderGL.cpp) list(APPEND GUI_SOURCES extern/imgui_patched/backends/imgui_impl_opengl3.cpp) list(APPEND DEPENDENCIES_DEFINES HAVE_RENDER_GL) + if (USE_GLES) + list(APPEND DEPENDENCIES_DEFINES USE_GLES) + list(APPEND DEPENDENCIES_DEFINES IMGUI_IMPL_OPENGL_ES2) + endif() if (WIN32) list(APPEND DEPENDENCIES_LIBRARIES opengl32) + elseif(USE_GLES) + list(APPEND DEPENDENCIES_LIBRARIES GLESv2) else() list(APPEND DEPENDENCIES_LIBRARIES GL) endif() diff --git a/src/gui/render/renderGL.cpp b/src/gui/render/renderGL.cpp index 0abc00cc9..951208abb 100644 --- a/src/gui/render/renderGL.cpp +++ b/src/gui/render/renderGL.cpp @@ -19,7 +19,13 @@ #include "renderGL.h" #include "../../ta-log.h" +#ifdef USE_GLES +#include "SDL_opengles2.h" +#define PIXEL_FORMAT GL_RGBA +#else #include "SDL_opengl.h" +#define PIXEL_FORMAT GL_UNSIGNED_INT_8_8_8_8_REV +#endif #include "backends/imgui_impl_opengl3.h" #define C(x) x; if (glGetError()!=GL_NO_ERROR) logW("OpenGL error in %s:%d: " #x,__FILE__,__LINE__); @@ -138,7 +144,7 @@ bool FurnaceGUIRenderGL::unlockTexture(void* which) { if (t->lockedData==NULL) return false; C(glBindTexture(GL_TEXTURE_2D,t->id)); - C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,t->width,t->height,0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV,t->lockedData)); + C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,t->width,t->height,0,GL_RGBA,PIXEL_FORMAT,t->lockedData)); C(glFlush()); delete[] t->lockedData; @@ -153,7 +159,7 @@ bool FurnaceGUIRenderGL::updateTexture(void* which, void* data, int pitch) { if (t->width*4!=pitch) return false; C(glBindTexture(GL_TEXTURE_2D,t->id)); - C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,t->width,t->height,0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV,data)); + C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,t->width,t->height,0,GL_RGBA,PIXEL_FORMAT,data)); return true; } @@ -163,7 +169,7 @@ void* FurnaceGUIRenderGL::createTexture(bool dynamic, int width, int height) { C(glBindTexture(GL_TEXTURE_2D,t->id)); C(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)); C(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)); - C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV,NULL)); + C(glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,PIXEL_FORMAT,NULL)); C(furActiveTexture(GL_TEXTURE0)); t->width=width; t->height=height; @@ -364,4 +370,4 @@ bool FurnaceGUIRenderGL::quit() { void FurnaceGUIRenderGL::quitGUI() { ImGui_ImplOpenGL3_Shutdown(); -} \ No newline at end of file +}