Add EGL context support and entry point

untested trying to link it with a native activity results in a linker error
This commit is contained in:
Curi0 2017-09-16 15:06:48 +05:30
parent 046ac02b23
commit a49f7b94df
6 changed files with 46 additions and 57 deletions

View File

@ -197,7 +197,7 @@ extern "C" {
#include <OpenGL/glu.h> #include <OpenGL/glu.h>
#endif #endif
#else /*__APPLE__*/ #elif !defined(ANDROID) /*__APPLE__*/
#include <GL/gl.h> #include <GL/gl.h>
#if defined(GLFW_INCLUDE_GLEXT) #if defined(GLFW_INCLUDE_GLEXT)
@ -5202,3 +5202,4 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window
#endif /* _glfw3_h_ */ #endif /* _glfw3_h_ */
extern void glfwMain();

View File

@ -63,7 +63,7 @@ elseif (_GLFW_ANDROID)
set(glfw_HEADERS ${common_HEADERS} android_platform.h android_joystick.h set(glfw_HEADERS ${common_HEADERS} android_platform.h android_joystick.h
posix_time.h posix_thread.h) posix_time.h posix_thread.h)
set(glfw_SOURCES ${common_SOURCES} android_init.c android_monitor.c android_window.c set(glfw_SOURCES ${common_SOURCES} android_init.c android_monitor.c android_window.c
android_joystick.c posix_time.c posix_thread.c) android_joystick.c posix_time.c posix_thread.c egl_context.c osmesa_context.c ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
endif() endif()
if (APPLE) if (APPLE)
@ -100,7 +100,8 @@ target_include_directories(glfw PUBLIC
target_include_directories(glfw PRIVATE target_include_directories(glfw PRIVATE
"${GLFW_SOURCE_DIR}/src" "${GLFW_SOURCE_DIR}/src"
"${GLFW_BINARY_DIR}/src" "${GLFW_BINARY_DIR}/src"
${glfw_INCLUDE_DIRS}) ${glfw_INCLUDE_DIRS}
${ANDROID_NDK}/sources/android/native_app_glue/)
# HACK: When building on MinGW, WINVER and UNICODE need to be defined before # HACK: When building on MinGW, WINVER and UNICODE need to be defined before
# the inclusion of stddef.h (by glfw3.h), which is itself included before # the inclusion of stddef.h (by glfw3.h), which is itself included before

View File

@ -27,24 +27,26 @@
#include <dlfcn.h> #include <dlfcn.h>
#define _GLFW_PLATFORM_CONTEXT_STATE #include "egl_context.h"
#define _GLFW_PLATFORM_MONITOR_STATE
#define _GLFW_PLATFORM_CURSOR_STATE
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE
#define _GLFW_EGL_CONTEXT_STATE
#define _GLFW_EGL_LIBRARY_CONTEXT_STATE
#include "osmesa_context.h" #include "osmesa_context.h"
#include "posix_time.h" #include "posix_time.h"
#include "posix_thread.h" #include "posix_thread.h"
#include "android_joystick.h" #include "android_joystick.h"
#include <android/native_window.h> #include <android/native_window.h>
#include <android_native_app_glue.h>
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
#define _glfw_dlclose(handle) dlclose(handle) #define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name) #define _glfw_dlsym(handle, name) dlsym(handle, name)
#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->android.app->window)
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowAndroid android #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowAndroid android
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE
#define _GLFW_PLATFORM_MONITOR_STATE
#define _GLFW_PLATFORM_CURSOR_STATE
#define _GLFW_PLATFORM_CONTEXT_STATE
#define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE
// Null-specific per-window data // Null-specific per-window data
// //
@ -52,7 +54,7 @@ typedef struct _GLFWwindowAndroid
{ {
int width; int width;
int height; int height;
ANativeWindow *window; struct android_app *app;
} _GLFWwindowAndroid; } _GLFWwindowAndroid;
typedef VkFlags VkAndroidSurfaceCreateFlagsKHR; typedef VkFlags VkAndroidSurfaceCreateFlagsKHR;

View File

@ -26,18 +26,24 @@
//======================================================================== //========================================================================
#include "internal.h" #include "internal.h"
#include <android_native_app_glue.h>
#include <android/log.h>
static int createNativeWindow(_GLFWwindow* window, struct engine {
const _GLFWwndconfig* wndconfig) struct android_app* app;
{ };
window->android.width = wndconfig->width; struct engine engine;
window->android.height = wndconfig->height;
// Android Entry Point
void android_main(struct android_app *app) {
memset(&engine, 0, sizeof(engine));
app->userData = &engine;
engine.app = app;
glfwMain();
return GLFW_TRUE;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW platform API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -47,24 +53,23 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
if (!createNativeWindow(window, wndconfig)) window->android.app = engine.app;
return GLFW_FALSE;
if (ctxconfig->client != GLFW_NO_API) if (ctxconfig->client != GLFW_NO_API)
{ {
if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API || if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
ctxconfig->source == GLFW_OSMESA_CONTEXT_API) {
if (!_glfwInitEGL())
return GLFW_FALSE;
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
return GLFW_FALSE;
}
else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
{ {
if (!_glfwInitOSMesa()) if (!_glfwInitOSMesa())
return GLFW_FALSE; return GLFW_FALSE;
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
return GLFW_FALSE; return GLFW_FALSE;
} }
else
{
_glfwInputError(GLFW_API_UNAVAILABLE, "Null: EGL not available");
return GLFW_FALSE;
}
} }
return GLFW_TRUE; return GLFW_TRUE;
@ -307,7 +312,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
memset(&sci, 0, sizeof(sci)); memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
sci.surface = window->android.window; sci.surface = window->android.app->window;
err = vkCreateAndroidSurfaceKHR(instance, &sci, allocator, surface); err = vkCreateAndroidSurfaceKHR(instance, &sci, allocator, surface);
if (err) if (err)

View File

@ -373,8 +373,12 @@ GLFWbool _glfwInitEGL(void)
_glfwTerminateEGL(); _glfwTerminateEGL();
return GLFW_FALSE; return GLFW_FALSE;
} }
#if !defined(ANDROID)
_glfw.egl.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY); _glfw.egl.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY);
#else
_glfw.egl.display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
#endif
if (_glfw.egl.display == EGL_NO_DISPLAY) if (_glfw.egl.display == EGL_NO_DISPLAY)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,

