From 50b46487c06b2c370376565848664a13a3027c1e Mon Sep 17 00:00:00 2001 From: Noah Huesser Date: Tue, 30 Jul 2019 02:08:22 +0200 Subject: [PATCH] Revamp done. --- src/drawing/drawable_tile.rs | 17 ++++--- src/drawing/painter.rs | 87 ++++++++++++++---------------------- 2 files changed, 41 insertions(+), 63 deletions(-) diff --git a/src/drawing/drawable_tile.rs b/src/drawing/drawable_tile.rs index c66adfe..5edb874 100644 --- a/src/drawing/drawable_tile.rs +++ b/src/drawing/drawable_tile.rs @@ -51,20 +51,19 @@ impl DrawableTile { render_pass: &mut RenderPass, layer_collection: &LayerCollection, tile_id: u32, - feature_id: u32, outline: bool ) { render_pass.set_index_buffer(&self.index_buffer, 0); render_pass.set_vertex_buffers(&[(&self.vertex_buffer, 0)]); for (id, range) in &self.features { - if feature_id == *id && range.len() > 0 && layer_collection.is_visible(*id) { - if outline { - if layer_collection.has_outline(*id) { - let range_start = tile_id << 1; - render_pass.draw_indexed(range.clone(), 0, 0 + range_start .. 1 + range_start); - } - } else { - let range_start = (tile_id << 1) | 1; + if range.len() > 0 && layer_collection.is_visible(*id) { + render_pass.set_stencil_reference(*id as u32); + + let range_start = (tile_id << 1) | 1; + render_pass.draw_indexed(range.clone(), 0, 0 + range_start .. 1 + range_start); + + if layer_collection.has_outline(*id) { + let range_start = tile_id << 1; render_pass.draw_indexed(range.clone(), 0, 0 + range_start .. 1 + range_start); } } diff --git a/src/drawing/painter.rs b/src/drawing/painter.rs index 688affa..2075e75 100644 --- a/src/drawing/painter.rs +++ b/src/drawing/painter.rs @@ -751,62 +751,41 @@ impl Painter { }); render_pass.set_pipeline(&self.blend_pipeline); render_pass.set_bind_group(0, &self.bind_group, &[]); - let tile_size = app_state.screen.get_tile_size() as f32; let vec = vec4(0.0, 0.0, 0.0, 1.0); let screen_dimensions = vec2(app_state.screen.width as f32, app_state.screen.height as f32) / 2.0; - for feature in layer_collection.iter_features() { - render_pass.set_stencil_reference(feature.id as u32); - // println!("start ================================"); - for (i, dt) in self.loaded_tiles.values_mut().enumerate() { - let matrix = app_state.screen.tile_to_global_space( - app_state.zoom, - &dt.tile_id - ); - let start = (matrix * &vec).xy() + &vec2(1.0, 1.0); - // dbg!(start); - let s = vec2({ - let x = (start.x * screen_dimensions.x).round(); - if x < 0.0 { 0.0 } else { x } - }, { - let y = (start.y * screen_dimensions.y).round(); - if y < 0.0 { 0.0 } else { y } - }); - // dbg!(s); - let matrix = app_state.screen.tile_to_global_space( - app_state.zoom, - &(dt.tile_id + TileId::new(dt.tile_id.z, 1, 1)) - ); - let end = (matrix * &vec).xy() + &vec2(1.0, 1.0); - // dbg!(end); - let e = vec2({ - let x = (end.x * screen_dimensions.x).round(); - if x < 0.0 { 0.0 } else { x } - }, { - let y = (end.y * screen_dimensions.y).round(); - if y < 0.0 { 0.0 } else { y } - }); - // dbg!(e); - - // dbg!(( - // (s.x), - // (s.y), - // ((e.x - s.x)), - // ((e.y - s.y)) - // )); - - render_pass.set_scissor_rect( - s.x as u32, - s.y as u32, - (e.x - s.x) as u32, - (e.y - s.y) as u32 - ); - dt.paint(&mut render_pass, &layer_collection, i as u32, feature.id, false); - } - - // for (i, dt) in self.loaded_tiles.values_mut().enumerate() { - // dt.paint(&mut render_pass, &layer_collection, i as u32, feature.id, true); - // } - first = false; + for (i, dt) in self.loaded_tiles.values_mut().enumerate() { + let matrix = app_state.screen.tile_to_global_space( + app_state.zoom, + &dt.tile_id + ); + let start = (matrix * &vec).xy() + &vec2(1.0, 1.0); + let s = vec2({ + let x = (start.x * screen_dimensions.x).round(); + if x < 0.0 { 0.0 } else { x } + }, { + let y = (start.y * screen_dimensions.y).round(); + if y < 0.0 { 0.0 } else { y } + }); + let matrix = app_state.screen.tile_to_global_space( + app_state.zoom, + &(dt.tile_id + TileId::new(dt.tile_id.z, 1, 1)) + ); + let end = (matrix * &vec).xy() + &vec2(1.0, 1.0); + let e = vec2({ + let x = (end.x * screen_dimensions.x).round(); + if x < 0.0 { 0.0 } else { x } + }, { + let y = (end.y * screen_dimensions.y).round(); + if y < 0.0 { 0.0 } else { y } + }); + + render_pass.set_scissor_rect( + s.x as u32, + s.y as u32, + (e.x - s.x) as u32, + (e.y - s.y) as u32 + ); + dt.paint(&mut render_pass, &layer_collection, i as u32, false); } } self.device.get_queue().submit(&[encoder.finish()]);