mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:10:43 +00:00
4cd22a9b5c
The render/ tree was the only place in the client still using kebab-case filenames. Brings ~80 files in line with the rest of src/client/ (BuildPreviewController, TransformHandler, etc.). Directories kept as they were (name-pass/, fx-pass/, passes/, utils/, debug/) since the codebase already mixes those. Two collisions surfaced and got resolved: render/types/ is a directory, not a file, so its imports kept the lowercase form; and the sed pass incidentally normalized core/pathfinding imports, which had to be reverted since that file is actually lowercase on disk despite some imports having referenced it as ./Types under macOS case-insensitive resolution.
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
/**
|
|
* DynamicInstanceBuffer — manages grow-on-demand instance buffers.
|
|
*
|
|
* Encapsulates the pattern of doubling capacity when needed, allocating new
|
|
* Float32Array, copying old data, and rebinding the GL buffer.
|
|
*/
|
|
|
|
export class DynamicInstanceBuffer {
|
|
private data: Float32Array;
|
|
private bytes: Uint8Array;
|
|
private capacity: number;
|
|
|
|
constructor(
|
|
private gl: WebGL2RenderingContext,
|
|
private buf: WebGLBuffer,
|
|
initialCapacity: number,
|
|
private floatsPerInstance: number,
|
|
) {
|
|
this.capacity = initialCapacity;
|
|
this.data = new Float32Array(initialCapacity * floatsPerInstance);
|
|
this.bytes = new Uint8Array(this.data.buffer);
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
|
gl.bufferData(gl.ARRAY_BUFFER, this.data.byteLength, gl.DYNAMIC_DRAW);
|
|
}
|
|
|
|
ensureCapacity(needed: number): void {
|
|
if (needed <= this.capacity) return;
|
|
while (this.capacity < needed) this.capacity *= 2;
|
|
const newData = new Float32Array(this.capacity * this.floatsPerInstance);
|
|
newData.set(this.data);
|
|
this.data = newData;
|
|
this.bytes = new Uint8Array(newData.buffer);
|
|
const gl = this.gl;
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.buf);
|
|
gl.bufferData(gl.ARRAY_BUFFER, this.data.byteLength, gl.DYNAMIC_DRAW);
|
|
}
|
|
|
|
get float32(): Float32Array {
|
|
return this.data;
|
|
}
|
|
|
|
get uint8(): Uint8Array {
|
|
return this.bytes;
|
|
}
|
|
|
|
get buffer(): WebGLBuffer {
|
|
return this.buf;
|
|
}
|
|
|
|
dispose(): void {
|
|
if (this.buf !== null && this.buf !== undefined) {
|
|
this.gl.deleteBuffer(this.buf);
|
|
}
|
|
}
|
|
}
|