View File

@ -25,31 +25,7 @@
// //
//======================================================================== //========================================================================
#if defined(_GLFW_USE_EGLPLATFORM_H) #include <EGL/eglplatform.h>
#include <EGL/eglplatform.h>
#elif defined(_GLFW_WIN32)
#define EGLAPIENTRY __stdcall
typedef HDC EGLNativeDisplayType;
typedef HWND EGLNativeWindowType;
#elif defined(_GLFW_COCOA)
#define EGLAPIENTRY
typedef void* EGLNativeDisplayType;
typedef id EGLNativeWindowType;
#elif defined(_GLFW_X11)
#define EGLAPIENTRY
typedef Display* EGLNativeDisplayType;
typedef Window EGLNativeWindowType;
#elif defined(_GLFW_WAYLAND)
#define EGLAPIENTRY
typedef struct wl_display* EGLNativeDisplayType;
typedef struct wl_egl_window* EGLNativeWindowType;
#elif defined(_GLFW_MIR)
#define EGLAPIENTRY
typedef MirEGLNativeDisplayType EGLNativeDisplayType;
typedef MirEGLNativeWindowType EGLNativeWindowType;
#else
#error "No supported EGL platform selected"
#endif
#define EGL_SUCCESS 0x3000 #define EGL_SUCCESS 0x3000
#define EGL_NOT_INITIALIZED 0x3001 #define EGL_NOT_INITIALIZED 0x3001