@@ -63,6 +63,21 @@ OpenXRFbCompositionLayerSettingsExtension::~OpenXRFbCompositionLayerSettingsExte
6363}
6464
6565void 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+
75137void 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+
80164Dictionary 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+
89194uint64_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);
0 commit comments