Struct truck_platform::Scene[][src]

pub struct Scene { /* fields omitted */ }

Wraps wgpu and provides an intuitive graphics API.

Scene is the most important in truck-platform. This structure holds information about rendering and serves as a bridge to the actual rendering of Rendered objects.

Implementations

impl Scene[src]

pub fn new(device_handler: DeviceHandler, scene_desc: &SceneDescriptor) -> Scene[src]

constructor

pub fn device_handler(&self) -> &DeviceHandler[src]

Returns the reference of its own DeviceHandler.

pub fn device(&self) -> &Arc<Device>[src]

Returns the reference of the device.

pub fn queue(&self) -> &Arc<Queue>[src]

Returns the reference of the queue.

pub fn sc_desc(&self) -> SwapChainDescriptor[src]

Returns the copy of swap chain descriptor.

pub fn lock_sc_desc(&self) -> LockResult<MutexGuard<'_, SwapChainDescriptor>>[src]

Locks the swap chain descriptor.

pub fn elapsed(&self) -> Duration[src]

Returns the elapsed time since the scene was created.

pub fn descriptor(&self) -> &SceneDescriptor[src]

Returns the reference of the descriptor.

pub fn descriptor_mut(&mut self) -> &mut SceneDescriptor[src]

Returns the mutable reference of the descriptor.

pub fn bind_group_layout(&self) -> &BindGroupLayout[src]

Returns the bind group layout in the scene.

pub fn camera_buffer(&self) -> BufferHandler[src]

Creates a UNIFORM buffer of the camera.

The bind group provides Scene holds this uniform buffer.

Shader Example

layout(set = 0, binding = 0) uniform Camera {
    mat4 camera_matrix;     // the camera matrix
    mat4 camera_projection; // the projection into the normalized view volume
};

pub fn lights_buffer(&self) -> BufferHandler[src]

Creates a STORAGE buffer of all lights.

The bind group provides Scene holds this uniform buffer.

Shader Example

struct Light {
    vec4 position;      // the position of light, position.w == 1.0
    vec4 color;         // the color of light, color.w == 1.0
    uvec4 light_type;   // Point => uvec4(0, 0, 0, 0), Uniform => uvec4(1, 0, 0, 0)
};

layout(set = 0, binding = 1) buffer Lights {
    Light lights[]; // the number of lights must be gotten from another place
};

pub fn scene_status_buffer(&self) -> BufferHandler[src]

Creates a UNIFORM buffer of the scene status.

The bind group provides Scene holds this uniform buffer.

Shader Example

layout(set = 0, binding = 2) uniform Scene {
    float time;     // elapsed time since the scene was created.
    uint nlights;   // the number of lights
};

pub fn scene_bind_group(&self) -> BindGroup[src]

Creates bind group.

Shader Examples

Suppose binded as set = 0.

layout(set = 0, binding = 0) uniform Camera {
    mat4 camera_matrix;     // the camera matrix
    mat4 camera_projection; // the projection into the normalized view volume
};

struct Light {
    vec4 position;      // the position of light, position.w == 1.0
    vec4 color;         // the color of light, color.w == 1.0
    uvec4 light_type;   // Point => uvec4(0, 0, 0, 0), Uniform => uvec4(1, 0, 0, 0)
};

layout(set = 0, binding = 1) buffer Lights {
    Light lights[];
};

layout(set = 0, binding = 2) uniform Scene {
    float time;     // elapsed time since the scene was created.
    uint nlights;   // the number of lights
};

pub fn add_object<R: Rendered>(&mut self, object: &R) -> bool[src]

Adds a render object to the scene.

If there already exists a render object with the same ID, replaces the render object and returns false.

pub fn add_objects<'a, R, I>(&mut self, objects: I) -> bool where
    R: 'a + Rendered,
    I: IntoIterator<Item = &'a R>, 
[src]

Adds render objects to the scene.

If there already exists a render object with the same ID, replaces the render object and returns false.

pub fn remove_object<R: Rendered>(&mut self, object: &R) -> bool[src]

Removes a render object from the scene.

If there does not exist the render object in the scene, does nothing and returns false.

pub fn remove_objects<'a, R, I>(&mut self, objects: I) -> bool where
    R: 'a + Rendered,
    I: IntoIterator<Item = &'a R>, 
[src]

Removes render objects from the scene.

If there exists a render object which does not exist in the scene, returns false.

pub fn clear_objects(&mut self)[src]

Removes all render objects from the scene.

pub fn number_of_objects(&self) -> usize[src]

Returns the number of the render objects in the scene.

pub fn update_vertex_buffer<R: Rendered>(&mut self, object: &R) -> bool[src]

Syncronizes the information of vertices of object in the CPU memory and that in the GPU memory.

If there does not exist the render object in the scene, does nothing and returns false.

pub fn update_vertex_buffers<'a, R, I>(&mut self, objects: I) -> bool where
    R: 'a + Rendered,
    I: IntoIterator<Item = &'a R>, 
[src]

Syncronizes the information of vertices of objects in the CPU memory and that in the GPU memory.

If there exists a render object which does not exist in the scene, returns false.

pub fn update_bind_group<R: Rendered>(&mut self, object: &R) -> bool[src]

Syncronizes the information of bind group of object in the CPU memory and that in the GPU memory.

If there does not exist the render object in the scene, does nothing and returns false.

pub fn update_bind_groups<'a, R, I>(&mut self, objects: I) -> bool where
    R: 'a + Rendered,
    I: IntoIterator<Item = &'a R>, 
[src]

Syncronizes the information of bind group of object in the CPU memory and that in the GPU memory.

If there exists a render object which does not exist in the scene, returns false.

pub fn update_pipeline<R: Rendered>(&mut self, object: &R) -> bool[src]

Syncronizes the information of pipeline of object in the CPU memory and that in the GPU memory.

If there does not exist the render object in the scene, does nothing and returns false.

pub fn update_pipelines<'a, R, I>(&mut self, objects: I) -> bool where
    R: 'a + Rendered,
    I: IntoIterator<Item = &'a R>, 
[src]

Syncronizes the information of pipeline of object in the CPU memory and that in the GPU memory.

If there exists a render object which does not exist in the scene, returns false.

pub fn render_scene(&mut self, view: &TextureView)[src]

Renders the scene to view.

Trait Implementations

impl Debug for Scene[src]

Auto Trait Implementations

impl !RefUnwindSafe for Scene

impl Send for Scene

impl Sync for Scene

impl Unpin for Scene

impl !UnwindSafe for Scene

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.