Class
UBOCache
View sourceProvides a world resource that manages named WebGL uniform buffers for shader uniform blocks.
Use it with WebglRenderPipeline when a pipeline contains named
uniform blocks so shader reflection and buffer binding use the same names.
Examples
import { UBOCache } from '@wimaengine/render-webgl'
function registerMaterialBlock(world, gl) {
const ubos = world.getResource(UBOCache)
ubos.create(gl, 'Material', 16)
const material = ubos.get('Material')
return material?.buffer
}Constructor
Methods
create(gl: WebGL2RenderingContext, name: string, size: number): void
View sourceCreates and registers a dynamic WebGL uniform buffer.
The buffer is allocated with createBuffer as a
gl.UNIFORM_BUFFER, bound to the next available binding point, and stored
under name. Binding points start at zero and increase by one for every
call. Creating another buffer with an existing name replaces that entry
and still consumes a new binding point.
get(name: string): UBO
View sourceReturns the registered uniform-buffer metadata for a name.
The result contains the WebGL buffer, its allocated binding point, and the requested size. No buffer is created when the name is absent.
