From 34a0c8c64807f79e21ace8c4bcbfdfdc6345e925 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 13 May 2024 19:47:36 +0200 Subject: [PATCH] wip smoverlay --- kubi/shaders/c2d.wgsl | 1 + kubi/src/rendering/primitives.rs | 16 ++++++++++++++++ kubi/src/rendering/primitives/fstri.rs | 24 ++++++++++++++++++++++++ kubi/src/rendering/submerge/pipeline.rs | 14 ++++++++++++++ kubi/src/rendering/sumberge.rs | 2 ++ 5 files changed, 57 insertions(+) create mode 100644 kubi/shaders/c2d.wgsl create mode 100644 kubi/src/rendering/primitives/fstri.rs create mode 100644 kubi/src/rendering/submerge/pipeline.rs diff --git a/kubi/shaders/c2d.wgsl b/kubi/shaders/c2d.wgsl new file mode 100644 index 0000000..471ce88 --- /dev/null +++ b/kubi/shaders/c2d.wgsl @@ -0,0 +1 @@ +//TODO diff --git a/kubi/src/rendering/primitives.rs b/kubi/src/rendering/primitives.rs index c7e85f3..05ef112 100644 --- a/kubi/src/rendering/primitives.rs +++ b/kubi/src/rendering/primitives.rs @@ -2,7 +2,9 @@ use bytemuck::{Pod, Zeroable}; use shipyard::{IntoWorkload, Workload}; mod cube; +mod fstri; pub use cube::CubePrimitive; +pub use fstri::FstriPrimitive; pub fn init_primitives() -> Workload { ( @@ -23,3 +25,17 @@ impl PrimitiveVertex { attributes: &wgpu::vertex_attr_array![0 => Float32x3], }; } + +#[derive(Clone, Copy, Default, Pod, Zeroable)] +#[repr(C, packed)] +pub struct PrimitiveVertex2 { + pub position: [f32; 2], +} + +impl PrimitiveVertex2 { + pub const LAYOUT: wgpu::VertexBufferLayout<'static> = wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as wgpu::BufferAddress, + step_mode: wgpu::VertexStepMode::Vertex, + attributes: &wgpu::vertex_attr_array![0 => Float32x2], + }; +} diff --git a/kubi/src/rendering/primitives/fstri.rs b/kubi/src/rendering/primitives/fstri.rs new file mode 100644 index 0000000..b6eb26d --- /dev/null +++ b/kubi/src/rendering/primitives/fstri.rs @@ -0,0 +1,24 @@ +use shipyard::{AllStoragesView, Unique, UniqueView}; +use wgpu::util::DeviceExt; +use crate::rendering::Renderer; +use super::PrimitiveVertex2; + +pub const FSTRI_VERTICES: &[PrimitiveVertex2] = &[ + PrimitiveVertex2 { position: [0.0, 0.0] }, + PrimitiveVertex2 { position: [1.0, 0.0] }, + PrimitiveVertex2 { position: [0.0, 1.0] }, + PrimitiveVertex2 { position: [1.0, 1.0] }, +]; + +#[derive(Unique)] +pub struct FstriPrimitive(wgpu::Buffer); + +pub fn init_fstri_primitive(storages: AllStoragesView) { + let renderer = storages.borrow::>().unwrap(); + let buffer = renderer.device().create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("fstri_vertex_buffer"), + contents: bytemuck::cast_slice(FSTRI_VERTICES), + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::VERTEX, + }); + storages.add_unique(FstriPrimitive(buffer)); +} diff --git a/kubi/src/rendering/submerge/pipeline.rs b/kubi/src/rendering/submerge/pipeline.rs new file mode 100644 index 0000000..0bcd41a --- /dev/null +++ b/kubi/src/rendering/submerge/pipeline.rs @@ -0,0 +1,14 @@ +pub fn create_render_pipeline( + ren: UniqueView, + stri_primitive: UniqueView, +) -> wgpu::RenderPipeline { + let shader = ren.device().create_shader_module( + wgpu::include_wgsl!("../../../shaders/c2d.wgsl") + ); + let pipeline_layout = ren.device().create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("smoverlay_pipeline_layout"), + bind_group_layouts: &[&ren.bind_group_layout], + push_constant_ranges: &[], + }); + //TODO +} diff --git a/kubi/src/rendering/sumberge.rs b/kubi/src/rendering/sumberge.rs index a44da40..89eebb0 100644 --- a/kubi/src/rendering/sumberge.rs +++ b/kubi/src/rendering/sumberge.rs @@ -1,3 +1,5 @@ +mod pipeline; + // use glium::{uniform, Blend, DrawParameters, Surface}; // use kubi_shared::transform::Transform; // use shipyard::{IntoIter, NonSendSync, UniqueView, UniqueViewMut, View};