mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Fix width of lines when zooming
This commit is contained in:
parent
f08c8491cf
commit
b9e6c1215c
@ -1,3 +1,4 @@
|
|||||||
|
use cgmath::num_traits::Pow;
|
||||||
use cgmath::Matrix4;
|
use cgmath::Matrix4;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
@ -354,6 +355,11 @@ impl RenderState {
|
|||||||
// TODO: What is StagingBelt for?
|
// TODO: What is StagingBelt for?
|
||||||
pub fn upload_tile_geometry(&mut self, scheduler: &mut IOScheduler) {
|
pub fn upload_tile_geometry(&mut self, scheduler: &mut IOScheduler) {
|
||||||
let visible_z = self.visible_z();
|
let visible_z = self.visible_z();
|
||||||
|
|
||||||
|
// Factor which determines how much we need to adjust the width of lines for example.
|
||||||
|
// If zoom == z -> zoom_factor == 1
|
||||||
|
let zoom_factor = 2.0_f64.powf(visible_z as f64 - self.zoom) as f32;
|
||||||
|
|
||||||
let view_region = self
|
let view_region = self
|
||||||
.camera
|
.camera
|
||||||
.view_region_bounding_box(&self.perspective)
|
.view_region_bounding_box(&self.perspective)
|
||||||
@ -392,7 +398,7 @@ impl RenderState {
|
|||||||
self.buffer_pool.update_tile_metadata(
|
self.buffer_pool.update_tile_metadata(
|
||||||
&self.queue,
|
&self.queue,
|
||||||
entry,
|
entry,
|
||||||
ShaderTileMetadata::new(transform.into()),
|
ShaderTileMetadata::new(transform.into(), zoom_factor),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +465,7 @@ impl RenderState {
|
|||||||
*coords,
|
*coords,
|
||||||
style_layer.clone(),
|
style_layer.clone(),
|
||||||
buffer,
|
buffer,
|
||||||
ShaderTileMetadata::new(transform.into()),
|
ShaderTileMetadata::new(transform.into(), zoom_factor),
|
||||||
&feature_metadata,
|
&feature_metadata,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,6 +137,11 @@ pub mod tile {
|
|||||||
format: wgpu::VertexFormat::Float32x4,
|
format: wgpu::VertexFormat::Float32x4,
|
||||||
shader_location: 7,
|
shader_location: 7,
|
||||||
},
|
},
|
||||||
|
wgpu::VertexAttribute {
|
||||||
|
offset: 4 * wgpu::VertexFormat::Float32x4.size(),
|
||||||
|
format: wgpu::VertexFormat::Float32,
|
||||||
|
shader_location: 9,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// vertex style
|
// vertex style
|
||||||
@ -302,10 +307,14 @@ pub struct ShaderFeatureStyle {
|
|||||||
#[derive(Copy, Clone, Pod, Zeroable)]
|
#[derive(Copy, Clone, Pod, Zeroable)]
|
||||||
pub struct ShaderTileMetadata {
|
pub struct ShaderTileMetadata {
|
||||||
pub transform: Mat4x4f32,
|
pub transform: Mat4x4f32,
|
||||||
|
pub zoom_factor: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShaderTileMetadata {
|
impl ShaderTileMetadata {
|
||||||
pub fn new(transform: Mat4x4f32) -> Self {
|
pub fn new(transform: Mat4x4f32, zoom_factor: f32) -> Self {
|
||||||
Self { transform }
|
Self {
|
||||||
|
transform,
|
||||||
|
zoom_factor,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,11 @@ fn main(
|
|||||||
[[location(6)]] translate3: vec4<f32>,
|
[[location(6)]] translate3: vec4<f32>,
|
||||||
[[location(7)]] translate4: vec4<f32>,
|
[[location(7)]] translate4: vec4<f32>,
|
||||||
[[location(8)]] color: vec4<f32>,
|
[[location(8)]] color: vec4<f32>,
|
||||||
|
[[location(9)]] zoom_factor: f32,
|
||||||
[[builtin(instance_index)]] instance_idx: u32 // instance_index is used when we have multiple instances of the same "object"
|
[[builtin(instance_index)]] instance_idx: u32 // instance_index is used when we have multiple instances of the same "object"
|
||||||
) -> VertexOutput {
|
) -> VertexOutput {
|
||||||
let z = 0.0;
|
let z = 0.0;
|
||||||
let width = 2.0;
|
let width = 3.0 * zoom_factor;
|
||||||
|
|
||||||
// The following code moves all "invisible" vertices to (0, 0, 0)
|
// The following code moves all "invisible" vertices to (0, 0, 0)
|
||||||
//if (color.w == 0.0) {
|
//if (color.w == 0.0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user