This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from m4gr3d/customize_oculus_runtime_parameters
Access vrapi display refresh rate config api.
- Loading branch information
Showing
7 changed files
with
143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[gd_resource type="NativeScript" load_steps=2 format=2] | ||
|
||
[ext_resource path="res://addons/godot_ovrmobile/godot_ovrmobile.gdnlib" type="GDNativeLibrary" id=1] | ||
|
||
[resource] | ||
resource_name = "OvrDisplayRefreshRate" | ||
class_name = "OvrDisplayRefreshRate" | ||
library = ExtResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "config_common.h" | ||
|
||
void *init_ovr_config_data_struct() { | ||
ovr_config_data_struct *ovr_config_data; | ||
|
||
ovr_config_data = (ovr_config_data_struct *)api->godot_alloc(sizeof(ovr_config_data_struct)); | ||
if (ovr_config_data != NULL) { | ||
ovr_config_data->ovr_mobile_session = ovrmobile::OvrMobileSession::get_singleton_instance(); | ||
} | ||
|
||
return ovr_config_data; | ||
} | ||
|
||
void reset_ovr_config_data_struct(ovr_config_data_struct *ovr_config_data) { | ||
if (ovr_config_data && ovr_config_data->ovr_mobile_session) { | ||
ovr_config_data->ovr_mobile_session = NULL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "ovr_display_refresh_rate.h" | ||
#include "config_common.h" | ||
#include <vector> | ||
|
||
static const char *kClassName = "OvrDisplayRefreshRate"; | ||
|
||
void register_gdnative_display_refresh_rate(void *handle) { | ||
// register the constructor and destructor of the OvrDisplayRefreshRate class for use in GDScript | ||
godot_instance_create_func create = { NULL, NULL, NULL }; | ||
create.create_func = &ovr_display_refresh_rate_constructor; | ||
|
||
godot_instance_destroy_func destroy = { NULL, NULL, NULL }; | ||
destroy.destroy_func = &ovr_display_refresh_rate_destructor; | ||
|
||
nativescript_api->godot_nativescript_register_class(handle, kClassName, "Reference", create, destroy); | ||
|
||
// register all the functions that we want to expose via the OvrDisplayRefreshRate class in GDScript | ||
godot_instance_method method = { NULL, NULL, NULL }; | ||
godot_method_attributes attributes = { GODOT_METHOD_RPC_MODE_DISABLED }; | ||
|
||
method.method = &get_supported_display_refresh_rates; | ||
nativescript_api->godot_nativescript_register_method(handle, kClassName, "get_supported_display_refresh_rates", attributes, method); | ||
|
||
method.method = &set_display_refresh_rate; | ||
nativescript_api->godot_nativescript_register_method(handle, kClassName, "set_display_refresh_rate", attributes, method); | ||
} | ||
|
||
GDCALLINGCONV void *ovr_display_refresh_rate_constructor(godot_object *instance, void *method_data) { | ||
return init_ovr_config_data_struct(); | ||
} | ||
|
||
GDCALLINGCONV void ovr_display_refresh_rate_destructor(godot_object *instance, void *method_data, void *user_data) { | ||
if (user_data) { | ||
reset_ovr_config_data_struct(static_cast<ovr_config_data_struct *>(user_data)); | ||
} | ||
} | ||
|
||
GDCALLINGCONV godot_variant get_supported_display_refresh_rates(godot_object *instance, void *method_data, void *p_user_data, int num_args, godot_variant **args) { | ||
CHECK_OVR( | ||
const int refresh_rates_count = vrapi_GetSystemPropertyInt(ovr_java, VRAPI_SYS_PROP_NUM_SUPPORTED_DISPLAY_REFRESH_RATES); | ||
std::vector<float> supported_refresh_rates(refresh_rates_count, 0.0F); | ||
vrapi_GetSystemPropertyFloatArray(ovr_java, VRAPI_SYS_PROP_SUPPORTED_DISPLAY_REFRESH_RATES, supported_refresh_rates.data(), refresh_rates_count); | ||
|
||
godot_array gd_return_array; | ||
api->godot_array_new(&gd_return_array); | ||
|
||
for (int i = 0; i < refresh_rates_count; i++) { | ||
godot_variant refresh_rate; | ||
api->godot_variant_new_real(&refresh_rate, supported_refresh_rates[i]); | ||
api->godot_array_push_back(&gd_return_array, &refresh_rate); | ||
api->godot_variant_destroy(&refresh_rate); | ||
} | ||
|
||
api->godot_variant_new_array(&ret, &gd_return_array); | ||
api->godot_array_destroy(&gd_return_array); | ||
|
||
) | ||
} | ||
|
||
GDCALLINGCONV godot_variant set_display_refresh_rate(godot_object *instance, void *method_data, void *p_user_data, int num_args, godot_variant **args) { | ||
CHECK_OVR( | ||
const double refresh_rate = api->godot_variant_as_real(args[0]); | ||
ovrResult result = vrapi_SetDisplayRefreshRate(ovr, refresh_rate); | ||
if (result == ovrSuccess) { | ||
api->godot_variant_new_bool(&ret, true); | ||
} | ||
|
||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//////////////////////////////////////////////////////////////////////////////////////////////// | ||
// GDNative module that exposes part of the oculus api. | ||
// Each exported class implements one section of the VrApi.h. | ||
// This implements the <Display refresh rate> section. | ||
|
||
#ifndef OVR_DISPLAY_REFRESH_RATE_H | ||
#define OVR_DISPLAY_REFRESH_RATE_H | ||
|
||
#include "../godot_calls.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// Registers the OvrDisplayRefreshRate class and functions to GDNative. | ||
// This method should be called from godot_ovrmobile_nativescript_init. | ||
void register_gdnative_display_refresh_rate(void *handle); | ||
|
||
GDCALLINGCONV void *ovr_display_refresh_rate_constructor(godot_object *instance, void *method_data); | ||
GDCALLINGCONV void ovr_display_refresh_rate_destructor(godot_object *instance, void *method_data, void *user_data); | ||
|
||
// implements VrApi.h: ovrResult vrapi_SetDisplayRefreshRate(ovrMobile * ovr, const float refreshRate); | ||
GDCALLINGCONV godot_variant set_display_refresh_rate(godot_object *instance, void *method_data, void *user_data, int num_args, godot_variant **args); | ||
|
||
// Utility method to access the display refresh rates supported by the device. | ||
GDCALLINGCONV godot_variant get_supported_display_refresh_rates(godot_object *instance, void *method_data, void *user_data, int num_args, godot_variant **args); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // OVR_DISPLAY_REFRESH_RATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters