From e5d800c344dac3e4b95ee6c5c326dbd8f0714594 Mon Sep 17 00:00:00 2001 From: Curi0 Date: Tue, 3 Oct 2017 13:38:28 +0530 Subject: [PATCH] Cleanup and refractoring EGL / OpenGL ES also now working --- include/GLFW/glfw3.h | 4 +--- src/android_init.c | 39 +++++++++++++++++++++++++++++++++++++++ src/android_platform.h | 5 +++-- src/android_window.c | 41 ----------------------------------------- 4 files changed, 43 insertions(+), 46 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 17ef60cc3..8d1600d91 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -5207,6 +5207,4 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window } #endif -#endif /* _glfw3_h_ */ - -extern int main(); \ No newline at end of file +#endif /* _glfw3_h_ */ \ No newline at end of file diff --git a/src/android_init.c b/src/android_init.c index b03b44476..b94e597ca 100644 --- a/src/android_init.c +++ b/src/android_init.c @@ -25,9 +25,47 @@ // //======================================================================== +#include #include "internal.h" +extern int main(); +void handle_cmd(struct android_app* _app, int32_t cmd) { + switch (cmd) { + case APP_CMD_INIT_WINDOW: + // The window is being shown so the initialization is finished. + app = _app; + break; + default: + __android_log_print(ANDROID_LOG_INFO, "GLFW", + "event not handled: %d", cmd); + } +} +// Android Entry Point +void android_main(struct android_app *app) { + app->onAppCmd = handle_cmd; + pthread_t t;pthread_create(&t, NULL, &main, NULL); // Call the main entry point + + while (1) { + int ident; + int events; + struct android_poll_source* source; + + while ((ident=ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0) { + + // Process this event. + if (source != NULL) { + source->process(app, source); + } + + // Check if we are exiting. + if (app->destroyRequested != 0) { + return; + } + } + } + +} ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// @@ -35,6 +73,7 @@ int _glfwPlatformInit(void) { _glfwInitTimerPOSIX(); + while (app == NULL); // Wait for the app to be initialized or the app will crash occasionally return GLFW_TRUE; } diff --git a/src/android_platform.h b/src/android_platform.h index 4d20f9008..f97f893e3 100644 --- a/src/android_platform.h +++ b/src/android_platform.h @@ -48,8 +48,9 @@ #define _GLFW_PLATFORM_CONTEXT_STATE #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE -// Null-specific per-window data -// +struct android_app* app; + +// Android-specific per-window data typedef struct _GLFWwindowAndroid { int width; diff --git a/src/android_window.c b/src/android_window.c index 1fd7e9384..4056438c0 100644 --- a/src/android_window.c +++ b/src/android_window.c @@ -29,46 +29,6 @@ #include #include -struct android_app* app; - -void handle_cmd(struct android_app* _app, int32_t cmd) { - switch (cmd) { - case APP_CMD_INIT_WINDOW: - // The window is being shown, get it ready. - app = _app; - __android_log_print(ANDROID_LOG_INFO, "GLFW", - "Window initialized"); - default: - __android_log_print(ANDROID_LOG_INFO, "GLFW", - "event not handled: %d", cmd); - } -} - -// Android Entry Point -void android_main(struct android_app *app) { - app->onAppCmd = handle_cmd; - pthread_t t;pthread_create(&t, NULL, &main, NULL); // Call the main entry point - - while (1) { - int ident; - int events; - struct android_poll_source* source; - - while ((ident=ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0) { - - // Process this event. - if (source != NULL) { - source->process(app, source); - } - - // Check if we are exiting. - if (app->destroyRequested != 0) { - return; - } - } - } - -} ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// @@ -78,7 +38,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig) { - while (app == NULL); // Wait for the app to be initialized or the app will crash occasionally window->android.app = app; if (ctxconfig->client != GLFW_NO_API)