Skip to content

Commit

Permalink
Add proxy methods to access newly added apis from gdscript and jni.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Sep 30, 2021
1 parent edbe9e2 commit 2695504
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 89 deletions.
45 changes: 45 additions & 0 deletions android/src/main/cpp/jni/openxr_config_jni.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <jni.h>

#include "jni/jni_util.h"
#include "openxr/extensions/xr_ext_performance_settings_extension_wrapper.h"
#include "openxr/extensions/xr_fb_color_space_extension_wrapper.h"
#include "openxr/extensions/xr_fb_display_refresh_rate_extension_wrapper.h"
#include "openxr/extensions/xr_fb_foveation_extension_wrapper.h"
#include <core/Array.hpp>
#include <core/Dictionary.hpp>

Expand Down Expand Up @@ -39,4 +41,47 @@ JNIEXPORT jdoubleArray JNICALL JNI_METHOD(getAvailableRefreshRates)(JNIEnv *env,
godot::Array refresh_rates = XRFbDisplayRefreshRateExtensionWrapper::get_singleton()->get_available_refresh_rates();
return array_to_jdoubleArray(env, refresh_rates);
}

JNIEXPORT jstring JNICALL JNI_METHOD(nativeGetSystemName)(JNIEnv *env, jclass) {
OpenXRApi *openxr_api = OpenXRApi::openxr_get_api();
String system_name = openxr_api->get_system_name();
jstring j_system_name = string_to_jstring(env, system_name);
OpenXRApi::openxr_release_api();
return j_system_name;
}

JNIEXPORT jint JNICALL JNI_METHOD(nativeGetCpuLevel)(JNIEnv *, jclass) {
return XRExtPerformanceSettingsExtensionWrapper::get_singleton()->get_cpu_level();
}

JNIEXPORT jboolean JNICALL JNI_METHOD(nativeSetCpuLevel)(JNIEnv *, jclass, jint level) {
return XRExtPerformanceSettingsExtensionWrapper::get_singleton()->set_cpu_level(static_cast<XrPerfSettingsLevelEXT>(level));
}

JNIEXPORT jint JNICALL JNI_METHOD(nativeGetGpuLevel)(JNIEnv *, jclass) {
return XRExtPerformanceSettingsExtensionWrapper::get_singleton()->get_gpu_level();
}

JNIEXPORT jboolean JNICALL JNI_METHOD(nativeSetGpuLevel)(JNIEnv *, jclass, jint level) {
return XRExtPerformanceSettingsExtensionWrapper::get_singleton()->set_gpu_level(static_cast<XrPerfSettingsLevelEXT>(level));
}

JNIEXPORT jfloat JNICALL JNI_METHOD(getRenderTargetSizeMultiplier)(JNIEnv *, jclass, jobject) {
OpenXRApi *openxr_api = OpenXRApi::openxr_get_api();
jfloat multiplier = openxr_api->get_render_target_size_multiplier();
OpenXRApi::openxr_release_api();
return multiplier;
}

JNIEXPORT jboolean JNICALL JNI_METHOD(setRenderTargetSizeMultiplier)(JNIEnv *, jclass, jobject, jfloat multiplier) {
OpenXRApi *openxr_api = OpenXRApi::openxr_get_api();
jboolean result = openxr_api->set_render_target_size_multiplier(multiplier);
OpenXRApi::openxr_release_api();
return result;
}

