1- use std:: {
2- f32:: consts:: PI ,
3- fs:: File ,
4- sync:: { Arc , LazyLock } ,
5- } ;
1+ use std:: { f32:: consts:: PI , fs:: File , sync:: Arc } ;
62
73use glam:: { Quat , Vec3A } ;
84use openxr as xr;
@@ -31,6 +27,7 @@ pub(super) struct Skybox {
3127 view : Arc < ImageView > ,
3228 sky : Option < WlxSwapchain > ,
3329 grid : Option < WlxSwapchain > ,
30+ grid_pose : xr:: Posef ,
3431 grid_color_scale_bias_khr : Option < Box < xr:: sys:: CompositionLayerColorScaleBiasKHR > > ,
3532}
3633
@@ -100,6 +97,7 @@ impl Skybox {
10097 view,
10198 sky : None ,
10299 grid : None ,
100+ grid_pose : translation_rotation_to_posef ( Vec3A :: ZERO , Quat :: from_rotation_x ( PI * -0.5 ) ) ,
103101 grid_color_scale_bias_khr : grid_color_scale_bias_khr,
104102 } )
105103 }
@@ -228,10 +226,6 @@ impl Skybox {
228226 const HI_VERT_ANGLE : f32 = 0.5 * PI ;
229227 const LO_VERT_ANGLE : f32 = -0.5 * PI ;
230228
231- static GRID_POSE : LazyLock < xr:: Posef > = LazyLock :: new ( || {
232- translation_rotation_to_posef ( Vec3A :: ZERO , Quat :: from_rotation_x ( PI * -0.5 ) )
233- } ) ;
234-
235229 let pose = xr:: Posef {
236230 orientation : xr:: Quaternionf :: IDENTITY ,
237231 position : xr:: Vector3f {
@@ -255,11 +249,12 @@ impl Skybox {
255249 . lower_vertical_angle ( LO_VERT_ANGLE ) ;
256250
257251 self . grid . as_mut ( ) . unwrap ( ) . ensure_image_released ( ) ?;
252+
258253 let flags = xr:: CompositionLayerFlags :: BLEND_TEXTURE_SOURCE_ALPHA
259254 | xr:: CompositionLayerFlags :: UNPREMULTIPLIED_ALPHA ;
260255 let mut grid = xr:: CompositionLayerQuad :: new ( )
261256 . layer_flags ( flags)
262- . pose ( * GRID_POSE )
257+ . pose ( self . grid_pose )
263258 . size ( xr:: Extent2Df {
264259 width : 10.0 ,
265260 height : 10.0 ,
@@ -270,7 +265,7 @@ impl Skybox {
270265
271266 if let Some ( grid_color_scale_bias_khr) = self . grid_color_scale_bias_khr . as_mut ( ) {
272267 let grid_opacity = app. session . config . grid_opacity ;
273- grid_color_scale_bias_khr. color_scale . a = grid_opacity * grid_opacity;
268+ grid_color_scale_bias_khr. color_scale . a = ( grid_opacity * grid_opacity) . clamp ( 0.0 , 1.0 ) ;
274269 unsafe {
275270 let raw = next_chain_insert ! ( grid, grid_color_scale_bias_khr) ;
276271 grid = xr:: CompositionLayerQuad :: from_raw ( raw) ;
0 commit comments