Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/openxr/doc_classes/OpenXRInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
Set foveation level from 0 (off) to 3 (high), the interface must be initialized before this is accessible.
[b]Note:[/b] Only works on the Compatibility renderer.
</member>
<member name="protected_content" type="bool" setter="set_protected_content" getter="is_protected_content" default="false">
If enabled, the OpenXR swapchain will be created with the [code]XR_SWAPCHAIN_CREATE_PROTECTED_CONTENT_BIT[/code] flag, which will protect its contents from CPU access.
</member>
<member name="render_target_size_multiplier" type="float" setter="set_render_target_size_multiplier" getter="get_render_target_size_multiplier" default="1.0">
The render size multiplier for the current HMD. Must be set before the interface has been initialized.
</member>
Expand Down
18 changes: 13 additions & 5 deletions modules/openxr/openxr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ bool OpenXRAPI::obtain_swapchain_formats() {
return true;
}

bool OpenXRAPI::create_main_swapchains(const Size2i &p_size) {
bool OpenXRAPI::create_main_swapchains(const Size2i &p_size, bool p_protected_content) {
ERR_NOT_ON_RENDER_THREAD_V(false);
ERR_FAIL_NULL_V(graphics_extension, false);
ERR_FAIL_COND_V(session == XR_NULL_HANDLE, false);
Expand All @@ -1254,11 +1254,19 @@ bool OpenXRAPI::create_main_swapchains(const Size2i &p_size) {
*/

render_state.main_swapchain_size = p_size;
render_state.swapchain_protected_content = p_protected_content;
uint32_t sample_count = 1;

// Check to see if content should be protected.
XrSwapchainCreateFlags create_flags = 0;

if (p_protected_content) {
create_flags = XR_SWAPCHAIN_CREATE_PROTECTED_CONTENT_BIT;
}

// We start with our color swapchain...
if (color_swapchain_format != 0) {
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_COLOR].create(0, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT, color_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_COLOR].create(create_flags, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT | XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT, color_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
return false;
}

Expand All @@ -1270,7 +1278,7 @@ bool OpenXRAPI::create_main_swapchains(const Size2i &p_size) {
// - we support our depth layer extension
// - we have our spacewarp extension (not yet implemented)
if (depth_swapchain_format != 0 && submit_depth_buffer && OpenXRCompositionLayerDepthExtension::get_singleton()->is_available()) {
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_DEPTH].create(0, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, depth_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
if (!render_state.main_swapchains[OPENXR_SWAPCHAIN_DEPTH].create(create_flags, XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, depth_swapchain_format, render_state.main_swapchain_size.width, render_state.main_swapchain_size.height, sample_count, view_configuration_views.size())) {
return false;
}

Expand Down Expand Up @@ -2293,12 +2301,12 @@ void OpenXRAPI::pre_render() {
OpenXRSwapChainInfo::free_queued();

Size2i swapchain_size = get_recommended_target_size();
if (swapchain_size != render_state.main_swapchain_size) {
if (swapchain_size != render_state.main_swapchain_size || protected_content != render_state.swapchain_protected_content) {
// Out with the old.
free_main_swapchains();

// In with the new.
create_main_swapchains(swapchain_size);
create_main_swapchains(swapchain_size, protected_content);
}

void *view_locate_info_next_pointer = nullptr;
Expand Down
7 changes: 6 additions & 1 deletion modules/openxr/openxr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class OpenXRAPI {
XrFrameState frame_state = { XR_TYPE_FRAME_STATE, nullptr, 0, 0, false };
double render_target_size_multiplier = 1.0;
Rect2i render_region;
bool protected_content = false;

OpenXRGraphicsExtensionWrapper *graphics_extension = nullptr;
XrSystemGraphicsProperties graphics_properties;
Expand Down Expand Up @@ -260,7 +261,7 @@ class OpenXRAPI {
bool load_supported_swapchain_formats();
bool is_swapchain_format_supported(int64_t p_swapchain_format);
bool obtain_swapchain_formats();
bool create_main_swapchains(const Size2i &p_size);
bool create_main_swapchains(const Size2i &p_size, bool p_protected_content);
void free_main_swapchains();
void destroy_session();

Expand Down Expand Up @@ -361,6 +362,7 @@ class OpenXRAPI {
};

Size2i main_swapchain_size;
bool swapchain_protected_content = false;
OpenXRSwapChainInfo main_swapchains[OPENXR_SWAPCHAIN_MAX];
} render_state;

Expand Down Expand Up @@ -620,6 +622,9 @@ class OpenXRAPI {
void set_emulate_environment_blend_mode_alpha_blend(bool p_enabled);
OpenXRAlphaBlendModeSupport is_environment_blend_mode_alpha_blend_supported();

void set_protected_content(bool p_protected_content) { protected_content = p_protected_content; }
bool is_protected_content() const { return protected_content; }

OpenXRAPI();
~OpenXRAPI();
};
20 changes: 20 additions & 0 deletions modules/openxr/openxr_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ void OpenXRInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_display_refresh_rate", "refresh_rate"), &OpenXRInterface::set_display_refresh_rate);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_refresh_rate"), "set_display_refresh_rate", "get_display_refresh_rate");

// Protected content
ClassDB::bind_method(D_METHOD("is_protected_content"), &OpenXRInterface::is_protected_content);
ClassDB::bind_method(D_METHOD("set_protected_content", "protected_content"), &OpenXRInterface::set_protected_content);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "protected_content"), "set_protected_content", "is_protected_content");

// Render Target size multiplier
ClassDB::bind_method(D_METHOD("get_render_target_size_multiplier"), &OpenXRInterface::get_render_target_size_multiplier);
ClassDB::bind_method(D_METHOD("set_render_target_size_multiplier", "multiplier"), &OpenXRInterface::set_render_target_size_multiplier);
Expand Down Expand Up @@ -836,6 +841,21 @@ PackedVector3Array OpenXRInterface::get_play_area() const {
return arr;
}

void OpenXRInterface::set_protected_content(bool p_protected_content) {
if (openxr_api == nullptr) {
return;
}

openxr_api->set_protected_content(p_protected_content);
}

bool OpenXRInterface::is_protected_content() const {
if (openxr_api == nullptr) {
return false;
}
return openxr_api->is_protected_content();
}

float OpenXRInterface::get_display_refresh_rate() const {
if (openxr_api == nullptr) {
return 0.0;
Expand Down
6 changes: 6 additions & 0 deletions modules/openxr/openxr_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ class OpenXRInterface : public XRInterface {
virtual bool set_play_area_mode(XRInterface::PlayAreaMode p_mode) override;
virtual PackedVector3Array get_play_area() const override;

/** protected content **/
// If enabled, protect content from CPU access.
void set_protected_content(bool p_protected_content);
// Returns true if the content is being protected from CPU access.
bool is_protected_content() const;

float get_display_refresh_rate() const;
void set_display_refresh_rate(float p_refresh_rate);
Array get_available_display_refresh_rates() const;
Expand Down