From 1c18c269dc590a3c43730133d13089b4f8ba5846 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Tue, 4 Jan 2022 23:18:51 +0100 Subject: [PATCH] ANDROID: Add GLAD support --- backends/graphics/android/android-graphics.cpp | 3 +-- backends/graphics3d/android/android-graphics3d.h | 2 -- backends/platform/android/android.cpp | 6 ++++++ backends/platform/android/android.h | 2 ++ backends/platform/android3d/android.cpp | 6 ++++++ backends/platform/android3d/android.h | 2 ++ backends/platform/android3d/graphics.h | 2 -- configure | 6 ++++-- graphics/opengl/context.cpp | 9 +++++++++ 9 files changed, 30 insertions(+), 8 deletions(-) diff --git a/backends/graphics/android/android-graphics.cpp b/backends/graphics/android/android-graphics.cpp index 2e76100bc58..410dd94f182 100644 --- a/backends/graphics/android/android-graphics.cpp +++ b/backends/graphics/android/android-graphics.cpp @@ -223,8 +223,7 @@ void AndroidGraphicsManager::touchControlNotifyChanged() { void *AndroidGraphicsManager::getProcAddress(const char *name) const { ENTER("%s", name); - // TODO: Support dynamically loaded OpenGL - return nullptr; + return androidGLgetProcAddress(name); } bool AndroidGraphicsManager::notifyMousePosition(Common::Point &mouse) { diff --git a/backends/graphics3d/android/android-graphics3d.h b/backends/graphics3d/android/android-graphics3d.h index 73edaa86c96..0e1d3b942f1 100644 --- a/backends/graphics3d/android/android-graphics3d.h +++ b/backends/graphics3d/android/android-graphics3d.h @@ -134,8 +134,6 @@ protected: void refreshScreen(); - void *getProcAddress(const char *name) const; - private: void initOverlay(); diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 4ec28f177f8..5624de31a18 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -40,6 +40,7 @@ // for the Android port #define FORBIDDEN_SYMBOL_EXCEPTION_printf +#include #include #include #include @@ -120,6 +121,11 @@ void checkGlError(const char *expr, const char *file, int line) { } #endif +void *androidGLgetProcAddress(const char *name) { + // This exists since Android 2.3 (API Level 9) + return (void *)eglGetProcAddress(name); +} + OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _audio_sample_rate(audio_sample_rate), _audio_buffer_size(audio_buffer_size), diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index 6111d1e33e7..75fe0d8cddc 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -93,6 +93,8 @@ extern void checkGlError(const char *expr, const char *file, int line); #define GLTHREADCHECK do { } while (false) #endif +void *androidGLgetProcAddress(const char *name); + class OSystem_Android : public ModularGraphicsBackend, Common::EventSource { private: // passed from the dark side diff --git a/backends/platform/android3d/android.cpp b/backends/platform/android3d/android.cpp index 0595711cc24..7625d0f8890 100644 --- a/backends/platform/android3d/android.cpp +++ b/backends/platform/android3d/android.cpp @@ -40,6 +40,7 @@ // for the Android port #define FORBIDDEN_SYMBOL_EXCEPTION_printf +#include #include #include #include @@ -118,6 +119,11 @@ void checkGlError(const char *expr, const char *file, int line) { } #endif +void *androidGLgetProcAddress(const char *name) { + // This exists since Android 2.3 (API Level 9) + return (void *)eglGetProcAddress(name); +} + OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _audio_sample_rate(audio_sample_rate), _audio_buffer_size(audio_buffer_size), diff --git a/backends/platform/android3d/android.h b/backends/platform/android3d/android.h index ad9acd19fbc..d1cfa9c1745 100644 --- a/backends/platform/android3d/android.h +++ b/backends/platform/android3d/android.h @@ -100,6 +100,8 @@ extern void checkGlError(const char *expr, const char *file, int line); #define GLTHREADCHECK do { } while (false) #endif +void *androidGLgetProcAddress(const char *name); + class OSystem_Android : public ModularGraphicsBackend, Common::EventSource { private: // passed from the dark side diff --git a/backends/platform/android3d/graphics.h b/backends/platform/android3d/graphics.h index b1c66f507dd..8fa5c35178e 100644 --- a/backends/platform/android3d/graphics.h +++ b/backends/platform/android3d/graphics.h @@ -114,8 +114,6 @@ protected: void refreshScreen(); - void *getProcAddress(const char *name) const; - private: void setCursorPaletteInternal(const byte *colors, uint start, uint num); void disableCursorPalette(); diff --git a/configure b/configure index aea37244594..2b937d5e18f 100755 --- a/configure +++ b/configure @@ -5334,10 +5334,12 @@ if test "$_opengl_mode" != none ; then android) # We require API level 16 while GLES2 APIs have been added in level 8 so we are safe for compilation _opengl_mode=gles2 + _opengl_glad=yes ;; android3d) # We require API level 16 while GLES2 APIs have been added in level 8 so we are safe for compilation _opengl_mode=gles2 + _opengl_glad=yes ;; openpandora) # Enable GLES only if user explicitely requested it @@ -6125,7 +6127,7 @@ case $_host_os in system_libs='' for lib in $LIBS; do case $lib in - -lz|-lm|-ldl|-lGLESv2) + -lz|-lm|-ldl) system_libs="$system_libs $lib" ;; *) @@ -6137,7 +6139,7 @@ case $_host_os in # -lgcc is carefully placed here - we want to catch # all toolchain symbols in *our* libraries rather # than pick up anything unhygenic from the Android libs. - LIBS="-Wl,-Bstatic $static_libs -Wl,-Bdynamic -lgcc $system_libs -llog -landroid -ljnigraphics -lGLESv2" + LIBS="-Wl,-Bstatic $static_libs -Wl,-Bdynamic -lgcc $system_libs -llog -landroid -ljnigraphics -lEGL" ;; ds) # Moved -Wl,--gc-sections here to avoid it interfering with the library checks diff --git a/graphics/opengl/context.cpp b/graphics/opengl/context.cpp index ba7c614397c..4076fe22654 100644 --- a/graphics/opengl/context.cpp +++ b/graphics/opengl/context.cpp @@ -38,6 +38,15 @@ static GLADapiproc loadFunc(void *userptr, const char *name) { return (GLADapiproc)SDL_GL_GetProcAddress(name); } + +#elif defined(__ANDROID__) +// To keep includes light, don't include EGL here and don't include Android headers +void *androidGLgetProcAddress(const char *name); + +static GLADapiproc loadFunc(void *userptr, const char *name) { + return (GLADapiproc)androidGLgetProcAddress(name); +} + #else #error Not implemented #endif