Android: Add 5 more myouAndroidGet*
for JNI VM, app context, and EGL handles.
This commit is contained in:
parent
50663f77fd
commit
19cc1dce28
5 changed files with 64 additions and 9 deletions
|
@ -376,6 +376,10 @@ when defined(android):
|
||||||
proc glfmAndroidGetActivity*(): pointer {.deprecated.} #ptr ANativeActivity
|
proc glfmAndroidGetActivity*(): pointer {.deprecated.} #ptr ANativeActivity
|
||||||
proc glfmAndroidGetActivity*(display: ptr GLFMDisplay): pointer
|
proc glfmAndroidGetActivity*(display: ptr GLFMDisplay): pointer
|
||||||
|
|
||||||
|
proc glfmGetEGLDisplay*(display: ptr GLFMDisplay): pointer
|
||||||
|
proc glfmGetEGLConfig*(display: ptr GLFMDisplay): pointer
|
||||||
|
proc glfmGetEGLContext*(display: ptr GLFMDisplay): pointer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2840,4 +2840,21 @@ NO_SANITIZE void *glfmGetAndroidActivity(const GLFMDisplay *display) {
|
||||||
return platformData->activity;
|
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__
|
// #endif // __ANDROID__
|
||||||
|
|
|
@ -94,10 +94,15 @@ export vmath except Quat, quat
|
||||||
import platform/platform
|
import platform/platform
|
||||||
when defined(android):
|
when defined(android):
|
||||||
export platform.myouAndroidGetActivity
|
export platform.myouAndroidGetActivity
|
||||||
|
export platform.myouAndroidGetJniVM
|
||||||
export platform.myouAndroidGetJniEnv
|
export platform.myouAndroidGetJniEnv
|
||||||
|
export platform.myouAndroidGetActivityContext
|
||||||
export platform.myouAndroidGetInternalDataPath
|
export platform.myouAndroidGetInternalDataPath
|
||||||
export platform.myouAndroidGetExternalDataPath
|
export platform.myouAndroidGetExternalDataPath
|
||||||
export platform.myouAndroidAPKFilePointerLength
|
export platform.myouAndroidAPKFilePointerLength
|
||||||
export platform.myouCloseMobileApp
|
export platform.myouCloseMobileApp
|
||||||
|
export platform.myouAndroidGetEGLDisplay
|
||||||
|
export platform.myouAndroidGetEGLConfig
|
||||||
|
export platform.myouAndroidGetEGLContext
|
||||||
|
|
||||||
export platform.myouSetKeyboardVisible
|
export platform.myouSetKeyboardVisible
|
||||||
|
|
|
@ -250,6 +250,7 @@ proc init_graphics*(engine: MyouEngine, width, height: int32, title: string,
|
||||||
glver,
|
glver,
|
||||||
GLFMColorFormatRGB888,
|
GLFMColorFormatRGB888,
|
||||||
GLFMDepthFormat16,
|
GLFMDepthFormat16,
|
||||||
|
# GLFMDepthFormat24,
|
||||||
GLFMStencilFormatNone,
|
GLFMStencilFormatNone,
|
||||||
GLFMMultisampleNone)
|
GLFMMultisampleNone)
|
||||||
|
|
||||||
|
@ -309,20 +310,38 @@ proc start_platform_main_loop*(engine1: MyouEngine, main_loop1: proc(self: MyouE
|
||||||
echo line
|
echo line
|
||||||
echo getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
glfm_breakpoint()
|
glfm_breakpoint()
|
||||||
|
# if not engine.vr_active:
|
||||||
window.glfmSwapBuffers()
|
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):
|
when defined(android):
|
||||||
window.glfmAndroidGetActivity()
|
cast[ptr ANativeActivity](window.glfmAndroidGetActivity())
|
||||||
|
|
||||||
proc platform_switch_screen*(screen: Screen): bool {.inline.} =
|
proc platform_switch_screen*(screen: Screen): bool {.inline.} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc myouAndroidGetJniVM*(): pointer =
|
||||||
|
when defined(android):
|
||||||
|
return myouAndroidGetActivity().vm
|
||||||
|
|
||||||
proc myouAndroidGetJniEnv*(): pointer =
|
proc myouAndroidGetJniEnv*(): pointer =
|
||||||
when defined(android):
|
when defined(android):
|
||||||
let activity = cast[ptr array[2, pointer]](window.glfmAndroidGetActivity())
|
let vm = cast[ptr ptr array[7, pointer]](myouAndroidGetJniVM())
|
||||||
# Ussing offsets from ANativeActivity
|
|
||||||
let vm = cast[ptr ptr array[7, pointer]](activity[1])
|
|
||||||
# Using offsets from jni.h
|
# Using offsets from jni.h
|
||||||
let getEnv = cast[proc(vm: pointer, penv: var pointer, version: int32): int32 {.cdecl, gcsafe.}](vm[][6])
|
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])
|
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
|
result = nil
|
||||||
# TODO: do we ever need to detach a thread from the VM?
|
# TODO: do we ever need to detach a thread from the VM?
|
||||||
|
|
||||||
|
proc myouAndroidGetActivityContext*(): pointer =
|
||||||
|
when defined(android):
|
||||||
|
return myouAndroidGetActivity().clazz
|
||||||
|
|
||||||
proc myouAndroidGetInternalDataPath*(): string =
|
proc myouAndroidGetInternalDataPath*(): string =
|
||||||
when defined(android):
|
when defined(android):
|
||||||
let activity = cast[ptr array[6, cstring]](window.glfmAndroidGetActivity())
|
return $myouAndroidGetActivity().internalDataPath
|
||||||
return $activity[4]
|
|
||||||
|
|
||||||
proc myouAndroidGetExternalDataPath*(): string =
|
proc myouAndroidGetExternalDataPath*(): string =
|
||||||
when defined(android):
|
when defined(android):
|
||||||
let activity = cast[ptr array[6, cstring]](window.glfmAndroidGetActivity())
|
let ac = myouAndroidGetActivity()
|
||||||
return $activity[5]
|
return $myouAndroidGetActivity().externalDataPath
|
||||||
|
|
||||||
when defined(android):
|
when defined(android):
|
||||||
proc AAssetManager_open(asset_manager: pointer, filename: cstring, mode: int32): pointer {.importc,cdecl.}
|
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 AAsset_getLength64(asset: pointer): int64 {.importc,cdecl.}
|
||||||
proc ANativeActivity_finish(activity: pointer) {.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
|
type myouAAssetObj = object
|
||||||
asset: pointer
|
asset: pointer
|
||||||
p*: pointer
|
p*: pointer
|
||||||
|
@ -383,3 +409,5 @@ proc myouSetKeyboardVisible*(show: bool) =
|
||||||
proc myouCloseMobileApp*() =
|
proc myouCloseMobileApp*() =
|
||||||
ANativeActivity_finish(window.glfmAndroidGetActivity())
|
ANativeActivity_finish(window.glfmAndroidGetActivity())
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
|
{.pop.}
|
|
@ -75,6 +75,7 @@ proc make_window*(width, height: int32, title: string): Window =
|
||||||
fist_window_is_used = true
|
fist_window_is_used = true
|
||||||
return windows[0]
|
return windows[0]
|
||||||
let window = createWindow(width, height, title, nil, windows.get_or_default(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.} =
|
discard glfw.setWindowCloseCallback(window, proc(window: Window) {.cdecl.} =
|
||||||
# TODO: flag to prevent it from being closed
|
# TODO: flag to prevent it from being closed
|
||||||
|
|
Loading…
Reference in a new issue