simplify more
This commit is contained in:
parent
f03da42b5e
commit
2fe3c69963
40 changed files with 690 additions and 873 deletions
19
src/utils/graphics/bind-group-cache.ts
Normal file
19
src/utils/graphics/bind-group-cache.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export const createBindGroupCache = <K1 extends object, K2 extends object>(
|
||||
factory: (key1: K1, key2: K2) => GPUBindGroup
|
||||
): ((key1: K1, key2: K2) => GPUBindGroup) => {
|
||||
const outer = new WeakMap<K1, WeakMap<K2, GPUBindGroup>>();
|
||||
return (key1, key2) => {
|
||||
let inner = outer.get(key1);
|
||||
if (!inner) {
|
||||
inner = new WeakMap();
|
||||
outer.set(key1, inner);
|
||||
}
|
||||
const cached = inner.get(key2);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const bindGroup = factory(key1, key2);
|
||||
inner.set(key2, bindGroup);
|
||||
return bindGroup;
|
||||
};
|
||||
};
|
||||
Loading…
Reference in a new issue