mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Cleanup
This commit is contained in:
parent
023e26df3c
commit
3b16a5ae62
@ -10,32 +10,16 @@ type Mat4f32 = [Vec4f32; 4];
|
||||
pub struct Globals {
|
||||
pub view_proj: Mat4f32, // 64 bytes
|
||||
pub view_position: Vec4f32, // 16 bytes
|
||||
pub resolution: Vec2f32, // 8 bytes
|
||||
pub scroll_offset: Vec2f32, // 8 bytes
|
||||
pub zoom: f32, // 4 bytes
|
||||
_pad1: i32, // _padX aligns it to 8 bytes = AlignOf(Vec2f32=vec2<f32>):
|
||||
// https://gpuweb.github.io/gpuweb/wgsl/#alignment-and-size
|
||||
_pad2: i32,
|
||||
_pad3: i32,
|
||||
}
|
||||
|
||||
impl Globals {
|
||||
pub fn new(
|
||||
view_proj: Mat4f32,
|
||||
view_position: Vec4f32,
|
||||
resolution: Vec2f32,
|
||||
scroll_offset: Vec2f32,
|
||||
zoom: f32,
|
||||
) -> Self {
|
||||
Self {
|
||||
view_proj,
|
||||
view_position,
|
||||
resolution,
|
||||
scroll_offset,
|
||||
zoom,
|
||||
_pad1: Default::default(),
|
||||
_pad2: Default::default(),
|
||||
_pad3: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,12 +2,6 @@
|
||||
struct Globals {
|
||||
view_proj: mat4x4<f32>;
|
||||
view_position: vec4<f32>;
|
||||
resolution: vec2<f32>;
|
||||
scroll_offset: vec2<f32>;
|
||||
zoom: f32;
|
||||
pad1: i32;
|
||||
pad2: i32;
|
||||
pad3: i32;
|
||||
};
|
||||
|
||||
struct Primitive {
|
||||
|
||||
@ -2,16 +2,15 @@ use std::cmp;
|
||||
use std::io::Cursor;
|
||||
use std::ops::Range;
|
||||
|
||||
use lyon::math::Vector;
|
||||
use lyon::tessellation::VertexBuffers;
|
||||
use vector_tile::parse_tile_reader;
|
||||
use wgpu::util::DeviceExt;
|
||||
use winit::event::{DeviceEvent, ElementState, KeyboardInput, VirtualKeyCode, WindowEvent};
|
||||
use winit::event::{DeviceEvent, ElementState, KeyboardInput, WindowEvent};
|
||||
use winit::window::Window;
|
||||
|
||||
use crate::fps_meter::FPSMeter;
|
||||
use crate::render::camera;
|
||||
use crate::render::camera::{Camera, CameraUniform};
|
||||
use crate::render::camera::{CameraUniform};
|
||||
use crate::render::tesselation::TileMask;
|
||||
|
||||
use super::piplines::*;
|
||||
@ -22,22 +21,14 @@ use super::tesselation::Tesselated;
|
||||
use super::texture::Texture;
|
||||
|
||||
pub struct SceneParams {
|
||||
pub target_zoom: f32,
|
||||
pub zoom: f32,
|
||||
pub target_scroll: Vector,
|
||||
pub scroll: Vector,
|
||||
pub stroke_width: f32,
|
||||
pub target_stroke_width: f32,
|
||||
stroke_width: f32,
|
||||
target_stroke_width: f32,
|
||||
cpu_primitives: Vec<Primitive>,
|
||||
}
|
||||
|
||||
impl Default for SceneParams {
|
||||
fn default() -> Self {
|
||||
SceneParams {
|
||||
target_zoom: 5.0,
|
||||
zoom: 5.0,
|
||||
target_scroll: Vector::new(70.0, 70.0),
|
||||
scroll: Vector::new(70.0, 70.0),
|
||||
stroke_width: 1.0,
|
||||
target_stroke_width: 1.0,
|
||||
cpu_primitives: vec![],
|
||||
@ -81,16 +72,17 @@ pub struct State {
|
||||
tile_mask_indices_uniform_buffer: wgpu::Buffer,
|
||||
tile_mask_range: Range<u32>,
|
||||
|
||||
camera: camera::Camera, // UPDATED!
|
||||
projection: camera::Projection, // NEW!
|
||||
camera_controller: camera::CameraController, // UPDAT
|
||||
camera_uniform: camera::CameraUniform, // UPDAT
|
||||
camera: camera::Camera,
|
||||
projection: camera::Projection,
|
||||
camera_controller: camera::CameraController,
|
||||
camera_uniform: camera::CameraUniform,
|
||||
mouse_pressed: bool,
|
||||
|
||||
scene: SceneParams,
|
||||
}
|
||||
|
||||
const TEST_TILES: &[u8] = include_bytes!("../../test-data/12-2176-1425.pbf");
|
||||
|
||||
impl SceneParams {
|
||||
pub fn new() -> Self {
|
||||
let mut cpu_primitives = Vec::with_capacity(PRIM_BUFFER_LEN);
|
||||
@ -410,7 +402,6 @@ impl State {
|
||||
}
|
||||
|
||||
pub fn input(&mut self, event: &DeviceEvent) -> bool {
|
||||
let scene = &mut self.scene;
|
||||
match event {
|
||||
DeviceEvent::Key(KeyboardInput {
|
||||
virtual_keycode: Some(key),
|
||||
@ -446,16 +437,12 @@ impl State {
|
||||
.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
{
|
||||
let position: [f32; 4] = [0., 0., 0., 0.];
|
||||
self.queue.write_buffer(
|
||||
&self.globals_uniform_buffer,
|
||||
0,
|
||||
bytemuck::cast_slice(&[Globals::new(
|
||||
self.camera_uniform.view_proj,
|
||||
position,
|
||||
[self.size.width as f32, self.size.height as f32],
|
||||
scene.scroll.to_array(),
|
||||
scene.zoom,
|
||||
self.camera_uniform.view_position,
|
||||
)]),
|
||||
);
|
||||
|
||||
@ -549,9 +536,7 @@ impl State {
|
||||
self.camera_uniform.update_view_proj(&self.camera, &self.projection);
|
||||
|
||||
|
||||
// Animate the zoom to match target_zoom
|
||||
scene.zoom += (scene.target_zoom - scene.zoom) / 3.0;
|
||||
scene.scroll = scene.scroll + (scene.target_scroll - scene.scroll) / 3.0;
|
||||
// Animate the stroke_width to match target_stroke_width
|
||||
scene.stroke_width =
|
||||
scene.stroke_width + (scene.target_stroke_width - scene.stroke_width) / 5.0;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user