mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Refactor platform
This commit is contained in:
parent
584f5956f9
commit
dd591f42ce
@ -8,7 +8,6 @@ pub struct FPSMeter {
|
||||
start: Instant,
|
||||
next_report: Instant,
|
||||
frame_count: u32,
|
||||
pub time_secs: f64,
|
||||
}
|
||||
|
||||
impl FPSMeter {
|
||||
@ -18,14 +17,12 @@ impl FPSMeter {
|
||||
start,
|
||||
next_report: start + Duration::from_secs(1),
|
||||
frame_count: 0,
|
||||
time_secs: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_and_print(&mut self) {
|
||||
self.frame_count += 1;
|
||||
let now = Instant::now();
|
||||
self.time_secs = (now - self.start).as_secs_f64();
|
||||
if now >= self.next_report {
|
||||
info!("{} FPS", self.frame_count);
|
||||
self.frame_count = 0;
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
pub use std::time::Instant;
|
||||
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
|
||||
|
||||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
|
||||
fn main() {
|
||||
pub fn main() {
|
||||
use winit::event_loop::EventLoop;
|
||||
use winit::window::WindowBuilder;
|
||||
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
use winit::event_loop::EventLoop;
|
||||
use winit::window::WindowBuilder;
|
||||
|
||||
pub use std::time::Instant;
|
||||
|
||||
// macOS and iOS (Metal)
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
|
||||
#[no_mangle]
|
||||
fn mapr_apple_main() {
|
||||
pub fn mapr_apple_main() {
|
||||
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
|
||||
5
src/platform/generic.rs
Normal file
5
src/platform/generic.rs
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
pub use std::time::Instant;
|
||||
|
||||
// Vulkan/OpenGL
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
@ -1,15 +1,37 @@
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub mod web;
|
||||
mod web;
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
pub mod apple;
|
||||
mod apple;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub mod android;
|
||||
mod android;
|
||||
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
target_arch = "aarch64",
|
||||
target_arch = "wasm32"
|
||||
)))]
|
||||
mod generic;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub use instant::Instant;
|
||||
pub use web::*;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use std::time::Instant;
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
pub use apple::*;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub use android::*;
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
target_arch = "aarch64",
|
||||
target_arch = "wasm32"
|
||||
)))]
|
||||
pub use generic::*;
|
||||
|
||||
|
||||
// FIXME: This limit is enforced by WebGL. Actually this makes sense!
|
||||
// FIXME: This can also be achieved by _pad attributes in shader_ffi.rs
|
||||
pub const MIN_BUFFER_SIZE: u64 = 32;
|
||||
|
||||
@ -17,6 +17,16 @@ use winit::window::{Window, WindowBuilder};
|
||||
mod io;
|
||||
mod wasm_experiment;
|
||||
|
||||
pub use instant::Instant;
|
||||
|
||||
// WebGPU
|
||||
#[cfg(not(feature = "web-webgl"))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8Unorm;
|
||||
|
||||
// WebGL
|
||||
#[cfg(feature = "web-webgl")]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn start() {
|
||||
if let Err(_) = console_log::init_with_level(Level::Info) {
|
||||
|
||||
@ -2,7 +2,6 @@ mod piplines;
|
||||
mod shader_ffi;
|
||||
mod tesselation;
|
||||
mod texture;
|
||||
mod platform_constants;
|
||||
mod camera;
|
||||
|
||||
pub mod state;
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
// WebGPU
|
||||
#[cfg(all(target_arch = "wasm32", not(feature = "web-webgl")))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8Unorm;
|
||||
// WebGL
|
||||
#[cfg(all(target_arch = "wasm32", feature = "web-webgl"))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
|
||||
// Vulkan/OpenGL
|
||||
#[cfg(target_os = "linux")]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
|
||||
// macOS and iOS (Metal)
|
||||
#[cfg(all(target_arch = "aarch64", not(target_os = "android")))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
|
||||
|
||||
// FIXME: This limit is enforced by WebGL. Actually this makes sense!
|
||||
// FIXME: This can also be achieved by _pad attributes in shader_ffi.rs
|
||||
pub const MIN_BUFFER_SIZE: u64 = 32;
|
||||
@ -63,7 +63,7 @@ impl VertexShaderState {
|
||||
}
|
||||
|
||||
pub mod tile {
|
||||
use crate::render::platform_constants::COLOR_TEXTURE_FORMAT;
|
||||
use crate::platform::COLOR_TEXTURE_FORMAT;
|
||||
use crate::render::shader_ffi::GpuVertexUniform;
|
||||
|
||||
use super::{VertexShaderState, ColorTargetState, FragmentShaderState};
|
||||
@ -103,7 +103,7 @@ pub mod tile {
|
||||
|
||||
|
||||
pub mod tile_mask {
|
||||
use crate::render::platform_constants::COLOR_TEXTURE_FORMAT;
|
||||
use crate::platform::COLOR_TEXTURE_FORMAT;
|
||||
use crate::render::shader_ffi::GpuVertexUniform;
|
||||
use super::{VertexShaderState, ColorTargetState, FragmentShaderState};
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ use crate::render::camera::CameraController;
|
||||
use crate::render::tesselation::TileMask;
|
||||
|
||||
use super::piplines::*;
|
||||
use super::platform_constants::{COLOR_TEXTURE_FORMAT, MIN_BUFFER_SIZE};
|
||||
use crate::platform::{COLOR_TEXTURE_FORMAT, MIN_BUFFER_SIZE};
|
||||
use super::shader_ffi::*;
|
||||
use super::tesselation::Tesselated;
|
||||
use super::texture::Texture;
|
||||
@ -512,7 +512,6 @@ impl State {
|
||||
if let Some(start) = self.scene.last_touch {
|
||||
let delta_x = start.0 - touch.location.x;
|
||||
let delta_y = start.1 - touch.location.y;
|
||||
warn!("touch {} {} {}", delta_x, delta_y, window.scale_factor());
|
||||
self.camera_controller.process_touch(delta_x / window.scale_factor(), delta_y / window.scale_factor());
|
||||
}
|
||||
|
||||
@ -655,7 +654,6 @@ impl State {
|
||||
|
||||
pub fn update(&mut self, dt: std::time::Duration) {
|
||||
let scene = &mut self.scene;
|
||||
let time_secs = self.fps_meter.time_secs as f32;
|
||||
|
||||
self.camera_controller.update_camera(&mut self.camera, dt);
|
||||
|
||||
@ -665,12 +663,13 @@ impl State {
|
||||
|
||||
// Animate the strokes of primitive
|
||||
scene.cpu_primitives[STROKE_PRIM_ID as usize].width = scene.stroke_width;
|
||||
/* scene.cpu_primitives[STROKE_PRIM_ID as usize].color = [
|
||||
/*
|
||||
scene.cpu_primitives[STROKE_PRIM_ID as usize].color = [
|
||||
(time_secs * 0.8 - 1.6).sin() * 0.1 + 0.1,
|
||||
(time_secs * 0.5 - 1.6).sin() * 0.1 + 0.1,
|
||||
(time_secs - 1.6).sin() * 0.1 + 0.1,
|
||||
1.0,
|
||||
];
|
||||
];
|
||||
*/
|
||||
self.fps_meter.update_and_print()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user