@thi.ng/webgl 5.0.14 → 6.0.4

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +112 -213
  2. package/README.md +15 -5
  3. package/api/buffers.d.ts +1 -1
  4. package/api/canvas.d.ts +1 -1
  5. package/api/material.d.ts +1 -1
  6. package/api/model.d.ts +3 -3
  7. package/api/multipass.d.ts +4 -4
  8. package/api/shader.d.ts +12 -6
  9. package/api/texture.d.ts +1 -1
  10. package/buffer.d.ts +3 -3
  11. package/buffer.js +4 -4
  12. package/canvas.d.ts +2 -2
  13. package/canvas.js +6 -3
  14. package/checks.d.ts +1 -1
  15. package/checks.js +1 -1
  16. package/draw.d.ts +1 -1
  17. package/draw.js +4 -4
  18. package/error.d.ts +11 -3
  19. package/error.js +2 -5
  20. package/fbo.d.ts +1 -1
  21. package/fbo.js +5 -5
  22. package/geo/cube.d.ts +1 -1
  23. package/geo/cube.js +2 -2
  24. package/geo/quad.d.ts +1 -1
  25. package/geo/quad.js +14 -11
  26. package/index.d.ts +32 -32
  27. package/index.js +32 -32
  28. package/{api/logger.d.ts → logger.d.ts} +1 -1
  29. package/{api/logger.js → logger.js} +1 -1
  30. package/material.d.ts +2 -2
  31. package/matrices.d.ts +2 -2
  32. package/matrices.js +5 -2
  33. package/multipass.d.ts +1 -1
  34. package/multipass.js +33 -15
  35. package/package.json +151 -40
  36. package/rbo.d.ts +1 -1
  37. package/rbo.js +1 -1
  38. package/readpixels.d.ts +1 -1
  39. package/readpixels.js +1 -1
  40. package/shader.d.ts +6 -6
  41. package/shader.js +33 -23
  42. package/shaders/lambert.d.ts +3 -3
  43. package/shaders/lambert.js +43 -11
  44. package/shaders/phong.d.ts +3 -3
  45. package/shaders/phong.js +38 -10
  46. package/shaders/pipeline.d.ts +1 -1
  47. package/shaders/pipeline.js +5 -1
  48. package/syntax.d.ts +2 -2
  49. package/syntax.js +2 -2
  50. package/texture.d.ts +1 -1
  51. package/texture.js +10 -6
  52. package/textures/checkerboard.js +9 -2
  53. package/textures/stripes.js +8 -2
  54. package/uniforms.d.ts +2 -2
  55. package/uniforms.js +2 -2
  56. package/utils.d.ts +4 -4
  57. package/utils.js +1 -1
  58. package/lib/index.js +0 -1820
  59. package/lib/index.js.map +0 -1
  60. package/lib/index.umd.js +0 -1
  61. package/lib/index.umd.js.map +0 -1
