Skip to content

Commit

Permalink
Revamp done.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Jul 30, 2019
1 parent 0692470 commit 50b4648
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 63 deletions.
17 changes: 8 additions & 9 deletions src/drawing/drawable_tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
87 changes: 33 additions & 54 deletions src/drawing/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down

0 comments on commit 50b4648

Please sign in to comment.