summaryrefslogtreecommitdiff
path: root/games/00_triangle/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'games/00_triangle/src/main.rs')
-rw-r--r--games/00_triangle/src/main.rs54
1 files changed, 53 insertions, 1 deletions
diff --git a/games/00_triangle/src/main.rs b/games/00_triangle/src/main.rs
index fd4a166..e9de614 100644
--- a/games/00_triangle/src/main.rs
+++ b/games/00_triangle/src/main.rs
@@ -15,6 +15,7 @@ pub struct State {
config: wgpu::SurfaceConfiguration,
is_surface_configured: bool,
window: Arc<Window>,
+ render_pipeline: wgpu::RenderPipeline,
}
impl State {
@@ -70,12 +71,60 @@ impl State {
color_space: wgpu::SurfaceColorSpace::Auto,
};
+ let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));
+
+ let render_pipeline_layout =
+ device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: Some("Render Pipeline Layout"),
+ bind_group_layouts: &[],
+ immediate_size: 0,
+ });
+
+ let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
+ label: Some("Render Pipeline"),
+ layout: Some(&render_pipeline_layout),
+ vertex: wgpu::VertexState {
+ module: &shader,
+ entry_point: Some("vs_main"),
+ buffers: &[],
+ compilation_options: wgpu::PipelineCompilationOptions::default(),
+ },
+ fragment: Some(wgpu::FragmentState {
+ module: &shader,
+ entry_point: Some("fs_main"),
+ targets: &[Some(wgpu::ColorTargetState {
+ format: config.format,
+ blend: Some(wgpu::BlendState::REPLACE),
+ write_mask: wgpu::ColorWrites::ALL,
+ })],
+ compilation_options: wgpu::PipelineCompilationOptions::default(),
+ }),
+ primitive: wgpu::PrimitiveState {
+ topology: wgpu::PrimitiveTopology::TriangleList,
+ strip_index_format: None,
+ front_face: wgpu::FrontFace::Ccw,
+ cull_mode: Some(wgpu::Face::Back),
+ polygon_mode: wgpu::PolygonMode::Fill,
+ unclipped_depth: false,
+ conservative: false,
+ },
+ depth_stencil: None,
+ multisample: wgpu::MultisampleState {
+ count: 1,
+ mask: !0,
+ alpha_to_coverage_enabled: false,
+ },
+ multiview_mask: None,
+ cache: None,
+ });
+
Ok(Self {
surface,
device,
queue,
config,
is_surface_configured: false,
+ render_pipeline,
window,
})
}
@@ -132,7 +181,7 @@ impl State {
});
{
- let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
+ let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
@@ -153,6 +202,9 @@ impl State {
timestamp_writes: None,
multiview_mask: None,
});
+
+ render_pass.set_pipeline(&self.render_pipeline);
+ render_pass.draw(0..3, 0..1);
}
self.queue.submit(std::iter::once(encoder.finish()));