diff --git a/libs/glfm/src/glfm.nim b/libs/glfm/src/glfm.nim index 3f291ee..568f984 100644 --- a/libs/glfm/src/glfm.nim +++ b/libs/glfm/src/glfm.nim @@ -376,6 +376,10 @@ when defined(android): proc glfmAndroidGetActivity*(): pointer {.deprecated.} #ptr ANativeActivity proc glfmAndroidGetActivity*(display: ptr GLFMDisplay): pointer + proc glfmGetEGLDisplay*(display: ptr GLFMDisplay): pointer + proc glfmGetEGLConfig*(display: ptr GLFMDisplay): pointer + proc glfmGetEGLContext*(display: ptr GLFMDisplay): pointer + diff --git a/libs/glfm/src/glfm_android.c b/libs/glfm/src/glfm_android.c index e8be328..0637e15 100644 --- a/libs/glfm/src/glfm_android.c +++ b/libs/glfm/src/glfm_android.c @@ -2840,4 +2840,21 @@ NO_SANITIZE void *glfmGetAndroidActivity(const GLFMDisplay *display) { return platformData->activity; } +NO_SANITIZE void *glfmGetEGLDisplay(const GLFMDisplay *display) { + GLFMPlatformData *platformData = (GLFMPlatformData *)display->platformData; + return (void*)platformData->eglDisplay; +} + +NO_SANITIZE void *glfmGetEGLConfig(const GLFMDisplay *display) { + GLFMPlatformData *platformData = (GLFMPlatformData *)display->platformData; + return (void*)platformData->eglConfig; +} + +NO_SANITIZE void *glfmGetEGLContext(const GLFMDisplay *display) { + GLFMPlatformData *platformData = (GLFMPlatformData *)display->platformData; + return (void*)platformData->eglContext; +} + + + // #endif // __ANDROID__ diff --git a/src/bundle.nim b/src/bundle.nim index 49f28a8..a71a8e2 100644 --- a/src/bundle.nim +++ b/src/bundle.nim @@ -94,10 +94,15 @@ export vmath except Quat, quat import platform/platform when defined(android): export platform.myouAndroidGetActivity + export platform.myouAndroidGetJniVM export platform.myouAndroidGetJniEnv + export platform.myouAndroidGetActivityContext export platform.myouAndroidGetInternalDataPath export platform.myouAndroidGetExternalDataPath export platform.myouAndroidAPKFilePointerLength export platform.myouCloseMobileApp + export platform.myouAndroidGetEGLDisplay + export platform.myouAndroidGetEGLConfig + export platform.myouAndroidGetEGLContext export platform.myouSetKeyboardVisible diff --git a/src/platform/glfm_wrap.nim b/src/platform/glfm_wrap.nim index fe6fd78..068d9c3 100644 --- a/src/platform/glfm_wrap.nim +++ b/src/platform/glfm_wrap.nim @@ -250,6 +250,7 @@ proc init_graphics*(engine: MyouEngine, width, height: int32, title: string, glver, GLFMColorFormatRGB888, GLFMDepthFormat16, + # GLFMDepthFormat24, GLFMStencilFormatNone, GLFMMultisampleNone) @@ -309,20 +310,38 @@ proc start_platform_main_loop*(engine1: MyouEngine, main_loop1: proc(self: MyouE echo line echo getCurrentExceptionMsg() glfm_breakpoint() + # if not engine.vr_active: window.glfmSwapBuffers() -proc myouAndroidGetActivity*(): pointer = +type ANativeActivity = object + callbacks: pointer + vm: pointer + env: pointer + clazz: pointer + internalDataPath: cstring + externalDataPath: cstring + sdkVersion: int32 + instance: pointer + assetManager: pointer + obbPath: cstring + +# Deal with ASan false positives +{.push noSanitize: ["address","hwaddress"].} #" + +proc myouAndroidGetActivity*(): ptr ANativeActivity = when defined(android): - window.glfmAndroidGetActivity() + cast[ptr ANativeActivity](window.glfmAndroidGetActivity()) proc platform_switch_screen*(screen: Screen): bool {.inline.} = discard +proc myouAndroidGetJniVM*(): pointer = + when defined(android): + return myouAndroidGetActivity().vm + proc myouAndroidGetJniEnv*(): pointer = when defined(android): - let activity = cast[ptr array[2, pointer]](window.glfmAndroidGetActivity()) - # Ussing offsets from ANativeActivity - let vm = cast[ptr ptr array[7, pointer]](activity[1]) + let vm = cast[ptr ptr array[7, pointer]](myouAndroidGetJniVM()) # Using offsets from jni.h let getEnv = cast[proc(vm: pointer, penv: var pointer, version: int32): int32 {.cdecl, gcsafe.}](vm[][6]) let attachCurrentThread = cast[proc(vm: pointer, penv: ptr pointer, args: pointer): int32 {.cdecl, gcsafe.}](vm[][4]) @@ -336,15 +355,18 @@ proc myouAndroidGetJniEnv*(): pointer = result = nil # TODO: do we ever need to detach a thread from the VM? +proc myouAndroidGetActivityContext*(): pointer = + when defined(android): + return myouAndroidGetActivity().clazz + proc myouAndroidGetInternalDataPath*(): string = when defined(android): - let activity = cast[ptr array[6, cstring]](window.glfmAndroidGetActivity()) - return $activity[4] + return $myouAndroidGetActivity().internalDataPath proc myouAndroidGetExternalDataPath*(): string = when defined(android): - let activity = cast[ptr array[6, cstring]](window.glfmAndroidGetActivity()) - return $activity[5] + let ac = myouAndroidGetActivity() + return $myouAndroidGetActivity().externalDataPath when defined(android): proc AAssetManager_open(asset_manager: pointer, filename: cstring, mode: int32): pointer {.importc,cdecl.} @@ -353,6 +375,10 @@ when defined(android): proc AAsset_getLength64(asset: pointer): int64 {.importc,cdecl.} proc ANativeActivity_finish(activity: pointer) {.importc,cdecl.} + proc myouAndroidGetEGLDisplay*(): pointer = glfmGetEGLDisplay(window) + proc myouAndroidGetEGLConfig*(): pointer = glfmGetEGLConfig(window) + proc myouAndroidGetEGLContext*(): pointer = glfmGetEGLContext(window) + type myouAAssetObj = object asset: pointer p*: pointer @@ -383,3 +409,5 @@ proc myouSetKeyboardVisible*(show: bool) = proc myouCloseMobileApp*() = ANativeActivity_finish(window.glfmAndroidGetActivity()) quit() + +{.pop.} \ No newline at end of file diff --git a/src/platform/glfw_wrap.nim b/src/platform/glfw_wrap.nim index 78bf898..63be00b 100644 --- a/src/platform/glfw_wrap.nim +++ b/src/platform/glfw_wrap.nim @@ -75,6 +75,7 @@ proc make_window*(width, height: int32, title: string): Window = fist_window_is_used = true return windows[0] let window = createWindow(width, height, title, nil, windows.get_or_default(0)) + doAssert window != nil, "Could not create window." discard glfw.setWindowCloseCallback(window, proc(window: Window) {.cdecl.} = # TODO: flag to prevent it from being closed