Skip to main content

WindowScene

Struct WindowScene 

Source
pub struct WindowScene { /* private fields */ }
Expand description

Utility for wrapper

Implementations§

Source§

impl WindowScene

Source

pub async fn from_window( window: Arc<Window>, scene_desc: &WindowSceneDescriptor, ) -> Self

Initialize scene compatible with window.

Source

pub const fn window(&self) -> &Arc<Window>

Get the reference of initializing window.

Source

pub const fn surface(&self) -> &Arc<Surface<'_>>

Get the reference of surface.

Source

pub fn size_alignment(&mut self)

Adjusts the size of the backend buffers (depth or sampling buffer) to the size of the window.

Source

pub fn render_frame(&mut self)

Render scene to initializing window.

Methods from Deref<Target = Scene>§

Source

pub fn compatible_texture(&self) -> Texture

Creates compatible texture for render attachment.

§Remarks

The usage of texture is TextureUsages::RENDER_ATTACHMENT | TetureUsages::COPY_SRC.

Source

pub fn device_handler(&self) -> &DeviceHandler

Returns the reference of its own DeviceHandler.

Source

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

Returns the reference of the device.

Source

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

Returns the reference of the queue.

Source

pub fn elapsed(&self) -> Duration

Returns the elapsed time since the scene was created.

Source

pub fn descriptor(&self) -> &SceneDescriptor

Returns the reference of the descriptor.

Source

pub fn descriptor_mut(&mut self) -> SceneDescriptorMut<'_>

Returns the mutable reference of the descriptor.

§Remarks

When the return value is dropped, the depth buffer and sampling buffer are automatically updated. Use studio_config_mut if you only want to update the colors of the camera, lights, and background.

Source

pub fn studio_config(&self) -> &StudioConfig

Returns the reference of the studio configuration.

Source

pub fn studio_config_mut(&mut self) -> &mut StudioConfig

Returns the mutable reference of the studio configuration.

Source

pub fn bind_group_layout(&self) -> &BindGroupLayout

Returns the bind group layout in the scene.

Source

pub fn camera_buffer(&self) -> BufferHandler

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
};
Source

pub fn lights_buffer(&self) -> BufferHandler

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
};
Source

pub fn scene_status_buffer(&self) -> BufferHandler

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 {
    vec4 bk_color;  // color of back ground
    float time;     // elapsed time since the scene was created.
    uint nlights;   // the number of lights
};
Source

pub fn scene_bind_group(&self) -> BindGroup

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
};
Source

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

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.

Source

pub fn set_visibility<R: Rendered>(&mut self, object: &R, visible: bool) -> bool

Sets the visibility of a render object.

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

Source

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

Adds render objects to the scene.

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

Source

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

Removes a render object from the scene.

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

Source

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

Removes render objects from the scene.

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

Source

pub fn clear_objects(&mut self)

Removes all render objects from the scene.

Source

pub fn number_of_objects(&self) -> usize

Returns the number of the render objects in the scene.

Source

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

Synchronizes 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.

Source

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

Synchronizes 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.

Source

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

Synchronizes 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.

Source

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

Synchronizes 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.

Source

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

Synchronizes 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.

Source

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

Synchronizes 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.

Source

pub fn render(&self, view: &TextureView)

Renders the scene to view.

Source

pub async fn render_to_buffer(&self) -> Vec<u8>

Render image to buffer.

Trait Implementations§

Source§

impl Debug for WindowScene

Source§

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

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

impl Deref for WindowScene

Source§

type Target = Scene

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for WindowScene

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more