@@ -7,7 +7,7 @@ use crate::blocks::block_type::BlockType;
7
7
use crate :: collision:: CollisionBox ;
8
8
use crate :: perf;
9
9
use crate :: persistence:: Saveable ;
10
- use crate :: pipeline:: { Pipeline , PipelineTrait } ;
10
+ use crate :: pipeline:: { MainPipeline , PipelineTrait } ;
11
11
use crate :: utils:: { ChunkFromPosition , RelativeFromAbsolute } ;
12
12
use crate :: water:: WaterPipeline ;
13
13
use crate :: {
@@ -105,6 +105,7 @@ impl State {
105
105
surface_config,
106
106
instance,
107
107
window : window. clone ( ) ,
108
+ main_pipeline : None ,
108
109
device,
109
110
world,
110
111
queue,
@@ -113,11 +114,10 @@ impl State {
113
114
camera_controller : CameraController :: default ( ) ,
114
115
} ;
115
116
116
- let world_pipeline = Box :: new ( Pipeline :: new ( & state) ) ;
117
+ state . main_pipeline = Some ( MainPipeline :: new ( & state) ) ;
117
118
let water_pipeline = Box :: new ( WaterPipeline :: new ( & state) ) ;
118
119
let ui_pipeline = Box :: new ( UIPipeline :: new ( & state) ) ;
119
120
120
- state. pipelines . push ( world_pipeline) ;
121
121
state. pipelines . push ( water_pipeline) ;
122
122
state. pipelines . push ( ui_pipeline) ;
123
123
@@ -243,7 +243,10 @@ impl State {
243
243
self . surface_config . height = new_size. height . max ( 1 ) ;
244
244
self . surface . configure ( & self . device , & self . surface_config ) ;
245
245
let new_depth = Texture :: create_depth_texture ( & self ) ;
246
- self . pipelines [ 0 ] . set_depth_texture ( new_depth) ;
246
+ self . main_pipeline
247
+ . as_mut ( )
248
+ . unwrap ( )
249
+ . set_depth_texture ( new_depth) ;
247
250
}
248
251
}
249
252
pub fn update ( & mut self , delta_time : f32 , total_time : f32 ) {
@@ -268,13 +271,11 @@ impl State {
268
271
269
272
let uniforms = Uniforms :: from ( & player. camera ) ;
270
273
271
- for pipeline in self . pipelines . iter ( ) {
272
- self . queue . write_buffer (
273
- pipeline. view_buffer ( ) ,
274
- 0 ,
275
- bytemuck:: cast_slice ( & [ uniforms. view ] ) ,
276
- )
277
- }
274
+ self . queue . write_buffer (
275
+ self . main_pipeline . as_ref ( ) . unwrap ( ) . view_buffer ( ) ,
276
+ 0 ,
277
+ bytemuck:: cast_slice ( & [ uniforms. view ] ) ,
278
+ ) ;
278
279
// Drop write lock
279
280
std:: mem:: drop ( player) ;
280
281
@@ -328,7 +329,7 @@ impl State {
328
329
} ,
329
330
} ) ] ,
330
331
depth_stencil_attachment : Some ( wgpu:: RenderPassDepthStencilAttachment {
331
- view : & self . pipelines [ 0 ] . depth_texture ( ) . view ,
332
+ view : & self . main_pipeline . as_ref ( ) . unwrap ( ) . depth_texture ( ) . view ,
332
333
depth_ops : Some ( wgpu:: Operations {
333
334
load : wgpu:: LoadOp :: Clear ( 1.0 ) ,
334
335
store : wgpu:: StoreOp :: Store ,
@@ -338,7 +339,7 @@ impl State {
338
339
timestamp_writes : None ,
339
340
occlusion_query_set : None ,
340
341
} ) ;
341
- let pipeline = & self . pipelines [ 0 ] ;
342
+ let pipeline = & self . main_pipeline . as_ref ( ) . unwrap ( ) ;
342
343
343
344
main_rpass. set_pipeline ( pipeline. pipeline ( ) ) ;
344
345
@@ -382,7 +383,7 @@ impl State {
382
383
} ,
383
384
} ) ] ,
384
385
depth_stencil_attachment : Some ( wgpu:: RenderPassDepthStencilAttachment {
385
- view : & self . pipelines [ 0 ] . depth_texture ( ) . view ,
386
+ view : & self . main_pipeline . as_ref ( ) . unwrap ( ) . depth_texture . view ,
386
387
depth_ops : Some ( wgpu:: Operations {
387
388
load : wgpu:: LoadOp :: Load ,
388
389
store : wgpu:: StoreOp :: Discard ,
@@ -392,12 +393,12 @@ impl State {
392
393
timestamp_writes : None ,
393
394
occlusion_query_set : None ,
394
395
} ) ;
395
- let pipeline = & self . pipelines [ 1 ] ;
396
+ let pipeline = & self . pipelines [ 0 ] ;
396
397
397
398
water_rpass. set_pipeline ( pipeline. pipeline ( ) ) ;
398
399
399
- water_rpass. set_bind_group ( 0 , pipeline . bind_group_0 ( ) , & [ ] ) ;
400
- water_rpass. set_bind_group ( 1 , pipeline . bind_group_1 ( ) , & [ ] ) ;
400
+ water_rpass. set_bind_group ( 0 , self . main_pipeline . as_ref ( ) . unwrap ( ) . bind_group_0 ( ) , & [ ] ) ;
401
+ water_rpass. set_bind_group ( 1 , self . main_pipeline . as_ref ( ) . unwrap ( ) . bind_group_1 ( ) , & [ ] ) ;
401
402
water_rpass. set_bind_group ( 3 , & player. camera . position_bind_group , & [ ] ) ;
402
403
403
404
for chunk in chunks. iter ( ) {
@@ -435,7 +436,7 @@ impl State {
435
436
} ,
436
437
} ) ] ,
437
438
depth_stencil_attachment : Some ( wgpu:: RenderPassDepthStencilAttachment {
438
- view : & self . pipelines [ 0 ] . depth_texture ( ) . view ,
439
+ view : & self . main_pipeline . as_ref ( ) . unwrap ( ) . depth_texture . view ,
439
440
depth_ops : Some ( wgpu:: Operations {
440
441
load : wgpu:: LoadOp :: Clear ( 1.0 ) ,
441
442
store : wgpu:: StoreOp :: Store ,
@@ -446,11 +447,19 @@ impl State {
446
447
occlusion_query_set : None ,
447
448
} ) ;
448
449
449
- let pipeline = & self . pipelines [ 2 ] ;
450
+ let pipeline = & self . pipelines [ 1 ] ;
450
451
ui_renderpass. set_pipeline ( pipeline. pipeline ( ) ) ;
451
452
452
- ui_renderpass. set_bind_group ( 0 , pipeline. bind_group_0 ( ) , & [ ] ) ;
453
- ui_renderpass. set_bind_group ( 1 , pipeline. bind_group_1 ( ) , & [ ] ) ;
453
+ ui_renderpass. set_bind_group (
454
+ 0 ,
455
+ self . main_pipeline . as_ref ( ) . unwrap ( ) . bind_group_0 ( ) ,
456
+ & [ ] ,
457
+ ) ;
458
+ ui_renderpass. set_bind_group (
459
+ 1 ,
460
+ self . main_pipeline . as_ref ( ) . unwrap ( ) . bind_group_1 ( ) ,
461
+ & [ ] ,
462
+ ) ;
454
463
455
464
ui_renderpass. set_vertex_buffer ( 0 , self . ui . vertex_buffer . slice ( ..) ) ;
456
465
ui_renderpass
@@ -475,6 +484,7 @@ pub struct State {
475
484
pub queue : Arc < wgpu:: Queue > ,
476
485
pub window : Arc < Mutex < Window > > ,
477
486
pub surface_config : wgpu:: SurfaceConfiguration ,
487
+ pub main_pipeline : Option < MainPipeline > ,
478
488
pub pipelines : Vec < Box < dyn PipelineTrait > > ,
479
489
pub player : Arc < RwLock < Player > > ,
480
490
pub world : World ,
0 commit comments