@thi.ng/webgl 6.2.21 → 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-01-10T15:20:19Z
3
+ - **Last updated**: 2023-02-10T14:03:11Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [6.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/webgl@6.3.0) (2023-02-05)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add Shader.withState() ([8a7a427](https://github.com/thi-ng/umbrella/commit/8a7a427))
17
+ - update WebGLArrayBuffer/IWebGLBuffer ([c1890ce](https://github.com/thi-ng/umbrella/commit/c1890ce))
18
+ - add optional `retain` ctor arg to retain handle to
19
+ - add .update() method
20
+ - update IWebGLBuffer interface
21
+
12
22
  ## [6.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/webgl@6.2.0) (2022-08-08)
13
23
 
14
24
  #### 🚀 Features
package/README.md CHANGED
@@ -95,7 +95,7 @@ For Node.js REPL:
95
95
  const webgl = await import("@thi.ng/webgl");
96
96
  ```
97
97
 
98
- Package sizes (brotli'd, pre-treeshake): ESM: 11.23 KB
98
+ Package sizes (brotli'd, pre-treeshake): ESM: 11.30 KB
99
99
 
100
100
  ## Dependencies
101
101
 
package/api/buffers.d.ts CHANGED
@@ -3,7 +3,8 @@ import type { ITexture } from "./texture.js";
3
3
  export type IndexBufferData = Uint16Array | Uint32Array;
4
4
  export interface IWebGLBuffer<T> extends IBind<void>, IRelease {
5
5
  set(data: T, mode?: GLenum): void;
6
- setChunk(data: T, offset: number): void;
6
+ setChunk(data: T, byteOffset: number): void;
7
+ update(): void;
7
8
  }
8
9
  export interface IConfigure<T> {
9
10
  configure(opts: T): boolean;
package/buffer.d.ts CHANGED
@@ -7,12 +7,22 @@ export declare class WebGLArrayBuffer<T extends TypedArray> implements IWebGLBuf
7
7
  buffer: WebGLBuffer;
8
8
  target: number;
9
9
  mode: number;
10
- constructor(gl: WebGLRenderingContext, data?: T, target?: number, mode?: number);
10
+ data?: T;
11
+ constructor(gl: WebGLRenderingContext, data?: T, target?: number, mode?: number, retain?: boolean);
11
12
  bind(): boolean;
12
13
  unbind(): boolean;
13
14
  release(): boolean;
15
+ /**
16
+ * Re-applies retained data (from ctor arg) using
17
+ * {@link WebGLArrayBuffer.set}. Presumably the underlying data has been
18
+ * updated elsewhere, but needs to be reflected to WebGL.
19
+ *
20
+ * @remarks
21
+ * If no data is retained, this method is a no-op.
22
+ */
23
+ update(): void;
14
24
  set(data: T, mode?: number): void;
15
- setChunk(data: T, offset?: number): void;
25
+ setChunk(data: T, byteOffset?: number): void;
16
26
  }
17
27
  export declare const defBuffer: (gl: WebGLRenderingContext, data?: TypedArray, target?: number, mode?: number) => WebGLArrayBuffer<Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array>;
18
28
  export declare const compileModel: (gl: WebGLRenderingContext, spec: ModelSpec, mode?: number) => ModelSpec;
package/buffer.js CHANGED
@@ -1,14 +1,18 @@
1
- import { asGLType } from "@thi.ng/api/typedarray";
1
+ import { asGLType, BIT_SHIFTS, typedArrayType, } from "@thi.ng/api/typedarray";
2
2
  import { DrawMode, } from "./api/model.js";
3
3
  import { isGL2Context } from "./checks.js";
4
4
  import { error } from "./error.js";
5
5
  export class WebGLArrayBuffer {
6
- constructor(gl, data, target = gl.ARRAY_BUFFER, mode = gl.STATIC_DRAW) {
6
+ constructor(gl, data, target = gl.ARRAY_BUFFER, mode = gl.STATIC_DRAW, retain = false) {
7
7
  this.gl = gl;
8
8
  this.buffer = gl.createBuffer() || error("error creating WebGL buffer");
9
9
  this.target = target;
10
10
  this.mode = mode;
11
- data && this.set(data);
11
+ if (data) {
12
+ this.set(data);
13
+ if (retain)
14
+ this.data = data;
15
+ }
12
16
  }
13
17
  bind() {
14
18
  this.gl.bindBuffer(this.target, this.buffer);
@@ -25,13 +29,30 @@ export class WebGLArrayBuffer {
25
29
  }
26
30
  return true;
27
31
  }
32
+ /**
33
+ * Re-applies retained data (from ctor arg) using
34
+ * {@link WebGLArrayBuffer.set}. Presumably the underlying data has been
35
+ * updated elsewhere, but needs to be reflected to WebGL.
36
+ *
37
+ * @remarks
38
+ * If no data is retained, this method is a no-op.
39
+ */
40
+ update() {
41
+ if (this.data)
42
+ this.set(this.data);
43
+ }
28
44
  set(data, mode = this.mode) {
29
45
  this.bind();
30
46
  this.gl.bufferData(this.target, data, mode);
47
+ if (this.data)
48
+ this.data = data;
31
49
  }
32
- setChunk(data, offset = 0) {
50
+ setChunk(data, byteOffset = 0) {
33
51
  this.bind();
34
- this.gl.bufferSubData(this.target, offset, data);
52
+ this.gl.bufferSubData(this.target, byteOffset, data);
53
+ if (this.data) {
54
+ this.data.set(data, byteOffset >>> BIT_SHIFTS[typedArrayType(data)]);
55
+ }
35
56
  }
36
57
  }
37
58
  export const defBuffer = (gl, data, target = gl.ARRAY_BUFFER, mode = gl.STATIC_DRAW) => new WebGLArrayBuffer(gl, data, target, mode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/webgl",
3
- "version": "6.2.21",
3
+ "version": "6.3.2",
4
4
  "description": "WebGL & GLSL abstraction layer",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -38,30 +38,30 @@
38
38
  "test": "testament test"
39
39
  },
40
40
  "dependencies": {
41
- "@thi.ng/adapt-dpi": "^2.2.6",
42
- "@thi.ng/api": "^8.6.3",
43
- "@thi.ng/associative": "^6.2.23",
44
- "@thi.ng/checks": "^3.3.7",
45
- "@thi.ng/equiv": "^2.1.17",
46
- "@thi.ng/errors": "^2.2.8",
47
- "@thi.ng/logger": "^1.4.7",
48
- "@thi.ng/matrices": "^2.1.40",
49
- "@thi.ng/memoize": "^3.1.22",
50
- "@thi.ng/pixel": "^4.1.0",
51
- "@thi.ng/shader-ast": "^0.12.37",
52
- "@thi.ng/shader-ast-glsl": "^0.4.37",
53
- "@thi.ng/shader-ast-stdlib": "^0.13.0",
54
- "@thi.ng/transducers": "^8.3.30",
55
- "@thi.ng/vector-pools": "^3.1.41",
56
- "@thi.ng/vectors": "^7.5.31"
41
+ "@thi.ng/adapt-dpi": "^2.2.8",
42
+ "@thi.ng/api": "^8.7.2",
43
+ "@thi.ng/associative": "^6.2.26",
44
+ "@thi.ng/checks": "^3.3.9",
45
+ "@thi.ng/equiv": "^2.1.19",
46
+ "@thi.ng/errors": "^2.2.11",
47
+ "@thi.ng/logger": "^1.4.9",
48
+ "@thi.ng/matrices": "^2.1.43",
49
+ "@thi.ng/memoize": "^3.1.25",
50
+ "@thi.ng/pixel": "^4.1.3",
51
+ "@thi.ng/shader-ast": "^0.12.40",
52
+ "@thi.ng/shader-ast-glsl": "^0.4.40",
53
+ "@thi.ng/shader-ast-stdlib": "^0.13.3",
54
+ "@thi.ng/transducers": "^8.3.33",
55
+ "@thi.ng/vector-pools": "^3.1.44",
56
+ "@thi.ng/vectors": "^7.6.2"
57
57
  },
58
58
  "devDependencies": {
59
- "@microsoft/api-extractor": "^7.33.7",
60
- "@thi.ng/testament": "^0.3.9",
61
- "rimraf": "^3.0.2",
59
+ "@microsoft/api-extractor": "^7.34.2",
60
+ "@thi.ng/testament": "^0.3.11",
61
+ "rimraf": "^4.1.2",
62
62
  "tools": "^0.0.1",
63
- "typedoc": "^0.23.22",
64
- "typescript": "^4.9.4"
63
+ "typedoc": "^0.23.24",
64
+ "typescript": "^4.9.5"
65
65
  },
66
66
  "keywords": [
67
67
  "2d",
@@ -219,5 +219,5 @@
219
219
  ],
220
220
  "year": 2014
221
221
  },
222
- "gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
222
+ "gitHead": "cafa4ecea90fb681949dc3885a5bd6ddefa38b51\n"
223
223
  }
package/shader.d.ts CHANGED
@@ -11,6 +11,14 @@ export declare class Shader implements IShader {
11
11
  protected warnAttrib: (x: string) => void;
12
12
  protected warnUni: (x: string) => void;
13
13
  constructor(gl: WebGLRenderingContext, program: WebGLProgram, attribs: IObjectOf<ShaderAttrib>, uniforms: ShaderUniforms, state?: Partial<ShaderState>);
14
+ /**
15
+ * Returns a shallow copy of this shader with its state config merged with
16
+ * given options (priority). Useful for re-using a shader, but applying
17
+ * different settings.
18
+ *
19
+ * @param state
20
+ */
21
+ withState(state: Partial<ShaderState>): Shader;
14
22
  bind(spec: ModelSpec): boolean;
15
23
  unbind(): boolean;
16
24
  release(): boolean;
package/shader.js CHANGED
@@ -30,6 +30,19 @@ export class Shader {
30
30
  this.uniforms = uniforms;
31
31
  this.state = state || {};
32
32
  }
33
+ /**
34
+ * Returns a shallow copy of this shader with its state config merged with
35
+ * given options (priority). Useful for re-using a shader, but applying
36
+ * different settings.
37
+ *
38
+ * @param state
39
+ */
40
+ withState(state) {
41
+ return new Shader(this.gl, this.program, this.attribs, this.uniforms, {
42
+ ...this.state,
43
+ ...state,
44
+ });
45
+ }
33
46
  bind(spec) {
34
47
  if (this.program) {
35
48
  this.gl.useProgram(this.program);