AdvancedCreate a new instance of the Bind Group.
Optionalresources: Record<string, BindResource | null>
The resources that are bound together for use by a shader, keyed by binding
name or by binding number. Don't mix the two: the first key decides which the group is. Either
way they take binding numbers 0, 1, 2... in order. By name, the keys are the shader's binding
names, and a null declares a binding to be set later with BindGroup#setResource.
ReadonlylayoutThe binding number of each resource by name, in the order the constructor was given them, or
null for a group keyed by number. With a layout, a shader's bindings are matched to this
group's resources by name, whatever numbers the shader gives them.
WebGL works out what to bind once per program, from the first shader drawn with it. Shaders that share a program must key the group at each group index the same way: all by number, or all by name with the names in the same order.
ReadonlyresourcesThe resources that are bound together for use by a shader, keyed by binding number.
Treat this as read-only and use BindGroup#setResource to add or replace a resource. A direct write skips the bind group's change tracking: the GPU bind group is not rebuilt, and the renderer never syncs the new resource's uniforms or marks it as in use.
Destroys this bind group and removes all listeners.
Returns the resource at the current specified index.
The binding number of the resource to get, or its name in a group keyed by name.
Set a resource at a given index. This function will ensure that listeners will be removed from the current resource and added to the new resource.
The resource to set.
The binding number to set the resource at, or its name in a group keyed by name.
Sets a resource at a given index without listening for its changes.
BindGroup#setResource adds a change listener to every resource it holds, so the group
re-keys when the resource changes or is destroyed. That listener costs more than the bind for a
slot that is re-pointed on every draw, such as a pass that binds this frame's pooled texture,
draws, and puts a placeholder back. Use this form for such a slot, and re-point it before the
resource changes or is destroyed. A subclass that watches its own resources can instead pass
every change of a resource it holds to onResourceChange.
The resource to set.
The index to set the resource at.
A bind group is a collection of resources that are bound together for use by a shader. They are essentially a wrapper for the WebGPU BindGroup class. But with the added bonus that WebGL can also work with them.
Bind groups resources must implement the BindResource interface. The following resources are supported:
Keyed by name, as in the examples below, the group knows which binding each name is, and the renderers match a shader's bindings to the group's resources by name. The shader's own binding numbers then don't matter, so shaders that number the same bindings differently, or declare only some of them, can share one group. Declare every binding the group will ever hold;
nullmarks one to be set later.The names must be the ones the shader declares its bindings with. A name the shader doesn't declare is ignored, and a shader binding the group has no name for gets no resource: WebGPU throws, and WebGL draws without it.
On WebGL, set a binding declared
nullbefore a shader first draws with the group, or declare it with a placeholder resource. WebGL works out what to bind the first time a program is used, and a binding still empty then is never bound, even once it is set.Keyed by number, the group has no layout and a shader reads binding
nfrom the group's bindingn.This bind group class will also watch for changes in its resources ensuring that the changes are reflected in the WebGPU BindGroup.
See
https://gpuweb.github.io/gpuweb/#dictdef-gpubindgroupdescriptor
Example
Example