Skip to content

Commit

Permalink
feat(webgl): add retain option to ModelAttributeSpec/IndexBufferSpec
Browse files Browse the repository at this point in the history
- update defBuffer()/initBuffer()
  • Loading branch information
postspectacular committed Apr 12, 2023
1 parent 0fde783 commit 3db4463
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/webgl/src/api/buffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export interface IndexBufferSpec {
* Raw attribute data from which `buffer` will be initialized
*/
data: IndexBufferData;
/**
* Only used if {@link IndexBufferSpec.buffer} is being auto-generated.
* If true (default: false), the buffer will retain a handler to the given
* {@link IndexBufferSpec.data} array and can be later conveniently
* updated via {@link WebGLArrayBuffer.update}.
*
* @defaultValue false
*/
retain?: boolean;
}

export interface FboOpts {
Expand Down
9 changes: 9 additions & 0 deletions packages/webgl/src/api/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ export interface ModelAttributeSpec {
* https://www.khronos.org/registry/OpenGL/extensions/ANGLE/ANGLE_instanced_arrays.txt
*/
divisor?: number;
/**
* Only used if {@link ModelAttributeSpec.buffer} is being auto-generated.
* If true (default: false), the buffer will retain a handler to the given
* {@link ModelAttributeSpec.data} array and can be later conveniently
* updated via {@link WebGLArrayBuffer.update}.
*
* @defaultValue false
*/
retain?: boolean;
}

export interface InstancingSpec {
Expand Down
7 changes: 4 additions & 3 deletions packages/webgl/src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ export const defBuffer = (
gl: WebGLRenderingContext,
data?: TypedArray,
target = gl.ARRAY_BUFFER,
mode = gl.STATIC_DRAW
) => new WebGLArrayBuffer(gl, data, target, mode);
mode = gl.STATIC_DRAW,
retain = false
) => new WebGLArrayBuffer(gl, data, target, mode, retain);

export const compileModel = (
gl: WebGLRenderingContext,
Expand Down Expand Up @@ -126,7 +127,7 @@ const initBuffer = (
if (src.buffer) {
src.data && src.buffer.set(<any>src.data);
} else {
src.buffer = new WebGLArrayBuffer(gl, src.data, type, mode);
src.buffer = new WebGLArrayBuffer(gl, src.data, type, mode, src.retain);
}
};

Expand Down

0 comments on commit 3db4463

Please sign in to comment.