Allow loading new DEM after one has already been loaded
This commit is contained in:
parent
b33af565f2
commit
420bfed5e9
|
|
@ -11,7 +11,7 @@ use {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct DemRenderer {
|
pub struct DemRenderer {
|
||||||
source: Rc<Dem>,
|
pub source: Rc<Dem>,
|
||||||
pipeline: wgpu::RenderPipeline,
|
pipeline: wgpu::RenderPipeline,
|
||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
vertex_buffer: wgpu::Buffer,
|
vertex_buffer: wgpu::Buffer,
|
||||||
|
|
|
||||||
|
|
@ -158,8 +158,12 @@ impl MvuApp<Model> for App {
|
||||||
async fn view(&mut self, model: Rc<Model>) -> Result<(), Box<dyn std::error::Error>> {
|
async fn view(&mut self, model: Rc<Model>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if let Some(context) = &mut self.context {
|
if let Some(context) = &mut self.context {
|
||||||
context.frame_timer.mark_frame_start();
|
context.frame_timer.mark_frame_start();
|
||||||
if context.scene_data.is_none() {
|
|
||||||
if let Some(dem) = &model.dem {
|
if let Some(dem) = &model.dem {
|
||||||
|
if context
|
||||||
|
.scene_data
|
||||||
|
.as_ref()
|
||||||
|
.is_none_or(|scene_data| scene_data.source.id != dem.id)
|
||||||
|
{
|
||||||
context.scene_data = Some(DemRenderer::new(
|
context.scene_data = Some(DemRenderer::new(
|
||||||
dem.clone(),
|
dem.clone(),
|
||||||
&context.device,
|
&context.device,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::mvu::File;
|
use crate::mvu::File;
|
||||||
|
use std::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Dem {
|
pub struct Dem {
|
||||||
|
|
@ -11,6 +12,7 @@ pub struct Dem {
|
||||||
pub z_min: f32,
|
pub z_min: f32,
|
||||||
pub z_max: f32,
|
pub z_max: f32,
|
||||||
pub grid: Vec<u16>,
|
pub grid: Vec<u16>,
|
||||||
|
pub id: Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for Dem {
|
impl std::fmt::Debug for Dem {
|
||||||
|
|
@ -46,6 +48,18 @@ pub struct DemBvhLayer {
|
||||||
pub data: Vec<u16>,
|
pub data: Vec<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
|
pub struct Id(u32);
|
||||||
|
|
||||||
|
impl Id {
|
||||||
|
fn get_next() -> Self {
|
||||||
|
NEXT_ID.fetch_add(1, Ordering::SeqCst);
|
||||||
|
Self(NEXT_ID.load(Ordering::SeqCst))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static NEXT_ID: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
/// Find the smallest number that's larger then the input and that is also one
|
/// Find the smallest number that's larger then the input and that is also one
|
||||||
/// less than a power of two.
|
/// less than a power of two.
|
||||||
fn round_bound(v: u32) -> u32 {
|
fn round_bound(v: u32) -> u32 {
|
||||||
|
|
@ -198,6 +212,7 @@ impl Dem {
|
||||||
z_min,
|
z_min,
|
||||||
z_max,
|
z_max,
|
||||||
grid,
|
grid,
|
||||||
|
id: Id::get_next(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
@ -283,6 +298,7 @@ mod tests {
|
||||||
z_min: z1.min(z2),
|
z_min: z1.min(z2),
|
||||||
z_max: z1.max(z2),
|
z_max: z1.max(z2),
|
||||||
grid,
|
grid,
|
||||||
|
id: Id::get_next()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue