|
@@ -3,7 +3,7 @@ use std::iter;
|
|
|
use wgpu::util::DeviceExt;
|
|
use wgpu::util::DeviceExt;
|
|
|
use winit::{event::WindowEvent, window::Window};
|
|
use winit::{event::WindowEvent, window::Window};
|
|
|
|
|
|
|
|
-use crate::{camera::{self, Camera}, camera_controller, camera_uniform, fps::Fps, vertex::Vertex, vertex_buffer::{VERT2, VERT3, VERTICES}};
|
|
|
|
|
|
|
+use crate::{camera::{self, Camera}, camera_controller, camera_uniform, fps::Fps, geometry_utils::{subdivide_plane2, Vertex3}, vertex::{Vertex, Vertex2}, vertex_buffer::{subdivide_plane, VERT2, VERT3, VERTICES}};
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct State<'a> {
|
|
pub struct State<'a> {
|
|
@@ -92,14 +92,34 @@ impl<'a> State<'a> {
|
|
|
surface.configure(&device, &config);
|
|
surface.configure(&device, &config);
|
|
|
//All the above is just for the surface
|
|
//All the above is just for the surface
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- let vert = VERT3;
|
|
|
|
|
- let num_vertices = vert.len() as u32;
|
|
|
|
|
|
|
+ const INITIAL_VERTICES: &[Vertex3] = &[
|
|
|
|
|
+ Vertex3 { position: [-1.0, -1.0, 0.0] }, // Bottom-left corner
|
|
|
|
|
+ Vertex3 { position: [1.0, -1.0, 0.0] }, // Bottom-right corner
|
|
|
|
|
+ Vertex3 { position: [-1.0, 1.0, 0.0] }, // Top-left corner
|
|
|
|
|
+ Vertex3 { position: [1.0, 1.0, 0.0] }, // Top-right corner
|
|
|
|
|
+ ];
|
|
|
|
|
+ let (vertex_data, num_vertices) = subdivide_plane2(
|
|
|
|
|
+ &device,
|
|
|
|
|
+ INITIAL_VERTICES,
|
|
|
|
|
+ -1.0, // x_min
|
|
|
|
|
+ 1.0, // x_max
|
|
|
|
|
+ -1.0, // y_min
|
|
|
|
|
+ 1.0, // y_max
|
|
|
|
|
+ 4, // subdivision level (adjust as needed)
|
|
|
|
|
+ );
|
|
|
|
|
+ //let vert = VERT3;
|
|
|
|
|
+ //let vert = subdivide_plane(&device, vertices, x_min, x_max, y_min, y_max, level);
|
|
|
|
|
+ //let num_vertices = vert.len() as u32;
|
|
|
//Now the vertex buffer
|
|
//Now the vertex buffer
|
|
|
|
|
+ // let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
|
|
|
|
+ // label: Some("Vertex Buffer"),
|
|
|
|
|
+ // usage: wgpu::BufferUsages::VERTEX,
|
|
|
|
|
+ // contents: bytemuck::cast_slice(vert)
|
|
|
|
|
+ // });
|
|
|
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
|
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
|
|
|
label: Some("Vertex Buffer"),
|
|
label: Some("Vertex Buffer"),
|
|
|
- usage: wgpu::BufferUsages::VERTEX,
|
|
|
|
|
- contents: bytemuck::cast_slice(vert)
|
|
|
|
|
|
|
+ contents: bytemuck::cast_slice(&vertex_data),
|
|
|
|
|
+ usage: wgpu::BufferUsages::VERTEX
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
//Camera creation
|
|
//Camera creation
|
|
@@ -183,7 +203,7 @@ impl<'a> State<'a> {
|
|
|
module: &shader_module,
|
|
module: &shader_module,
|
|
|
entry_point: "vs_main",
|
|
entry_point: "vs_main",
|
|
|
buffers: &[
|
|
buffers: &[
|
|
|
- Vertex::desc()
|
|
|
|
|
|
|
+ Vertex3::desc()
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|
|
|
fragment: Some(wgpu::FragmentState {
|
|
fragment: Some(wgpu::FragmentState {
|
|
@@ -201,7 +221,7 @@ impl<'a> State<'a> {
|
|
|
primitive: wgpu::PrimitiveState {
|
|
primitive: wgpu::PrimitiveState {
|
|
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
|
|
strip_index_format: None,
|
|
strip_index_format: None,
|
|
|
- front_face: wgpu::FrontFace::Ccw,
|
|
|
|
|
|
|
+ front_face: wgpu::FrontFace::Cw,
|
|
|
cull_mode: Some(wgpu::Face::Back),
|
|
cull_mode: Some(wgpu::Face::Back),
|
|
|
// Setting this to anything other than Fill requires Features::POLYGON_MODE_LINE
|
|
// Setting this to anything other than Fill requires Features::POLYGON_MODE_LINE
|
|
|
// or Features::POLYGON_MODE_POINT
|
|
// or Features::POLYGON_MODE_POINT
|