oculus quest running and android compiling and running
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ PanoPainter.sdf
|
|||||||
*.iml
|
*.iml
|
||||||
android/.idea
|
android/.idea
|
||||||
android/android/build/
|
android/android/build/
|
||||||
|
android/android/gradle/
|
||||||
android/android/.gradle/
|
android/android/.gradle/
|
||||||
android/android/.externalNativeBuild/
|
android/android/.externalNativeBuild/
|
||||||
android/android/.idea
|
android/android/.idea
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -49,3 +49,6 @@
|
|||||||
[submodule "libs/fmt"]
|
[submodule "libs/fmt"]
|
||||||
path = libs/fmt
|
path = libs/fmt
|
||||||
url = https://github.com/fmtlib/fmt.git
|
url = https://github.com/fmtlib/fmt.git
|
||||||
|
[submodule "libs/ovr_mobile"]
|
||||||
|
path = libs/ovr_mobile
|
||||||
|
url = https://bitbucket.org/omigamedev/ovr_mobile.git
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ android {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
manifest.srcFile 'src/main/AndroidManifest.xml'
|
manifest.srcFile 'src/main/AndroidManifest.xml'
|
||||||
java.srcDirs = ['../src/java']
|
java.srcDirs = ['../src/java', 'src/main/java']
|
||||||
//jniLibs.srcDir 'libs'
|
//jniLibs.srcDir 'libs'
|
||||||
res.srcDirs = ['../src/res']
|
res.srcDirs = ['../src/res']
|
||||||
//assets.srcDirs = ['../../assets']
|
//assets.srcDirs = ['../../assets']
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.omixlab.panopainter;
|
||||||
|
|
||||||
|
public class Platform {
|
||||||
|
public static final String[] Libs = new String[]{};
|
||||||
|
}
|
||||||
@@ -11,8 +11,11 @@ add_library(
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_library(vrapi SHARED IMPORTED)
|
add_library(vrapi SHARED IMPORTED)
|
||||||
set_target_properties(vrapi PROPERTIES IMPORTED_LOCATION
|
set_target_properties(
|
||||||
C:/ovr_sdk_mobile_1.23/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so)
|
vrapi
|
||||||
|
PROPERTIES IMPORTED_LOCATION
|
||||||
|
${CMAKE_SOURCE_DIR}/../../libs/ovr_mobile/lib/${ANDROID_ABI}/libvrapi.so
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Specifies a library name, specifies whether the library is STATIC or
|
# Specifies a library name, specifies whether the library is STATIC or
|
||||||
@@ -47,6 +50,7 @@ add_library(
|
|||||||
../../libs/poly2tri/poly2tri/sweep/sweep.cc
|
../../libs/poly2tri/poly2tri/sweep/sweep.cc
|
||||||
../../libs/fmt/src/format.cc
|
../../libs/fmt/src/format.cc
|
||||||
../src/cpp/main.cpp
|
../src/cpp/main.cpp
|
||||||
|
src/main/cpp/oculus_vr.cpp
|
||||||
../../src/pch.cpp
|
../../src/pch.cpp
|
||||||
../../src/util.cpp
|
../../src/util.cpp
|
||||||
../../src/rtt.cpp
|
../../src/rtt.cpp
|
||||||
@@ -116,7 +120,8 @@ add_library(
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(native-lib PRIVATE
|
target_include_directories(native-lib PRIVATE
|
||||||
C:/ovr_sdk_mobile_1.23/VrApi/Include
|
../../libs/ovr_mobile/include
|
||||||
|
src/main/cpp
|
||||||
../src/cpp
|
../src/cpp
|
||||||
../../src
|
../../src
|
||||||
../../libs/glm
|
../../libs/glm
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ android {
|
|||||||
// Sets optional flags for the C compiler.
|
// Sets optional flags for the C compiler.
|
||||||
//cFlags "-D_EXAMPLE_C_FLAG1", "-D_EXAMPLE_C_FLAG2"
|
//cFlags "-D_EXAMPLE_C_FLAG1", "-D_EXAMPLE_C_FLAG2"
|
||||||
// Sets a flag to enable format macro constants for the C++ compiler.
|
// Sets a flag to enable format macro constants for the C++ compiler.
|
||||||
//cppFlags "-D__STDC_FORMAT_MACROS"
|
cppFlags "-D__QUEST__"
|
||||||
arguments "-DANDROID_TOOLCHAIN=clang",
|
arguments "-DANDROID_TOOLCHAIN=clang",
|
||||||
//"-DANDROID_PLATFORM=android-19",
|
//"-DANDROID_PLATFORM=android-19",
|
||||||
"-DANDROID_STL=c++_shared",
|
"-DANDROID_STL=c++_shared",
|
||||||
@@ -138,8 +138,8 @@ android {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
manifest.srcFile 'src/main/AndroidManifest.xml'
|
manifest.srcFile 'src/main/AndroidManifest.xml'
|
||||||
java.srcDirs = ['../src/java']
|
java.srcDirs = ['../src/java', 'src/main/java']
|
||||||
//jniLibs.srcDir 'libs'
|
jniLibs.srcDirs = ['../../libs/ovr_mobile/lib']
|
||||||
res.srcDirs = ['../src/res']
|
res.srcDirs = ['../src/res']
|
||||||
//assets.srcDirs = ['../../assets']
|
//assets.srcDirs = ['../../assets']
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.omixlab.panopainter">
|
package="com.omixlab.panopainter">
|
||||||
|
<!-- Tell the system this app requires OpenGL ES 3.1. -->
|
||||||
|
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<application android:label="@string/app_name"
|
<application android:label="@string/app_name"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
||||||
|
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
|
||||||
<activity android:name=".MainActivity"
|
<activity android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:configChanges="orientation|keyboardHidden"
|
android:launchMode="singleTask"
|
||||||
android:screenOrientation="fullUser"
|
android:configChanges="screenSize|screenLayout|orientation|keyboardHidden|keyboard|navigation|uiMode"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:screenOrientation="landscape">
|
||||||
<meta-data android:name="android.app.lib_name"
|
<meta-data android:name="android.app.lib_name"
|
||||||
android:value="native-lib" />
|
android:value="native-lib" />
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
126
android/quest/src/main/cpp/oculus_vr.cpp
Normal file
126
android/quest/src/main/cpp/oculus_vr.cpp
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
#include "oculus_vr.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "rtt.h"
|
||||||
|
#include "app.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
ovrJava java;
|
||||||
|
RTT ovr_eyes[3][2];
|
||||||
|
ovrTextureSwapChain* swap_chain[2];
|
||||||
|
int swap_chain_count = 0;
|
||||||
|
int swap_chain_index = 0;
|
||||||
|
ovrMobile* ovr_context = nullptr;
|
||||||
|
uint64_t ovr_frame = 0;
|
||||||
|
|
||||||
|
void oculus_init(JavaVM* vm, JNIEnv* jni, jobject activity_class)
|
||||||
|
{
|
||||||
|
java.Vm = vm;
|
||||||
|
java.Env = jni;
|
||||||
|
java.ActivityObject = activity_class;
|
||||||
|
|
||||||
|
LOG("init OVR");
|
||||||
|
const ovrInitParms initParms = vrapi_DefaultInitParms( &java );
|
||||||
|
int32_t initResult = vrapi_Initialize( &initParms );
|
||||||
|
if ( initResult != VRAPI_INITIALIZE_SUCCESS )
|
||||||
|
{
|
||||||
|
// If intialization failed, vrapi_* function calls will not be available.
|
||||||
|
exit( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void oculus_init_vr(EGLDisplay display, EGLContext context, ANativeWindow* surface)
|
||||||
|
{
|
||||||
|
LOG("init swapchain");
|
||||||
|
int rtt_w = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_WIDTH);
|
||||||
|
int rtt_h = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_HEIGHT);
|
||||||
|
LOG("ovr suggested texture size %d %d", rtt_w, rtt_h);
|
||||||
|
for (int eye = 0; eye < 2; eye++)
|
||||||
|
{
|
||||||
|
swap_chain[eye] = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_2D, GL_RGBA8, rtt_w, rtt_h, 1, 3);
|
||||||
|
swap_chain_count = vrapi_GetTextureSwapChainLength(swap_chain[eye]);
|
||||||
|
for (int i = 0; i < swap_chain_count; i++)
|
||||||
|
{
|
||||||
|
auto texid = vrapi_GetTextureSwapChainHandle(swap_chain[eye], i);
|
||||||
|
if (!ovr_eyes[i][eye].create(rtt_w, rtt_h, texid, GL_RGBA8, true))
|
||||||
|
{
|
||||||
|
ovr_eyes[i][eye].bindFramebuffer();
|
||||||
|
ovr_eyes[i][eye].clear({1, 0, 1, 1});
|
||||||
|
ovr_eyes[i][eye].unbindFramebuffer();
|
||||||
|
LOG("FAILED create fb for eye %d", eye);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG("create eye %d", eye);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG("vrapi_DefaultModeParms");
|
||||||
|
ovrModeParms parms = vrapi_DefaultModeParms( &java );
|
||||||
|
// No need to reset the FLAG_FULLSCREEN window flag when using a View
|
||||||
|
//parms.Flags &= ~VRAPI_MODE_FLAG_RESET_WINDOW_FULLSCREEN;
|
||||||
|
|
||||||
|
parms.Flags |= VRAPI_MODE_FLAG_NATIVE_WINDOW;
|
||||||
|
parms.Display = (size_t)display;
|
||||||
|
parms.WindowSurface = (size_t)surface;
|
||||||
|
parms.ShareContext = (size_t)context;
|
||||||
|
LOG("enter vr mode");
|
||||||
|
ovr_context = vrapi_EnterVrMode(&parms);
|
||||||
|
if (!ovr_context)
|
||||||
|
{
|
||||||
|
LOG("EnterVRMode FAILED");
|
||||||
|
}
|
||||||
|
LOG("vr mode entered");
|
||||||
|
|
||||||
|
vrapi_SetClockLevels(ovr_context, 2, 2);
|
||||||
|
vrapi_SetPerfThread(ovr_context, VRAPI_PERF_THREAD_TYPE_MAIN, gettid());
|
||||||
|
vrapi_SetPerfThread(ovr_context, VRAPI_PERF_THREAD_TYPE_RENDERER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void oculus_draw()
|
||||||
|
{
|
||||||
|
// BEGIN OVR
|
||||||
|
const double predictedDisplayTime = vrapi_GetPredictedDisplayTime(ovr_context, ovr_frame);
|
||||||
|
const ovrTracking2 tracking = vrapi_GetPredictedTracking2(ovr_context, predictedDisplayTime);
|
||||||
|
auto layer = vrapi_DefaultLayerProjection2();
|
||||||
|
//ovrVector4f red = {1, 1, 0, 1};
|
||||||
|
//auto layer = vrapi_DefaultLayerSolidColorProjection2(&red);
|
||||||
|
layer.HeadPose = tracking.HeadPose;
|
||||||
|
for (int eye = 0; eye < 2; eye++)
|
||||||
|
{
|
||||||
|
auto& rtt = ovr_eyes[swap_chain_index][eye];
|
||||||
|
rtt.bindFramebuffer();
|
||||||
|
rtt.clear({1, 0, 1, 1});
|
||||||
|
glViewport(0, 0, rtt.getWidth(), rtt.getHeight());
|
||||||
|
auto proj_ovr = ovrMatrix4f_Transpose(&tracking.Eye[eye].ProjectionMatrix);
|
||||||
|
glm::mat4 proj = glm::make_mat4(reinterpret_cast<const float*>(&proj_ovr));
|
||||||
|
auto view_ovr = ovrMatrix4f_Transpose(&tracking.Eye[eye].ViewMatrix);
|
||||||
|
glm::mat4 view = glm::make_mat4(reinterpret_cast<const float*>(&view_ovr));
|
||||||
|
auto pose_ovr = ovrMatrix4f_CreateFromQuaternion(&tracking.HeadPose.Pose.Orientation);
|
||||||
|
auto pose_ovr_tp = ovrMatrix4f_Transpose(&pose_ovr);
|
||||||
|
glm::mat4 pose = glm::make_mat4(reinterpret_cast<float*>(&pose_ovr_tp));
|
||||||
|
App::I.vr_draw(proj, view, pose);
|
||||||
|
rtt.unbindFramebuffer();
|
||||||
|
layer.Textures[eye].ColorSwapChain = swap_chain[eye];
|
||||||
|
layer.Textures[eye].SwapChainIndex = swap_chain_index;
|
||||||
|
layer.Textures[eye].TexCoordsFromTanAngles =
|
||||||
|
ovrMatrix4f_TanAngleMatrixFromProjection(&tracking.Eye[eye].ProjectionMatrix);
|
||||||
|
}
|
||||||
|
layer.Header.Flags |= VRAPI_FRAME_LAYER_FLAG_CHROMATIC_ABERRATION_CORRECTION;
|
||||||
|
|
||||||
|
const ovrLayerHeader2 * layers[] = { &layer.Header };
|
||||||
|
|
||||||
|
ovrSubmitFrameDescription2 frameDesc = { 0 };
|
||||||
|
frameDesc.Flags = 0;
|
||||||
|
frameDesc.SwapInterval = 1;
|
||||||
|
frameDesc.FrameIndex = ovr_frame;
|
||||||
|
frameDesc.DisplayTime = predictedDisplayTime;
|
||||||
|
frameDesc.LayerCount = 1;
|
||||||
|
frameDesc.Layers = layers;
|
||||||
|
|
||||||
|
vrapi_SubmitFrame2(ovr_context, &frameDesc);
|
||||||
|
|
||||||
|
ovr_frame++;
|
||||||
|
swap_chain_index = (swap_chain_index + 1) % swap_chain_count;
|
||||||
|
}
|
||||||
15
android/quest/src/main/cpp/oculus_vr.h
Normal file
15
android/quest/src/main/cpp/oculus_vr.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <VrApi_Types.h>
|
||||||
|
#include <VrApi.h>
|
||||||
|
#include <VrApi_Helpers.h>
|
||||||
|
#include <VrApi_SystemUtils.h>
|
||||||
|
#include <VrApi_Input.h>
|
||||||
|
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
#include <EGL/eglext.h>
|
||||||
|
#include <android/window.h>
|
||||||
|
|
||||||
|
void oculus_init(JavaVM* vm, JNIEnv* jni, jobject activity_class);
|
||||||
|
void oculus_init_vr(EGLDisplay display, EGLContext context, ANativeWindow* surface);
|
||||||
|
void oculus_draw();
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.omixlab.panopainter;
|
||||||
|
|
||||||
|
public class Platform {
|
||||||
|
public static final String[] Libs = new String[]{"vrapi"};
|
||||||
|
}
|
||||||
@@ -26,11 +26,7 @@
|
|||||||
#include <EGL/eglext.h>
|
#include <EGL/eglext.h>
|
||||||
#include <android/window.h>
|
#include <android/window.h>
|
||||||
#include <sys/prctl.h> // for prctl( PR_SET_NAME )
|
#include <sys/prctl.h> // for prctl( PR_SET_NAME )
|
||||||
|
#include <unistd.h>
|
||||||
#include "VrApi.h"
|
|
||||||
#include "VrApi_Helpers.h"
|
|
||||||
#include "VrApi_SystemUtils.h"
|
|
||||||
#include "VrApi_Input.h"
|
|
||||||
|
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
@@ -39,6 +35,10 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "com_omixlab_panopainter_MainActivity.h"
|
#include "com_omixlab_panopainter_MainActivity.h"
|
||||||
|
|
||||||
|
#ifdef __QUEST__
|
||||||
|
#include "oculus_vr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (*GLDEBUGPROC)(GLenum source,
|
typedef void (*GLDEBUGPROC)(GLenum source,
|
||||||
GLenum type,
|
GLenum type,
|
||||||
GLuint id,
|
GLuint id,
|
||||||
@@ -62,6 +62,7 @@ EGLContext g_context = EGL_NO_CONTEXT;
|
|||||||
std::recursive_mutex mutex;
|
std::recursive_mutex mutex;
|
||||||
int mutex_count = 0;
|
int mutex_count = 0;
|
||||||
struct engine g_engine;
|
struct engine g_engine;
|
||||||
|
JNIEnv* jni;
|
||||||
|
|
||||||
jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
|
jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
|
||||||
{
|
{
|
||||||
@@ -87,39 +88,25 @@ int GetUnicodeChar(struct android_app* app, int eventType, int keyCode, int meta
|
|||||||
#define COMBINING_ACCENT 0x80000000
|
#define COMBINING_ACCENT 0x80000000
|
||||||
#define COMBINING_ACCENT_MASK 0x7fffffff
|
#define COMBINING_ACCENT_MASK 0x7fffffff
|
||||||
|
|
||||||
JavaVM* javaVM = app->activity->vm;
|
jclass class_key_event = jni->FindClass("android/view/KeyEvent");
|
||||||
JNIEnv* jniEnv = app->activity->env;
|
|
||||||
|
|
||||||
JavaVMAttachArgs attachArgs;
|
|
||||||
attachArgs.version = JNI_VERSION_1_6;
|
|
||||||
attachArgs.name = "NativeThread";
|
|
||||||
attachArgs.group = NULL;
|
|
||||||
|
|
||||||
jint result = javaVM->AttachCurrentThread(&jniEnv, &attachArgs);
|
|
||||||
if(result == JNI_ERR)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
jclass class_key_event = jniEnv->FindClass("android/view/KeyEvent");
|
|
||||||
int unicodeKey;
|
int unicodeKey;
|
||||||
|
|
||||||
if(metaState == 0)
|
if(metaState == 0)
|
||||||
{
|
{
|
||||||
jmethodID method_get_unicode_char = jniEnv->GetMethodID(class_key_event, "getUnicodeChar", "()I");
|
jmethodID method_get_unicode_char = jni->GetMethodID(class_key_event, "getUnicodeChar", "()I");
|
||||||
jmethodID eventConstructor = jniEnv->GetMethodID(class_key_event, "<init>", "(II)V");
|
jmethodID eventConstructor = jni->GetMethodID(class_key_event, "<init>", "(II)V");
|
||||||
jobject eventObj = jniEnv->NewObject(class_key_event, eventConstructor, eventType, keyCode);
|
jobject eventObj = jni->NewObject(class_key_event, eventConstructor, eventType, keyCode);
|
||||||
|
|
||||||
unicodeKey = jniEnv->CallIntMethod(eventObj, method_get_unicode_char);
|
unicodeKey = jni->CallIntMethod(eventObj, method_get_unicode_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jmethodID method_get_unicode_char = jniEnv->GetMethodID(class_key_event, "getUnicodeChar", "(I)I");
|
jmethodID method_get_unicode_char = jni->GetMethodID(class_key_event, "getUnicodeChar", "(I)I");
|
||||||
jmethodID eventConstructor = jniEnv->GetMethodID(class_key_event, "<init>", "(II)V");
|
jmethodID eventConstructor = jni->GetMethodID(class_key_event, "<init>", "(II)V");
|
||||||
jobject eventObj = jniEnv->NewObject(class_key_event, eventConstructor, eventType, keyCode);
|
jobject eventObj = jni->NewObject(class_key_event, eventConstructor, eventType, keyCode);
|
||||||
|
|
||||||
unicodeKey = jniEnv->CallIntMethod(eventObj, method_get_unicode_char, metaState);
|
unicodeKey = jni->CallIntMethod(eventObj, method_get_unicode_char, metaState);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((unicodeKey & COMBINING_ACCENT) != 0)
|
if ((unicodeKey & COMBINING_ACCENT) != 0)
|
||||||
@@ -127,8 +114,6 @@ int GetUnicodeChar(struct android_app* app, int eventType, int keyCode, int meta
|
|||||||
unicodeKey = unicodeKey & COMBINING_ACCENT_MASK;
|
unicodeKey = unicodeKey & COMBINING_ACCENT_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
javaVM->DetachCurrentThread();
|
|
||||||
|
|
||||||
LOG("Unicode key is: %d", unicodeKey);
|
LOG("Unicode key is: %d", unicodeKey);
|
||||||
return unicodeKey;
|
return unicodeKey;
|
||||||
}
|
}
|
||||||
@@ -174,88 +159,67 @@ struct locker
|
|||||||
// see https://groups.google.com/forum/#!topic/android-ndk/Tk3g00wLKhk
|
// see https://groups.google.com/forum/#!topic/android-ndk/Tk3g00wLKhk
|
||||||
void displayKeyboard(android_app* mApplication, bool pShow)
|
void displayKeyboard(android_app* mApplication, bool pShow)
|
||||||
{
|
{
|
||||||
// Attaches the current thread to the JVM.
|
|
||||||
jint lResult;
|
|
||||||
jint lFlags = 0;
|
|
||||||
|
|
||||||
JavaVM* lJavaVM = mApplication->activity->vm;
|
|
||||||
JNIEnv* lJNIEnv = mApplication->activity->env;
|
|
||||||
|
|
||||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
|
||||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
|
||||||
lJavaVMAttachArgs.name = "NativeThread";
|
|
||||||
lJavaVMAttachArgs.group = NULL;
|
|
||||||
|
|
||||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv,
|
|
||||||
&lJavaVMAttachArgs);
|
|
||||||
if (lResult == JNI_ERR) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieves NativeActivity.
|
// Retrieves NativeActivity.
|
||||||
jobject lNativeActivity = mApplication->activity->clazz;
|
jobject lNativeActivity = mApplication->activity->clazz;
|
||||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
|
||||||
|
|
||||||
// Retrieves Context.INPUT_METHOD_SERVICE.
|
// Retrieves Context.INPUT_METHOD_SERVICE.
|
||||||
jclass ClassContext = lJNIEnv->FindClass("android/content/Context");
|
jclass ClassContext = jni->FindClass("android/content/Context");
|
||||||
jfieldID FieldINPUT_METHOD_SERVICE =
|
jfieldID FieldINPUT_METHOD_SERVICE =
|
||||||
lJNIEnv->GetStaticFieldID(ClassContext, "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
|
jni->GetStaticFieldID(ClassContext, "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
|
||||||
jobject INPUT_METHOD_SERVICE =
|
jobject INPUT_METHOD_SERVICE =
|
||||||
lJNIEnv->GetStaticObjectField(ClassContext,
|
jni->GetStaticObjectField(ClassContext,
|
||||||
FieldINPUT_METHOD_SERVICE);
|
FieldINPUT_METHOD_SERVICE);
|
||||||
//jniCheck(INPUT_METHOD_SERVICE);
|
//jniCheck(INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
// Runs getSystemService(Context.INPUT_METHOD_SERVICE).
|
// Runs getSystemService(Context.INPUT_METHOD_SERVICE).
|
||||||
jclass ClassInputMethodManager = lJNIEnv->FindClass(
|
jclass ClassInputMethodManager = jni->FindClass(
|
||||||
"android/view/inputmethod/InputMethodManager");
|
"android/view/inputmethod/InputMethodManager");
|
||||||
jmethodID MethodGetSystemService = lJNIEnv->GetMethodID(
|
jmethodID MethodGetSystemService = jni->GetMethodID(
|
||||||
ClassNativeActivity, "getSystemService",
|
ClassNativeActivity, "getSystemService",
|
||||||
"(Ljava/lang/String;)Ljava/lang/Object;");
|
"(Ljava/lang/String;)Ljava/lang/Object;");
|
||||||
jobject lInputMethodManager = lJNIEnv->CallObjectMethod(
|
jobject lInputMethodManager = jni->CallObjectMethod(
|
||||||
lNativeActivity, MethodGetSystemService,
|
lNativeActivity, MethodGetSystemService,
|
||||||
INPUT_METHOD_SERVICE);
|
INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
// Runs getWindow().getDecorView().
|
// Runs getWindow().getDecorView().
|
||||||
jmethodID MethodGetWindow = lJNIEnv->GetMethodID(
|
jmethodID MethodGetWindow = jni->GetMethodID(
|
||||||
ClassNativeActivity, "getWindow",
|
ClassNativeActivity, "getWindow",
|
||||||
"()Landroid/view/Window;");
|
"()Landroid/view/Window;");
|
||||||
jobject lWindow = lJNIEnv->CallObjectMethod(lNativeActivity,
|
jobject lWindow = jni->CallObjectMethod(lNativeActivity,
|
||||||
MethodGetWindow);
|
MethodGetWindow);
|
||||||
jclass ClassWindow = lJNIEnv->FindClass(
|
jclass ClassWindow = jni->FindClass(
|
||||||
"android/view/Window");
|
"android/view/Window");
|
||||||
jmethodID MethodGetDecorView = lJNIEnv->GetMethodID(
|
jmethodID MethodGetDecorView = jni->GetMethodID(
|
||||||
ClassWindow, "getDecorView", "()Landroid/view/View;");
|
ClassWindow, "getDecorView", "()Landroid/view/View;");
|
||||||
jobject lDecorView = lJNIEnv->CallObjectMethod(lWindow,
|
jobject lDecorView = jni->CallObjectMethod(lWindow,
|
||||||
MethodGetDecorView);
|
MethodGetDecorView);
|
||||||
|
|
||||||
if (pShow) {
|
if (pShow) {
|
||||||
// Runs lInputMethodManager.showSoftInput(...).
|
// Runs lInputMethodManager.showSoftInput(...).
|
||||||
jmethodID MethodShowSoftInput = lJNIEnv->GetMethodID(
|
jmethodID MethodShowSoftInput = jni->GetMethodID(
|
||||||
ClassInputMethodManager, "showSoftInput",
|
ClassInputMethodManager, "showSoftInput",
|
||||||
"(Landroid/view/View;I)Z");
|
"(Landroid/view/View;I)Z");
|
||||||
jboolean lResult = lJNIEnv->CallBooleanMethod(
|
jboolean lResult = jni->CallBooleanMethod(
|
||||||
lInputMethodManager, MethodShowSoftInput,
|
lInputMethodManager, MethodShowSoftInput,
|
||||||
lDecorView, lFlags);
|
lDecorView, 0);
|
||||||
} else {
|
} else {
|
||||||
// Runs lWindow.getViewToken()
|
// Runs lWindow.getViewToken()
|
||||||
jclass ClassView = lJNIEnv->FindClass(
|
jclass ClassView = jni->FindClass(
|
||||||
"android/view/View");
|
"android/view/View");
|
||||||
jmethodID MethodGetWindowToken = lJNIEnv->GetMethodID(
|
jmethodID MethodGetWindowToken = jni->GetMethodID(
|
||||||
ClassView, "getWindowToken", "()Landroid/os/IBinder;");
|
ClassView, "getWindowToken", "()Landroid/os/IBinder;");
|
||||||
jobject lBinder = lJNIEnv->CallObjectMethod(lDecorView,
|
jobject lBinder = jni->CallObjectMethod(lDecorView,
|
||||||
MethodGetWindowToken);
|
MethodGetWindowToken);
|
||||||
|
|
||||||
// lInputMethodManager.hideSoftInput(...).
|
// lInputMethodManager.hideSoftInput(...).
|
||||||
jmethodID MethodHideSoftInput = lJNIEnv->GetMethodID(
|
jmethodID MethodHideSoftInput = jni->GetMethodID(
|
||||||
ClassInputMethodManager, "hideSoftInputFromWindow",
|
ClassInputMethodManager, "hideSoftInputFromWindow",
|
||||||
"(Landroid/os/IBinder;I)Z");
|
"(Landroid/os/IBinder;I)Z");
|
||||||
jboolean lRes = lJNIEnv->CallBooleanMethod(
|
jboolean lRes = jni->CallBooleanMethod(
|
||||||
lInputMethodManager, MethodHideSoftInput,
|
lInputMethodManager, MethodHideSoftInput,
|
||||||
lBinder, lFlags);
|
lBinder, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finished with the JVM.
|
|
||||||
lJavaVM->DetachCurrentThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -315,102 +279,39 @@ JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_contentRectChan
|
|||||||
|
|
||||||
void android_pick_file(android_app* mApplication, std::function<void(std::string)> callback)
|
void android_pick_file(android_app* mApplication, std::function<void(std::string)> callback)
|
||||||
{
|
{
|
||||||
// Attaches the current thread to the JVM.
|
|
||||||
jint lResult;
|
|
||||||
jint lFlags = 0;
|
|
||||||
|
|
||||||
JavaVM* lJavaVM = mApplication->activity->vm;
|
|
||||||
JNIEnv* lJNIEnv = mApplication->activity->env;
|
|
||||||
|
|
||||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
|
||||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
|
||||||
lJavaVMAttachArgs.name = "NativeThread";
|
|
||||||
lJavaVMAttachArgs.group = NULL;
|
|
||||||
|
|
||||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
|
|
||||||
if (lResult == JNI_ERR)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pick_file_callback = callback;
|
pick_file_callback = callback;
|
||||||
|
|
||||||
// Retrieves NativeActivity.
|
// Retrieves NativeActivity.
|
||||||
jobject lNativeActivity = mApplication->activity->clazz;
|
jobject lNativeActivity = mApplication->activity->clazz;
|
||||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
|
||||||
|
|
||||||
jmethodID MethodPickFile = lJNIEnv->GetMethodID(ClassNativeActivity, "pickFile", "()V");
|
jmethodID MethodPickFile = jni->GetMethodID(ClassNativeActivity, "pickFile", "()V");
|
||||||
lJNIEnv->CallVoidMethod(lNativeActivity, MethodPickFile);
|
jni->CallVoidMethod(lNativeActivity, MethodPickFile);
|
||||||
|
|
||||||
// Finished with the JVM.
|
|
||||||
lJavaVM->DetachCurrentThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float get_display_density(android_app* mApplication)
|
float get_display_density(android_app* mApplication)
|
||||||
{
|
{
|
||||||
// Attaches the current thread to the JVM.
|
|
||||||
jint lResult;
|
|
||||||
jint lFlags = 0;
|
|
||||||
|
|
||||||
JavaVM* lJavaVM = mApplication->activity->vm;
|
|
||||||
JNIEnv* lJNIEnv = mApplication->activity->env;
|
|
||||||
|
|
||||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
|
||||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
|
||||||
lJavaVMAttachArgs.name = "NativeThread";
|
|
||||||
lJavaVMAttachArgs.group = NULL;
|
|
||||||
|
|
||||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
|
|
||||||
if (lResult == JNI_ERR)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieves NativeActivity.
|
// Retrieves NativeActivity.
|
||||||
jobject lNativeActivity = mApplication->activity->clazz;
|
jobject lNativeActivity = mApplication->activity->clazz;
|
||||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
|
||||||
|
|
||||||
jmethodID MethodPickFile = lJNIEnv->GetMethodID(ClassNativeActivity, "getDensity", "()F");
|
jmethodID MethodPickFile = jni->GetMethodID(ClassNativeActivity, "getDensity", "()F");
|
||||||
float density = lJNIEnv->CallFloatMethod(lNativeActivity, MethodPickFile);
|
float density = jni->CallFloatMethod(lNativeActivity, MethodPickFile);
|
||||||
|
|
||||||
// Finished with the JVM.
|
|
||||||
lJavaVM->DetachCurrentThread();
|
|
||||||
return density;
|
return density;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_data_path(android_app* mApplication)
|
std::string get_data_path(android_app* mApplication)
|
||||||
{
|
{
|
||||||
// Attaches the current thread to the JVM.
|
|
||||||
jint lResult;
|
|
||||||
jint lFlags = 0;
|
|
||||||
|
|
||||||
JavaVM* lJavaVM = mApplication->activity->vm;
|
|
||||||
JNIEnv* lJNIEnv = mApplication->activity->env;
|
|
||||||
|
|
||||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
|
||||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
|
||||||
lJavaVMAttachArgs.name = "NativeThread";
|
|
||||||
lJavaVMAttachArgs.group = NULL;
|
|
||||||
|
|
||||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
|
|
||||||
if (lResult == JNI_ERR)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieves NativeActivity.
|
// Retrieves NativeActivity.
|
||||||
jobject lNativeActivity = mApplication->activity->clazz;
|
jobject lNativeActivity = mApplication->activity->clazz;
|
||||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
|
||||||
|
|
||||||
jmethodID MethodPickFile = lJNIEnv->GetMethodID(ClassNativeActivity, "getDataPath", "()Ljava/lang/String;");
|
jmethodID MethodPickFile = jni->GetMethodID(ClassNativeActivity, "getDataPath", "()Ljava/lang/String;");
|
||||||
jstring path = (jstring)lJNIEnv->CallObjectMethod(lNativeActivity, MethodPickFile);
|
jstring path = (jstring)jni->CallObjectMethod(lNativeActivity, MethodPickFile);
|
||||||
|
|
||||||
const char* path_utf = lJNIEnv->GetStringUTFChars(path, nullptr);
|
const char* path_utf = jni->GetStringUTFChars(path, nullptr);
|
||||||
std::string file_path = path_utf; // create a copy
|
std::string file_path = path_utf; // create a copy
|
||||||
lJNIEnv->ReleaseStringUTFChars(path, path_utf);
|
jni->ReleaseStringUTFChars(path, path_utf);
|
||||||
|
|
||||||
// Finished with the JVM.
|
|
||||||
lJavaVM->DetachCurrentThread();
|
|
||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,11 +328,15 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
* component compatible with on-screen windows
|
* component compatible with on-screen windows
|
||||||
*/
|
*/
|
||||||
const EGLint attribs[] = {
|
const EGLint attribs[] = {
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
|
||||||
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
|
||||||
EGL_BLUE_SIZE, 8,
|
EGL_BLUE_SIZE, 8,
|
||||||
EGL_GREEN_SIZE, 8,
|
EGL_GREEN_SIZE, 8,
|
||||||
EGL_RED_SIZE, 8,
|
EGL_RED_SIZE, 8,
|
||||||
EGL_DEPTH_SIZE, 24,
|
EGL_ALPHA_SIZE, 8,
|
||||||
|
EGL_DEPTH_SIZE, 0,
|
||||||
|
EGL_STENCIL_SIZE, 0,
|
||||||
|
EGL_SAMPLES, 0,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
EGLint w, h, dummy, format;
|
EGLint w, h, dummy, format;
|
||||||
@@ -460,12 +365,13 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
auto i = 0;
|
auto i = 0;
|
||||||
for (; i < numConfigs; i++) {
|
for (; i < numConfigs; i++) {
|
||||||
auto& cfg = supportedConfigs[i];
|
auto& cfg = supportedConfigs[i];
|
||||||
EGLint r, g, b, d;
|
EGLint r, g, b, a, d;
|
||||||
if (eglGetConfigAttrib(display, cfg, EGL_RED_SIZE, &r) &&
|
if (eglGetConfigAttrib(display, cfg, EGL_RED_SIZE, &r) &&
|
||||||
eglGetConfigAttrib(display, cfg, EGL_GREEN_SIZE, &g) &&
|
eglGetConfigAttrib(display, cfg, EGL_GREEN_SIZE, &g) &&
|
||||||
eglGetConfigAttrib(display, cfg, EGL_BLUE_SIZE, &b) &&
|
eglGetConfigAttrib(display, cfg, EGL_BLUE_SIZE, &b) &&
|
||||||
|
eglGetConfigAttrib(display, cfg, EGL_ALPHA_SIZE, &a) &&
|
||||||
eglGetConfigAttrib(display, cfg, EGL_DEPTH_SIZE, &d) &&
|
eglGetConfigAttrib(display, cfg, EGL_DEPTH_SIZE, &d) &&
|
||||||
r == 8 && g == 8 && b == 8 && d == 0 ) {
|
r == 8 && g == 8 && b == 8 && a == 8 && d == 0 ) {
|
||||||
|
|
||||||
config = supportedConfigs[i];
|
config = supportedConfigs[i];
|
||||||
break;
|
break;
|
||||||
@@ -483,9 +389,9 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
|
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
|
||||||
|
|
||||||
const EGLint attribs_test[] = {
|
const EGLint attribs_test[] = {
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||||
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
||||||
//EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
|
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -503,7 +409,7 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
{
|
{
|
||||||
LOG("EGL: debug and forward context failed");
|
LOG("EGL: debug and forward context failed");
|
||||||
const EGLint attribs_test[] = {
|
const EGLint attribs_test[] = {
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||||
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
@@ -512,7 +418,7 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
{
|
{
|
||||||
LOG("EGL: only forward context failed");
|
LOG("EGL: only forward context failed");
|
||||||
const EGLint attribs_test[] = {
|
const EGLint attribs_test[] = {
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||||
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR,
|
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR,
|
||||||
//EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
|
//EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
@@ -522,7 +428,7 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
{
|
{
|
||||||
LOG("EGL: only debug context failed");
|
LOG("EGL: only debug context failed");
|
||||||
const EGLint attribs_test[] = {
|
const EGLint attribs_test[] = {
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test);
|
context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test);
|
||||||
@@ -565,9 +471,9 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
engine->height = h;
|
engine->height = h;
|
||||||
engine->state.angle = 0;
|
engine->state.angle = 0;
|
||||||
|
|
||||||
float density = get_display_density(engine->app);
|
//float density = get_display_density(engine->app);
|
||||||
LOG("density %f", density);
|
//LOG("density %f", density);
|
||||||
App::I.zoom = density / 1.5;
|
//App::I.zoom = density / 1.5;
|
||||||
|
|
||||||
g_display = display;
|
g_display = display;
|
||||||
g_context = context;
|
g_context = context;
|
||||||
@@ -673,6 +579,10 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
//LOG("PROP: %s", os_props[""].c_str());
|
//LOG("PROP: %s", os_props[""].c_str());
|
||||||
//LOG("PROP: %s", os_props[""].c_str());
|
//LOG("PROP: %s", os_props[""].c_str());
|
||||||
|
|
||||||
|
#ifdef __QUEST__
|
||||||
|
oculus_init_vr(display, context, engine->app->window);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialize GL state.
|
// Initialize GL state.
|
||||||
|
|
||||||
android_async_lock(engine);
|
android_async_lock(engine);
|
||||||
@@ -696,6 +606,7 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
App::I.height = h;
|
App::I.height = h;
|
||||||
App::I.redraw = true;
|
App::I.redraw = true;
|
||||||
App::I.init();
|
App::I.init();
|
||||||
|
App::I.resize(w, h);
|
||||||
|
|
||||||
LOG("All ready");
|
LOG("All ready");
|
||||||
engine->animating = 1;
|
engine->animating = 1;
|
||||||
@@ -710,11 +621,38 @@ static int engine_init_display(struct engine* engine) {
|
|||||||
static void engine_draw_frame(struct engine* engine) {
|
static void engine_draw_frame(struct engine* engine) {
|
||||||
static auto start = std::chrono::high_resolution_clock::now();
|
static auto start = std::chrono::high_resolution_clock::now();
|
||||||
static float elapsed = 0;
|
static float elapsed = 0;
|
||||||
|
static float elapsed_1s = 0;
|
||||||
|
static int rendered_frames = 0;
|
||||||
locker _lock(engine);
|
locker _lock(engine);
|
||||||
|
|
||||||
if (engine->display == EGL_NO_DISPLAY)
|
if (engine->display == EGL_NO_DISPLAY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
|
auto dt = std::chrono::duration<float>(now - start);
|
||||||
|
start = now;
|
||||||
|
elapsed += dt.count();
|
||||||
|
elapsed_1s += dt.count();
|
||||||
|
App::I.tick(dt.count());
|
||||||
|
|
||||||
|
if (elapsed_1s > 1.f)
|
||||||
|
{
|
||||||
|
LOG("vr %d fps", rendered_frames);
|
||||||
|
elapsed_1s = 0;
|
||||||
|
rendered_frames = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float fps60 = 1.f / 60.f;
|
||||||
|
if (elapsed < fps60)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rendered_frames++;
|
||||||
|
elapsed = 0;
|
||||||
|
|
||||||
|
#ifdef __QUEST__
|
||||||
|
App::I.vr_draw_ui();
|
||||||
|
oculus_draw();
|
||||||
|
#else
|
||||||
/*
|
/*
|
||||||
int w, h;
|
int w, h;
|
||||||
eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w);
|
eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w);
|
||||||
@@ -729,12 +667,6 @@ static void engine_draw_frame(struct engine* engine) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
|
||||||
auto dt = std::chrono::duration<float>(now - start);
|
|
||||||
start = now;
|
|
||||||
elapsed += dt.count();
|
|
||||||
App::I.tick(dt.count());
|
|
||||||
|
|
||||||
if (!(App::I.redraw || App::I.animate))
|
if (!(App::I.redraw || App::I.animate))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -743,6 +675,7 @@ static void engine_draw_frame(struct engine* engine) {
|
|||||||
elapsed = 0;
|
elapsed = 0;
|
||||||
|
|
||||||
eglSwapBuffers(engine->display, engine->surface);
|
eglSwapBuffers(engine->display, engine->surface);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1051,23 +984,14 @@ void android_main(struct android_app* state) {
|
|||||||
|
|
||||||
ANativeActivity_setWindowFlags(state->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0 );
|
ANativeActivity_setWindowFlags(state->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0 );
|
||||||
|
|
||||||
ovrJava java;
|
state->activity->vm->AttachCurrentThread(&jni, nullptr);
|
||||||
java.Vm = state->activity->vm;
|
|
||||||
(*java.Vm).AttachCurrentThread(&java.Env, NULL );
|
#ifdef __QUEST__
|
||||||
java.ActivityObject = state->activity->clazz;
|
oculus_init(state->activity->vm, jni, state->activity->clazz);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Note that AttachCurrentThread will reset the thread name.
|
// Note that AttachCurrentThread will reset the thread name.
|
||||||
prctl( PR_SET_NAME, (long)"OVR::Main", 0, 0, 0 );
|
prctl(PR_SET_NAME, (long)"PanoPainter Main", 0, 0, 0);
|
||||||
|
|
||||||
const ovrInitParms initParms = vrapi_DefaultInitParms( &java );
|
|
||||||
int32_t initResult = vrapi_Initialize( &initParms );
|
|
||||||
if ( initResult != VRAPI_INITIALIZE_SUCCESS )
|
|
||||||
{
|
|
||||||
// If intialization failed, vrapi_* function calls will not be available.
|
|
||||||
exit( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// END OVR
|
|
||||||
|
|
||||||
// Prepare to monitor accelerometer
|
// Prepare to monitor accelerometer
|
||||||
/*
|
/*
|
||||||
@@ -1098,7 +1022,7 @@ void android_main(struct android_app* state) {
|
|||||||
// If animating, we loop until all events are read, then continue
|
// If animating, we loop until all events are read, then continue
|
||||||
// to draw the next frame of animation.
|
// to draw the next frame of animation.
|
||||||
bool used = false;
|
bool used = false;
|
||||||
int timeout = g_engine.display != EGL_NO_DISPLAY ? 100 : -1;
|
int timeout = g_engine.display != EGL_NO_DISPLAY ? 0 : -1;
|
||||||
while (!used && (ident=ALooper_pollOnce(timeout, NULL, &events,
|
while (!used && (ident=ALooper_pollOnce(timeout, NULL, &events,
|
||||||
(void**)&source)) != ALOOPER_POLL_ERROR) {
|
(void**)&source)) != ALOOPER_POLL_ERROR) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.omixlab.panopainter;
|
package com.omixlab.panopainter;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.NativeActivity;
|
import android.app.NativeActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -14,14 +13,13 @@ import android.view.View;
|
|||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import com.omixlab.panopainter.Platform;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
public class MainActivity extends NativeActivity {
|
public class MainActivity extends NativeActivity {
|
||||||
static {
|
static {
|
||||||
|
for (String lib : Platform.Libs)
|
||||||
|
System.loadLibrary(lib);
|
||||||
System.loadLibrary("native-lib");
|
System.loadLibrary("native-lib");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
libs/ovr_mobile
Submodule
1
libs/ovr_mobile
Submodule
Submodule libs/ovr_mobile added at fceeb641f1
Reference in New Issue
Block a user