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.
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.
Sourcepub fn create(context: &WebGl2RenderingContext) -> Option<GlVertexArray>
pub fn create(context: &WebGl2RenderingContext) -> Option<GlVertexArray>
Sourcepub fn bind(&self, context: &WebGl2RenderingContext)
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.
Sourcepub fn set_layout(
&self,
context: &WebGl2RenderingContext,
buffer: &GlBuffer,
layout: &VertexBufferLayout,
)
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.
Sourcepub fn set_instance_layout(
&self,
context: &WebGl2RenderingContext,
buffer: &GlBuffer,
layout: &VertexBufferLayout,
)
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 beInstance.
Sourcepub fn set_divisor(
&self,
context: &WebGl2RenderingContext,
index: u32,
divisor: u32,
)
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.
Sourcepub fn unbind(context: &WebGl2RenderingContext)
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.
Sourcepub fn delete(&self, context: &WebGl2RenderingContext)
pub fn delete(&self, context: &WebGl2RenderingContext)
Releases the array object’s recorded state.
§Arguments
&WebGl2RenderingContext- The context to release against.