@@ -85,114 +85,6 @@ impl NormalizedWindowRef {
85
85
}
86
86
}
87
87
88
- /// Presentation mode for a window.
89
- ///
90
- /// The presentation mode specifies when a frame is presented to the window. The `Fifo`
91
- /// option corresponds to a traditional `VSync`, where the framerate is capped by the
92
- /// display refresh rate. Both `Immediate` and `Mailbox` are low-latency and are not
93
- /// capped by the refresh rate, but may not be available on all platforms. Tearing
94
- /// may be observed with `Immediate` mode, but will not be observed with `Mailbox` or
95
- /// `Fifo`.
96
- ///
97
- /// `AutoVsync` or `AutoNoVsync` will gracefully fallback to `Fifo` when unavailable.
98
- ///
99
- /// `Immediate` or `Mailbox` will panic if not supported by the platform.
100
- #[ repr( C ) ]
101
- #[ derive( Default , Copy , Clone , Debug , PartialEq , Eq , Hash , Reflect , FromReflect ) ]
102
- #[ cfg_attr(
103
- feature = "serialize" ,
104
- derive( serde:: Serialize , serde:: Deserialize ) ,
105
- reflect( Serialize , Deserialize )
106
- ) ]
107
- #[ reflect( Debug , PartialEq , Hash ) ]
108
- #[ doc( alias = "vsync" ) ]
109
- pub enum PresentMode {
110
- /// Chooses FifoRelaxed -> Fifo based on availability.
111
- ///
112
- /// Because of the fallback behavior, it is supported everywhere.
113
- AutoVsync = 0 ,
114
- /// Chooses Immediate -> Mailbox -> Fifo (on web) based on availability.
115
- ///
116
- /// Because of the fallback behavior, it is supported everywhere.
117
- AutoNoVsync = 1 ,
118
- /// The presentation engine does **not** wait for a vertical blanking period and
119
- /// the request is presented immediately. This is a low-latency presentation mode,
120
- /// but visible tearing may be observed. Not optimal for mobile.
121
- ///
122
- /// Selecting this variant will panic if not supported, it is preferred to use
123
- /// [`PresentMode::AutoNoVsync`].
124
- Immediate = 2 ,
125
- /// The presentation engine waits for the next vertical blanking period to update
126
- /// the current image, but frames may be submitted without delay. This is a low-latency
127
- /// presentation mode and visible tearing will **not** be observed. Not optimal for mobile.
128
- ///
129
- /// Selecting this variant will panic if not supported, it is preferred to use
130
- /// [`PresentMode::AutoNoVsync`].
131
- Mailbox = 3 ,
132
- /// The presentation engine waits for the next vertical blanking period to update
133
- /// the current image. The framerate will be capped at the display refresh rate,
134
- /// corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile.
135
- #[ default]
136
- Fifo = 4 , // NOTE: The explicit ordinal values mirror wgpu.
137
- }
138
-
139
- /// Specifies how the alpha channel of the textures should be handled during compositing.
140
- #[ repr( C ) ]
141
- #[ derive( Default , Debug , Clone , Copy , PartialEq , Eq , Hash , Reflect , FromReflect ) ]
142
- #[ cfg_attr(
143
- feature = "serialize" ,
144
- derive( serde:: Serialize , serde:: Deserialize ) ,
145
- reflect( Serialize , Deserialize )
146
- ) ]
147
- #[ reflect( Debug , PartialEq , Hash ) ]
148
- pub enum CompositeAlphaMode {
149
- /// Chooses either `Opaque` or `Inherit` automatically, depending on the
150
- /// `alpha_mode` that the current surface can support.
151
- #[ default]
152
- Auto = 0 ,
153
- /// The alpha channel, if it exists, of the textures is ignored in the
154
- /// compositing process. Instead, the textures is treated as if it has a
155
- /// constant alpha of 1.0.
156
- Opaque = 1 ,
157
- /// The alpha channel, if it exists, of the textures is respected in the
158
- /// compositing process. The non-alpha channels of the textures are
159
- /// expected to already be multiplied by the alpha channel by the
160
- /// application.
161
- PreMultiplied = 2 ,
162
- /// The alpha channel, if it exists, of the textures is respected in the
163
- /// compositing process. The non-alpha channels of the textures are not
164
- /// expected to already be multiplied by the alpha channel by the
165
- /// application; instead, the compositor will multiply the non-alpha
166
- /// channels of the texture by the alpha channel during compositing.
167
- PostMultiplied = 3 ,
168
- /// The alpha channel, if it exists, of the textures is unknown for processing
169
- /// during compositing. Instead, the application is responsible for setting
170
- /// the composite alpha blending mode using native WSI command. If not set,
171
- /// then a platform-specific default will be used.
172
- Inherit = 4 ,
173
- }
174
-
175
- /// Defines the way a window is displayed
176
- #[ derive( Default , Debug , Clone , Copy , PartialEq , Eq , Reflect , FromReflect ) ]
177
- #[ cfg_attr(
178
- feature = "serialize" ,
179
- derive( serde:: Serialize , serde:: Deserialize ) ,
180
- reflect( Serialize , Deserialize )
181
- ) ]
182
- #[ reflect( Debug , PartialEq ) ]
183
- pub enum WindowMode {
184
- /// Creates a window that uses the given size.
185
- #[ default]
186
- Windowed ,
187
- /// Creates a borderless window that uses the full size of the screen.
188
- BorderlessFullscreen ,
189
- /// Creates a fullscreen window that will render at desktop resolution. The app will use the closest supported size
190
- /// from the given size and scale it to fit the screen.
191
- SizedFullscreen ,
192
- /// Creates a fullscreen window that uses the maximum supported size.
193
- Fullscreen ,
194
- }
195
-
196
88
/// Define how a window will be created and how it will behave.
197
89
#[ derive( Component , Debug , Clone , Reflect , FromReflect ) ]
198
90
#[ cfg_attr(
@@ -533,32 +425,6 @@ impl Default for WindowResolution {
533
425
}
534
426
}
535
427
536
- /// Defines if and how the cursor is grabbed.
537
- ///
538
- /// ## Platform-specific
539
- ///
540
- /// - **`Windows`** doesn't support [`CursorGrabMode::Locked`]
541
- /// - **`macOS`** doesn't support [`CursorGrabMode::Confined`]
542
- /// - **`iOS/Android`** don't have cursors.
543
- ///
544
- /// Since `Windows` and `macOS` have different [`CursorGrabMode`] support, we first try to set the grab mode that was asked for. If it doesn't work then use the alternate grab mode.
545
- #[ derive( Default , Debug , Clone , Copy , PartialEq , Eq , Reflect , FromReflect ) ]
546
- #[ cfg_attr(
547
- feature = "serialize" ,
548
- derive( serde:: Serialize , serde:: Deserialize ) ,
549
- reflect( Serialize , Deserialize )
550
- ) ]
551
- #[ reflect( Debug , PartialEq , Default ) ]
552
- pub enum CursorGrabMode {
553
- /// The cursor can freely leave the window.
554
- #[ default]
555
- None ,
556
- /// The cursor is confined to the window area.
557
- Confined ,
558
- /// The cursor is locked inside the window area to a certain position.
559
- Locked ,
560
- }
561
-
562
428
impl WindowResolution {
563
429
/// Creates a new [`WindowResolution`].
564
430
pub fn new ( logical_width : f32 , logical_height : f32 ) -> Self {
@@ -689,6 +555,32 @@ impl From<bevy_math::DVec2> for WindowResolution {
689
555
}
690
556
}
691
557
558
+ /// Defines if and how the cursor is grabbed.
559
+ ///
560
+ /// ## Platform-specific
561
+ ///
562
+ /// - **`Windows`** doesn't support [`CursorGrabMode::Locked`]
563
+ /// - **`macOS`** doesn't support [`CursorGrabMode::Confined`]
564
+ /// - **`iOS/Android`** don't have cursors.
565
+ ///
566
+ /// Since `Windows` and `macOS` have different [`CursorGrabMode`] support, we first try to set the grab mode that was asked for. If it doesn't work then use the alternate grab mode.
567
+ #[ derive( Default , Debug , Clone , Copy , PartialEq , Eq , Reflect , FromReflect ) ]
568
+ #[ cfg_attr(
569
+ feature = "serialize" ,
570
+ derive( serde:: Serialize , serde:: Deserialize ) ,
571
+ reflect( Serialize , Deserialize )
572
+ ) ]
573
+ #[ reflect( Debug , PartialEq , Default ) ]
574
+ pub enum CursorGrabMode {
575
+ /// The cursor can freely leave the window.
576
+ #[ default]
577
+ None ,
578
+ /// The cursor is confined to the window area.
579
+ Confined ,
580
+ /// The cursor is locked inside the window area to a certain position.
581
+ Locked ,
582
+ }
583
+
692
584
/// Stores internal state that isn't directly accessible.
693
585
#[ derive( Default , Debug , Copy , Clone , PartialEq , Eq , Reflect , FromReflect ) ]
694
586
#[ cfg_attr(
@@ -734,3 +626,111 @@ pub enum MonitorSelection {
734
626
/// Uses monitor with the specified index.
735
627
Index ( usize ) ,
736
628
}
629
+
630
+ /// Presentation mode for a window.
631
+ ///
632
+ /// The presentation mode specifies when a frame is presented to the window. The `Fifo`
633
+ /// option corresponds to a traditional `VSync`, where the framerate is capped by the
634
+ /// display refresh rate. Both `Immediate` and `Mailbox` are low-latency and are not
635
+ /// capped by the refresh rate, but may not be available on all platforms. Tearing
636
+ /// may be observed with `Immediate` mode, but will not be observed with `Mailbox` or
637
+ /// `Fifo`.
638
+ ///
639
+ /// `AutoVsync` or `AutoNoVsync` will gracefully fallback to `Fifo` when unavailable.
640
+ ///
641
+ /// `Immediate` or `Mailbox` will panic if not supported by the platform.
642
+ #[ repr( C ) ]
643
+ #[ derive( Default , Copy , Clone , Debug , PartialEq , Eq , Hash , Reflect , FromReflect ) ]
644
+ #[ cfg_attr(
645
+ feature = "serialize" ,
646
+ derive( serde:: Serialize , serde:: Deserialize ) ,
647
+ reflect( Serialize , Deserialize )
648
+ ) ]
649
+ #[ reflect( Debug , PartialEq , Hash ) ]
650
+ #[ doc( alias = "vsync" ) ]
651
+ pub enum PresentMode {
652
+ /// Chooses FifoRelaxed -> Fifo based on availability.
653
+ ///
654
+ /// Because of the fallback behavior, it is supported everywhere.
655
+ AutoVsync = 0 ,
656
+ /// Chooses Immediate -> Mailbox -> Fifo (on web) based on availability.
657
+ ///
658
+ /// Because of the fallback behavior, it is supported everywhere.
659
+ AutoNoVsync = 1 ,
660
+ /// The presentation engine does **not** wait for a vertical blanking period and
661
+ /// the request is presented immediately. This is a low-latency presentation mode,
662
+ /// but visible tearing may be observed. Not optimal for mobile.
663
+ ///
664
+ /// Selecting this variant will panic if not supported, it is preferred to use
665
+ /// [`PresentMode::AutoNoVsync`].
666
+ Immediate = 2 ,
667
+ /// The presentation engine waits for the next vertical blanking period to update
668
+ /// the current image, but frames may be submitted without delay. This is a low-latency
669
+ /// presentation mode and visible tearing will **not** be observed. Not optimal for mobile.
670
+ ///
671
+ /// Selecting this variant will panic if not supported, it is preferred to use
672
+ /// [`PresentMode::AutoNoVsync`].
673
+ Mailbox = 3 ,
674
+ /// The presentation engine waits for the next vertical blanking period to update
675
+ /// the current image. The framerate will be capped at the display refresh rate,
676
+ /// corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile.
677
+ #[ default]
678
+ Fifo = 4 , // NOTE: The explicit ordinal values mirror wgpu.
679
+ }
680
+
681
+ /// Specifies how the alpha channel of the textures should be handled during compositing.
682
+ #[ repr( C ) ]
683
+ #[ derive( Default , Debug , Clone , Copy , PartialEq , Eq , Hash , Reflect , FromReflect ) ]
684
+ #[ cfg_attr(
685
+ feature = "serialize" ,
686
+ derive( serde:: Serialize , serde:: Deserialize ) ,
687
+ reflect( Serialize , Deserialize )
688
+ ) ]
689
+ #[ reflect( Debug , PartialEq , Hash ) ]
690
+ pub enum CompositeAlphaMode {
691
+ /// Chooses either `Opaque` or `Inherit` automatically, depending on the
692
+ /// `alpha_mode` that the current surface can support.
693
+ #[ default]
694
+ Auto = 0 ,
695
+ /// The alpha channel, if it exists, of the textures is ignored in the
696
+ /// compositing process. Instead, the textures is treated as if it has a
697
+ /// constant alpha of 1.0.
698
+ Opaque = 1 ,
699
+ /// The alpha channel, if it exists, of the textures is respected in the
700
+ /// compositing process. The non-alpha channels of the textures are
701
+ /// expected to already be multiplied by the alpha channel by the
702
+ /// application.
703
+ PreMultiplied = 2 ,
704
+ /// The alpha channel, if it exists, of the textures is respected in the
705
+ /// compositing process. The non-alpha channels of the textures are not
706
+ /// expected to already be multiplied by the alpha channel by the
707
+ /// application; instead, the compositor will multiply the non-alpha
708
+ /// channels of the texture by the alpha channel during compositing.
709
+ PostMultiplied = 3 ,
710
+ /// The alpha channel, if it exists, of the textures is unknown for processing
711
+ /// during compositing. Instead, the application is responsible for setting
712
+ /// the composite alpha blending mode using native WSI command. If not set,
713
+ /// then a platform-specific default will be used.
714
+ Inherit = 4 ,
715
+ }
716
+
717
+ /// Defines the way a window is displayed
718
+ #[ derive( Default , Debug , Clone , Copy , PartialEq , Eq , Reflect , FromReflect ) ]
719
+ #[ cfg_attr(
720
+ feature = "serialize" ,
721
+ derive( serde:: Serialize , serde:: Deserialize ) ,
722
+ reflect( Serialize , Deserialize )
723
+ ) ]
724
+ #[ reflect( Debug , PartialEq ) ]
725
+ pub enum WindowMode {
726
+ /// Creates a window that uses the given size.
727
+ #[ default]
728
+ Windowed ,
729
+ /// Creates a borderless window that uses the full size of the screen.
730
+ BorderlessFullscreen ,
731
+ /// Creates a fullscreen window that will render at desktop resolution. The app will use the closest supported size
732
+ /// from the given size and scale it to fit the screen.
733
+ SizedFullscreen ,
734
+ /// Creates a fullscreen window that uses the maximum supported size.
735
+ Fullscreen ,
736
+ }
0 commit comments