playcanvas
Version:
PlayCanvas WebGL game engine
26 lines (23 loc) • 875 B
JavaScript
import { BindGroupFormat, BindUniformBufferFormat } from './bind-group-format.js';
import { BindGroup } from './bind-group.js';
import { UNIFORM_BUFFER_DEFAULT_SLOT_NAME, SHADERSTAGE_VERTEX, SHADERSTAGE_FRAGMENT } from './constants.js';
class DynamicBuffer {
constructor(device){
this.bindGroupCache = new Map();
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 };