Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,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)
Expand Down Expand Up @@ -429,9 +433,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})
Expand Down
11 changes: 10 additions & 1 deletion src/android/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include <dlfcn.h>
#include <EGL/egl.h>
#include <glad/glad.h>

#include "common.h"
#include "data_win.h"
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/gl/gl_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "matrix_math.h"
#include "text_utils.h"

#if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
#if defined(__EMSCRIPTEN__)
#include <GLES3/gl3.h>
#else
#include <glad/glad.h>
Expand Down Expand Up @@ -51,15 +51,15 @@ static const char* baseFragmentShader =
// ===[ Runtime OpenGL extension checks ]===

static bool hasFBO() {
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
#if !defined(__EMSCRIPTEN__)
return (glGenFramebuffers || glGenFramebuffersEXT);
#else
return true;
#endif
}

static bool hasVAO() {
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
#if !defined(__EMSCRIPTEN__)
return (glGenVertexArrays || glGenVertexArraysOES);
#else
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/gl/gl_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "common.h"
#include "renderer.h"
#include "runner.h"
#if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
#if defined(__EMSCRIPTEN__)
#include <GLES3/gl3.h>
#else
#include <glad/glad.h>
Expand Down
9 changes: 5 additions & 4 deletions src/gl_common/gl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include "common.h"
#include <stdint.h>

#if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
#if defined(__EMSCRIPTEN__)
#include <GLES3/gl3.h>
#elif PLATFORM_PS3
#elif defined(__ANDROID__) || !defined(PLATFORM_PS3)
#include <glad/glad.h>
#endif
#if PLATFORM_PS3
#include "ps3gl.h"
#include "rsxutil.h"
#else
#include <glad/glad.h>
#endif

// ===[ Letterbox blit ]===
Expand Down
2 changes: 1 addition & 1 deletion src/gl_common/gl_wrappers.h
Original file line number Diff line number Diff line change
@@ -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 rt_glBindVertexArray(GLuint vao) {
Expand Down
Loading