package/canvas.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { adaptDPI } from "@thi.ng/adapt-dpi";
2
- import { isString } from "@thi.ng/checks";
3
- import { error } from "./error";
2
+ import { isString } from "@thi.ng/checks/is-string";
3
+ import { error } from "./error.js";
4
4
  const defaultOpts = {
5
5
  alpha: true,
6
6
  antialias: true,
@@ -19,7 +19,10 @@ export const glCanvas = (opts = {}) => {
19
19
  opts.height && (canvas.height = opts.height);
20
20
  opts.autoScale !== false && adaptDPI(canvas, canvas.width, canvas.height);
21
21
  opts.parent && opts.parent.appendChild(canvas);
22
- const gl = canvas.getContext(opts.version === 2 ? "webgl2" : "webgl", Object.assign(Object.assign({}, defaultOpts), opts.opts));
22
+ const gl = canvas.getContext(opts.version === 2 ? "webgl2" : "webgl", {
23
+ ...defaultOpts,
24
+ ...opts.opts,
25
+ });
23
26
  if (!gl) {
24
27
  error("WebGL unavailable");
25
28
  }
package/checks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ITexture } from "./api/texture";
1
+ import { ITexture } from "./api/texture.js";
2
2
  export declare const isGL2Context: (gl: WebGLRenderingContext | WebGL2RenderingContext) => gl is WebGL2RenderingContext;
3
3
  export declare const isFloatTexture: (tex: ITexture) => boolean;
4
4
  //# sourceMappingURL=checks.d.ts.map
package/checks.js CHANGED
@@ -1,4 +1,4 @@
1
- import { TextureType } from "./api/texture";
1
+ import { TextureType } from "./api/texture.js";
2
2
  export const isGL2Context = (gl) => typeof WebGL2RenderingContext !== "undefined" &&
3
3
  gl instanceof WebGL2RenderingContext;
4
4
  export const isFloatTexture = (tex) => tex.type === TextureType.FLOAT ||
package/draw.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ModelSpec } from "./api/model";
1
+ import type { ModelSpec } from "./api/model.js";
2
2
  export interface DrawFlags {
3
3
  /**
4
4
  * Unless false (default: true), bind modelspec's textures
package/draw.js CHANGED
@@ -1,7 +1,7 @@
1
- import { isArray } from "@thi.ng/checks";
2
- import { isGL2Context } from "./checks";
3
- import { error } from "./error";
4
- import { bindTextures, unbindTextures } from "./texture";
1
+ import { isArray } from "@thi.ng/checks/is-array";
2
+ import { isGL2Context } from "./checks.js";
3
+ import { error } from "./error.js";
4
+ import { bindTextures, unbindTextures } from "./texture.js";
5
5
  export const draw = (specs, opts = {}) => {
6
6
  const _specs = isArray(specs) ? specs : [specs];
7
7
  for (let i = 0, n = _specs.length; i < n; i++) {
package/error.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- export declare class WebGLError extends Error {
2
- constructor(msg?: string);
3
- }
1
+ /// <reference types="node" />
2
+ export declare const WebGLError: {
3
+ new (msg?: string | undefined): {
4
+ name: string;
5
+ message: string;
6
+ stack?: string | undefined;
7
+ };
8
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
9
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
10
+ stackTraceLimit: number;
11
+ };
4
12
  export declare const error: (msg?: string | undefined) => never;
5
13
  //# sourceMappingURL=error.d.ts.map
package/error.js CHANGED
@@ -1,8 +1,5 @@
1
- export class WebGLError extends Error {
2
- constructor(msg) {
3
- super(`WebGL error ${msg ? ": " + msg : ""}`);
4
- }
5
- }
1
+ import { defError } from "@thi.ng/errors/deferror";
2
+ export const WebGLError = defError(() => "WebGL");
6
3
  export const error = (msg) => {
7
4
  throw new WebGLError(msg);
8
5
  };
package/fbo.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FboOpts, IFbo } from "./api/buffers";
1
+ import type { FboOpts, IFbo } from "./api/buffers.js";
2
2
  /**
3
3
  * WebGL framebuffer wrapper w/ automatic detection & support for
4
4
  * multiple render targets (color attachments) and optional depth
package/fbo.js CHANGED
@@ -1,8 +1,8 @@
1
- import { assert } from "@thi.ng/api";
2
- import { TEX_FORMATS } from "./api/texture";
3
- import { isGL2Context } from "./checks";
4
- import { error } from "./error";
5
- import { RBO } from "./rbo";
1
+ import { assert } from "@thi.ng/errors/assert";
2
+ import { TEX_FORMATS } from "./api/texture.js";
3
+ import { isGL2Context } from "./checks.js";
4
+ import { error } from "./error.js";
5
+ import { RBO } from "./rbo.js";
6
6
  const GL_COLOR_ATTACHMENT0_WEBGL = 0x8ce0;
7
7
  const GL_MAX_COLOR_ATTACHMENTS_WEBGL = 0x8cdf;
8
8
  /**
package/geo/cube.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ModelSpec } from "../api/model";
1
+ import { ModelSpec } from "../api/model.js";
2
2
  export interface CubeOpts {
3
3
  size: number;
4
4
  normal: boolean;
package/geo/cube.js CHANGED
@@ -1,7 +1,7 @@
1
- import { DrawMode } from "../api/model";
1
+ import { DrawMode } from "../api/model.js";
2
2
  // prettier-ignore
3
3
  export const defCubeModel = (opts) => {
4
- opts = Object.assign({ size: 1, normal: true, uv: true }, opts);
4
+ opts = { size: 1, normal: true, uv: true, ...opts };
5
5
  const s = opts.size;
6
6
  const spec = {
7
7
  attribs: {
package/geo/quad.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ModelSpec } from "../api/model";
1
+ import { ModelSpec } from "../api/model.js";
2
2
  export interface QuadOpts {
3
3
  /**
4
4
  * Side length of the quad in each direction (always square).
package/geo/quad.js CHANGED
@@ -1,10 +1,11 @@
1
- import { DrawMode } from "../api/model";
1
+ import { DrawMode } from "../api/model.js";
2
2
  export const defQuadModel = (opts) => {
3
- let { size, uv, center } = Object.assign({ size: 2, uv: true, center: true }, opts);
3
+ let { size, uv, center } = { size: 2, uv: true, center: true, ...opts };
4
4
  size *= 0.5;
5
5
  const o = center ? 0 : size;
6
6
  return {
7
- attribs: Object.assign({ position: {
7
+ attribs: {
8
+ position: {
8
9
  data: new Float32Array([
9
10
  o - size,
10
11
  o - size,
@@ -16,14 +17,16 @@ export const defQuadModel = (opts) => {
16
17
  o + size,
17
18
  ]),
18
19
  size: 2,
19
- } }, (uv
20
- ? {
21
- uv: {
22
- data: new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]),
23
- size: 2,
24
- },
25
- }
26
- : null)),
20
+ },
21
+ ...(uv
22
+ ? {
23
+ uv: {
24
+ data: new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]),
25
+ size: 2,
26
+ },
27
+ }
28
+ : null),
29
+ },
27
30
  uniforms: {},
28
31
  shader: null,
29
32
  mode: DrawMode.TRIANGLE_STRIP,
package/index.d.ts CHANGED
@@ -1,33 +1,33 @@
1
- export * from "./api/blend";
2
- export * from "./api/buffers";
3
- export * from "./api/canvas";
4
- export * from "./api/ext";
5
- export * from "./api/glsl";
6
- export * from "./api/logger";
7
- export * from "./api/material";
8
- export * from "./api/model";
9
- export * from "./api/shader";
10
- export * from "./api/texture";
11
- export * from "./buffer";
12
- export * from "./canvas";
13
- export * from "./checks";
14
- export * from "./draw";
15
- export * from "./error";
16
- export * from "./fbo";
17
- export * from "./material";
18
- export * from "./matrices";
19
- export * from "./multipass";
20
- export * from "./rbo";
21
- export * from "./readpixels";
22
- export * from "./shader";
23
- export * from "./syntax";
24
- export * from "./texture";
25
- export * from "./utils";
26
- export * from "./shaders/lambert";
27
- export * from "./shaders/phong";
28
- export * from "./shaders/pipeline";
29
- export * from "./textures/checkerboard";
30
- export * from "./textures/stripes";
31
- export * from "./geo/cube";
32
- export * from "./geo/quad";
1
+ export * from "./api/blend.js";
2
+ export * from "./api/buffers.js";
3
+ export * from "./api/canvas.js";
4
+ export * from "./api/ext.js";
5
+ export * from "./api/glsl.js";
6
+ export * from "./api/material.js";
7
+ export * from "./api/model.js";
8
+ export * from "./api/shader.js";
9
+ export * from "./api/texture.js";
10
+ export * from "./buffer.js";
11
+ export * from "./canvas.js";
12
+ export * from "./checks.js";
13
+ export * from "./draw.js";
14
+ export * from "./error.js";
15
+ export * from "./fbo.js";
16
+ export * from "./logger.js";
17
+ export * from "./material.js";
18
+ export * from "./matrices.js";
19
+ export * from "./multipass.js";
20
+ export * from "./rbo.js";
21
+ export * from "./readpixels.js";
22
+ export * from "./shader.js";
23
+ export * from "./syntax.js";
24
+ export * from "./texture.js";
25
+ export * from "./utils.js";
26
+ export * from "./shaders/lambert.js";
27
+ export * from "./shaders/phong.js";
28
+ export * from "./shaders/pipeline.js";
29
+ export * from "./textures/checkerboard.js";
30
+ export * from "./textures/stripes.js";
31
+ export * from "./geo/cube.js";
32
+ export * from "./geo/quad.js";
33
33
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,32 +1,32 @@
1
- export * from "./api/blend";
2
- export * from "./api/buffers";
3
- export * from "./api/canvas";
4
- export * from "./api/ext";
5
- export * from "./api/glsl";
6
- export * from "./api/logger";
7
- export * from "./api/material";
8
- export * from "./api/model";
9
- export * from "./api/shader";
10
- export * from "./api/texture";
11
- export * from "./buffer";
12
- export * from "./canvas";
13
- export * from "./checks";
14
- export * from "./draw";
15
- export * from "./error";
16
- export * from "./fbo";
17
- export * from "./material";
18
- export * from "./matrices";
19
- export * from "./multipass";
20
- export * from "./rbo";
21
- export * from "./readpixels";
22
- export * from "./shader";
23
- export * from "./syntax";
24
- export * from "./texture";
25
- export * from "./utils";
26
- export * from "./shaders/lambert";
27
- export * from "./shaders/phong";
28
- export * from "./shaders/pipeline";
29
- export * from "./textures/checkerboard";
30
- export * from "./textures/stripes";
31
- export * from "./geo/cube";
32
- export * from "./geo/quad";
1
+ export * from "./api/blend.js";
2
+ export * from "./api/buffers.js";
3
+ export * from "./api/canvas.js";
4
+ export * from "./api/ext.js";
5
+ export * from "./api/glsl.js";
6
+ export * from "./api/material.js";
7
+ export * from "./api/model.js";
8
+ export * from "./api/shader.js";
9
+ export * from "./api/texture.js";
10
+ export * from "./buffer.js";
11
+ export * from "./canvas.js";
12
+ export * from "./checks.js";
13
+ export * from "./draw.js";
14
+ export * from "./error.js";
15
+ export * from "./fbo.js";
16
+ export * from "./logger.js";
17
+ export * from "./material.js";
18
+ export * from "./matrices.js";
19
+ export * from "./multipass.js";
20
+ export * from "./rbo.js";
21
+ export * from "./readpixels.js";
22
+ export * from "./shader.js";
23
+ export * from "./syntax.js";
24
+ export * from "./texture.js";
25
+ export * from "./utils.js";
26
+ export * from "./shaders/lambert.js";
27
+ export * from "./shaders/phong.js";
28
+ export * from "./shaders/pipeline.js";
29
+ export * from "./textures/checkerboard.js";
30
+ export * from "./textures/stripes.js";
31
+ export * from "./geo/cube.js";
32
+ export * from "./geo/quad.js";
@@ -1,4 +1,4 @@
1
- import { ILogger } from "@thi.ng/api";
1
+ import type { ILogger } from "@thi.ng/logger";
2
2
  export declare let LOGGER: ILogger;
3
3
  export declare const setLogger: (logger: ILogger) => ILogger;
4
4
  //# sourceMappingURL=logger.d.ts.map
@@ -1,3 +1,3 @@
1
- import { NULL_LOGGER } from "@thi.ng/api";
1
+ import { NULL_LOGGER } from "@thi.ng/logger/null";
2
2
  export let LOGGER = NULL_LOGGER;
3
3
  export const setLogger = (logger) => (LOGGER = logger);
package/material.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Material } from "./api/material";
2
- import type { ShaderUniformSpecs } from "./api/shader";
1
+ import type { Material } from "./api/material.js";
2
+ import type { ShaderUniformSpecs } from "./api/shader.js";
3
3
  export declare const DEFAULT_MATERIAL: Material;
4
4
  export declare const defMaterial: (mat?: Partial<Material>, flags?: Partial<Record<keyof Material, boolean>>, base?: Material) => ShaderUniformSpecs;
5
5
  //# sourceMappingURL=material.d.ts.map
package/matrices.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { IObjectOf } from "@thi.ng/api";
2
2
  import type { ReadonlyVec } from "@thi.ng/vectors";
3
- import type { GLMat4 } from "./api/glsl";
4
- import type { ShaderUniforms } from "./api/shader";
3
+ import type { GLMat4 } from "./api/glsl.js";
4
+ import type { ShaderUniforms } from "./api/shader.js";
5
5
  /**
6
6
  * Computes the inverse transpose of given 4x4 matrix uniform, i.e.
7
7
  * `transpose(invert(m))`.
package/matrices.js CHANGED
@@ -1,5 +1,8 @@
1
- import { isNumber } from "@thi.ng/checks";
2
- import { IDENT44, mulM44, normal44, ortho } from "@thi.ng/matrices";
1
+ import { isNumber } from "@thi.ng/checks/is-number";
2
+ import { IDENT44 } from "@thi.ng/matrices/constants";
3
+ import { mulM44 } from "@thi.ng/matrices/mulm";
4
+ import { normal44 } from "@thi.ng/matrices/normal-mat";
5
+ import { ortho } from "@thi.ng/matrices/ortho";
3
6
  const $ = (a, b, id) => a[id] || b[id].defaultVal || IDENT44;
4
7
  /**
5
8
  * Computes the inverse transpose of given 4x4 matrix uniform, i.e.
package/multipass.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Multipass, MultipassOpts, PassOpts } from "./api/multipass";
1
+ import type { Multipass, MultipassOpts, PassOpts } from "./api/multipass.js";
2
2
  export declare const defMultiPass: (opts: MultipassOpts) => Multipass;
3
3
  /**
4
4
  * Returns a dynamically generated single pass spec ({@link PassOpts}) for use
package/multipass.js CHANGED
@@ -1,14 +1,22 @@
1
- import { assert } from "@thi.ng/api";
2
- import { $xy, assign, defMain, INT0, ivec2, texelFetch, } from "@thi.ng/shader-ast";
3
- import { assocObj, map, range, some, transduce } from "@thi.ng/transducers";
4
- import { compileModel } from "./buffer";
5
- import { isFloatTexture, isGL2Context } from "./checks";
6
- import { draw } from "./draw";
7
- import { defFBO } from "./fbo";
8
- import { defQuadModel } from "./geo/quad";
9
- import { defShader } from "./shader";
10
- import { PASSTHROUGH_VS } from "./shaders/pipeline";
11
- import { defTexture } from "./texture";
1
+ import { assert } from "@thi.ng/errors/assert";
2
+ import { assign } from "@thi.ng/shader-ast/ast/assign";
3
+ import { defMain } from "@thi.ng/shader-ast/ast/function";
4
+ import { INT0, ivec2 } from "@thi.ng/shader-ast/ast/lit";
5
+ import { $xy } from "@thi.ng/shader-ast/ast/swizzle";
6
+ import { texelFetch } from "@thi.ng/shader-ast/builtin/texture";
7
+ import { assocObj } from "@thi.ng/transducers/assoc-obj";
8
+ import { map } from "@thi.ng/transducers/map";
9
+ import { range } from "@thi.ng/transducers/range";
10
+ import { some } from "@thi.ng/transducers/some";
11
+ import { transduce } from "@thi.ng/transducers/transduce";
12
+ import { compileModel } from "./buffer.js";
13
+ import { isFloatTexture, isGL2Context } from "./checks.js";
14
+ import { draw } from "./draw.js";
15
+ import { defFBO } from "./fbo.js";
16
+ import { defQuadModel } from "./geo/quad.js";
17
+ import { defShader } from "./shader.js";
18
+ import { PASSTHROUGH_VS } from "./shaders/pipeline.js";
19
+ import { defTexture } from "./texture.js";
12
20
  export const defMultiPass = (opts) => {
13
21
  const gl = opts.gl;
14
22
  const numPasses = opts.passes.length;
@@ -70,9 +78,9 @@ const initPasses = (opts, textures) => {
70
78
  const gl = opts.gl;
71
79
  const model = compileModel(gl, defQuadModel({ uv: false }));
72
80
  return opts.passes.map((pass) => {
73
- const m = pass.model ? compileModel(gl, pass.model) : Object.assign({}, model);
81
+ const m = pass.model ? compileModel(gl, pass.model) : { ...model };
74
82
  m.shader = initShader(gl, pass, textures);
75
- m.uniforms = Object.assign({}, pass.uniformVals);
83
+ m.uniforms = { ...pass.uniformVals };
76
84
  pass.inputs.length > 0 &&
77
85
  (m.textures = pass.inputs.map((id) => textures[id]));
78
86
  return m;
@@ -90,7 +98,10 @@ const initShader = (gl, pass, textures) => {
90
98
  position: "vec2",
91
99
  },
92
100
  varying: pass.varying,
93
- uniforms: Object.assign(Object.assign({}, pass.uniforms), transduce(map((i) => [`input${i}`, ["sampler2D", i]]), assocObj(), range(numIns))),
101
+ uniforms: {
102
+ ...pass.uniforms,
103
+ ...transduce(map((i) => [`input${i}`, ["sampler2D", i]]), assocObj(), range(numIns)),
104
+ },
94
105
  outputs: numOuts
95
106
  ? transduce(map((i) => [
96
107
  `output${i}`,
@@ -117,7 +128,14 @@ const initShader = (gl, pass, textures) => {
117
128
  return defShader(gl, spec);
118
129
  };
119
130
  const initTextures = (opts) => Object.keys(opts.textures).reduce((acc, id) => {
120
- acc[id] = defTexture(opts.gl, Object.assign({ width: opts.width, height: opts.height, filter: opts.gl.NEAREST, wrap: opts.gl.CLAMP_TO_EDGE, image: null }, opts.textures[id]));
131
+ acc[id] = defTexture(opts.gl, {
132
+ width: opts.width,
133
+ height: opts.height,
134
+ filter: opts.gl.NEAREST,
135
+ wrap: opts.gl.CLAMP_TO_EDGE,
136
+ image: null,
137
+ ...opts.textures[id],
138
+ });
121
139
  return acc;
122
140
  }, {});
123
141
  const initBuffers = (opts, textures, useMainBuffer) => (useMainBuffer