Skip to content

Commit 07b9a06

Browse files
committed
Add support for enabling XR_FB_composition_layer_settings on the projection layer
1 parent 73f87b9 commit 07b9a06

File tree

3 files changed

+135
-23
lines changed

3 files changed

+135
-23
lines changed

plugin/src/main/cpp/extensions/openxr_fb_composition_layer_settings_extension.cpp

Lines changed: 107 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ OpenXRFbCompositionLayerSettingsExtension::~OpenXRFbCompositionLayerSettingsExte
6363
}
6464

6565
void OpenXRFbCompositionLayerSettingsExtension::_bind_methods() {
66+
ClassDB::bind_method(D_METHOD("is_enabled"), &OpenXRFbCompositionLayerSettingsExtension::is_enabled);
67+
68+
ClassDB::bind_method(D_METHOD("set_projection_layer_auto_filter_enabled", "enabled"), &OpenXRFbCompositionLayerSettingsExtension::set_projection_layer_auto_filter_enabled);
69+
ClassDB::bind_method(D_METHOD("is_projection_layer_auto_filter_enabled"), &OpenXRFbCompositionLayerSettingsExtension::is_projection_layer_auto_filter_enabled);
70+
71+
ClassDB::bind_method(D_METHOD("set_projection_layer_supersampling_mode", "supersampling_mode"), &OpenXRFbCompositionLayerSettingsExtension::set_projection_layer_supersampling_mode);
72+
ClassDB::bind_method(D_METHOD("get_projection_layer_supersampling_mode"), &OpenXRFbCompositionLayerSettingsExtension::get_projection_layer_supersampling_mode);
73+
74+
ClassDB::bind_method(D_METHOD("set_projection_layer_sharpening_mode", "sharpening_mode"), &OpenXRFbCompositionLayerSettingsExtension::set_projection_layer_sharpening_mode);
75+
ClassDB::bind_method(D_METHOD("get_projection_layer_sharpening_mode"), &OpenXRFbCompositionLayerSettingsExtension::get_projection_layer_sharpening_mode);
76+
77+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "projection_layer_auto_filter_enabled", PROPERTY_HINT_NONE, ""), "set_projection_layer_auto_filter_enabled", "is_projection_layer_auto_filter_enabled");
78+
ADD_PROPERTY(PropertyInfo(Variant::INT, "projection_layer_supersampling_mode", PROPERTY_HINT_ENUM, "Disabled,Normal,Quality"), "set_projection_layer_supersampling_mode", "get_projection_layer_supersampling_mode");
79+
ADD_PROPERTY(PropertyInfo(Variant::INT, "projection_layer_sharpening_mode", PROPERTY_HINT_ENUM, "Disabled,Normal,Quality"), "set_projection_layer_sharpening_mode", "get_projection_layer_sharpening_mode");
80+
6681
BIND_ENUM_CONSTANT(SUPERSAMPLING_MODE_DISABLED);
6782
BIND_ENUM_CONSTANT(SUPERSAMPLING_MODE_NORMAL);
6883
BIND_ENUM_CONSTANT(SUPERSAMPLING_MODE_QUALITY);
@@ -72,11 +87,80 @@ void OpenXRFbCompositionLayerSettingsExtension::_bind_methods() {
7287
BIND_ENUM_CONSTANT(SHARPENING_MODE_QUALITY);
7388
}
7489

90+
bool OpenXRFbCompositionLayerSettingsExtension::is_enabled() const {
91+
return fb_composition_layer_settings;
92+
}
93+
94+
void OpenXRFbCompositionLayerSettingsExtension::set_projection_layer_auto_filter_enabled(bool p_enabled) {
95+
ERR_FAIL_COND_MSG(!is_enabled(), "XR_FB_composition_layer_settings is not enabled");
96+
projection_layer_auto_filter_enabled = p_enabled;
97+
}
98+
99+
bool OpenXRFbCompositionLayerSettingsExtension::is_projection_layer_auto_filter_enabled() const {
100+
return projection_layer_auto_filter_enabled;
101+
}
102+
103+
void OpenXRFbCompositionLayerSettingsExtension::set_projection_layer_sharpening_mode(OpenXRFbCompositionLayerSettingsExtension::SharpeningMode p_sharpening_mode) {
104+
ERR_FAIL_COND_MSG(!is_enabled(), "XR_FB_composition_layer_settings is not enabled");
105+
projection_layer_sharpening_mode = p_sharpening_mode;
106+
}
107+
108+
OpenXRFbCompositionLayerSettingsExtension::SharpeningMode OpenXRFbCompositionLayerSettingsExtension::get_projection_layer_sharpening_mode() const {
109+
return projection_layer_sharpening_mode;
110+
}
111+
112+
void OpenXRFbCompositionLayerSettingsExtension::set_projection_layer_supersampling_mode(OpenXRFbCompositionLayerSettingsExtension::SupersamplingMode p_supersampling_mode) {
113+
ERR_FAIL_COND_MSG(!is_enabled(), "XR_FB_composition_layer_settings is not enabled");
114+
projection_layer_supersampling_mode = p_supersampling_mode;
115+
}
116+
117+
OpenXRFbCompositionLayerSettingsExtension::SupersamplingMode OpenXRFbCompositionLayerSettingsExtension::get_projection_layer_supersampling_mode() const {
118+
return projection_layer_supersampling_mode;
119+
}
120+
121+
void OpenXRFbCompositionLayerSettingsExtension::_on_session_created(uint64_t p_session) {
122+
if (!is_enabled()) {
123+
return;
124+
}
125+
126+
get_openxr_api()->register_projection_layer_extension(this);
127+
}
128+
129+
void OpenXRFbCompositionLayerSettingsExtension::_on_session_destroyed() {
130+
if (!is_enabled()) {
131+
return;
132+
}
133+
134+
get_openxr_api()->unregister_projection_layer_extension(this);
135+
}
136+
75137
void OpenXRFbCompositionLayerSettingsExtension::cleanup() {
76138
fb_composition_layer_settings = false;
77139
meta_automatic_layer_filter = false;
78140
}
79141

