Vertex

Struct Vertex 

Source
#[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

Source

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
Hide additional 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§

Source§

impl Clone for Vertex

Source§

fn clone(&self) -> Vertex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Vertex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Zeroable for Vertex

Source§

fn zeroed() -> Self

Source§

impl Copy for Vertex

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

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

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,