Skip to main content

GlUniformBlock

Struct GlUniformBlock 

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

A uniform buffer bound to a numbered binding point.

WebGL 2 has no bind groups: the equivalent of a var<uniform> block is a WebGlBuffer bound to UNIFORM_BUFFER at a binding index the shader agrees on. This holds both halves of that agreement, the buffer and the binding point, so swapping programs cannot leave the two out of sync.

Implementations§

Source§

impl GlUniformBlock

Implements allocation, record upload, and binding-point management for a uniform buffer.

§Performance

The capacity check mirrors GlBuffer’s, so a block whose record count grows re-orphans rather than reallocating. Updating one record at a fixed offset is what makes a per-object transform upload possible without rewriting the whole block.

Source

pub fn create( context: &WebGl2RenderingContext, size: u32, binding: u32, ) -> Option<GlUniformBlock>

Allocates a uniform buffer of at least size bytes and binds it to binding.

§Arguments
  • &WebGl2RenderingContext - The context to allocate against.
  • u32 - The byte capacity to reserve.
  • u32 - The binding point the shader reads from.
§Returns
  • Option<GlUniformBlock> - The allocated block, or None when the driver refused to create one.
Source

pub fn bind(&self, context: &WebGl2RenderingContext)

Binds the block’s buffer to its recorded binding point.

§Arguments
  • &WebGl2RenderingContext - The context to bind against.
Source

pub fn update( &mut self, context: &WebGl2RenderingContext, offset: u32, data: &[u8], ) -> bool

Writes data at offset bytes, re-allocating only if the write would outgrow the block.

§Arguments
  • &WebGl2RenderingContext - The context to upload through.
  • u32 - The byte offset to write at.
  • &[u8] - The bytes to write.
§Returns
  • bool - true when the write was issued.
Source

pub fn set_mat4( &mut self, context: &WebGl2RenderingContext, offset: u32, matrix: &Matrix4x4, ) -> bool

Writes one Matrix4x4 into the record at offset, in bytes.

The conversion goes through a fixed-size stack array rather than a heap one, so uploading a per-object transform costs no allocation. The bound is checked rather than trusted, because an out-of-range offset would otherwise hand the driver a sub-range write that silently truncates the transform.

§Arguments
  • &WebGl2RenderingContext - The context to upload through.
  • u32 - The byte offset of the record to write.
  • &Matrix4x4 - The transform to upload.
§Returns
  • bool - true when the record fit inside the block.
Source

pub fn delete(&mut self, context: &WebGl2RenderingContext)

Releases the block’s buffer.

§Arguments
  • &WebGl2RenderingContext - The context to release against.
Source§

impl GlUniformBlock

Source

pub fn get_buffer(&self) -> &WebGlBuffer

Source

pub fn get_mut_buffer(&mut self) -> &mut WebGlBuffer

Source

pub fn set_buffer(&mut self, val: WebGlBuffer) -> &mut Self

Source

pub fn get_binding(&self) -> u32

Source

pub fn get_mut_binding(&mut self) -> &mut u32

Source

pub fn set_binding(&mut self, val: u32) -> &mut Self

Source

pub fn get_capacity(&self) -> u32

Source

pub fn get_mut_capacity(&mut self) -> &mut u32

Source

pub fn set_capacity(&mut self, val: u32) -> &mut Self

Trait Implementations§

Source§

impl Clone for GlUniformBlock

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 GlUniformBlock

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more