142+
XrCompositionLayerSettingsFlagsFB OpenXRFbCompositionLayerSettingsExtension::_from_sharpening_mode(OpenXRFbCompositionLayerSettingsExtension::SharpeningMode p_sharpening_mode) const {
143+
switch (p_sharpening_mode) {
144+
case SHARPENING_MODE_DISABLED:
145+
return 0;
146+
case SHARPENING_MODE_NORMAL:
147+
return XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB;
148+
case SHARPENING_MODE_QUALITY:
149+
return XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB;
150+
}
151+
}
152+
153+
XrCompositionLayerSettingsFlagsFB OpenXRFbCompositionLayerSettingsExtension::_from_supersampling_mode(OpenXRFbCompositionLayerSettingsExtension::SupersamplingMode p_supersampling_mode) const {
154+
switch (p_supersampling_mode) {
155+
case SUPERSAMPLING_MODE_DISABLED:
156+
return 0;
157+
case SUPERSAMPLING_MODE_NORMAL:
158+
return XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB;
159+
case SUPERSAMPLING_MODE_QUALITY:
160+
return XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB;
161+
}
162+
}
163+
80164
Dictionary OpenXRFbCompositionLayerSettingsExtension::_get_requested_extensions(uint64_t p_xr_version) {
81165
Dictionary result;
82166
for (auto ext : request_extensions) {
@@ -86,6 +170,27 @@ Dictionary OpenXRFbCompositionLayerSettingsExtension::_get_requested_extensions(
86170
return result;
87171
}
88172

173+
uint64_t OpenXRFbCompositionLayerSettingsExtension::_set_projection_layer_and_get_next_pointer(void *p_next_pointer) {
174+
if (!is_enabled()) {
175+
return reinterpret_cast<uint64_t>(p_next_pointer);
176+
}
177+
178+
projection_layer_settings.layerFlags = 0;
179+
projection_layer_settings.layerFlags |= _from_sharpening_mode(projection_layer_sharpening_mode);
180+
projection_layer_settings.layerFlags |= _from_supersampling_mode(projection_layer_supersampling_mode);
181+
182+
if (projection_layer_settings.layerFlags == 0) {
183+
return reinterpret_cast<uint64_t>(p_next_pointer);
184+
}
185+
186+
if (meta_automatic_layer_filter && projection_layer_auto_filter_enabled) {
187+
projection_layer_settings.layerFlags |= XR_COMPOSITION_LAYER_SETTINGS_AUTO_LAYER_FILTER_BIT_META;
188+
}
189+
190+
projection_layer_settings.next = p_next_pointer;
191+
return reinterpret_cast<uint64_t>(&projection_layer_settings);
192+
}
193+
89194
uint64_t OpenXRFbCompositionLayerSettingsExtension::_set_viewport_composition_layer_and_get_next_pointer(const void *p_layer, const Dictionary &p_property_values, void *p_next_pointer) {
90195
if (!fb_composition_layer_settings) {
91196
return reinterpret_cast<uint64_t>(p_next_pointer);
@@ -113,29 +218,8 @@ uint64_t OpenXRFbCompositionLayerSettingsExtension::_set_viewport_composition_la
113218
return reinterpret_cast<uint64_t>(settings);
114219
}
115220

116-
switch ((SupersamplingMode)(int)p_property_values.get(SUPERSAMPLING_MODE_PROPERTY_NAME, SUPERSAMPLING_MODE_DISABLED)) {
117-
case SUPERSAMPLING_MODE_NORMAL: {
118-
settings->layerFlags |= XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB;
119-
} break;
120-
case SUPERSAMPLING_MODE_QUALITY: {
121-
settings->layerFlags |= XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB;
122-
} break;
123-
case SUPERSAMPLING_MODE_DISABLED: {
124-
// Do not enable any supersampling mode flags.
125-
} break;
126-
}
127-
128-
switch ((SharpeningMode)(int)p_property_values.get(SHARPENING_MODE_PROPERTY_NAME, SHARPENING_MODE_DISABLED)) {
129-
case SHARPENING_MODE_NORMAL: {
130-
settings->layerFlags |= XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB;
131-
} break;
132-
case SHARPENING_MODE_QUALITY: {
133-
settings->layerFlags |= XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB;
134-
} break;
135-
case SHARPENING_MODE_DISABLED: {
136-
// Do not enable any sharpening mode flags.
137-
} break;
138-
}
221+
settings->layerFlags |= _from_supersampling_mode((SupersamplingMode)(int)p_property_values.get(SUPERSAMPLING_MODE_PROPERTY_NAME, SUPERSAMPLING_MODE_DISABLED));
222+
settings->layerFlags |= _from_sharpening_mode((SharpeningMode)(int)p_property_values.get(SHARPENING_MODE_PROPERTY_NAME, SHARPENING_MODE_DISABLED));
139223

140224
if (settings->layerFlags == 0) {
141225
return reinterpret_cast<uint64_t>(p_next_pointer);

plugin/src/main/cpp/include/extensions/openxr_fb_composition_layer_settings_extension.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ class OpenXRFbCompositionLayerSettingsExtension : public OpenXRExtensionWrapper
6161
virtual void _on_viewport_composition_layer_destroyed(const void *p_layer) override;
6262
virtual TypedArray<Dictionary> _get_viewport_composition_layer_extension_properties() override;
6363
virtual Dictionary _get_viewport_composition_layer_extension_property_defaults() override;
64+
virtual uint64_t _set_projection_layer_and_get_next_pointer(void *p_next_pointer) override;
65+
66+
virtual void _on_session_created(uint64_t p_session) override;
67+
virtual void _on_session_destroyed() override;
68+
69+
bool is_enabled() const;
70+
71+
void set_projection_layer_auto_filter_enabled(bool p_enabled);
72+
bool is_projection_layer_auto_filter_enabled() const;
73+
74+
void set_projection_layer_supersampling_mode(SupersamplingMode p_supersampling_mode);
75+
SupersamplingMode get_projection_layer_supersampling_mode() const;
76+
77+
void set_projection_layer_sharpening_mode(SharpeningMode p_sharpening_mode);
78+
SharpeningMode get_projection_layer_sharpening_mode() const;
6479

6580
OpenXRFbCompositionLayerSettingsExtension();
6681
~OpenXRFbCompositionLayerSettingsExtension();
@@ -70,6 +85,8 @@ class OpenXRFbCompositionLayerSettingsExtension : public OpenXRExtensionWrapper
7085

7186
private:
7287
void cleanup();
88+
XrCompositionLayerSettingsFlagsFB _from_sharpening_mode(SharpeningMode p_sharpening_mode) const;
89+
XrCompositionLayerSettingsFlagsFB _from_supersampling_mode(SupersamplingMode p_supersampling_mode) const;
7390

7491
static OpenXRFbCompositionLayerSettingsExtension *singleton;
7592

@@ -79,6 +96,16 @@ class OpenXRFbCompositionLayerSettingsExtension : public OpenXRExtensionWrapper
7996
bool meta_automatic_layer_filter = false;
8097

8198
HashMap<const XrCompositionLayerBaseHeader *, XrCompositionLayerSettingsFB> layer_structs;
99+
100+
XrCompositionLayerSettingsFB projection_layer_settings = {
101+
XR_TYPE_COMPOSITION_LAYER_SETTINGS_FB, // type
102+
nullptr, // next
103+
0, // layerFlags
104+
};
105+
106+
bool projection_layer_auto_filter_enabled = false;
107+
SupersamplingMode projection_layer_supersampling_mode = SUPERSAMPLING_MODE_DISABLED;
108+
SharpeningMode projection_layer_sharpening_mode = SHARPENING_MODE_DISABLED;
82109
};
83110

84111
VARIANT_ENUM_CAST(OpenXRFbCompositionLayerSettingsExtension::SupersamplingMode);

plugin/src/main/cpp/register_types.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ void initialize_plugin_module(ModuleInitializationLevel p_level) {
406406
_register_extension_as_singleton(OpenXRFbCompositionLayerImageLayoutExtension::get_singleton());
407407
_register_extension_as_singleton(OpenXRFbCompositionLayerSecureContentExtension::get_singleton());
408408
_register_extension_as_singleton(OpenXRFbCompositionLayerAlphaBlendExtension::get_singleton());
409+
_register_extension_as_singleton(OpenXRFbCompositionLayerSettingsExtension::get_singleton());
409410

410411
// @todo GH Issue 304: Remove check for meta headers when feature becomes part of OpenXR spec.
411412
#ifdef META_HEADERS_ENABLED

0 commit comments

Comments
 (0)