summaryrefslogtreecommitdiff
path: root/src/camera.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera.rs')
-rw-r--r--src/camera.rs57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/camera.rs b/src/camera.rs
index edc3405..3ae33b4 100644
--- a/src/camera.rs
+++ b/src/camera.rs
@@ -19,31 +19,6 @@ fn inverse_aspect_ratio(width: u32, height: u32) -> f32 {
(height as f32) / (width as f32)
}
-fn create_buffer(device: &wgpu::Device) -> wgpu::Buffer {
- device.create_buffer(&wgpu::BufferDescriptor {
- label: Some("Camera Uniform"),
- size: size_of::<CameraUniform>() as wgpu::BufferAddress,
- usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
- mapped_at_creation: false,
- })
-}
-
-fn create_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
- device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
- label: Some("Camera Bind Group Layout"),
- entries: &[wgpu::BindGroupLayoutEntry {
- binding: 0,
- visibility: wgpu::ShaderStages::VERTEX,
- ty: wgpu::BindingType::Buffer {
- ty: wgpu::BufferBindingType::Uniform,
- has_dynamic_offset: false,
- min_binding_size: None,
- },
- count: None,
- }],
- })
-}
-
fn create_bind_group(
device: &wgpu::Device,
buffer: &wgpu::Buffer,
@@ -66,9 +41,35 @@ impl Camera {
width: u32,
height: u32,
) -> (Self, wgpu::BindGroupLayout) {
- let buffer = create_buffer(device);
- let bind_group_layout = create_bind_group_layout(device);
- let bind_group = create_bind_group(device, &buffer, &bind_group_layout);
+ let buffer = device.create_buffer(&wgpu::BufferDescriptor {
+ label: Some("Camera Uniform"),
+ size: size_of::<CameraUniform>() as wgpu::BufferAddress,
+ usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
+ mapped_at_creation: false,
+ });
+
+ let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
+ label: Some("Camera Bind Group Layout"),
+ entries: &[wgpu::BindGroupLayoutEntry {
+ binding: 0,
+ visibility: wgpu::ShaderStages::VERTEX,
+ ty: wgpu::BindingType::Buffer {
+ ty: wgpu::BufferBindingType::Uniform,
+ has_dynamic_offset: false,
+ min_binding_size: None,
+ },
+ count: None,
+ }],
+ });
+
+ let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: Some("Camera Bind Group"),
+ layout: &bind_group_layout,
+ entries: &[wgpu::BindGroupEntry {
+ binding: 0,
+ resource: buffer.as_entire_binding(),
+ }],
+ });
(
Self {