playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
27 lines (26 loc) • 860 B
JavaScript
import { BindGroupFormat, BindUniformBufferFormat } from "./bind-group-format.js";
import { BindGroup } from "./bind-group.js";
import { SHADERSTAGE_FRAGMENT, SHADERSTAGE_VERTEX, UNIFORM_BUFFER_DEFAULT_SLOT_NAME } from "./constants.js";
class DynamicBuffer {
device;
bindGroupCache = /* @__PURE__ */ new Map();
constructor(device) {
this.device = device;
this.bindGroupFormat = new BindGroupFormat(this.device, [
new BindUniformBufferFormat(UNIFORM_BUFFER_DEFAULT_SLOT_NAME, SHADERSTAGE_VERTEX | SHADERSTAGE_FRAGMENT)
]);
}
getBindGroup(ub) {
const ubSize = ub.format.byteSize;
let bindGroup = this.bindGroupCache.get(ubSize);
if (!bindGroup) {
bindGroup = new BindGroup(this.device, this.bindGroupFormat, ub);
bindGroup.update();
this.bindGroupCache.set(ubSize, bindGroup);
}
return bindGroup;
}
}
export {
DynamicBuffer
};