[][src]Struct web_glitz::buffer::Buffer

pub struct Buffer<T> where
    T: ?Sized
{ /* fields omitted */ }

A GPU-accessible memory buffer that contains typed data.

Example

use web_glitz::buffer::{Buffer, UsageHint};

let buffer: Buffer<[f32]> = context.create_buffer([1.0, 2.0, 3.0, 4.0], UsageHint::StreamDraw);

A buffer can be created with any data that implements IntoBuffer.

Implementations

impl<T> Buffer<T> where
    T: ?Sized
[src]

pub fn usage_hint(&self) -> UsageHint[src]

Returns the UsageHint that was specified for this Buffer when it was created.

See UsageHint for details.

impl<T> Buffer<T> where
    T: Copy
[src]

pub fn upload_command<D>(&self, data: D) -> UploadCommand<T, D> where
    D: Borrow<T> + Send + Sync + 'static, 
[src]

Returns a command which, when executed will replace the data contained in this Buffer with the given data.

pub fn download_command(&self) -> DownloadCommand<T>[src]

Returns a command which, when executed will copy the data contained in this Buffer into a Box.

When the task is finished, the Box containing the copied data will be output.

impl<T> Buffer<MaybeUninit<T>>[src]

pub unsafe fn assume_init(self) -> Buffer<T>[src]

Converts to Buffer<T>.

Safety

Any tasks that read from the buffer after assume_init was called, must only be executed after the buffer was initialized. Note that certain tasks may wait on GPU fences and allow a runtime to progress other tasks while its waiting on the fence. As such, submitting your initialization tasks as part of a task that includes fencing (these are typically tasks that include "download" commands), may not guarantee that the buffer was initialized before any tasks that are submitted later will begin executing.

impl<T> Buffer<[T]>[src]

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

Returns the number of elements contained in this Buffer.

pub fn get<I>(&self, index: I) -> Option<BufferView<'_, I::Output>> where
    I: BufferSliceIndex<T>, 
[src]

Returns a BufferView on an element or a slice of the elements this Buffer, depending on the type of index.

  • If given a position, returns a view on the element at that position or None if out of bounds.
  • If given a range, returns a view on the slice of elements corresponding to that range, or None if out of bounds.

Examples

use web_glitz::buffer::UsageHint;

let buffer = context.create_buffer([1.0, 2.0, 3.0, 4.0], UsageHint::StreamDraw);

buffer.get(1); // Some BufferView<f32> containing `2.0`
buffer.get(1..3); // Some BufferView<[f32]> containing `[2.0, 3.0]`
buffer.get(..2); // Some BufferView<[f32]> containing `[1.0 2.0]`
buffer.get(4); // None (index out of bounds)

pub unsafe fn get_unchecked<I>(&self, index: I) -> BufferView<'_, I::Output> where
    I: BufferSliceIndex<T>, 
[src]

Returns a BufferView on an element or a slice of the elements this Buffer, depending on the type of index, without doing bounds checking.

  • If given a position, returns a view on the element at that position, without doing bounds checking.
  • If given a range, returns a view on the slice of elements corresponding to that range, without doing bounds checking.

Examples

use web_glitz::buffer::UsageHint;

let buffer = context.create_buffer([1.0, 2.0, 3.0, 4.0], UsageHint::StreamDraw);

unsafe { buffer.get_unchecked(1) }; // BufferView<f32> containing `2.0`

Unsafe

Only safe if index is in bounds. See [get] for a safe alternative.

impl<T> Buffer<[T]> where
    T: Copy
[src]

pub fn upload_command<D>(&self, data: D) -> UploadCommand<[T], D> where
    D: Borrow<[T]> + Send + Sync + 'static, 
[src]

Returns a command which, when executed will replace the elements contained in this Buffer with the elements in given data.

If the data contains fewer elements than this Buffer, then only the first N elements will be replaced, where N is the number of elements in the given data.

If the data contains more elements than this Buffer, then only the first M elements in the data will be used to update this Buffer, where M is the number of elements in the Buffer.

pub fn download_command(&self) -> DownloadCommand<[T]>[src]

Returns a command which, when executed will copy the elements contained in this Buffer into a Box as a boxed slice.

When the task is finished, the Box containing the copied data will be output.

impl<T> Buffer<[MaybeUninit<T>]>[src]

pub unsafe fn assume_init(self) -> Buffer<[T]>[src]

Converts to Buffer<[T]>.

Safety

Any tasks that read from the buffer after assume_init was called, must only be executed after the buffer was initialized. Note that certain tasks may wait on GPU fences and allow a runtime to progress other tasks while its waiting on the fence. As such, submitting your initialization tasks as part of a task that includes fencing (these are typically tasks that include "download" commands), may not guarantee that the buffer was initialized before any tasks that are submitted later will begin executing.

Trait Implementations

impl<'a, T, const LEN: usize> From<&'a Buffer<[T; LEN]>> for BufferView<'a, [T]>[src]

impl<'a, T> From<&'a Buffer<T>> for BufferView<'a, T> where
    T: ?Sized
[src]

impl<'a, T, const LEN: usize> From<&'a mut Buffer<[T; LEN]>> for BufferView<'a, [T]>[src]

impl<'a, T, const LEN: usize> From<&'a mut Buffer<[T; LEN]>> for BufferViewMut<'a, [T]>[src]

impl<'a, T> From<&'a mut Buffer<T>> for BufferView<'a, T> where
    T: ?Sized
[src]

impl<'a, T> From<&'a mut Buffer<T>> for BufferViewMut<'a, T> where
    T: ?Sized
[src]

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

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

impl<'a, T> Resource for &'a Buffer<T> where
    T: InterfaceBlock
[src]

type Encoding = BufferView<'a, T>

impl<'a, T> TransformFeedbackBuffer for &'a mut Buffer<[T]>[src]

impl<'a, T> TypedTransformFeedbackBuffer for &'a mut Buffer<[T]> where
    T: TransformFeedback
[src]

impl<T> TypedVertexBuffer for Buffer<[T]> where
    T: Vertex
[src]

type Vertex = T

impl<'a, T> TypedVertexBuffer for &'a Buffer<[T]> where
    T: Vertex
[src]

type Vertex = T

impl<'a, T> TypedVertexBuffer for &'a mut Buffer<[T]> where
    T: Vertex
[src]

type Vertex = T

impl<T> VertexBuffer for Buffer<[T]>[src]

impl<'a, T> VertexBuffer for &'a Buffer<[T]>[src]

impl<'a, T> VertexBuffer for &'a mut Buffer<[T]>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Buffer<T>

impl<T> !Send for Buffer<T>

impl<T> !Sync for Buffer<T>

impl<T: ?Sized> Unpin for Buffer<T>

impl<T> !UnwindSafe for Buffer<T>

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, U> Into<U> for T where
    U: From<T>, 
[src]

impl<D, T> IntoBuffer<T> for D where
    D: Borrow<T> + 'static,
    T: Copy + 'static, 
[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.