@@ -4,6 +4,7 @@ extern crate sdl2;
4
4
extern crate wgpu;
5
5
6
6
use std:: borrow:: Cow ;
7
+ use wgpu:: { SurfaceError , SurfaceTexture } ;
7
8
8
9
use sdl2:: event:: { Event , WindowEvent } ;
9
10
use sdl2:: keyboard:: Keycode ;
@@ -26,6 +27,7 @@ fn main() -> Result<(), String> {
26
27
let surface = unsafe { instance. create_surface ( & window) } ;
27
28
let adapter_opt = pollster:: block_on ( instance. request_adapter ( & wgpu:: RequestAdapterOptions {
28
29
power_preference : wgpu:: PowerPreference :: HighPerformance ,
30
+ force_fallback_adapter : false ,
29
31
compatible_surface : Some ( & surface) ,
30
32
} ) ) ;
31
33
let adapter = match adapter_opt {
@@ -81,37 +83,23 @@ fn main() -> Result<(), String> {
81
83
module : & shader,
82
84
entry_point : "fs_main" ,
83
85
} ) ,
84
- //rasterization_state: Some(wgpu::RasterizationStateDescriptor {
85
- // depth_bias: 0,
86
- // depth_bias_slope_scale: 0.0,
87
- // depth_bias_clamp: 0.0,
88
- //}),
89
86
primitive : wgpu:: PrimitiveState {
90
87
topology : wgpu:: PrimitiveTopology :: TriangleList ,
91
88
strip_index_format : None ,
92
89
front_face : wgpu:: FrontFace :: Ccw ,
93
90
cull_mode : Some ( wgpu:: Face :: Front ) ,
94
- clamp_depth : false ,
91
+ unclipped_depth : false ,
95
92
polygon_mode : wgpu:: PolygonMode :: Fill ,
96
93
conservative : false ,
97
94
} ,
98
- //color_states: &[wgpu::ColorStateDescriptor {
99
- // format: wgpu::TextureFormat::Bgra8UnormSrgb,
100
- // color_blend: wgpu::BlendDescriptor::REPLACE,
101
- // alpha_blend: wgpu::BlendDescriptor::REPLACE,
102
- // write_mask: wgpu::ColorWrite::ALL,
103
- //}],
104
- //vertex_state: wgpu::VertexStateDescriptor {
105
- // index_format: wgpu::IndexFormat::Uint16,
106
- // vertex_buffers: &[],
107
- //},
108
95
depth_stencil : None ,
109
96
label : None ,
110
97
multisample : wgpu:: MultisampleState {
111
98
count : 1 ,
112
99
mask : !0 ,
113
100
alpha_to_coverage_enabled : false ,
114
101
} ,
102
+ multiview : None
115
103
} ) ;
116
104
117
105
let mut config = wgpu:: SurfaceConfiguration {
@@ -149,13 +137,20 @@ fn main() -> Result<(), String> {
149
137
}
150
138
}
151
139
152
- let frame_res = surface. get_current_frame ( ) ;
153
- let frame = match frame_res {
154
- Ok ( a) => a,
155
- Err ( e) => return Err ( format ! ( "Timeout getting next texture: {}" , e) ) ,
156
- } ;
140
+ let mut frame = match surface. get_current_texture ( ) {
141
+ Ok ( frame) => { frame} ,
142
+ Err ( err) => {
143
+ let reason = match ( err) {
144
+ SurfaceError :: Timeout => { "Timeout" }
145
+ SurfaceError :: Outdated => { "Outdated" }
146
+ SurfaceError :: Lost => { "Lost" }
147
+ SurfaceError :: OutOfMemory => { "OutOfMemory" }
148
+ } ;
149
+ panic ! ( "Failed to get current surface texture! Reason: {}" , reason)
150
+ }
151
+ } ;
152
+
157
153
let output = frame
158
- . output
159
154
. texture
160
155
. create_view ( & wgpu:: TextureViewDescriptor :: default ( ) ) ;
161
156
let mut encoder = device. create_command_encoder ( & wgpu:: CommandEncoderDescriptor {
@@ -179,8 +174,8 @@ fn main() -> Result<(), String> {
179
174
rpass. set_bind_group ( 0 , & bind_group, & [ ] ) ;
180
175
rpass. draw ( 0 ..3 , 0 ..1 ) ;
181
176
}
182
-
183
177
queue. submit ( [ encoder. finish ( ) ] ) ;
178
+ frame. present ( ) ;
184
179
}
185
180
186
181
Ok ( ( ) )
0 commit comments