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.
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.
Sourcepub fn create(
context: &WebGl2RenderingContext,
size: u32,
binding: u32,
) -> Option<GlUniformBlock>
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, orNonewhen the driver refused to create one.
Sourcepub fn bind(&self, context: &WebGl2RenderingContext)
pub fn bind(&self, context: &WebGl2RenderingContext)
Binds the block’s buffer to its recorded binding point.
§Arguments
&WebGl2RenderingContext- The context to bind against.
Sourcepub fn update(
&mut self,
context: &WebGl2RenderingContext,
offset: u32,
data: &[u8],
) -> bool
pub fn update( &mut self, context: &WebGl2RenderingContext, offset: u32, data: &[u8], ) -> bool
Sourcepub fn set_mat4(
&mut self,
context: &WebGl2RenderingContext,
offset: u32,
matrix: &Matrix4x4,
) -> bool
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-truewhen the record fit inside the block.