JNIEXPORT void JNICALL JNI_METHOD(nativeSetFoveationLevel)(JNIEnv *, jclass, jint foveation_level, jboolean is_dynamic) {
XrFoveationDynamicFB foveation_dynamic = is_dynamic ? XR_FOVEATION_DYNAMIC_LEVEL_ENABLED_FB : XR_FOVEATION_DYNAMIC_DISABLED_FB;
XRFbFoveationExtensionWrapper::get_singleton()->set_foveation_level(static_cast<XrFoveationLevelFB>(foveation_level), foveation_dynamic);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.godotengine.plugin.vr.openxr.api

/**
* For reference, see https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrFoveationLevelFB
*/
enum class FoveationLevel(internal val value: Int) {
/**
* No foveation
*/
NONE(0),

/**
* Less foveation (higher periphery visual fidelity, lower performance)
*/
LOW(1),

/**
* Medium foveation (medium periphery visual fidelity, medium performance)
*/
MEDIUM(2),

/**
* High foveation (lower periphery visual fidelity, higher performance)
*/
HIGH(3);

companion object {
fun toFoveationLevel(value: Int): FoveationLevel {
for (level in values()) {
if (level.value == value) {
return level
}
}
return NONE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,21 @@ package org.godotengine.plugin.vr.openxr.api
import org.godotengine.plugin.vr.openxr.OpenXRPlugin

/**
* See https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrColorSpaceFB for reference.
*/
enum class XrColorSpace(internal val value: Int) {
/**
* No color correction, not recommended for production use.
*/
XR_COLOR_SPACE_UNMANAGED(0),

/**
* Standard Rec. 2020 chromacities.
* This is the preferred color space for standardized color across all Oculus HMDs
* with D65 white point.
*/
XR_COLOR_SPACE_REC2020(1),

/**
* Standard Rec. 709 chromaticities, similar to sRGB.
*/
XR_COLOR_SPACE_REC709(2),

/**
* Unique color space, between P3 and Adobe RGB using D75 white point.
*
* Color Space Details with Chromacity Primaries in CIE 1931 xy:
* Red: (0.666, 0.334)
* Green: (0.238, 0.714)
* Blue: (0.139, 0.053)
* White: (0.298, 0.318)
*/
XR_COLOR_SPACE_RIFT_CV1(3),

/**
* Unique color space. Similar to Rec 709 using D75.
*
* Color Space Details with Chromacity Primaries in CIE 1931 xy:
* Red: (0.640, 0.330)
* Green: (0.292, 0.586)
* Blue: (0.156, 0.058)
* White: (0.298, 0.318)
*/
XR_COLOR_SPACE_RIFT_S(4),

/**
* Unique color space. Similar to Rift CV1 using D75 white point
*
* Color Space Details with Chromacity Primaries in CIE 1931 xy:
* Red: (0.661, 0.338)
* Green: (0.228, 0.718)
* Blue: (0.142, 0.042)
* White: (0.298, 0.318)
*/
XR_COLOR_SPACE_QUEST(5),

/**
* Similar to DCI-P3, but uses D65 white point instead.
*
* Color Space Details with Chromacity Primaries in CIE 1931 xy:
* Red: (0.680, 0.320)
* Green: (0.265, 0.690)
* Blue: (0.150, 0.060)
* White: (0.313, 0.329)
*/
XR_COLOR_SPACE_P3(6),

/**
* Standard Adobe chromacities.
*/
XR_COLOR_SPACE_ADOBE_RGB(7);

companion object {
fun toXrColorSpace(value: Int): XrColorSpace {
for (colorSpace in values()) {
if (colorSpace.value == value) {
return colorSpace
}
}
return XR_COLOR_SPACE_UNMANAGED
}
}
}

/**
* Used to retrieve the device color space.
* Used to retrieve the system color space.
*/
fun OpenXRPlugin.getColorSpace() = XrColorSpace.toXrColorSpace(nativeGetXrColorSpace())

private external fun nativeGetXrColorSpace(): Int

/**
* Update the device color space.
* Update the system color space.
*/
fun OpenXRPlugin.setColorSpace(colorSpace: XrColorSpace) = nativeSetXrColorSpace(colorSpace.value)

private external fun nativeSetXrColorSpace(colorSpace: Int)

/**
* Retrieve the list of color spaces supported on this device.
* Retrieve the list of color spaces supported on this system.
*/
fun OpenXRPlugin.getAvailableColorSpaces() : Array<XrColorSpace> {
val colorSpaces = nativeGetAvailableXrColorSpaces()
Expand All @@ -111,16 +29,68 @@ fun OpenXRPlugin.getAvailableColorSpaces() : Array<XrColorSpace> {
private external fun nativeGetAvailableXrColorSpaces(): IntArray

/**
* Retrieve the device current refresh rate.
* Retrieve the system current refresh rate.
*/
external fun OpenXRPlugin.getRefreshRate(): Double

/**
* Update the device's refresh rate.
* Update the system's refresh rate.
*/
external fun OpenXRPlugin.setRefreshRate(refreshRate: Double)

/**
* Retrieve the list of refresh rates supported by this device.
* Retrieve the list of refresh rates supported by this system.
*/
external fun OpenXRPlugin.getAvailableRefreshRates(): DoubleArray

/**
* Return the current [SystemType] type.
*/
fun OpenXRPlugin.getSystemType() = SystemType.toSystemType(nativeGetSystemName())

private external fun nativeGetSystemName(): String

/**
* Retrieve the system's cpu performance settings level.
*/
fun OpenXRPlugin.getCpuLevel() = PerformanceSettingsLevel.toPerformanceSettingsLevel(nativeGetCpuLevel())

private external fun nativeGetCpuLevel(): Int

/**
* Update the system's cpu performance settings level.
*/
fun OpenXRPlugin.setCpuLevel(level: PerformanceSettingsLevel) = nativeSetCpuLevel(level.value)

private external fun nativeSetCpuLevel(level: Int): Boolean

/**
* Retrieve the system's gpu performance settings level.
*/
external fun OpenXRPlugin.getAvailableRefreshRates(): DoubleArray
fun OpenXRPlugin.getGpuLevel() = PerformanceSettingsLevel.toPerformanceSettingsLevel(nativeGetGpuLevel())

private external fun nativeGetGpuLevel(): Int

/**
* Update the system's gpu performance settings level.
*/
fun OpenXRPlugin.setGpuLevel(level: PerformanceSettingsLevel) = nativeSetGpuLevel(level.value)

private external fun nativeSetGpuLevel(level: Int): Boolean

/**
* Retrieve the factor by which the render target size is multiplied.
*/
external fun OpenXRPlugin.getRenderTargetSizeMultiplier(): Float

/**
* Set the factor by which to multiply the recommended render target size for the app.
*/
external fun OpenXRPlugin.setRenderTargetSizeMultiplier(multiplier: Float): Boolean

/**
* Set the system foveation level
*/
fun OpenXRPlugin.setFoveationLevel(level: FoveationLevel, isDynamic: Boolean) = nativeSetFoveationLevel(level.value, isDynamic)

private external fun nativeSetFoveationLevel(level: Int, isDynamic: Boolean)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.godotengine.plugin.vr.openxr.api

/**
* For reference, see https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XrPerfSettingsLevelEXT
*/
enum class PerformanceSettingsLevel(internal val value: Int) {
/**
* Used by the application to indicate that it enters a non-XR section
* (head-locked / static screen), during which power savings are to be prioritized.
*/
POWER_SAVINGS(0),

/**
* Used by the application to indicate that it enters a low and stable complexity section,
* during which reducing power is more important than occasional late rendering frames.
*/
SUSTAINED_LOW(25),

/**
* Used by the application to indicate that it enters a high or dynamic complexity section,
* during which the XR Runtime strives for consistent XR compositing and frame rendering within
* a thermally sustainable range(*).
*
* This is the default if the application does not specify its performance level.
*/
SUSTAINED_HIGH(50),

/**
* Used to indicate that the application enters a section with very high complexity,
* during which the XR Runtime is allowed to step up beyond the thermally sustainable range.
*
* This is meant to be used for short-term durations (< 30 seconds).
*/
BOOST(75);

companion object {
fun toPerformanceSettingsLevel(value: Int): PerformanceSettingsLevel {
for (level in values()) {
if (level.value == value) {
return level
}
}

return SUSTAINED_HIGH
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.godotengine.plugin.vr.openxr.api

/**
* Represents OpenXR systems.
*/
enum class SystemType(internal val systemName: String) {
UNKNOWN(""),
OCULUS_QUEST("Oculus Quest"), // TODO: Validate device name
OCULUS_QUEST2("Oculus Quest2"); // TODO: Validate device name

companion object {
fun toSystemType(value: String?): SystemType {
if (value == null) {
return UNKNOWN
}

for (systemType in values()) {
if (systemType.systemName == value) {
return systemType
}
}
return UNKNOWN
}
}
}
Loading

0 comments on commit 2695504

Please sign in to comment.