|
|
@@ -1,5 +1,6 @@
|
|
|
use std::iter;
|
|
|
|
|
|
+use wgpu::{util::DeviceExt, BlendState, ColorTargetState, PipelineLayoutDescriptor, RenderPipelineDescriptor};
|
|
|
use winit::{
|
|
|
event::*,
|
|
|
event_loop::EventLoop,
|
|
|
@@ -16,6 +17,8 @@ struct State<'a> {
|
|
|
queue: wgpu::Queue,
|
|
|
config: wgpu::SurfaceConfiguration,
|
|
|
size: winit::dpi::PhysicalSize<u32>,
|
|
|
+ render_pipeline : wgpu::RenderPipeline,
|
|
|
+ vertex_buffer: wgpu::Buffer,
|
|
|
// The window must be declared after the surface so
|
|
|
// it gets dropped after it as the surface contains
|
|
|
// unsafe references to the window's resources.
|
|
|
@@ -87,8 +90,68 @@ impl<'a> State<'a> {
|
|
|
view_formats: vec![],
|
|
|
};
|
|
|
|
|
|
+ let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
|
|
+ label: Some("Shader 1 from shader.wgsl"),
|
|
|
+ source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor{
|
|
|
+ label: Some("Pipeline Layout"),
|
|
|
+ bind_group_layouts: &[
|
|
|
+
|
|
|
+ ],
|
|
|
+ push_constant_ranges: &[]
|
|
|
+ });
|
|
|
+
|
|
|
+ let render_pipeline = device.create_render_pipeline(&RenderPipelineDescriptor{
|
|
|
+ label: Some("RenderPipeline"),
|
|
|
+ layout: Some(&pipeline_layout),
|
|
|
+ vertex: wgpu::VertexState {
|
|
|
+ module: &shader,
|
|
|
+ entry_point: "@vertex",
|
|
|
+ buffers: &[
|
|
|
+ Vertex::desc(),
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ primitive: wgpu::PrimitiveState{
|
|
|
+ topology: wgpu::PrimitiveTopology::TriangleList,
|
|
|
+ strip_index_format: None,
|
|
|
+ front_face: wgpu::FrontFace::Ccw,
|
|
|
+ cull_mode: Some(wgpu::Face::Back),
|
|
|
+ unclipped_depth: false,
|
|
|
+ polygon_mode: wgpu::PolygonMode::Line,
|
|
|
+ conservative: false
|
|
|
+ },
|
|
|
+ depth_stencil: None,
|
|
|
+ multisample: wgpu::MultisampleState{
|
|
|
+ count: 1,
|
|
|
+ mask: !0,
|
|
|
+ alpha_to_coverage_enabled: false,
|
|
|
+ },
|
|
|
+ fragment: Some(wgpu::FragmentState{
|
|
|
+ module: &shader,
|
|
|
+ entry_point: "@fragment",
|
|
|
+ targets: &[Some(ColorTargetState{
|
|
|
+ format: config.format,
|
|
|
+ blend: Some(BlendState::REPLACE),
|
|
|
+ write_mask: wgpu::ColorWrites::ALL
|
|
|
+ })]
|
|
|
+ }),
|
|
|
+ multiview: None
|
|
|
+ });
|
|
|
+ let plan1 = generate_plane();
|
|
|
+ let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
|
|
+ label: Some("Vertex Buffer 1"),
|
|
|
+ contents: bytemuck::cast_slice(todo!()),
|
|
|
+ usage: wgpu::BufferUsages::VERTEX,
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
Self {
|
|
|
surface,
|
|
|
+ vertex_buffer,
|
|
|
+ render_pipeline,
|
|
|
device,
|
|
|
queue,
|
|
|
config,
|
|
|
@@ -130,7 +193,7 @@ impl<'a> State<'a> {
|
|
|
});
|
|
|
|
|
|
{
|
|
|
- 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,
|
|
|
@@ -149,6 +212,8 @@ impl<'a> State<'a> {
|
|
|
occlusion_query_set: None,
|
|
|
timestamp_writes: None,
|
|
|
});
|
|
|
+ render_pass.set_pipeline(&self.render_pipeline);
|
|
|
+ //render_pass.draws
|
|
|
}
|
|
|
|
|
|
self.queue.submit(iter::once(encoder.finish()));
|