mirror of
https://github.com/hannobraun/Fornjot
synced 2025-10-09 09:28:24 +00:00
Merge shaders
into pipelines
This commit is contained in:
parent
8052b65384
commit
f4838b14ee
@ -5,7 +5,7 @@ use wgpu::util::DeviceExt;
|
|||||||
|
|
||||||
use crate::geometry::Operation;
|
use crate::geometry::Operation;
|
||||||
|
|
||||||
use super::shaders::{TrianglesVertex, VerticesVertex};
|
use super::pipelines::{TrianglesVertex, VerticesVertex};
|
||||||
|
|
||||||
pub struct Geometry<V> {
|
pub struct Geometry<V> {
|
||||||
pub vertices: wgpu::Buffer,
|
pub vertices: wgpu::Buffer,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
mod geometry;
|
mod geometry;
|
||||||
mod pipelines;
|
mod pipelines;
|
||||||
mod renderer;
|
mod renderer;
|
||||||
mod shaders;
|
|
||||||
|
|
||||||
pub use self::renderer::Renderer;
|
pub use self::renderer::Renderer;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
mod pipeline;
|
mod pipeline;
|
||||||
|
|
||||||
pub use self::pipeline::Pipeline;
|
use glam::Mat4;
|
||||||
|
|
||||||
use super::shaders::{TrianglesVertex, VerticesVertex};
|
pub use self::pipeline::Pipeline;
|
||||||
|
|
||||||
pub struct Pipelines {
|
pub struct Pipelines {
|
||||||
pub vertices: Pipeline<VerticesVertex>,
|
pub vertices: Pipeline<VerticesVertex>,
|
||||||
@ -34,3 +34,55 @@ impl Pipelines {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct Uniforms {
|
||||||
|
pub transform: Mat4,
|
||||||
|
pub transform_for_normals: Mat4,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Uniforms {
|
||||||
|
pub fn from_transform(transform: Mat4) -> Self {
|
||||||
|
let transform_for_normals = transform.inverse().transpose();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
transform,
|
||||||
|
transform_for_normals,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Vertex {
|
||||||
|
const ATTRIBUTES: &[wgpu::VertexAttribute];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct TrianglesVertex {
|
||||||
|
pub position: [f32; 3],
|
||||||
|
pub normal: [f32; 3],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Vertex for TrianglesVertex {
|
||||||
|
const ATTRIBUTES: &[wgpu::VertexAttribute] = &wgpu::vertex_attr_array![
|
||||||
|
0 => Float32x3,
|
||||||
|
1 => Float32x3,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct VerticesVertex {
|
||||||
|
pub position: [f32; 3],
|
||||||
|
pub center: [f32; 3],
|
||||||
|
pub radius: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Vertex for VerticesVertex {
|
||||||
|
const ATTRIBUTES: &[wgpu::VertexAttribute] = &wgpu::vertex_attr_array![
|
||||||
|
0 => Float32x3,
|
||||||
|
1 => Float32x3,
|
||||||
|
2 => Float32,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use crate::render::{geometry::Geometry, shaders::Vertex};
|
use crate::render::geometry::Geometry;
|
||||||
|
|
||||||
|
use super::Vertex;
|
||||||
|
|
||||||
pub struct Pipeline<V> {
|
pub struct Pipeline<V> {
|
||||||
render_pipeline: wgpu::RenderPipeline,
|
render_pipeline: wgpu::RenderPipeline,
|
||||||
|
@ -7,7 +7,10 @@ use winit::window::Window;
|
|||||||
|
|
||||||
use crate::geometry::Operation;
|
use crate::geometry::Operation;
|
||||||
|
|
||||||
use super::{geometry::Geometry, pipelines::Pipelines, shaders::Uniforms};
|
use super::{
|
||||||
|
geometry::Geometry,
|
||||||
|
pipelines::{Pipelines, Uniforms},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
pub surface: wgpu::Surface<'static>,
|
pub surface: wgpu::Surface<'static>,
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
use glam::Mat4;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct Uniforms {
|
|
||||||
pub transform: Mat4,
|
|
||||||
pub transform_for_normals: Mat4,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Uniforms {
|
|
||||||
pub fn from_transform(transform: Mat4) -> Self {
|
|
||||||
let transform_for_normals = transform.inverse().transpose();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
transform,
|
|
||||||
transform_for_normals,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Vertex {
|
|
||||||
const ATTRIBUTES: &[wgpu::VertexAttribute];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct TrianglesVertex {
|
|
||||||
pub position: [f32; 3],
|
|
||||||
pub normal: [f32; 3],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Vertex for TrianglesVertex {
|
|
||||||
const ATTRIBUTES: &[wgpu::VertexAttribute] = &wgpu::vertex_attr_array![
|
|
||||||
0 => Float32x3,
|
|
||||||
1 => Float32x3,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct VerticesVertex {
|
|
||||||
pub position: [f32; 3],
|
|
||||||
pub center: [f32; 3],
|
|
||||||
pub radius: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Vertex for VerticesVertex {
|
|
||||||
const ATTRIBUTES: &[wgpu::VertexAttribute] = &wgpu::vertex_attr_array![
|
|
||||||
0 => Float32x3,
|
|
||||||
1 => Float32x3,
|
|
||||||
2 => Float32,
|
|
||||||
];
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user