mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-04 01:48:28 +00:00
Consolidate more pipeline code in Pipeline
This commit is contained in:
parent
7e9e7ab2e3
commit
71f15297e7
@ -1,6 +1,11 @@
|
||||
use std::f32::consts::PI;
|
||||
|
||||
use glam::{Mat4, Vec3};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::render::geometry::Geometry;
|
||||
|
||||
use super::triangles;
|
||||
use super::{pipelines::Uniforms, triangles};
|
||||
|
||||
pub struct Pipeline {
|
||||
render_pipeline: wgpu::RenderPipeline,
|
||||
@ -11,8 +16,18 @@ impl Pipeline {
|
||||
pub fn new(
|
||||
device: &wgpu::Device,
|
||||
surface_configuration: &wgpu::SurfaceConfiguration,
|
||||
uniforms: &wgpu::Buffer,
|
||||
) -> Self {
|
||||
let aspect_ratio = surface_configuration.width as f32
|
||||
/ surface_configuration.height as f32;
|
||||
let uniforms =
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: None,
|
||||
contents: bytemuck::cast_slice(&[Uniforms::from_transform(
|
||||
default_transform(aspect_ratio),
|
||||
)]),
|
||||
usage: wgpu::BufferUsages::UNIFORM,
|
||||
});
|
||||
|
||||
let bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
@ -123,3 +138,14 @@ impl Pipeline {
|
||||
pub trait IsVertex {
|
||||
const ATTRIBUTES: &[wgpu::VertexAttribute];
|
||||
}
|
||||
|
||||
fn default_transform(aspect_ratio: f32) -> Mat4 {
|
||||
let fov_y_radians = std::f32::consts::PI / 2.;
|
||||
let z_near = 0.1;
|
||||
let z_far = 10.;
|
||||
|
||||
Mat4::perspective_rh(fov_y_radians, aspect_ratio, z_near, z_far)
|
||||
* Mat4::from_translation(Vec3::new(0., 0., -2.))
|
||||
* Mat4::from_rotation_x(-PI / 4.)
|
||||
* Mat4::from_rotation_z(PI / 4.)
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
use std::f32::consts::PI;
|
||||
|
||||
use glam::{Mat4, Vec3};
|
||||
use wgpu::util::DeviceExt;
|
||||
use glam::Mat4;
|
||||
|
||||
use super::Pipeline;
|
||||
|
||||
@ -14,22 +11,7 @@ impl Pipelines {
|
||||
device: &wgpu::Device,
|
||||
surface_configuration: &wgpu::SurfaceConfiguration,
|
||||
) -> Self {
|
||||
let aspect_ratio = surface_configuration.width as f32
|
||||
/ surface_configuration.height as f32;
|
||||
let uniforms =
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: None,
|
||||
contents: bytemuck::cast_slice(&[Uniforms::from_transform(
|
||||
default_transform(aspect_ratio),
|
||||
)]),
|
||||
usage: wgpu::BufferUsages::UNIFORM,
|
||||
});
|
||||
|
||||
let triangles = Pipeline::new(
|
||||
device,
|
||||
surface_configuration,
|
||||
&uniforms,
|
||||
);
|
||||
let triangles = Pipeline::new(device, surface_configuration);
|
||||
|
||||
Self { triangles }
|
||||
}
|
||||
@ -52,14 +34,3 @@ impl Uniforms {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_transform(aspect_ratio: f32) -> Mat4 {
|
||||
let fov_y_radians = std::f32::consts::PI / 2.;
|
||||
let z_near = 0.1;
|
||||
let z_far = 10.;
|
||||
|
||||
Mat4::perspective_rh(fov_y_radians, aspect_ratio, z_near, z_far)
|
||||
* Mat4::from_translation(Vec3::new(0., 0., -2.))
|
||||
* Mat4::from_rotation_x(-PI / 4.)
|
||||
* Mat4::from_rotation_z(PI / 4.)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user