diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f3b37c27..847a8c69a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -389,7 +389,11 @@ elseif(PLATFORM STREQUAL "android") target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl) target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_common) target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/image) - add_compile_definitions(ENABLE_GLES PLATFORM_ANDROID) + add_compile_definitions(PLATFORM_ANDROID) + + # GLAD + add_library(glad STATIC vendor/glad/src/glad.c) + target_include_directories(glad PUBLIC vendor/glad/include) # Butterscotch VM/interpreter profiler option(ENABLE_VM_GML_PROFILER "Enable Butterscotch VM/interpreter profiler" ON) @@ -430,9 +434,9 @@ elseif(PLATFORM STREQUAL "android") # Android NDK system libraries: # - log: __android_log_* - # - GLESv3: OpenGL ES 3.0 functions + # - EGL: eglGetProcAddress used by the Glad GLES2 loader # - OpenSLES: miniaudio's OpenSL ES backend (it dlopen's libaaudio.so at runtime when available, so no link-time aaudio dep) - target_link_libraries(butterscotch PRIVATE log GLESv3 OpenSLES bzip2 stb_ds sha1 stb_vorbis) + target_link_libraries(butterscotch PRIVATE glad log EGL OpenSLES bzip2 stb_ds sha1 stb_vorbis) elseif(PLATFORM STREQUAL "ps2") file(GLOB DEBUG_FONT_SOURCES src/debug_font/*.c) target_sources(butterscotch PRIVATE ${DEBUG_FONT_SOURCES}) diff --git a/src/android/main.c b/src/android/main.c index ec44c2ae7..7b1cbc2f9 100644 --- a/src/android/main.c +++ b/src/android/main.c @@ -5,7 +5,9 @@ #include #include #include -#include +#include +#include +#include #include "common.h" #include "data_win.h" @@ -406,6 +408,13 @@ JNIEXPORT jboolean JNICALL JNI_FN(startRunner)(JNIEnv* env, MAYBE_UNUSED jclass return JNI_FALSE; } gHostFramebuffer = (GLuint) jHostFramebuffer; + + if (!gladLoadGLES2Loader((GLADloadproc)eglGetProcAddress)) { + LOGE("Failed to load OpenGL ES via Glad"); + return JNI_FALSE; + } + LOGI("GL Version: %s", glGetString(GL_VERSION)); + const char* dataWinPath = (*env)->GetStringUTFChars(env, jDataWinPath, nullptr); const char* savesPath = (*env)->GetStringUTFChars(env, jSavesPath, nullptr); char** gameArgs = nullptr; diff --git a/src/gl/gl_renderer.c b/src/gl/gl_renderer.c index 3ee52a901..d6df0437f 100644 --- a/src/gl/gl_renderer.c +++ b/src/gl/gl_renderer.c @@ -2,7 +2,7 @@ #include "matrix_math.h" #include "text_utils.h" -#if defined(__EMSCRIPTEN__) || defined(__ANDROID__) +#if defined(__EMSCRIPTEN__) #include #else #include @@ -52,7 +52,7 @@ static const char* baseFragmentShader = // ===[ Runtime OpenGL extension checks ]=== static bool hasFBO() { -#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) +#if !defined(__EMSCRIPTEN__) return glGenFramebuffers; #else return true; @@ -60,7 +60,7 @@ static bool hasFBO() { } static bool hasVAO() { -#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) +#if !defined(__EMSCRIPTEN__) return glGenVertexArrays; #else return true; diff --git a/src/gl/gl_renderer.h b/src/gl/gl_renderer.h index 26a5a7178..598e3e7ae 100644 --- a/src/gl/gl_renderer.h +++ b/src/gl/gl_renderer.h @@ -4,7 +4,7 @@ #include "common.h" #include "renderer.h" #include "runner.h" -#if defined(__EMSCRIPTEN__) || defined(__ANDROID__) +#if defined(__EMSCRIPTEN__) #include #else #include diff --git a/src/gl_common/gl_common.h b/src/gl_common/gl_common.h index 5a66b86f9..0ba12664c 100644 --- a/src/gl_common/gl_common.h +++ b/src/gl_common/gl_common.h @@ -4,13 +4,14 @@ #include "common.h" #include -#if defined(__EMSCRIPTEN__) || defined(__ANDROID__) +#if defined(__EMSCRIPTEN__) #include -#elif PLATFORM_PS3 +#elif defined(__ANDROID__) || !defined(PLATFORM_PS3) +#include +#endif +#if PLATFORM_PS3 #include "ps3gl.h" #include "rsxutil.h" -#else -#include #endif // ===[ Letterbox blit ]=== diff --git a/src/gl_common/gl_wrappers.h b/src/gl_common/gl_wrappers.h index 01ce02abe..ae8d51e8f 100644 --- a/src/gl_common/gl_wrappers.h +++ b/src/gl_common/gl_wrappers.h @@ -1,4 +1,4 @@ -#if !defined(_BS_GL_WRAPPERS_H_) && !defined(__EMSCRIPTEN__) && !defined(PLATFORM_PS3) && !defined(__ANDROID__) +#if !defined(_BS_GL_WRAPPERS_H_) && !defined(__EMSCRIPTEN__) && !defined(PLATFORM_PS3) #define _BS_GL_WRAPPERS_H_ static inline void gl_init_wrappers(void) {