diff --git a/examples/README.md b/examples/README.md index 0c40308d7..3174616ea 100644 --- a/examples/README.md +++ b/examples/README.md @@ -13,7 +13,7 @@ All framework-based examples render to the window. | Feature | boids | cube | mipmap | msaa-line | shadow | skybox | texture-arrays | water | | ---------------------- | ------ | ------ | ------ | --------- | ------ | ------ | -------------- | ------ | | WGSL shaders | :star: | :star: | :star: | :star: | :star: | :star: | | | -| vertex attributes | :star: | :star: | :star: | :star: | :star: | :star: | :star: | :star: | +| vertex attributes | :star: | :star: | | :star: | :star: | :star: | :star: | :star: | | instancing | :star: | | | | | | | | | lines and points | | | | :star: | | | | | | dynamic buffer offsets | | | | | :star: | | | | @@ -41,6 +41,7 @@ All framework-based examples render to the window. | - polygon mode | | :star: | | | | | | | | - queries | | | :star: | | | | | | | *integrations* | | | | | | | | | +| - typed arena | | | | | | | | | | - obj loading | | | | | | :star: | | | ## Hacking diff --git a/examples/mipmap/draw.wgsl b/examples/mipmap/draw.wgsl index 6e2c82d29..56afdd028 100644 --- a/examples/mipmap/draw.wgsl +++ b/examples/mipmap/draw.wgsl @@ -1,5 +1,5 @@ -[[location(0)]] -var in_position_vs: vec4; +[[builtin(vertex_index)]] +var in_vertex_index: u32; [[builtin(position)]] var out_position: vec4; [[location(0)]] @@ -14,8 +14,12 @@ var r_data: Locals; [[stage(vertex)]] fn vs_main() { - out_tex_coords_vs = 0.05 * in_position_vs.xy + vec2(0.5, 0.5); - out_position = r_data.transform * in_position_vs; + var pos: vec2 = vec2( + 100.0 * (1.0 - f32(in_vertex_index & 2u)), + 1000.0 * f32(in_vertex_index & 1u) + ); + out_tex_coords_vs = 0.05 * pos + vec2(0.5, 0.5); + out_position = r_data.transform * vec4(pos, 0.0, 1.0); } [[location(0)]] diff --git a/examples/mipmap/main.rs b/examples/mipmap/main.rs index 0071709e5..e2c1df571 100644 --- a/examples/mipmap/main.rs +++ b/examples/mipmap/main.rs @@ -9,30 +9,6 @@ const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; const MIP_LEVEL_COUNT: u32 = 9; const MIP_PASS_COUNT: u32 = MIP_LEVEL_COUNT - 1; -#[repr(C)] -#[derive(Clone, Copy, Pod, Zeroable)] -struct Vertex { - #[allow(dead_code)] - pos: [f32; 4], -} - -fn create_vertices() -> Vec { - vec![ - Vertex { - pos: [100.0, 0.0, 0.0, 1.0], - }, - Vertex { - pos: [100.0, 1000.0, 0.0, 1.0], - }, - Vertex { - pos: [-100.0, 0.0, 0.0, 1.0], - }, - Vertex { - pos: [-100.0, 1000.0, 0.0, 1.0], - }, - ] -} - fn create_texels(size: usize, cx: f32, cy: f32) -> Vec { use std::iter; @@ -78,7 +54,6 @@ struct QueryData { } struct Example { - vertex_buf: wgpu::Buffer, bind_group: wgpu::BindGroup, uniform_buf: wgpu::Buffer, draw_pipeline: wgpu::RenderPipeline, @@ -238,15 +213,6 @@ impl framework::Example for Example { let mut init_encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - // Create the vertex and index buffers - let vertex_size = mem::size_of::(); - let vertex_data = create_vertices(); - let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Vertex Buffer"), - contents: bytemuck::cast_slice(&vertex_data), - usage: wgpu::BufferUsage::VERTEX, - }); - // Create the texture let size = 1 << MIP_LEVEL_COUNT; let texels = create_texels(size as usize, -0.8, 0.156); @@ -330,11 +296,7 @@ impl framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", - buffers: &[wgpu::VertexBufferLayout { - array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float4], - }], + buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, @@ -464,7 +426,6 @@ impl framework::Example for Example { } Example { - vertex_buf, bind_group, uniform_buf, draw_pipeline, @@ -516,7 +477,6 @@ impl framework::Example for Example { }); rpass.set_pipeline(&self.draw_pipeline); rpass.set_bind_group(0, &self.bind_group, &[]); - rpass.set_vertex_buffer(0, self.vertex_buf.slice(..)); rpass.draw(0..4, 0..1); }