#[repr(C)]pub struct Vertex {
pub position: [f32; 3],
pub tex_coords: [f32; 2],
pub normal: [f32; 3],
}Expand description
A rust representation of what a Vertex that is passed to mesh and onto WGPU and its shaders.
Fields§
§position: [f32; 3]§tex_coords: [f32; 2]§normal: [f32; 3]Implementations§
Source§impl Vertex
impl Vertex
Sourcepub fn desc() -> VertexBufferLayout<'static>
pub fn desc() -> VertexBufferLayout<'static>
Examples found in repository?
examples/test_components.rs (line 61)
41 fn create(engine: &mut RenderEngine) -> Self {
42 // generate camera
43 let mut camera = Camera::new(
44 &engine,
45 engine.config.width as f32 / engine.config.height as f32,
46 45.0, 0.1, 100.0
47 );
48 camera.position = (0.0, 0.0, 5.0).into();
49 camera.update(engine);
50
51 // create instances
52 let instances = vec![Transform {
53 position: cgmath::Vector3 { x: 0.0, y: 0.0, z: 0.0 },
54 rotation: cgmath::Quaternion::euler_deg_z(0.0),
55 scale: (1.0, 1.0, 1.0).into()
56 }];
57
58 engine.verify_pipeline_exists("forte.test", |engine| {
59 Pipeline::new(
60 "std", &engine, include_str!("rotating_cube.wgsl"),
61 &[Vertex::desc(), TransformRaw::desc()],
62 &[
63 &engine.device.create_bind_group_layout(&Camera::BIND_LAYOUT),
64 &engine.device.create_bind_group_layout(&Texture::BIND_LAYOUT),
65 ],
66 true
67 )
68 });
69
70 Self {
71 instance_buffer: TransformRaw::buffer_from_generic(engine, &instances),
72 mesh: engine.create_mesh("test", VERTICES, INDICES),
73 texture: engine.create_texture("test", include_bytes!("rotating_cube.png")),
74 camera, instances,
75 test: "".to_string()
76 }
77 }More examples
examples/rotating_cube.rs (line 50)
46 fn create(mut engine: RenderEngine) -> Self {
47 // create render pipeline
48 let pipeline = Pipeline::new(
49 "std", &engine, include_str!("rotating_cube.wgsl"),
50 &[Vertex::desc(), TransformRaw::desc()],
51 &[
52 &engine.device.create_bind_group_layout(&Camera::BIND_LAYOUT),
53 &engine.device.create_bind_group_layout(&Texture::BIND_LAYOUT),
54 ],
55 true
56 );
57
58 // generate camera
59 let mut camera = Camera::new(
60 &engine,
61 engine.config.width as f32 / engine.config.height as f32,
62 45.0, 0.1, 100.0
63 );
64 camera.position = (0.0, 0.0, 5.0).into();
65 camera.update(&mut engine);
66 let camera_controller = CameraController::new(0.02);
67
68 // create instances
69 let instances = vec![Transform {
70 position: cgmath::Vector3 { x: 0.0, y: 0.0, z: 0.0 },
71 rotation: cgmath::Quaternion::from_axis_angle(cgmath::Vector3::unit_z(), cgmath::Deg(0.0)),
72 scale: (1.0, 1.0, 1.0).into()
73 }];
74
75 // create instance buffer
76 let instance_data = instances.iter().map(TransformRaw::from_generic).collect::<Vec<_>>();
77 let instance_buffer = engine.device.create_buffer_init(
78 &wgpu::util::BufferInitDescriptor {
79 label: Some("Instance Buffer"),
80 contents: bytemuck::cast_slice(&instance_data),
81 usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST
82 }
83 );
84
85 let mesh = engine.create_mesh("test", VERTICES, INDICES);
86 let texture = engine.create_texture("test", include_bytes!("rotating_cube.png"));
87
88 // create instance of self
89 Self {
90 render_engine: engine,
91 mesh, texture,
92 camera, pipeline,
93 controller: camera_controller,
94 instances, instance_buffer
95 }
96 }Trait Implementations§
impl Copy for Vertex
impl Pod for Vertex
Auto Trait Implementations§
impl Freeze for Vertex
impl RefUnwindSafe for Vertex
impl Send for Vertex
impl Sync for Vertex
impl Unpin for Vertex
impl UnwindSafe for Vertex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.