1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-04 13:33:34 +00:00
lovr/src/core/os_android.c

199 lines
4.4 KiB
C
Raw Normal View History

2019-12-14 03:58:22 +00:00
#include "os.h"
#include <stdio.h>
#include <unistd.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
2020-01-29 05:42:44 +00:00
static struct {
EGLDisplay display;
EGLContext context;
EGLSurface surface;
} state;
// Currently, the Android entrypoint is in lovr-oculus-mobile, so this one is not enabled.
#if 0
#include <android_native_app_glue.h>
#include <android/log.h>
static JavaVM* lovrJavaVM;
static JNIEnv* lovrJNIEnv;
int main(int argc, char** argv);
static void onAppCmd(struct android_app* app, int32_t cmd) {
// pause, resume, events, etc.
}
void android_main(struct android_app* app) {
lovrJavaVM = app->activity->vm;
lovrJavaVM->AttachCurrentThread(&lovrJNIEnv, NULL);
app->onAppCmd = onAppCmd;
main(0, NULL);
lovrJavaVM->DetachCurrentThread();
}
#endif
bool lovrPlatformInit() {
return true;
}
void lovrPlatformDestroy() {
2020-01-29 05:42:44 +00:00
#if 0
if (state.display) eglMakeCurrent(state.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (state.surface) eglDestroySurface(state.display, state.surface);
if (state.context) eglDestroyContext(state.display, state.context);
if (state.display) eglTerminate(state.display);
memset(&state, 0, sizeof(state));
#endif
}
const char* lovrPlatformGetName() {
return "Android";
}
void lovrPlatformPollEvents() {
// TODO
}
2019-06-17 01:55:21 +00:00
void lovrPlatformOpenConsole() {
// TODO
2019-06-17 01:55:21 +00:00
}
bool lovrPlatformCreateWindow(WindowFlags* flags) {
2020-01-29 05:42:44 +00:00
#if 0 // lovr-oculus-mobile creates the EGL context right now
if (state.display) {
return true;
}
if ((state.display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
return false;
}
if (eglInitialize(state.display, NULL, NULL) == EGL_FALSE) {
return false;
}
EGLConfig configs[1024];
EGLint configCount;
if (eglGetConfigs(state.display, configs, sizeof(configs) / sizeof(configs[0]), &configCount) == EGL_FALSE) {
return false;
}
const EGLint attributes[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 0,
EGL_STENCIL_SIZE, 0,
EGL_SAMPLES, 0,
EGL_NONE
};
EGLconfig config = 0;
for (EGLint i = 0; i < configCount && !config; i++) {
EGLint value, mask;
mask = EGL_OPENGL_ES3_BIT_KHR;
if (!eglGetConfigAttrib(state.display, configs[i], EGL_RENDERABLE_TYPE, &value) || (value & mask) != mask) {
continue;
}
mask = EGL_PBUFFER_BIT | EGL_WINDOW_BIT;
if (!eglGetConfigAttrib(state.display, configs[i], EGL_SURFACE_TYPE, &value) || (value & mask) != mask) {
continue;
}
for (int a = 0; a < sizeof(attributes) / sizeof(attributes[0]); a += 2) {
if (attributes[a] == EGL_NONE) {
config = configs[i];
break;
}
if (!eglGetConfigAttrib(state.display, configs[i], attributes[a], &value) || value != attributes[a + 1]) {
break;
}
}
}
EGLint contextAttributes[] = {
EGL_CONTEXT_CLIENT_VERSION, 3,
EGL_NONE
};
if ((state.context = eglCreateContext(state.display, configs[i], EGL_NO_CONTEXT, contextAttributes)) == EGL_NO_CONTEXT) {
return false;
}
EGLint surfaceAttributes[] = {
EGL_WIDTH, 16,
EGL_HEIGHT, 16,
EGL_NONE
};
if ((state.surface = eglCreatePbufferSurface(state.display, config, surfaceAttributes)) == EGL_NO_SURFACE) {
eglDestroyContext(state.context);
return false;
}
if (eglMakeCurrent(state.display, state.surface, state.surface, state.context) == EGL_FALSE) {
eglDestroySurface(state.surface);
eglDestroyContext(state.context);
}
#endif
return true;
}
void lovrPlatformGetWindowSize(int* width, int* height) {
if (width) *width = 0;
if (height) *height = 0;
}
void lovrPlatformSwapBuffers() {
//
}
void* lovrPlatformGetProcAddress(const char* function) {
return (void*) eglGetProcAddress(function);
}
void lovrPlatformOnWindowClose(windowCloseCallback callback) {
//
}
2020-01-28 05:10:27 +00:00
void lovrPlatformOnWindowFocus(windowFocusCallback callback) {
//
}
void lovrPlatformOnWindowResize(windowResizeCallback callback) {
//
}
void lovrPlatformOnMouseButton(mouseButtonCallback callback) {
//
}
2019-06-06 03:22:51 +00:00
void lovrPlatformOnKeyboardEvent(keyboardCallback callback) {
//
}
void lovrPlatformGetMousePosition(double* x, double* y) {
*x = *y = 0.;
}
void lovrPlatformSetMouseMode(MouseMode mode) {
//
}
bool lovrPlatformIsMouseDown(MouseButton button) {
return false;
}
bool lovrPlatformIsKeyDown(KeyCode key) {
return false;
}
2019-05-20 11:02:25 +00:00
void lovrPlatformSleep(double seconds) {
usleep((unsigned int) (seconds * 1000000));
}