@@ -6,20 +6,30 @@ use wgpu::rwh::{
66use super :: {
77 gpu:: Gpu ,
88 instance:: Instance ,
9+ texture:: {
10+ TextureFormat ,
11+ TextureUsages ,
12+ } ,
913} ;
1014use crate :: winit:: WindowHandle ;
1115
1216/// Present modes supported by the surface.
13- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
1417///
1518/// This wrapper hides the underlying `wgpu` type from higher layers while
1619/// preserving the same semantics.
20+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
1721pub enum PresentMode {
22+ /// Vsync enabled; frames wait for vertical blanking interval.
1823 Fifo ,
24+ /// Vsync with relaxed timing; may tear if frames miss the interval.
1925 FifoRelaxed ,
26+ /// No Vsync; immediate presentation (may tear).
2027 Immediate ,
28+ /// Triple-buffered presentation when supported.
2129 Mailbox ,
30+ /// Automatic Vsync selection by the platform.
2231 AutoVsync ,
32+ /// Automatic non-Vsync selection by the platform.
2333 AutoNoVsync ,
2434}
2535
@@ -48,98 +58,30 @@ impl PresentMode {
4858 }
4959}
5060
51- /// Wrapper for texture usage flags used by surfaces.
52- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
53- pub struct TextureUsages ( wgpu:: TextureUsages ) ;
54-
55- impl TextureUsages {
56- /// Render attachment usage.
57- pub const RENDER_ATTACHMENT : TextureUsages =
58- TextureUsages ( wgpu:: TextureUsages :: RENDER_ATTACHMENT ) ;
59- /// Texture binding usage.
60- pub const TEXTURE_BINDING : TextureUsages =
61- TextureUsages ( wgpu:: TextureUsages :: TEXTURE_BINDING ) ;
62- /// Copy destination usage.
63- pub const COPY_DST : TextureUsages =
64- TextureUsages ( wgpu:: TextureUsages :: COPY_DST ) ;
65- /// Copy source usage.
66- pub const COPY_SRC : TextureUsages =
67- TextureUsages ( wgpu:: TextureUsages :: COPY_SRC ) ;
68-
69- pub ( crate ) fn to_wgpu ( self ) -> wgpu:: TextureUsages {
70- return self . 0 ;
71- }
72-
73- pub ( crate ) fn from_wgpu ( flags : wgpu:: TextureUsages ) -> Self {
74- return TextureUsages ( flags) ;
75- }
76-
77- /// Check whether this flags set contains another set.
78- pub fn contains ( self , other : TextureUsages ) -> bool {
79- return self . 0 . contains ( other. 0 ) ;
80- }
81- }
82-
83- impl std:: ops:: BitOr for TextureUsages {
84- type Output = TextureUsages ;
85-
86- fn bitor ( self , rhs : TextureUsages ) -> TextureUsages {
87- return TextureUsages ( self . 0 | rhs. 0 ) ;
88- }
89- }
90-
91- /// Wrapper around a surface color format.
92- #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
93- pub struct SurfaceFormat ( wgpu:: TextureFormat ) ;
94-
95- impl SurfaceFormat {
96- /// Common sRGB swapchain format used for windowed rendering.
97- pub const BGRA8_UNORM_SRGB : SurfaceFormat =
98- SurfaceFormat ( wgpu:: TextureFormat :: Bgra8UnormSrgb ) ;
99-
100- pub ( crate ) fn to_wgpu ( self ) -> wgpu:: TextureFormat {
101- return self . 0 ;
102- }
103-
104- pub ( crate ) fn from_wgpu ( fmt : wgpu:: TextureFormat ) -> Self {
105- return SurfaceFormat ( fmt) ;
106- }
107-
108- /// Whether this format is sRGB.
109- pub fn is_srgb ( self ) -> bool {
110- return self . 0 . is_srgb ( ) ;
111- }
112-
113- /// Return the sRGB variant of the format when applicable.
114- pub fn add_srgb_suffix ( self ) -> Self {
115- return SurfaceFormat ( self . 0 . add_srgb_suffix ( ) ) ;
116- }
117- }
118-
11961/// Public, engine-facing surface configuration that avoids exposing `wgpu`.
12062#[ derive( Clone , Debug ) ]
12163pub struct SurfaceConfig {
12264 pub width : u32 ,
12365 pub height : u32 ,
124- pub format : SurfaceFormat ,
66+ pub format : TextureFormat ,
12567 pub present_mode : PresentMode ,
12668 pub usage : TextureUsages ,
127- pub view_formats : Vec < SurfaceFormat > ,
69+ pub view_formats : Vec < TextureFormat > ,
12870}
12971
13072impl SurfaceConfig {
13173 pub ( crate ) fn from_wgpu ( config : & wgpu:: SurfaceConfiguration ) -> Self {
13274 return SurfaceConfig {
13375 width : config. width ,
13476 height : config. height ,
135- format : SurfaceFormat :: from_wgpu ( config. format ) ,
77+ format : TextureFormat :: from_wgpu ( config. format ) ,
13678 present_mode : PresentMode :: from_wgpu ( config. present_mode ) ,
13779 usage : TextureUsages :: from_wgpu ( config. usage ) ,
13880 view_formats : config
13981 . view_formats
14082 . iter ( )
14183 . copied ( )
142- . map ( SurfaceFormat :: from_wgpu)
84+ . map ( TextureFormat :: from_wgpu)
14385 . collect ( ) ,
14486 } ;
14587 }
@@ -267,7 +209,7 @@ pub struct Surface<'window> {
267209 label : String ,
268210 surface : wgpu:: Surface < ' window > ,
269211 configuration : Option < SurfaceConfig > ,
270- format : Option < SurfaceFormat > ,
212+ format : Option < TextureFormat > ,
271213}
272214
273215impl < ' window > Surface < ' window > {
@@ -287,19 +229,19 @@ impl<'window> Surface<'window> {
287229 }
288230
289231 /// Preferred surface format if known (set during configuration).
290- pub fn format ( & self ) -> Option < SurfaceFormat > {
232+ pub fn format ( & self ) -> Option < TextureFormat > {
291233 return self . format ;
292234 }
293235
294236 /// Configure the surface and cache the result for queries such as `format()`.
295- pub ( crate ) fn configure_raw (
237+ fn configure_raw (
296238 & mut self ,
297239 device : & wgpu:: Device ,
298240 config : & wgpu:: SurfaceConfiguration ,
299241 ) {
300242 self . surface . configure ( device, config) ;
301243 self . configuration = Some ( SurfaceConfig :: from_wgpu ( config) ) ;
302- self . format = Some ( SurfaceFormat :: from_wgpu ( config. format ) ) ;
244+ self . format = Some ( TextureFormat :: from_wgpu ( config. format ) ) ;
303245 }
304246
305247 /// Configure the surface using common engine defaults:
0 commit comments