@thi.ng/webgl 6.9.87 → 6.9.90

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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 210 standalone projects, maintained as part
10
+ > This is one of 211 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -126,7 +126,7 @@ Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
126
126
 
127
127
  ## Usage examples
128
128
 
129
- 23 projects in this repo's
129
+ 24 projects in this repo's
130
130
  [/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
131
131
  directory are using this package:
132
132
 
@@ -143,6 +143,7 @@ directory are using this package:
143
143
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-tunnel.jpg" width="240"/> | WebGL & Canvas2D textured tunnel shader | [Demo](https://demo.thi.ng/umbrella/shader-ast-tunnel/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-tunnel) |
144
144
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-graph.jpg" width="240"/> | Minimal shader graph developed during livestream #2 | [Demo](https://demo.thi.ng/umbrella/shader-graph/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-graph) |
145
145
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/soa-ecs-100k.png" width="240"/> | Entity Component System w/ 100k 3D particles | [Demo](https://demo.thi.ng/umbrella/soa-ecs/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/soa-ecs) |
146
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-cube.png" width="240"/> | 3D arcball controller to rotate the camera view of a colored cube | [Demo](https://demo.thi.ng/umbrella/webgl-arcball/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-arcball) |
146
147
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-channel-mixer.jpg" width="240"/> | rdom & WebGL-based image channel editor | [Demo](https://demo.thi.ng/umbrella/webgl-channel-mixer/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-channel-mixer) |
147
148
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-cube.png" width="240"/> | WebGL multi-colored cube mesh | [Demo](https://demo.thi.ng/umbrella/webgl-cube/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-cube) |
148
149
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-cubemap.jpg" width="240"/> | WebGL cube maps with async texture loading | [Demo](https://demo.thi.ng/umbrella/webgl-cubemap/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-cubemap) |
package/buffer.d.ts CHANGED
@@ -26,15 +26,16 @@ export declare class WebGLArrayBuffer<T extends TypedArray> implements IWebGLBuf
26
26
  }
27
27
  export declare const defBuffer: (gl: WebGLRenderingContext, data?: TypedArray, target?: GLenum, mode?: GLenum, retain?: boolean) => WebGLArrayBuffer<Float32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Uint8ClampedArray<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>>;
28
28
  /**
29
- * Takes a model spec and compiles all buffers (attributes, indices) and shader
30
- * (if not already compiled), then returns compiled spec, ready for use with
31
- * {@link draw}.
29
+ * Takes a model spec (or array of specs) and compiles all buffers (attributes,
30
+ * indices) and shaders (if not already compiled), then returns compiled spec(s),
31
+ * ready for use with {@link draw}.
32
32
  *
33
33
  * @param gl
34
34
  * @param spec
35
35
  * @param mode
36
36
  */
37
- export declare const compileModel: (gl: WebGLRenderingContext, spec: ModelSpec | UncompiledModelSpec, mode?: 35044) => ModelSpec;
37
+ export declare function compileModel(gl: WebGLRenderingContext, spec: ModelSpec | UncompiledModelSpec, mode?: GLenum): ModelSpec;
38
+ export declare function compileModel(gl: WebGLRenderingContext, spec: (ModelSpec | UncompiledModelSpec)[], mode?: GLenum): ModelSpec[];
38
39
  export declare const compileIndices: (gl: WebGLRenderingContext, index?: IndexBufferSpec, mode?: GLenum) => IndexBufferSpec | undefined;
39
40
  export declare const compileVAO: (gl: WebGLRenderingContext, spec: ModelSpec) => WebGLVertexArrayObject | undefined;
40
41
  export declare const compileAttribPool: (gl: WebGLRenderingContext, pool: AttribPool, ids?: string[], target?: GLenum, mode?: GLenum) => ModelAttributeSpecs;
package/buffer.js CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  asGLType,
4
4
  typedArrayType
5
5
  } from "@thi.ng/api/typedarray";
