mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-03 17:52:15 +00:00
Moved geometry uniforms from fade shared to fade images shared.
Fixed fade geometry uniforms using the wrong layout.
This commit is contained in:
parent
2fec20ad75
commit
ea100295ab
@ -8,7 +8,7 @@ use {
|
||||
slide::{self, PanelSlideShared},
|
||||
},
|
||||
crate::panel::state::fade::PanelFadeImageSlot,
|
||||
std::collections::{HashMap, hash_map},
|
||||
std::collections::HashMap,
|
||||
tokio::sync::OnceCell,
|
||||
winit::window::WindowId,
|
||||
zsw_wgpu::Wgpu,
|
||||
@ -63,17 +63,15 @@ pub struct PanelGeometryFadeUniforms {
|
||||
}
|
||||
impl PanelGeometryFadeUniforms {
|
||||
/// Returns an image's uniforms
|
||||
pub async fn image(
|
||||
pub fn image(
|
||||
&mut self,
|
||||
wgpu: &Wgpu,
|
||||
shared: &PanelFadeImagesShared,
|
||||
slot: PanelFadeImageSlot,
|
||||
) -> &mut PanelGeometryFadeImageUniforms {
|
||||
match self.images.entry(slot) {
|
||||
hash_map::Entry::Occupied(entry) => entry.into_mut(),
|
||||
hash_map::Entry::Vacant(entry) =>
|
||||
entry.insert(fade::images::create_image_geometry_uniforms(wgpu, shared).await),
|
||||
}
|
||||
self.images
|
||||
.entry(slot)
|
||||
.or_insert_with(|| fade::images::create_image_geometry_uniforms(wgpu, shared))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -283,7 +283,7 @@ impl PanelsRenderer {
|
||||
let bind_group_layouts = match panel.state {
|
||||
PanelState::None(_) => &[&shared.none.geometry_uniforms_bind_group_layout] as &[_],
|
||||
PanelState::Fade(_) => &[
|
||||
&shared.fade.geometry_uniforms_bind_group_layout,
|
||||
&shared.fade.images.geometry_uniforms_bind_group_layout,
|
||||
shared.fade.images.image_bind_group_layout(wgpu).await,
|
||||
],
|
||||
PanelState::Slide(_) => &[&shared.slide.geometry_uniforms_bind_group_layout],
|
||||
@ -461,7 +461,7 @@ impl PanelsRenderer {
|
||||
|
||||
let mut image_metrics = HashMap::new();
|
||||
for (panel_image_slot, panel_image) in panel_state.images().iter() {
|
||||
let geometry_uniforms = geometry_uniforms.image(wgpu, &shared.images, panel_image_slot).await;
|
||||
let geometry_uniforms = geometry_uniforms.image(wgpu, &shared.images, panel_image_slot);
|
||||
|
||||
let progress = match panel_image_slot {
|
||||
PanelFadeImageSlot::Prev => 1.0 - f32::max((f - p) / d, 0.0),
|
||||
|
||||
@ -269,9 +269,6 @@ impl PanelFadeState {
|
||||
/// Panel fade shared
|
||||
#[derive(Debug)]
|
||||
pub struct PanelFadeShared {
|
||||
/// Geometry uniforms bind group layout
|
||||
pub geometry_uniforms_bind_group_layout: wgpu::BindGroupLayout,
|
||||
|
||||
/// Images
|
||||
pub images: PanelFadeImagesShared,
|
||||
}
|
||||
@ -279,33 +276,12 @@ pub struct PanelFadeShared {
|
||||
impl PanelFadeShared {
|
||||
/// Creates the shared
|
||||
pub fn new(wgpu: &Wgpu) -> Self {
|
||||
let geometry_uniforms_bind_group_layout = self::create_geometry_uniforms_bind_group_layout(wgpu);
|
||||
|
||||
Self {
|
||||
geometry_uniforms_bind_group_layout,
|
||||
images: PanelFadeImagesShared::new(),
|
||||
images: PanelFadeImagesShared::new(wgpu),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the geometry uniforms bind group layout
|
||||
fn create_geometry_uniforms_bind_group_layout(wgpu: &Wgpu) -> wgpu::BindGroupLayout {
|
||||
let descriptor = wgpu::BindGroupLayoutDescriptor {
|
||||
label: Some("zsw-panel-fade-geometry-uniforms-bind-group-layout"),
|
||||
entries: &[wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::VERTEX_FRAGMENT,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
},
|
||||
count: None,
|
||||
}],
|
||||
};
|
||||
|
||||
wgpu.device.create_bind_group_layout(&descriptor)
|
||||
}
|
||||
|
||||
/// Converts a chrono time delta into a duration, indicating whether it's positive or negative
|
||||
fn time_delta_to_duration(delta: TimeDelta) -> (Duration, bool) {
|
||||
|
||||
@ -18,14 +18,20 @@ use {
|
||||
/// Panel fade images shared
|
||||
#[derive(Debug)]
|
||||
pub struct PanelFadeImagesShared {
|
||||
/// Geometry uniforms bind group layout
|
||||
pub geometry_uniforms_bind_group_layout: wgpu::BindGroupLayout,
|
||||
|
||||
/// Image bind group layout
|
||||
pub image_bind_group_layout: OnceCell<wgpu::BindGroupLayout>,
|
||||
}
|
||||
|
||||
impl PanelFadeImagesShared {
|
||||
/// Creates the shared
|
||||
pub fn new() -> Self {
|
||||
pub fn new(wgpu: &Wgpu) -> Self {
|
||||
let geometry_uniforms_bind_group_layout = self::create_geometry_uniforms_bind_group_layout(wgpu);
|
||||
|
||||
Self {
|
||||
geometry_uniforms_bind_group_layout,
|
||||
image_bind_group_layout: OnceCell::new(),
|
||||
}
|
||||
}
|
||||
@ -365,11 +371,27 @@ fn create_image_bind_group(
|
||||
wgpu.device.create_bind_group(&descriptor)
|
||||
}
|
||||
|
||||
/// Creates the geometry uniforms bind group layout
|
||||
fn create_geometry_uniforms_bind_group_layout(wgpu: &Wgpu) -> wgpu::BindGroupLayout {
|
||||
let descriptor = wgpu::BindGroupLayoutDescriptor {
|
||||
label: Some("zsw-panel-fade-geometry-uniforms-bind-group-layout"),
|
||||
entries: &[wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::VERTEX_FRAGMENT,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
},
|
||||
count: None,
|
||||
}],
|
||||
};
|
||||
|
||||
wgpu.device.create_bind_group_layout(&descriptor)
|
||||
}
|
||||
|
||||
/// Creates the image geometry uniforms
|
||||
pub async fn create_image_geometry_uniforms(
|
||||
wgpu: &Wgpu,
|
||||
shared: &PanelFadeImagesShared,
|
||||
) -> PanelGeometryFadeImageUniforms {
|
||||
pub fn create_image_geometry_uniforms(wgpu: &Wgpu, shared: &PanelFadeImagesShared) -> PanelGeometryFadeImageUniforms {
|
||||
// Create the uniforms
|
||||
let buffer_descriptor = wgpu::BufferDescriptor {
|
||||
label: Some("zsw-panel-fade-geometry-uniforms-buffer"),
|
||||
@ -391,7 +413,7 @@ pub async fn create_image_geometry_uniforms(
|
||||
// Create the uniform bind group
|
||||
let bind_group_descriptor = wgpu::BindGroupDescriptor {
|
||||
label: Some("zsw-panel-fade-geometry-uniforms-bind-group"),
|
||||
layout: shared.image_bind_group_layout(wgpu).await,
|
||||
layout: &shared.geometry_uniforms_bind_group_layout,
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: buffer.as_entire_binding(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user