oculus quest running and android compiling and running
This commit is contained in:
@@ -11,8 +11,11 @@ add_library(
|
||||
)
|
||||
|
||||
add_library(vrapi SHARED IMPORTED)
|
||||
set_target_properties(vrapi PROPERTIES IMPORTED_LOCATION
|
||||
C:/ovr_sdk_mobile_1.23/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so)
|
||||
set_target_properties(
|
||||
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
|
||||
@@ -47,6 +50,7 @@ add_library(
|
||||
../../libs/poly2tri/poly2tri/sweep/sweep.cc
|
||||
../../libs/fmt/src/format.cc
|
||||
../src/cpp/main.cpp
|
||||
src/main/cpp/oculus_vr.cpp
|
||||
../../src/pch.cpp
|
||||
../../src/util.cpp
|
||||
../../src/rtt.cpp
|
||||
@@ -116,7 +120,8 @@ add_library(
|
||||
)
|
||||
|
||||
target_include_directories(native-lib PRIVATE
|
||||
C:/ovr_sdk_mobile_1.23/VrApi/Include
|
||||
../../libs/ovr_mobile/include
|
||||
src/main/cpp
|
||||
../src/cpp
|
||||
../../src
|
||||
../../libs/glm
|
||||
|
||||
@@ -83,7 +83,7 @@ android {
|
||||
// Sets optional flags for the C compiler.
|
||||
//cFlags "-D_EXAMPLE_C_FLAG1", "-D_EXAMPLE_C_FLAG2"
|
||||
// Sets a flag to enable format macro constants for the C++ compiler.
|
||||
//cppFlags "-D__STDC_FORMAT_MACROS"
|
||||
cppFlags "-D__QUEST__"
|
||||
arguments "-DANDROID_TOOLCHAIN=clang",
|
||||
//"-DANDROID_PLATFORM=android-19",
|
||||
"-DANDROID_STL=c++_shared",
|
||||
@@ -138,8 +138,8 @@ android {
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'src/main/AndroidManifest.xml'
|
||||
java.srcDirs = ['../src/java']
|
||||
//jniLibs.srcDir 'libs'
|
||||
java.srcDirs = ['../src/java', 'src/main/java']
|
||||
jniLibs.srcDirs = ['../../libs/ovr_mobile/lib']
|
||||
res.srcDirs = ['../src/res']
|
||||
//assets.srcDirs = ['../../assets']
|
||||
}
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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.WRITE_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"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:allowBackup="false"
|
||||
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"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:screenOrientation="fullUser"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
android:launchMode="singleTask"
|
||||
android:configChanges="screenSize|screenLayout|orientation|keyboardHidden|keyboard|navigation|uiMode"
|
||||
android:screenOrientation="landscape">
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="native-lib" />
|
||||
<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"};
|
||||
}
|
||||
Reference in New Issue
Block a user