6
+ import { isArray } from "@thi.ng/checks/is-array";
6
7
  import { isPlainObject } from "@thi.ng/checks/is-plain-object";
7
8
  import {
8
9
  DrawMode
@@ -69,7 +70,10 @@ class WebGLArrayBuffer {
69
70
  }
70
71
  }
71
72
  const defBuffer = (gl, data, target = gl.ARRAY_BUFFER, mode = gl.STATIC_DRAW, retain = false) => new WebGLArrayBuffer(gl, data, target, mode, retain);
72
- const compileModel = (gl, spec, mode = gl.STATIC_DRAW) => {
73
+ function compileModel(gl, spec, mode) {
74
+ return isArray(spec) ? spec.map((x) => __compileModel(gl, x, mode)) : __compileModel(gl, spec, mode);
75
+ }
76
+ const __compileModel = (gl, spec, mode = gl.STATIC_DRAW) => {
73
77
  if (spec.attribPool) {
74
78
  spec.attribs = compileAttribPool(
75
79
  gl,
@@ -111,7 +115,7 @@ const __initBuffer = (gl, src, type, mode) => {
111
115
  };
112
116
  const __compileAttribs = (gl, attribs, mode) => {
113
117
  if (attribs) {
114
- for (let id in attribs) {
118
+ for (const id in attribs) {
115
119
  __initBuffer(gl, attribs[id], gl.ARRAY_BUFFER, mode);
116
120
  }
117
121
  }
@@ -154,7 +158,7 @@ const compileVAO = (gl, spec) => {
154
158
  const compileAttribPool = (gl, pool, ids, target = gl.ARRAY_BUFFER, mode = gl.STATIC_DRAW) => {
155
159
  const buf = defBuffer(gl, pool.bytes(), target, mode, true);
156
160
  const spec = {};
157
- for (let id of ids || Object.keys(pool.specs)) {
161
+ for (const id of ids || Object.keys(pool.specs)) {
158
162
  const attr = pool.specs[id];
159
163
  spec[id] = {
160
164
  buffer: buf,
package/canvas.js CHANGED
@@ -44,7 +44,7 @@ const glCanvas = (opts = {}) => {
44
44
  const getExtensions = (gl, ids, required = true) => {
45
45
  const ext = {};
46
46
  if (ids) {
47
- for (let id of ids) {
47
+ for (const id of ids) {
48
48
  ext[id] = gl.getExtension(id);
49
49
  required && !ext[id] && error(`extension ${id} not available`);
50
50
  }
package/draw.js CHANGED
@@ -43,7 +43,7 @@ const __drawInstanced = (gl, spec) => {
43
43
  const sattribs = spec.shader.attribs;
44
44
  const iattribs = spec.instances.attribs;
45
45
  spec.shader.bindAttribs(iattribs);
46
- for (let id in iattribs) {
46
+ for (const id in iattribs) {
47
47
  const attr = sattribs[id];
48
48
  if (attr) {
49
49
  let div = iattribs[id].divisor;
@@ -82,7 +82,7 @@ const __drawInstanced = (gl, spec) => {
82
82
  spec.instances.num
83
83
  );
84
84
  }
85
- for (let id in iattribs) {
85
+ for (const id in iattribs) {
86
86
  const attr = sattribs[id];
87
87
  attr && (isGL2 ? gl.vertexAttribDivisor(attr.loc, 0) : ext.vertexAttribDivisorANGLE(attr.loc, 0));
88
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/webgl",
3
- "version": "6.9.87",
3
+ "version": "6.9.90",
4
4
  "description": "WebGL & GLSL abstraction layer",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -43,22 +43,22 @@
43
43
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
44
44
  },
45
45
  "dependencies": {
46
- "@thi.ng/api": "^8.12.8",
47
- "@thi.ng/canvas": "^1.1.1",
48
- "@thi.ng/checks": "^3.7.24",
49
- "@thi.ng/equiv": "^2.1.98",
50
- "@thi.ng/errors": "^2.5.48",
51
- "@thi.ng/logger": "^3.2.7",
52
- "@thi.ng/matrices": "^3.0.28",
53
- "@thi.ng/memoize": "^4.0.32",
54
- "@thi.ng/object-utils": "^1.3.0",
55
- "@thi.ng/pixel": "^7.5.17",
56
- "@thi.ng/shader-ast": "^1.1.30",
57
- "@thi.ng/shader-ast-glsl": "^1.0.49",
58
- "@thi.ng/shader-ast-stdlib": "^1.0.49",
59
- "@thi.ng/transducers": "^9.6.17",
60
- "@thi.ng/vector-pools": "^3.2.78",
61
- "@thi.ng/vectors": "^8.6.13"
46
+ "@thi.ng/api": "^8.12.10",
47
+ "@thi.ng/canvas": "^1.1.3",
48
+ "@thi.ng/checks": "^3.8.0",
49
+ "@thi.ng/equiv": "^2.1.100",
50
+ "@thi.ng/errors": "^2.5.50",
51
+ "@thi.ng/logger": "^3.2.9",
52
+ "@thi.ng/matrices": "^3.0.30",
53
+ "@thi.ng/memoize": "^4.0.34",
54
+ "@thi.ng/object-utils": "^1.3.2",
55
+ "@thi.ng/pixel": "^7.5.19",
56
+ "@thi.ng/shader-ast": "^1.1.32",
57
+ "@thi.ng/shader-ast-glsl": "^1.0.51",
58
+ "@thi.ng/shader-ast-stdlib": "^1.0.51",
59
+ "@thi.ng/transducers": "^9.6.19",
60
+ "@thi.ng/vector-pools": "^3.2.80",
61
+ "@thi.ng/vectors": "^8.6.15"
62
62
  },
63
63
  "devDependencies": {
64
64
  "esbuild": "^0.27.0",
@@ -227,5 +227,5 @@
227
227
  ],
228
228
  "year": 2014
229
229
  },
230
- "gitHead": "be6e7657b1e5c54d7d648d1b52888a7297e95a17\n"
230
+ "gitHead": "824bf9047b5a10f777c5c5b4aeecf0c750a22c75\n"
231
231
  }
package/shader.js CHANGED
@@ -71,7 +71,7 @@ class Shader {
71
71
  }
72
72
  unbind() {
73
73
  let shaderAttrib;
74
- for (let id in this.attribs) {
74
+ for (const id in this.attribs) {
75
75
  if (shaderAttrib = this.attribs[id]) {
76
76
  this.gl.disableVertexAttribArray(shaderAttrib.loc);
77
77
  }
@@ -90,7 +90,7 @@ class Shader {
90
90
  bindAttribs(specAttribs) {
91
91
  const gl = this.gl;
92
92
  let shaderAttrib;
93
- for (let id in specAttribs) {
93
+ for (const id in specAttribs) {
94
94
  if (shaderAttrib = this.attribs[id]) {
95
95
  const attr = specAttribs[id];
96
96
  attr.buffer.bind();
@@ -110,7 +110,7 @@ class Shader {
110
110
  }
111
111
  bindUniforms(specUnis = {}) {
112
112
  const shaderUnis = this.uniforms;
113
- for (let id in specUnis) {
113
+ for (const id in specUnis) {
114
114
  const u = shaderUnis[id];
115
115
  if (u) {
116
116
  let val = specUnis[id];
@@ -120,7 +120,7 @@ class Shader {
120
120
  this.warnUni(id);
121
121
  }
122
122
  }
123
- for (let id in shaderUnis) {
123
+ for (const id in shaderUnis) {
124
124
  if (shaderUnis.hasOwnProperty(id) && (!specUnis || !existsAndNotNull(specUnis[id]))) {
125
125
  const u = shaderUnis[id];
126
126
  const val = u.defaultFn ? u.defaultFn(shaderUnis, specUnis) : u.defaultVal;
@@ -188,7 +188,7 @@ const defShader = (gl, spec, opts) => {
188
188
  };
189
189
  const __compileVars = (attribs, syntax, prefixes) => {
190
190
  let decls = [];
191
- for (let id in attribs) {
191
+ for (const id in attribs) {
192
192
  if (attribs.hasOwnProperty(id)) {
193
193
  decls.push(syntax(id, attribs[id], prefixes));
194
194
  }
@@ -203,7 +203,7 @@ const __compileExtensionPragma = (id, behavior, version) => {
203
203
  ` : "";
204
204
  };
205
205
  const __initShaderExtensions = (gl, exts) => {
206
- for (let id in exts) {
206
+ for (const id in exts) {
207
207
  const state = exts[id];
208
208
  if (state === true || state === "require") {
209
209
  getExtensions(gl, [id], state === "require");
@@ -213,7 +213,7 @@ const __initShaderExtensions = (gl, exts) => {
213
213
  const __compilePrelude = (spec, version) => {
214
214
  let prelude = spec.pre ? spec.replacePrelude ? spec.pre : spec.pre + "\n" + GLSL_HEADER : GLSL_HEADER;
215
215
  if (spec.ext) {
216
- for (let id in spec.ext) {
216
+ for (const id in spec.ext) {
217
217
  prelude += __compileExtensionPragma(
218
218
  id,
219
219
  spec.ext[id],
@@ -224,7 +224,7 @@ const __compilePrelude = (spec, version) => {
224
224
  return prelude;
225
225
  };
226
226
  const __compileIODecls = (decl, src, dest) => {
227
- for (let id in src) {
227
+ for (const id in src) {
228
228
  const a = src[id];
229
229
  dest[id] = isArray(a) ? decl(a[0], id, { loc: a[1] }) : decl(a, id);
230
230
  }
@@ -235,13 +235,13 @@ const __varyingOpts = (v) => {
235
235
  return [vtype, opts];
236
236
  };
237
237
  const __compileVaryingDecls = (spec, decl, acc) => {
238
- for (let id in spec.varying) {
238
+ for (const id in spec.varying) {
239
239
  const [vtype, opts] = __varyingOpts(spec.varying[id]);
240
240
  acc[id] = decl(vtype, id, opts);
241
241
  }
242
242
  };
243
243
  const __compileUniformDecls = (spec, acc) => {
244
- for (let id in spec.uniforms) {
244
+ for (const id in spec.uniforms) {
245
245
  const u = spec.uniforms[id];
246
246
  acc[id] = isArray(u) ? uniform(
247
247
  u[0],
@@ -266,7 +266,7 @@ const shaderSourceFromAST = (spec, type, version, opts = {}) => {
266
266
  if (version >= GLSLVersion.GLES_300) {
267
267
  __compileIODecls(output, outs, outputs);
268
268
  } else {
269
- for (let id in outs) {
269
+ for (const id in outs) {
270
270
  const o = outs[id];
271
271
  if (isArray(o) && o[0] === "vec4") {
272
272
  prelude += `#define ${id} gl_FragData[${o[1]}]
@@ -342,7 +342,7 @@ ${errors}`);
342
342
  };
343
343
  const __initAttributes = (gl, prog, attribs) => {
344
344
  const res = {};
345
- for (let id in attribs) {
345
+ for (const id in attribs) {
346
346
  const val = attribs[id];
347
347
  const [type, loc] = isArray(val) ? val : [val, null];
348
348
  const aid = id;
@@ -360,7 +360,7 @@ const __initAttributes = (gl, prog, attribs) => {
360
360
  };
361
361
  const __initUniforms = (gl, prog, uniforms = {}) => {
362
362
  const res = {};
363
- for (let id in uniforms) {
363
+ for (const id in uniforms) {
364
364
  const val = uniforms[id];
365
365
  let type;
366
366
  let t1, t2, defaultVal, defaultFn;