Skip to main content

GlVertexArray

Struct GlVertexArray 

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

A vertex array object: the recorded bundle of buffer bindings and vertex attribute formats.

Binding a VAO replaces up to a dozen bindBuffer / enableVertexAttribArray / vertexAttribPointer calls with one, which is what makes per-mesh draw state cheap enough to change on every draw call.

Implementations§

Source§

impl GlVertexArray

Implements vertex array binding and attribute description.

§Performance

Everything a draw needs to know about its vertex data, which buffer feeds which attribute at what stride and offset and how far each instance advances, is recorded once into the array object. A draw then costs one bindVertexArray instead of roughly three calls per attribute, which is what makes it affordable to change mesh between draws in the same frame.

Source

pub fn create(context: &WebGl2RenderingContext) -> Option<GlVertexArray>

Allocates an unbound vertex array object.

§Arguments
  • &WebGl2RenderingContext - The context to allocate against.
§Returns
  • Option<GlVertexArray> - The allocated array object, or None when the driver refused to create one.
Source

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

Makes the array object current, so subsequent attribute and buffer bindings are recorded into it rather than into the context’s default state.

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

pub fn set_layout( &self, context: &WebGl2RenderingContext, buffer: &GlBuffer, layout: &VertexBufferLayout, )

Binds buffer and describes every attribute in layout against it.

A layout whose step mode is Instance sets a per-attribute divisor of one, which is what makes WebGl2Backend::draw_elements_instanced advance the buffer once per instance rather than once per vertex. The divisor is set on every attribute rather than assumed fresh, because reusing an attribute index with a different step mode would otherwise inherit the previous divisor.

§Arguments
  • &WebGl2RenderingContext - The context to record into.
  • &GlBuffer - The buffer the attributes read from.
  • &VertexBufferLayout - The stride, step mode, and attribute list to record.
Source

pub fn set_instance_layout( &self, context: &WebGl2RenderingContext, buffer: &GlBuffer, layout: &VertexBufferLayout, )

Binds a second buffer and describes the attributes that read from it, leaving the ones already recorded alone.

The case a single buffer cannot express is a mesh whose positions advance per vertex while its per-instance transforms live in a separate buffer. One VAO records one array-buffer binding, so the second buffer is bound and described inside the same VAO.

§Arguments
  • &WebGl2RenderingContext - The context to record into.
  • &GlBuffer - The buffer the attributes read from.
  • &VertexBufferLayout - The attributes to record, whose step mode should be Instance.
Source

pub fn set_divisor( &self, context: &WebGl2RenderingContext, index: u32, divisor: u32, )

Records an explicit per-attribute divisor, overriding whatever the layout’s step mode implied.

§Arguments
  • &WebGl2RenderingContext - The context to record into.
  • u32 - The attribute index, as recorded on the layout.
  • u32 - The divisor: zero per vertex, one per instance.
Source

pub fn unbind(context: &WebGl2RenderingContext)

Unbinds the array object, restoring the context’s default vertex state.

Worth calling before a draw that reads no vertex data at all, a full-screen triangle generated from gl_VertexID say, because leaving an array object bound would keep its attribute buffers alive in the driver’s state.

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

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

Releases the array object’s recorded state.

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

impl GlVertexArray

Source

pub fn get_vao(&self) -> &WebGlVertexArrayObject

Source

pub fn get_mut_vao(&mut self) -> &mut WebGlVertexArrayObject

Source

pub fn set_vao(&mut self, val: WebGlVertexArrayObject) -> &mut Self

Trait Implementations§

Source§

impl Clone for GlVertexArray

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 GlVertexArray

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