Skip to main content

Context

Struct Context 

Source
pub struct Context(/* private fields */);
Expand description

The main dunge context.

Implementations§

Source§

impl Context

Source

pub fn make_shader<I, S>(&self, render: Render<I, S>) -> Shader<I, S>

Source

pub fn make_set<I, G, const N: usize>( &self, shader: &Shader<I, G::Inner>, set: G, ) -> UniqueSet<G::Inner>
where G: Groups<N>,

Source

pub fn make_uniform<V>(&self, value: &V) -> Uniform<V>
where V: Value + Bytes,

Creates a uniform from the given value.

Source

pub fn make_storage<V>(&self, value: &V) -> Option<Storage<V>>
where V: StorageValue + ?Sized,

Creates a storage from the given value.

Source

pub fn make_layer<V, I, S, C>( &self, shader: &RenderShader<S, V, I>, conf: C, ) -> Layer<Input<V, I, S>>
where C: Into<Config>,

Creates a layer for the given render shader.

This method also accepts a config which defines the layer’s properties.

Source

pub fn make_mesh<V>(&self, data: &MeshData<'_, V>) -> Mesh<V>
where V: Bytes,

Creates a mesh with the given data.

Source

pub fn make_row<V>(&self, value: &[V]) -> Option<Row<V>>
where V: Value + Bytes,

Creates a row with the given data.

Source

pub fn make_texture<U>(&self, data: TextureData<'_, U>) -> TextureBuffer<2, U>
where U: TextureUsages,

Creates a 2D texture with the given data.

Source

pub fn make_sampler(&self, filter: Filter) -> TextureSampler

Creates a sampler with the filter value.

Source

pub fn make_buffer<U>(&self, data: BufferData<'_, U>) -> Buffer<U>
where U: BufferUsages,

Creates a buffer with the given data.

§Examples
use dunge::buffer::BufferData;

let cx = dunge::context().await?;

// Create a buffer filled with four `i32` numbers
let data = BufferData::new(&[1, 2, 3, 4])
    .read()     // set a usage to read from the buffer
    .copy_to(); // set a usage to copy to the buffer

let buffer = cx.make_buffer(data);
Source

pub async fn read<'buf, U>( &self, buf: &'buf mut Buffer<U>, ) -> Result<Read<'buf>, ReadFailed>
where U: Read,

Reads from a buffer.

Source

pub async fn write<'buf, U>( &self, buf: &'buf mut Buffer<U>, ) -> Result<Write<'buf>, WriteFailed>
where U: Write,

Writes to a buffer.

Source

pub async fn shed<F>(&self, f: F)
where F: FnOnce(&mut Scheduler),

Runs a closure that schedules GPU work.

The closure receives a scheduler object capable of scheduling various GPU operations, such as rendering, compute, or data copying. All scheduled operations will begin executing as soon as possible. This function is asynchronous and awaiting it will wait until all scheduled operations have completed.

§Examples

Typical window render loop:

use dunge::Options;

let cx = dunge::context().await?;
let (window, layer, mesh) = ..

loop {
    let redraw = window.redraw().await;

    cx.shed(|s| {
        let opts = Options::default();
        s.render(&redraw, opts).layer(&layer).draw(&mesh);
    })
    .await;

    redraw.present();
}

See the render function for more details.

Source

pub fn update_group<S, G, const N: usize>( &self, set: &mut UniqueSet<S>, handler: &GroupHandler<G::Inner, N>, group: G, )
where S: Nth<N, Output = G::Inner>, G: Group,

Source

pub fn wgpu_info(&self) -> AdapterInfo

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Context

Source§

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

Formats the value using the given formatter. Read more

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<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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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