Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor overlay support to use SubViewportContainer #155

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions demo/overlay_main.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Node

var _xr_interface_openvr : XRInterfaceOpenVR


func _enter_tree():
_xr_interface_openvr = OpenVRInterface.get_interface()

_xr_interface_openvr.set_application_type(2)
_xr_interface_openvr.set_tracking_universe(1)

if not _xr_interface_openvr.initialize():
print("Failed to connect to OpenVR")

38 changes: 38 additions & 0 deletions demo/overlay_main.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[gd_scene load_steps=2 format=3 uid="uid://c2n2wcnoskmmr"]

[ext_resource type="Script" path="res://overlay_main.gd" id="1_jfubd"]

[node name="OverlayMain" type="HBoxContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_jfubd")

[node name="Label" type="Label" parent="."]
layout_mode = 2
text = "This is a demo of creating anOpenVR Overlay from a SubViewport!

Use Run Current Scene (F6) to try this."
horizontal_alignment = 1
vertical_alignment = 1

[node name="OpenVROverlayContainer" type="OpenVROverlayContainer" parent="."]
absolute_position = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.4, -1.4)
layout_mode = 2
size_flags_horizontal = 3
stretch = true

[node name="SubViewport" type="SubViewport" parent="OpenVROverlayContainer"]
handle_input_locally = false
size = Vector2i(639, 648)
render_target_update_mode = 4

[node name="Label" type="Label" parent="OpenVROverlayContainer/SubViewport"]
offset_right = 634.0
offset_bottom = 648.0
size_flags_vertical = 3
text = "I appear in an overlay too!"
horizontal_alignment = 1
vertical_alignment = 1
202 changes: 0 additions & 202 deletions src/open_vr/OpenVROverlay.cpp

This file was deleted.

44 changes: 0 additions & 44 deletions src/open_vr/OpenVROverlay.h

This file was deleted.

17 changes: 13 additions & 4 deletions src/open_vr/openvr_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,14 @@ int openvr_data::get_overlay_count() {
return (int)overlays.size();
}

openvr_data::overlay openvr_data::get_overlay(int p_overlay_id) {
return overlays[p_overlay_id];
openvr_data::overlay *openvr_data::get_overlay(int p_overlay_id) {
return &overlays[p_overlay_id];
}

int openvr_data::add_overlay(vr::VROverlayHandle_t p_new_value, godot::RID p_viewport_rid) {
int openvr_data::add_overlay(vr::VROverlayHandle_t p_new_value, ObjectID p_container_instance_id) {
overlay new_entry;
new_entry.handle = p_new_value;
new_entry.viewport_rid = p_viewport_rid;
new_entry.container_instance_id = p_container_instance_id;

overlays.push_back(new_entry);
return (int)overlays.size() - 1;
Expand Down Expand Up @@ -645,6 +645,15 @@ void openvr_data::pre_render_update() {

////////////////////////////////////////////////////////////////
// Interact with tracking info
vr::TrackedDeviceIndex_t openvr_data::get_tracked_device_index(Ref<XRPositionalTracker> p_tracker) {
for (uint32_t i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) {
if (tracked_devices[i].tracker == p_tracker) {
return i;
}
}

return vr::k_unTrackedDeviceIndexInvalid;
}

////////////////////////////////////////////////////////////////
// Register an action set
Expand Down
16 changes: 8 additions & 8 deletions src/open_vr/openvr_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@ class openvr_data {
RAW
};

struct overlay {
vr::VROverlayHandle_t handle;
ObjectID container_instance_id;
};

private:
static openvr_data *singleton;

int use_count;

vr::IVRRenderModels *render_models;

// structure to record which overlays go with which viewport
struct overlay {
vr::VROverlayHandle_t handle;
godot::RID viewport_rid;
};

std::vector<overlay> overlays;

OpenVRApplicationType application_type;
Expand Down Expand Up @@ -186,12 +185,13 @@ class openvr_data {

// interact with tracking info
const godot::Transform3D get_hmd_transform() const;
vr::TrackedDeviceIndex_t get_tracked_device_index(Ref<XRPositionalTracker> p_tracker);

////////////////////////////////////////////////////////////////
// overlay
int get_overlay_count();
overlay get_overlay(int p_overlay_id);
int add_overlay(vr::VROverlayHandle_t p_new_value, godot::RID p_viewport_rid);
overlay *get_overlay(int p_overlay_id);
int add_overlay(vr::VROverlayHandle_t p_new_value, ObjectID p_container_instance_id);
void remove_overlay(int p_overlay_id);

////////////////////////////////////////////////////////////////
Expand Down
Loading