mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Simplify and move Stencil reference functions (#241)
* TileViewPattern: simplify the stencil_reference matching * Move stencil_reference_value_?d from TileViewPattern to WorldTileCoords * Remove no longer used stencil_reference_value_2d function The 2d version of calculating the stencil value is only valid for cases where only tiles from exactly one zoom level are displayed at once. As soon as multiple zoom levels are presented at once, the stencil value needs to be distinct across zoom levels
This commit is contained in:
parent
dd8e22ee55
commit
021376acaf
@ -456,6 +456,20 @@ impl WorldTileCoords {
|
||||
z: self.z - 1,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns unique stencil reference values for WorldTileCoords which are 3D.
|
||||
/// Tiles from arbitrary `z` can lie next to each other, because we mix tiles from
|
||||
/// different levels based on availability.
|
||||
pub fn stencil_reference_value_3d(&self) -> u8 {
|
||||
const CASES: u8 = 4;
|
||||
let z = u8::from(self.z);
|
||||
match (self.x % 2 == 0, self.y % 2 == 0) {
|
||||
(true, true) => 0 + z * CASES,
|
||||
(true, false) => 1 + z * CASES,
|
||||
(false, true) => 2 + z * CASES,
|
||||
(false, false) => 3 + z * CASES,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(i32, i32, ZoomLevel)> for WorldTileCoords {
|
||||
|
||||
@ -86,7 +86,7 @@ impl RenderCommand<TileShape> for DrawMask {
|
||||
tracing::trace!("Drawing mask {}", &source_shape.coords());
|
||||
|
||||
// Draw mask with stencil value of e.g. parent
|
||||
let reference = tile_view_pattern.stencil_reference_value_3d(&source_shape.coords()) as u32;
|
||||
let reference = source_shape.coords().stencil_reference_value_3d() as u32;
|
||||
|
||||
pass.set_stencil_reference(reference);
|
||||
pass.set_vertex_buffer(
|
||||
@ -135,7 +135,7 @@ impl RenderCommand<(IndexEntry, TileShape)> for DrawTile {
|
||||
(&state.buffer_pool, &state.tile_view_pattern) else { return RenderCommandResult::Failure; };
|
||||
|
||||
// Uses stencil value of requested tile and the shape of the requested tile
|
||||
let reference = tile_view_pattern.stencil_reference_value_3d(&shape.coords()) as u32;
|
||||
let reference = shape.coords().stencil_reference_value_3d() as u32;
|
||||
|
||||
tracing::trace!(
|
||||
"Drawing layer {:?} at {}",
|
||||
|
||||
@ -235,30 +235,4 @@ impl<Q: Queue<B>, B> TileViewPattern<Q, B> {
|
||||
}
|
||||
queue.write_buffer(&self.buffer.inner, 0, raw_buffer);
|
||||
}
|
||||
|
||||
/// 2D version of [`TileViewPattern::stencil_reference_value_3d`]. This is kept for reference.
|
||||
/// For the 2D case we do not take into account the Z value, so only 4 cases exist.
|
||||
pub fn stencil_reference_value_2d(&self, world_coords: &WorldTileCoords) -> u8 {
|
||||
match (world_coords.x, world_coords.y) {
|
||||
(x, y) if x % 2 == 0 && y % 2 == 0 => 2,
|
||||
(x, y) if x % 2 == 0 && y % 2 != 0 => 1,
|
||||
(x, y) if x % 2 != 0 && y % 2 == 0 => 4,
|
||||
(x, y) if x % 2 != 0 && y % 2 != 0 => 3,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns unique stencil reference values for WorldTileCoords which are 3D.
|
||||
/// Tiles from arbitrary `z` can lie next to each other, because we mix tiles from
|
||||
/// different levels based on availability.
|
||||
pub fn stencil_reference_value_3d(&self, world_coords: &WorldTileCoords) -> u8 {
|
||||
const CASES: u8 = 4;
|
||||
match (world_coords.x, world_coords.y, u8::from(world_coords.z)) {
|
||||
(x, y, z) if x % 2 == 0 && y % 2 == 0 => 0 + z * CASES,
|
||||
(x, y, z) if x % 2 == 0 && y % 2 != 0 => 1 + z * CASES,
|
||||
(x, y, z) if x % 2 != 0 && y % 2 == 0 => 2 + z * CASES,
|
||||
(x, y, z) if x % 2 != 0 && y % 2 != 0 => 3 + z * CASES,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user