summaryrefslogtreecommitdiff
path: root/src/renderer.rs
diff options
context:
space:
mode:
authorMicha White <botahamec@outlook.com>2022-09-18 15:30:56 -0400
committerMicha White <botahamec@outlook.com>2022-09-18 15:30:56 -0400
commitd613b20803f41eeb4f6ae27003d5bfa371502930 (patch)
tree233f1906d0150b4fce80af3fb63dceeb70f308da /src/renderer.rs
parentffee09ada476b3a350f331718d60fa806b564bad (diff)
Created a vertex buffer
Diffstat (limited to 'src/renderer.rs')
-rw-r--r--src/renderer.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/renderer.rs b/src/renderer.rs
index 2264ab5..dc8ecb2 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -1,7 +1,9 @@
-use crate::config::RenderWindowConfig;
+use std::convert::TryInto;
+
+use crate::{vertex::SQUARE, RenderWindowConfig, Vertex};
use pollster::FutureExt;
use thiserror::Error;
-use wgpu::include_wgsl;
+use wgpu::{include_wgsl, util::DeviceExt};
use winit::{
dpi::PhysicalSize,
error::OsError,
@@ -40,6 +42,8 @@ pub struct Renderer {
queue: wgpu::Queue,
surface_config: wgpu::SurfaceConfiguration,
render_pipeline: wgpu::RenderPipeline,
+ square_vertex_buffer: wgpu::Buffer,
+ square_vertices: u32,
window: Window,
}
@@ -100,7 +104,7 @@ impl Renderer {
None,
)
.block_on()
- .unwrap();
+ .expect("there was no device with the selected features");
// configuration for the surface
let surface_config = config.to_surface_configuration(
@@ -124,7 +128,7 @@ impl Renderer {
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
- buffers: &[],
+ buffers: &[Vertex::desc()],
},
// information about the fragment shader
fragment: Some(wgpu::FragmentState {
@@ -156,12 +160,25 @@ impl Renderer {
multiview: None,
});
+ // the vertex buffer used for rendering squares
+ let square_vertices = SQUARE
+ .len()
+ .try_into()
+ .expect("expected fewer than 3 billion vertices in a square");
+ let square_vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some("Square Vertex Buffer"),
+ contents: bytemuck::cast_slice(&SQUARE),
+ usage: wgpu::BufferUsages::VERTEX,
+ });
+
Ok(Self {
surface,
device,
queue,
surface_config,
render_pipeline,
+ square_vertex_buffer,
+ square_vertices,
window,
})
}
@@ -214,7 +231,8 @@ impl Renderer {
});
render_pass.set_pipeline(&self.render_pipeline);
- render_pass.draw(0..4, 0..1);
+ render_pass.set_vertex_buffer(0, self.square_vertex_buffer.slice(..));
+ render_pass.draw(0..self.square_vertices, 0..1);
}
// the encoder can't finish building the command buffer until the
// render pass is dropped