@thi.ng/webgl 6.8.15 → 6.9.1

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**: 2024-05-08T18:24:31Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
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,21 @@ 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.9.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/webgl@6.9.0) (2024-06-21)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add UncompiledModelSpec, update compileModel() ([95be119](https://github.com/thi-ng/umbrella/commit/95be119))
17
+ - update WebGLCanvasOpts, switch to WebGL v2 by default ([6bb029e](https://github.com/thi-ng/umbrella/commit/6bb029e))
18
+ - add docs
19
+ - add `ModelSpec.instancePool` ([c4d695f](https://github.com/thi-ng/umbrella/commit/c4d695f))
20
+ - add new `instancePool` option to specify instance attribs via AttribPool
21
+ - update `compileModel()` to support new option
22
+
23
+ #### ♻️ Refactoring
24
+
25
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
26
+
12
27
  ### [6.8.12](https://github.com/thi-ng/umbrella/tree/@thi.ng/webgl@6.8.12) (2024-04-20)
13
28
 
14
29
  #### ♻️ Refactoring
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 192 standalone projects, maintained as part
10
+ > This is one of 189 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
  >
@@ -100,7 +100,7 @@ Browser ESM import:
100
100
 
101
101
  [JSDelivr documentation](https://www.jsdelivr.com/)
102
102
 
103
- Package sizes (brotli'd, pre-treeshake): ESM: 11.64 KB
103
+ Package sizes (brotli'd, pre-treeshake): ESM: 11.67 KB
104
104
 
105
105
  ## Dependencies
106
106
 
@@ -127,27 +127,29 @@ Several projects in this repo's
127
127
  [/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
128
128
  directory are using this package:
129
129
 
130
- | Screenshot | Description | Live demo | Source |
131
- |:-----------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------|:----------------------------------------------------------|:---------------------------------------------------------------------------------------|
132
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-easings.png" width="240"/> | Shader-AST meta-programming techniques for animated function plots | [Demo](https://demo.thi.ng/umbrella/shader-ast-easings/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-easings) |
133
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-evo.jpg" width="240"/> | Evolutionary shader generation using genetic programming | [Demo](https://demo.thi.ng/umbrella/shader-ast-evo/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-evo) |
134
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-noise.jpg" width="240"/> | HOF shader procedural noise function composition | [Demo](https://demo.thi.ng/umbrella/shader-ast-noise/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-noise) |
135
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/shader-ast/shader-ast-raymarch.jpg" width="240"/> | WebGL & JS canvas2D raymarch shader cross-compilation | [Demo](https://demo.thi.ng/umbrella/shader-ast-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-raymarch) |
136
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-sdf2d.jpg" width="240"/> | WebGL & JS canvas 2D SDF | [Demo](https://demo.thi.ng/umbrella/shader-ast-sdf2d/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-sdf2d) |
137
- | <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) |
138
- | <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) |
139
- | <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) |
140
- | <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) |
141
- | <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) |
142
- | <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) |
143
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-float-fbo.jpg" width="240"/> | Drawing to floating point offscreen / multi-pass shader pipeline | [Demo](https://demo.thi.ng/umbrella/webgl-float-fbo/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-float-fbo) |
144
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-game-of-life.png" width="240"/> | Game of Life implemented as WebGL2 multi-pass shader pipeline | [Demo](https://demo.thi.ng/umbrella/webgl-game-of-life/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-game-of-life) |
145
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-grid.jpg" width="240"/> | WebGL instancing, animated grid | [Demo](https://demo.thi.ng/umbrella/webgl-grid/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-grid) |
146
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-msdf.jpg" width="240"/> | WebGL MSDF text rendering & particle system | [Demo](https://demo.thi.ng/umbrella/webgl-msdf/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-msdf) |
147
- | | Minimal multi-pass / GPGPU example | [Demo](https://demo.thi.ng/umbrella/webgl-multipass/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-multipass) |
148
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-shadertoy.jpg" width="240"/> | Shadertoy-like WebGL setup | [Demo](https://demo.thi.ng/umbrella/webgl-shadertoy/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-shadertoy) |
149
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-ssao.jpg" width="240"/> | WebGL screenspace ambient occlusion | [Demo](https://demo.thi.ng/umbrella/webgl-ssao/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-ssao) |
150
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-texture-paint.jpg" width="240"/> | Interactively drawing to & reading from a WebGL offscreen render texture | [Demo](https://demo.thi.ng/umbrella/webgl-texture-paint/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-texture-paint) |
130
+ | Screenshot | Description | Live demo | Source |
131
+ |:------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------|:-------------------------------------------------------------|:------------------------------------------------------------------------------------------|
132
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-webgl-attrib-pool.jpg" width="240"/> | Augmenting thi.ng/geom shapes for WebGL, using instancing & attribute buffers | [Demo](https://demo.thi.ng/umbrella/geom-webgl-attrib-pool/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-webgl-attrib-pool) |
133
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-webgl-basics.jpg" width="240"/> | Converting thi.ng/geom shape types for WebGL | [Demo](https://demo.thi.ng/umbrella/geom-webgl-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-webgl-basics) |
134
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-easings.png" width="240"/> | Shader-AST meta-programming techniques for animated function plots | [Demo](https://demo.thi.ng/umbrella/shader-ast-easings/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-easings) |
135
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-evo.jpg" width="240"/> | Evolutionary shader generation using genetic programming | [Demo](https://demo.thi.ng/umbrella/shader-ast-evo/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-evo) |
136
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-noise.jpg" width="240"/> | HOF shader procedural noise function composition | [Demo](https://demo.thi.ng/umbrella/shader-ast-noise/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-noise) |
137
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/shader-ast/shader-ast-raymarch.jpg" width="240"/> | WebGL & JS canvas2D raymarch shader cross-compilation | [Demo](https://demo.thi.ng/umbrella/shader-ast-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-raymarch) |
138
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-sdf2d.jpg" width="240"/> | WebGL & JS canvas 2D SDF | [Demo](https://demo.thi.ng/umbrella/shader-ast-sdf2d/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-sdf2d) |
139
+ | <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) |
140
+ | <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) |
141
+ | <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) |
142
+ | <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) |
143
+ | <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) |
144
+ | <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) |
145
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-float-fbo.jpg" width="240"/> | Drawing to floating point offscreen / multi-pass shader pipeline | [Demo](https://demo.thi.ng/umbrella/webgl-float-fbo/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-float-fbo) |
146
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-game-of-life.png" width="240"/> | Game of Life implemented as WebGL2 multi-pass shader pipeline | [Demo](https://demo.thi.ng/umbrella/webgl-game-of-life/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-game-of-life) |
147
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-grid.jpg" width="240"/> | WebGL instancing, animated grid | [Demo](https://demo.thi.ng/umbrella/webgl-grid/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-grid) |
148
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-msdf.jpg" width="240"/> | WebGL MSDF text rendering & particle system | [Demo](https://demo.thi.ng/umbrella/webgl-msdf/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-msdf) |
149
+ | | Minimal multi-pass / GPGPU example | [Demo](https://demo.thi.ng/umbrella/webgl-multipass/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-multipass) |
150
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-shadertoy.jpg" width="240"/> | Shadertoy-like WebGL setup | [Demo](https://demo.thi.ng/umbrella/webgl-shadertoy/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-shadertoy) |
151
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-ssao.jpg" width="240"/> | WebGL screenspace ambient occlusion | [Demo](https://demo.thi.ng/umbrella/webgl-ssao/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-ssao) |
152
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-texture-paint.jpg" width="240"/> | Interactively drawing to & reading from a WebGL offscreen render texture | [Demo](https://demo.thi.ng/umbrella/webgl-texture-paint/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-texture-paint) |
151
153
 
152
154
  ## API
153
155
 
package/api/canvas.d.ts CHANGED
@@ -1,12 +1,34 @@
1
1
  import type { WebGLExtensionMap } from "./ext.js";
2
2
  export interface WeblGLCanvasOpts {
3
3
  canvas: string | HTMLCanvasElement;
4
+ /**
5
+ * Parent element to attach the canvas to
6
+ */
4
7
  parent: HTMLElement;
8
+ /**
9
+ * WebGL context options
10
+ */
5
11
  opts: Partial<WebGLContextAttributes>;
12
+ /**
13
+ * WebGL version
14
+ *
15
+ * @defaultValue 2
16
+ */
6
17
  version: 1 | 2;
7
18
  width: number;
8
19
  height: number;
20
+ /**
21
+ * Unless false, the canvas will adapt to the current window's
22
+ * `devicePixelRatio` setting, i.e. the `drawingBufferWidth` will be
23
+ * configured `width * dpr` (same for height).
24
+ *
25
+ * @defaultValue true
26
+ */
9
27
  autoScale: boolean;
28
+ /**
29
+ * Event listener to respond to a loss of the WebGL context (triggered by
30
+ * the browser).
31
+ */
10
32
  onContextLost: EventListener;
11
33
  ext: (keyof WebGLExtensionMap)[];
12
34
  }
package/api/model.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { GLType, IObjectOf, Type } from "@thi.ng/api";
2
2
  import type { AttribPool } from "@thi.ng/vector-pools";
3
3
  import type { IndexBufferSpec, IWebGLBuffer } from "./buffers.js";
4
- import type { AttribBufferData, IShader, UniformValues } from "./shader.js";
4
+ import type { AttribBufferData, IShader, ShaderSpec, UniformValues } from "./shader.js";
5
5
  import type { ITexture } from "./texture.js";
6
6
  export declare enum DrawMode {
7
7
  POINTS = 0,
@@ -19,13 +19,13 @@ export interface ModelSpec {
19
19
  */
20
20
  shader: IShader;
21
21
  /**
22
- * GLSL attribute declarations
22
+ * GLSL attribute declarations. Also see {@link ModelSpec.attribPool} as
23
+ * alternative input format.
23
24
  */
24
25
  attribs: ModelAttributeSpecs;
25
26
  /**
26
27
  * Geometry attributes given as
27
- * [`AttribPool`](https://docs.thi.ng/umbrella/vector-pools/classes/AttribPool.html)
28
- * instance.
28
+ * [`AttribPool`](https://docs.thi.ng/umbrella/vector-pools/classes/AttribPool.html).
29
29
  */
30
30
  attribPool?: AttribPool;
31
31
  /**
@@ -43,9 +43,15 @@ export interface ModelSpec {
43
43
  */
44
44
  textures?: ITexture[];
45
45
  /**
46
- * Extra configuration for instanced geometry
46
+ * Extra configuration for instanced geometry. Also see
47
+ * {@link ModelSpec.instancePool} as alternative input format.
47
48
  */
48
49
  instances?: InstancingSpec;
50
+ /**
51
+ * Instance attributes given as
52
+ * [`AttribPool`](https://docs.thi.ng/umbrella/vector-pools/classes/AttribPool.html).
53
+ */
54
+ instancePool?: AttribPool;
49
55
  /**
50
56
  * WebGL draw mode. Defaults to `TRIANGLES`
51
57
  */
@@ -55,6 +61,13 @@ export interface ModelSpec {
55
61
  */
56
62
  num: number;
57
63
  }
64
+ /**
65
+ * Version of {@link ModelSpec} in which neither any buffers nor the shader have
66
+ * been compiled yet and the latter is only specified as {@link ShaderSpec}.
67
+ */
68
+ export interface UncompiledModelSpec extends Omit<ModelSpec, "shader"> {
69
+ shader: ShaderSpec;
70
+ }
58
71
  /**
59
72
  * Data specification of a single WebGL attribute
60
73
  */
package/buffer.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type TypedArray } from "@thi.ng/api/typedarray";
2
2
  import type { AttribPool } from "@thi.ng/vector-pools";
3
3
  import type { IWebGLBuffer, IndexBufferSpec } from "./api/buffers.js";
4
- import { type ModelAttributeSpecs, type ModelSpec } from "./api/model.js";
4
+ import { type ModelAttributeSpecs, type ModelSpec, type UncompiledModelSpec } from "./api/model.js";
5
5
  export declare class WebGLArrayBuffer<T extends TypedArray> implements IWebGLBuffer<T> {
6
6
  gl: WebGLRenderingContext;
7
7
  buffer: WebGLBuffer;
@@ -25,7 +25,16 @@ export declare class WebGLArrayBuffer<T extends TypedArray> implements IWebGLBuf
25
25
  setChunk(data: T, byteOffset?: number): void;
26
26
  }
27
27
  export declare const defBuffer: (gl: WebGLRenderingContext, data?: TypedArray, target?: GLenum, mode?: GLenum, retain?: boolean) => WebGLArrayBuffer<Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array>;
28
- export declare const compileModel: (gl: WebGLRenderingContext, spec: ModelSpec, mode?: 35044) => ModelSpec;
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}.
32
+ *
33
+ * @param gl
34
+ * @param spec
35
+ * @param mode
36
+ */
37
+ export declare const compileModel: (gl: WebGLRenderingContext, spec: ModelSpec | UncompiledModelSpec, mode?: 35044) => ModelSpec;
29
38
  export declare const compileIndices: (gl: WebGLRenderingContext, index?: IndexBufferSpec, mode?: GLenum) => IndexBufferSpec | undefined;
30
39
  export declare const compileVAO: (gl: WebGLRenderingContext, spec: ModelSpec) => WebGLVertexArrayObject | undefined;
31
40
  export declare const compileAttribPool: (gl: WebGLRenderingContext, pool: AttribPool, ids?: string[], target?: GLenum, mode?: GLenum) => ModelAttributeSpecs;
package/buffer.js CHANGED
@@ -3,11 +3,13 @@ import {
3
3
  asGLType,
4
4
  typedArrayType
5
5
  } from "@thi.ng/api/typedarray";
6
+ import { isPlainObject } from "@thi.ng/checks/is-plain-object";
6
7
  import {
7
8
  DrawMode
8
9
  } from "./api/model.js";
9
10
  import { isGL2Context } from "./checks.js";
10
11
  import { error } from "./error.js";
12
+ import { defShader } from "./shader.js";
11
13
  class WebGLArrayBuffer {
12
14
  gl;
13
15
  buffer;
@@ -77,31 +79,47 @@ const compileModel = (gl, spec, mode = gl.STATIC_DRAW) => {
77
79
  mode
78
80
  );
79
81
  } else {
80
- compileAttribs(gl, spec.attribs, mode);
82
+ __compileAttribs(gl, spec.attribs, mode);
83
+ }
84
+ if (spec.instancePool) {
85
+ spec.instances = {
86
+ attribs: compileAttribPool(
87
+ gl,
88
+ spec.instancePool,
89
+ void 0,
90
+ gl.ARRAY_BUFFER,
91
+ mode
92
+ ),
93
+ num: spec.instancePool.capacity
94
+ };
95
+ } else if (spec.instances) {
96
+ __compileAttribs(gl, spec.instances.attribs, mode);
81
97
  }
82
- spec.instances && compileAttribs(gl, spec.instances.attribs, mode);
83
98
  compileIndices(gl, spec.indices, mode);
84
99
  spec.mode == null && (spec.mode = DrawMode.TRIANGLES);
100
+ if (isPlainObject(spec.shader)) {
101
+ spec.shader = defShader(gl, spec.shader);
102
+ }
85
103
  return spec;
86
104
  };
87
- const initBuffer = (gl, src, type, mode) => {
105
+ const __initBuffer = (gl, src, type, mode) => {
88
106
  if (src.buffer) {
89
107
  src.data && src.buffer.set(src.data);
90
108
  } else {
91
109
  src.buffer = new WebGLArrayBuffer(gl, src.data, type, mode, src.retain);
92
110
  }
93
111
  };
94
- const compileAttribs = (gl, attribs, mode) => {
112
+ const __compileAttribs = (gl, attribs, mode) => {
95
113
  if (attribs) {
96
114
  for (let id in attribs) {
97
- initBuffer(gl, attribs[id], gl.ARRAY_BUFFER, mode);
115
+ __initBuffer(gl, attribs[id], gl.ARRAY_BUFFER, mode);
98
116
  }
99
117
  }
100
118
  return attribs;
101
119
  };
102
120
  const compileIndices = (gl, index, mode = gl.STATIC_DRAW) => {
103
121
  if (index) {
104
- initBuffer(gl, index, gl.ELEMENT_ARRAY_BUFFER, mode);
122
+ __initBuffer(gl, index, gl.ELEMENT_ARRAY_BUFFER, mode);
105
123
  }
106
124
  return index;
107
125
  };
@@ -134,7 +152,7 @@ const compileVAO = (gl, spec) => {
134
152
  }
135
153
  };
136
154
  const compileAttribPool = (gl, pool, ids, target = gl.ARRAY_BUFFER, mode = gl.STATIC_DRAW) => {
137
- const buf = defBuffer(gl, pool.bytes(), target, mode);
155
+ const buf = defBuffer(gl, pool.bytes(), target, mode, true);
138
156
  const spec = {};
139
157
  for (let id of ids || Object.keys(pool.specs)) {
140
158
  const attr = pool.specs[id];
package/canvas.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { adaptDPI } from "@thi.ng/canvas";
2
2
  import { isString } from "@thi.ng/checks/is-string";
3
3
  import { error } from "./error.js";
4
- const defaultOpts = {
4
+ const DEFAULT_OPTS = {
5
5
  alpha: true,
6
6
  antialias: true,
7
7
  depth: true,
@@ -16,9 +16,9 @@ const glCanvas = (opts = {}) => {
16
16
  opts.autoScale !== false && adaptDPI(canvas, canvas.width, canvas.height);
17
17
  opts.parent && opts.parent.appendChild(canvas);
18
18
  const gl = canvas.getContext(
19
- opts.version === 2 ? "webgl2" : "webgl",
19
+ opts.version !== 1 ? "webgl2" : "webgl",
20
20
  {
21
- ...defaultOpts,
21
+ ...DEFAULT_OPTS,
22
22
  ...opts.opts
23
23
  }
24
24
  );
package/draw.js CHANGED
@@ -14,7 +14,7 @@ const draw = (specs, opts = {}) => {
14
14
  if (indices && indices.buffer) {
15
15
  indices.buffer.bind();
16
16
  if (spec.instances) {
17
- drawInstanced(gl, spec);
17
+ __drawInstanced(gl, spec);
18
18
  } else {
19
19
  gl.drawElements(
20
20
  spec.mode,
@@ -25,7 +25,7 @@ const draw = (specs, opts = {}) => {
25
25
  }
26
26
  } else {
27
27
  if (spec.instances) {
28
- drawInstanced(gl, spec);
28
+ __drawInstanced(gl, spec);
29
29
  } else {
30
30
  gl.drawArrays(spec.mode, 0, spec.num);
31
31
  }
@@ -34,7 +34,7 @@ const draw = (specs, opts = {}) => {
34
34
  opts.unbindTex && unbindTextures(spec.textures);
35
35
  }
36
36
  };
37
- const drawInstanced = (gl, spec) => {
37
+ const __drawInstanced = (gl, spec) => {
38
38
  const isGL2 = isGL2Context(gl);
39
39
  const ext = !isGL2 ? gl.getExtension("ANGLE_instanced_arrays") : void 0;
40
40
  if (!(isGL2 || ext)) {
package/error.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- /// <reference types="node" />
2
1
  export declare const WebGLError: {
3
2
  new (msg?: string | undefined): {
4
3
  origMessage: string;
5
4
  name: string;
6
5
  message: string;
7
- stack?: string | undefined;
6
+ stack?: string;
8
7
  cause?: unknown;
9
8
  };
10
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
9
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
11
10
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
12
11
  stackTraceLimit: number;
13
12
  };
package/multipass.js CHANGED
@@ -29,9 +29,9 @@ const defMultiPass = (opts) => {
29
29
  const numPasses = opts.passes.length;
30
30
  assert(numPasses > 0, "require at least one shader pass");
31
31
  const useMainBuffer = !opts.passes[numPasses - 1].outputs.length;
32
- const textures = initTextures(opts);
33
- const passes = initPasses(opts, textures);
34
- const fbos = initBuffers(opts, textures, useMainBuffer);
32
+ const textures = __initTextures(opts);
33
+ const passes = __initPasses(opts, textures);
34
+ const fbos = __initBuffers(opts, textures, useMainBuffer);
35
35
  const drawPass = (i, time, isFBO = true) => {
36
36
  isFBO && fbos[i].bind();
37
37
  const spec = opts.passes[i];
@@ -82,12 +82,12 @@ const defMultiPass = (opts) => {
82
82
  };
83
83
  return instance;
84
84
  };
85
- const initPasses = (opts, textures) => {
85
+ const __initPasses = (opts, textures) => {
86
86
  const gl = opts.gl;
87
87
  const model = compileModel(gl, defQuadModel({ uv: false }));
88
88
  return opts.passes.map((pass) => {
89
89
  const m = pass.model ? compileModel(gl, pass.model) : { ...model };
90
- m.shader = initShader(gl, pass, textures);
90
+ m.shader = __initShader(gl, pass, textures);
91
91
  m.uniforms = { ...pass.uniformVals };
92
92
  pass.inputs.length > 0 && (m.textures = pass.inputs.map((id) => textures[id]));
93
93
  return m;
@@ -98,7 +98,7 @@ const TEX_TYPE_MAP = {
98
98
  [TextureTarget.TEXTURE_3D]: S3D,
99
99
  [TextureTarget.TEXTURE_CUBE_MAP]: "samplerCube"
100
100
  };
101
- const initShader = (gl, pass, textures) => {
101
+ const __initShader = (gl, pass, textures) => {
102
102
  const isGL2 = isGL2Context(gl);
103
103
  const numOuts = pass.outputs.length;
104
104
  const ext = { ...pass.ext };
@@ -146,7 +146,7 @@ const initShader = (gl, pass, textures) => {
146
146
  }
147
147
  return defShader(gl, spec);
148
148
  };
149
- const initTextures = (opts) => Object.keys(opts.textures).reduce((acc, id) => {
149
+ const __initTextures = (opts) => Object.keys(opts.textures).reduce((acc, id) => {
150
150
  acc[id] = defTexture(opts.gl, {
151
151
  width: opts.width,
152
152
  height: opts.height,
@@ -158,7 +158,7 @@ const initTextures = (opts) => Object.keys(opts.textures).reduce((acc, id) => {
158
158
  });
159
159
  return acc;
160
160
  }, {});
161
- const initBuffers = (opts, textures, useMainBuffer) => (useMainBuffer ? opts.passes.slice(0, opts.passes.length - 1) : opts.passes).map(
161
+ const __initBuffers = (opts, textures, useMainBuffer) => (useMainBuffer ? opts.passes.slice(0, opts.passes.length - 1) : opts.passes).map(
162
162
  (pass) => defFBO(opts.gl, { tex: pass.outputs.map((id) => textures[id]) })
163
163
  );
164
164
  const passCopy = (src, dest) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/webgl",
3
- "version": "6.8.15",
3
+ "version": "6.9.1",
4
4
  "description": "WebGL & GLSL abstraction layer",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/webgl#readme",
13
+ "homepage": "https://thi.ng/webgl",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -40,28 +40,28 @@
40
40
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@thi.ng/api": "^8.11.2",
44
- "@thi.ng/associative": "^6.3.60",
45
- "@thi.ng/canvas": "^0.2.19",
46
- "@thi.ng/checks": "^3.6.4",
47
- "@thi.ng/equiv": "^2.1.58",
48
- "@thi.ng/errors": "^2.5.7",
49
- "@thi.ng/logger": "^3.0.12",
50
- "@thi.ng/matrices": "^2.3.37",
51
- "@thi.ng/memoize": "^3.3.4",
52
- "@thi.ng/pixel": "^6.1.32",
53
- "@thi.ng/shader-ast": "^0.15.15",
54
- "@thi.ng/shader-ast-glsl": "^0.4.123",
55
- "@thi.ng/shader-ast-stdlib": "^0.18.15",
56
- "@thi.ng/transducers": "^9.0.5",
57
- "@thi.ng/vector-pools": "^3.1.129",
58
- "@thi.ng/vectors": "^7.10.31"
43
+ "@thi.ng/api": "^8.11.4",
44
+ "@thi.ng/associative": "^6.3.62",
45
+ "@thi.ng/canvas": "^0.2.21",
46
+ "@thi.ng/checks": "^3.6.6",
47
+ "@thi.ng/equiv": "^2.1.60",
48
+ "@thi.ng/errors": "^2.5.9",
49
+ "@thi.ng/logger": "^3.0.14",
50
+ "@thi.ng/matrices": "^2.4.1",
51
+ "@thi.ng/memoize": "^3.3.6",
52
+ "@thi.ng/pixel": "^6.1.34",
53
+ "@thi.ng/shader-ast": "^0.15.17",
54
+ "@thi.ng/shader-ast-glsl": "^0.4.125",
55
+ "@thi.ng/shader-ast-stdlib": "^0.18.17",
56
+ "@thi.ng/transducers": "^9.0.7",
57
+ "@thi.ng/vector-pools": "^3.2.1",
58
+ "@thi.ng/vectors": "^7.11.1"
59
59
  },
60
60
  "devDependencies": {
61
- "@microsoft/api-extractor": "^7.43.2",
62
- "esbuild": "^0.21.1",
61
+ "@microsoft/api-extractor": "^7.47.0",
62
+ "esbuild": "^0.21.5",
63
63
  "typedoc": "^0.25.13",
64
- "typescript": "^5.4.5"
64
+ "typescript": "^5.5.2"
65
65
  },
66
66
  "keywords": [
67
67
  "2d",
@@ -220,5 +220,5 @@
220
220
  ],
221
221
  "year": 2014
222
222
  },
223
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
223
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
224
224
  }
package/readpixels.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { UIntArray } from "@thi.ng/api";
2
2
  import type { ITexture, ReadableTextureFormat, TextureType } from "./api/texture.js";
3
- export declare const readPixels: <T extends Float32Array | UIntArray>(gl: WebGLRenderingContext, x: number, y: number, w: number, h: number, format: ReadableTextureFormat, type: TextureType, out: T) => T;
4
- export declare const readTexture: <T extends Float32Array | Uint8Array | Uint16Array | Uint32Array>(gl: WebGLRenderingContext, tex: ITexture, format: ReadableTextureFormat, type: TextureType, out: T) => T;
3
+ export declare const readPixels: <T extends UIntArray | Float32Array>(gl: WebGLRenderingContext, x: number, y: number, w: number, h: number, format: ReadableTextureFormat, type: TextureType, out: T) => T;
4
+ export declare const readTexture: <T extends Uint8Array | Uint16Array | Uint32Array | Float32Array>(gl: WebGLRenderingContext, tex: ITexture, format: ReadableTextureFormat, type: TextureType, out: T) => T;
5
5
  //# sourceMappingURL=readpixels.d.ts.map
package/shader.js CHANGED
@@ -170,7 +170,7 @@ const defShader = (gl, spec, opts) => {
170
170
  const logger = opts?.logger || LOGGER;
171
171
  logger.debug(srcVS);
172
172
  logger.debug(srcFS);
173
- spec.ext && initShaderExtensions(gl, spec.ext);
173
+ spec.ext && __initShaderExtensions(gl, spec.ext);
174
174
  const vs = compileShader(gl, gl.VERTEX_SHADER, srcVS);
175
175
  const fs = compileShader(gl, gl.FRAGMENT_SHADER, srcFS);
176
176
  const program2 = gl.createProgram() || error("error creating shader program");
@@ -178,15 +178,15 @@ const defShader = (gl, spec, opts) => {
178
178
  gl.attachShader(program2, fs);
179
179
  gl.linkProgram(program2);
180
180
  if (gl.getProgramParameter(program2, gl.LINK_STATUS)) {
181
- const attribs = initAttributes(gl, program2, spec.attribs);
182
- const uniforms = initUniforms(gl, program2, spec.uniforms);
181
+ const attribs = __initAttributes(gl, program2, spec.attribs);
182
+ const uniforms = __initUniforms(gl, program2, spec.uniforms);
183
183
  gl.deleteShader(vs);
184
184
  gl.deleteShader(fs);
185
185
  return new Shader(gl, program2, attribs, uniforms, spec.state);
186
186
  }
187
187
  throw new Error(`Error linking shader: ${gl.getProgramInfoLog(program2)}`);
188
188
  };
189
- const compileVars = (attribs, syntax, prefixes) => {
189
+ const __compileVars = (attribs, syntax, prefixes) => {
190
190
  let decls = [];
191
191
  for (let id in attribs) {
192
192
  if (attribs.hasOwnProperty(id)) {
@@ -196,13 +196,13 @@ const compileVars = (attribs, syntax, prefixes) => {
196
196
  decls.push("");
197
197
  return decls.join("\n");
198
198
  };
199
- const compileExtensionPragma = (id, behavior, version) => {
199
+ const __compileExtensionPragma = (id, behavior, version) => {
200
200
  const ext = GL_EXT_INFO[id];
201
201
  const gl2 = version === GLSLVersion.GLES_300;
202
202
  return ext && (!gl2 && ext.gl || gl2 && ext.gl2) ? `#extension ${ext && ext.alias || id} : ${isBoolean(behavior) ? behavior ? "enable" : "disable" : behavior}
203
203
  ` : "";
204
204
  };
205
- const initShaderExtensions = (gl, exts) => {
205
+ const __initShaderExtensions = (gl, exts) => {
206
206
  for (let id in exts) {
207
207
  const state = exts[id];
208
208
  if (state === true || state === "require") {
@@ -210,11 +210,11 @@ const initShaderExtensions = (gl, exts) => {
210
210
  }
211
211
  }
212
212
  };
213
- const compilePrelude = (spec, version) => {
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
216
  for (let id in spec.ext) {
217
- prelude += compileExtensionPragma(
217
+ prelude += __compileExtensionPragma(
218
218
  id,
219
219
  spec.ext[id],
220
220
  version
@@ -223,24 +223,24 @@ const compilePrelude = (spec, version) => {
223
223
  }
224
224
  return prelude;
225
225
  };
226
- const compileIODecls = (decl, src, dest) => {
226
+ const __compileIODecls = (decl, src, dest) => {
227
227
  for (let 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
  }
231
231
  };
232
- const varyingOpts = (v) => {
232
+ const __varyingOpts = (v) => {
233
233
  const [vtype, opts] = isArray(v) ? [v[0], { num: v[1] }] : [v, {}];
234
234
  /(u?int|[ui]vec[234])/.test(vtype) && (opts.smooth = "flat");
235
235
  return [vtype, opts];
236
236
  };
237
- const compileVaryingDecls = (spec, decl, acc) => {
237
+ const __compileVaryingDecls = (spec, decl, acc) => {
238
238
  for (let id in spec.varying) {
239
- const [vtype, opts] = varyingOpts(spec.varying[id]);
239
+ const [vtype, opts] = __varyingOpts(spec.varying[id]);
240
240
  acc[id] = decl(vtype, id, opts);
241
241
  }
242
242
  };
243
- const compileUniformDecls = (spec, acc) => {
243
+ const __compileUniformDecls = (spec, acc) => {
244
244
  for (let id in spec.uniforms) {
245
245
  const u = spec.uniforms[id];
246
246
  acc[id] = isArray(u) ? uniform(
@@ -251,20 +251,20 @@ const compileUniformDecls = (spec, acc) => {
251
251
  }
252
252
  };
253
253
  const shaderSourceFromAST = (spec, type, version, opts = {}) => {
254
- let prelude = compilePrelude(spec, version);
254
+ let prelude = __compilePrelude(spec, version);
255
255
  const inputs = {};
256
256
  const outputs = {};
257
257
  const outputAliases = {};
258
258
  const unis = {};
259
- spec.uniforms && compileUniformDecls(spec, unis);
259
+ spec.uniforms && __compileUniformDecls(spec, unis);
260
260
  if (type === "vs") {
261
- compileIODecls(input, spec.attribs, inputs);
262
- spec.varying && compileVaryingDecls(spec, output, outputs);
261
+ __compileIODecls(input, spec.attribs, inputs);
262
+ spec.varying && __compileVaryingDecls(spec, output, outputs);
263
263
  } else {
264
- spec.varying && compileVaryingDecls(spec, input, inputs);
264
+ spec.varying && __compileVaryingDecls(spec, input, inputs);
265
265
  const outs = spec.outputs || DEFAULT_OUTPUT;
266
266
  if (version >= GLSLVersion.GLES_300) {
267
- compileIODecls(output, outs, outputs);
267
+ __compileIODecls(output, outs, outputs);
268
268
  } else {
269
269
  for (let id in outs) {
270
270
  const o = outs[id];
@@ -303,15 +303,15 @@ const prepareShaderSource = (spec, type, version) => {
303
303
  let src = "";
304
304
  src += `#version ${version}
305
305
  `;
306
- src += compilePrelude(spec, version);
306
+ src += __compilePrelude(spec, version);
307
307
  if (spec.generateDecls !== false) {
308
- src += isVS ? compileVars(spec.attribs, syntax.attrib, prefixes) : compileVars(
308
+ src += isVS ? __compileVars(spec.attribs, syntax.attrib, prefixes) : __compileVars(
309
309
  spec.outputs || DEFAULT_OUTPUT,
310
310
  syntax.output,
311
311
  prefixes
312
312
  );
313
- src += compileVars(spec.varying, syntax.varying[type], prefixes);
314
- src += compileVars(spec.uniforms, syntax.uniform, prefixes);
313
+ src += __compileVars(spec.varying, syntax.varying[type], prefixes);
314
+ src += __compileVars(spec.uniforms, syntax.uniform, prefixes);
315
315
  }
316
316
  src += spec[type];
317
317
  spec.post && (src += "\n" + spec.post);
@@ -324,9 +324,9 @@ const compileShader = (gl, type, src) => {
324
324
  if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
325
325
  return shader;
326
326
  }
327
- return parseAndThrowShaderError(gl, shader, src);
327
+ return __parseAndThrowShaderError(gl, shader, src);
328
328
  };
329
- const parseAndThrowShaderError = (gl, shader, src) => {
329
+ const __parseAndThrowShaderError = (gl, shader, src) => {
330
330
  const lines = src.split("\n");
331
331
  const log = gl.getShaderInfoLog(shader).split("\n");
332
332
  const errors = log.map((line) => {
@@ -340,7 +340,7 @@ ${lines[parseInt(ln) - 1]}`;
340
340
  return error(`Error compiling shader:
341
341
  ${errors}`);
342
342
  };
343
- const initAttributes = (gl, prog, attribs) => {
343
+ const __initAttributes = (gl, prog, attribs) => {
344
344
  const res = {};
345
345
  for (let id in attribs) {
346
346
  const val = attribs[id];
@@ -358,7 +358,7 @@ const initAttributes = (gl, prog, attribs) => {
358
358
  }
359
359
  return res;
360
360
  };
361
- const initUniforms = (gl, prog, uniforms = {}) => {
361
+ const __initUniforms = (gl, prog, uniforms = {}) => {
362
362
  const res = {};
363
363
  for (let id in uniforms) {
364
364
  const val = uniforms[id];
package/syntax.js CHANGED
@@ -20,10 +20,10 @@ const SYNTAX = {
20
20
  number: 100,
21
21
  attrib: (id, type, pre) => `attribute ${isArray(type) ? type[0] : type} ${pre.a}${id};`,
22
22
  varying: {
23
- vs: (id, type, pre) => arrayDecl("varying", type, pre.v + id),
24
- fs: (id, type, pre) => arrayDecl("varying", type, pre.v + id)
23
+ vs: (id, type, pre) => __arrayDecl("varying", type, pre.v + id),
24
+ fs: (id, type, pre) => __arrayDecl("varying", type, pre.v + id)
25
25
  },
26
- uniform: (id, u, pre) => arrayDecl("uniform", u, pre.u + id),
26
+ uniform: (id, u, pre) => __arrayDecl("uniform", u, pre.u + id),
27
27
  output: (id, type, pre) => isArray(type) ? `#define ${pre.o}${id} gl_FragData[${type[1]}]` : ""
28
28
  },
29
29
  /**
@@ -33,14 +33,14 @@ const SYNTAX = {
33
33
  number: 300,
34
34
  attrib: (id, type, pre) => isArray(type) ? `layout(location=${type[1]}) in ${type[0]} ${pre.a}${id};` : `in ${type} ${pre.a}${id};`,
35
35
  varying: {
36
- vs: (id, type, pre) => arrayDecl("out", type, pre.v + id),
37
- fs: (id, type, pre) => arrayDecl("in", type, pre.v + id)
36
+ vs: (id, type, pre) => __arrayDecl("out", type, pre.v + id),
37
+ fs: (id, type, pre) => __arrayDecl("in", type, pre.v + id)
38
38
  },
39
- uniform: (id, u, pre) => arrayDecl("uniform", u, pre.u + id),
39
+ uniform: (id, u, pre) => __arrayDecl("uniform", u, pre.u + id),
40
40
  output: (id, type, pre) => isArray(type) ? `layout(location=${type[1]}) out ${type[0]} ${pre.o}${id};` : `out ${type} ${pre.o}${id};`
41
41
  }
42
42
  };
43
- const arrayDecl = (qualifier, decl, id) => {
43
+ const __arrayDecl = (qualifier, decl, id) => {
44
44
  const type = isArray(decl) ? decl[0] : decl;
45
45
  return type.indexOf("[]") > 0 ? `${qualifier} ${type.replace("[]", "")} ${id}[${decl[1]}];` : `${qualifier} ${type} ${id};`;
46
46
  };
package/uniforms.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { equivArrayLike } from "@thi.ng/equiv";
2
2
  import { IDENT22, IDENT33, IDENT44 } from "@thi.ng/matrices/constants";
3
3
  import { ZERO2, ZERO3, ZERO4 } from "@thi.ng/vectors/api";
4
- const uniformS = (fn) => (gl, loc, defaultVal = 0) => {
4
+ const __uniformS = (fn) => (gl, loc, defaultVal = 0) => {
5
5
  let prev;
6
6
  return (x) => {
7
7
  x = x === void 0 ? defaultVal : x;
@@ -11,7 +11,7 @@ const uniformS = (fn) => (gl, loc, defaultVal = 0) => {
11
11
  }
12
12
  };
13
13
  };
14
- const uniformV = (fn, sysDefault) => (gl, loc, defaultVal = sysDefault) => {
14
+ const __uniformV = (fn, sysDefault) => (gl, loc, defaultVal = sysDefault) => {
15
15
  let prev = [];
16
16
  return (x) => {
17
17
  x = x === void 0 ? defaultVal : x;
@@ -21,7 +21,7 @@ const uniformV = (fn, sysDefault) => (gl, loc, defaultVal = sysDefault) => {
21
21
  }
22
22
  };
23
23
  };
24
- const uniformM = (fn, sysDefault) => (gl, loc, defaultVal = sysDefault) => {
24
+ const __uniformM = (fn, sysDefault) => (gl, loc, defaultVal = sysDefault) => {
25
25
  let prev = [];
26
26
  return (x) => {
27
27
  x = x === void 0 ? defaultVal : x;
@@ -33,48 +33,48 @@ const uniformM = (fn, sysDefault) => (gl, loc, defaultVal = sysDefault) => {
33
33
  };
34
34
  const Z1 = [0];
35
35
  const UNIFORM_SETTERS = {
36
- bool: uniformS("i"),
37
- float: uniformS("f"),
38
- int: uniformS("i"),
39
- uint: uniformS("ui"),
40
- bvec2: uniformV("2iv", ZERO2),
41
- bvec3: uniformV("3iv", ZERO3),
42
- bvec4: uniformV("4iv", ZERO4),
43
- ivec2: uniformV("2iv", ZERO2),
44
- ivec3: uniformV("3iv", ZERO3),
45
- ivec4: uniformV("4iv", ZERO4),
46
- vec2: uniformV("2fv", ZERO2),
47
- vec3: uniformV("3fv", ZERO3),
48
- vec4: uniformV("4fv", ZERO4),
49
- mat2: uniformM("2fv", IDENT22),
50
- mat3: uniformM("3fv", IDENT33),
51
- mat4: uniformM("4fv", IDENT44),
52
- sampler2D: uniformS("i"),
53
- sampler2DShadow: uniformS("i"),
54
- sampler3D: uniformS("i"),
55
- samplerCube: uniformS("i"),
56
- samplerCubeShadow: uniformS("i"),
57
- "bool[]": uniformV("1iv", Z1),
58
- "float[]": uniformV("1fv", Z1),
59
- "int[]": uniformV("1iv", Z1),
60
- "uint[]": uniformV("1uiv", Z1),
61
- "bvec2[]": uniformV("2iv", ZERO2),
62
- "bvec3[]": uniformV("3iv", ZERO3),
63
- "bvec4[]": uniformV("4iv", ZERO4),
64
- "ivec2[]": uniformV("2iv", ZERO2),
65
- "ivec3[]": uniformV("3iv", ZERO3),
66
- "ivec4[]": uniformV("4iv", ZERO4),
67
- "vec2[]": uniformV("2fv", ZERO2),
68
- "vec3[]": uniformV("3fv", ZERO3),
69
- "vec4[]": uniformV("4fv", ZERO4),
70
- "mat2[]": uniformM("2fv", ZERO2),
71
- "mat3[]": uniformM("3fv", ZERO3),
72
- "mat4[]": uniformM("4fv", ZERO4),
73
- "sampler2D[]": uniformV("1iv", Z1),
74
- "sampler2DShadow[]": uniformV("1iv", Z1),
75
- "sampler3D[]": uniformV("1iv", Z1),
76
- "samplerCube[]": uniformV("1iv", Z1),
77
- "samplerCubeShadow[]": uniformV("1iv", Z1)
36
+ bool: __uniformS("i"),
37
+ float: __uniformS("f"),
38
+ int: __uniformS("i"),
39
+ uint: __uniformS("ui"),
40
+ bvec2: __uniformV("2iv", ZERO2),
41
+ bvec3: __uniformV("3iv", ZERO3),
42
+ bvec4: __uniformV("4iv", ZERO4),
43
+ ivec2: __uniformV("2iv", ZERO2),
44
+ ivec3: __uniformV("3iv", ZERO3),
45
+ ivec4: __uniformV("4iv", ZERO4),
46
+ vec2: __uniformV("2fv", ZERO2),
47
+ vec3: __uniformV("3fv", ZERO3),
48
+ vec4: __uniformV("4fv", ZERO4),
49
+ mat2: __uniformM("2fv", IDENT22),
50
+ mat3: __uniformM("3fv", IDENT33),
51
+ mat4: __uniformM("4fv", IDENT44),
52
+ sampler2D: __uniformS("i"),
53
+ sampler2DShadow: __uniformS("i"),
54
+ sampler3D: __uniformS("i"),
55
+ samplerCube: __uniformS("i"),
56
+ samplerCubeShadow: __uniformS("i"),
57
+ "bool[]": __uniformV("1iv", Z1),
58
+ "float[]": __uniformV("1fv", Z1),
59
+ "int[]": __uniformV("1iv", Z1),
60
+ "uint[]": __uniformV("1uiv", Z1),
61
+ "bvec2[]": __uniformV("2iv", ZERO2),
62
+ "bvec3[]": __uniformV("3iv", ZERO3),
63
+ "bvec4[]": __uniformV("4iv", ZERO4),
64
+ "ivec2[]": __uniformV("2iv", ZERO2),
65
+ "ivec3[]": __uniformV("3iv", ZERO3),
66
+ "ivec4[]": __uniformV("4iv", ZERO4),
67
+ "vec2[]": __uniformV("2fv", ZERO2),
68
+ "vec3[]": __uniformV("3fv", ZERO3),
69
+ "vec4[]": __uniformV("4fv", ZERO4),
70
+ "mat2[]": __uniformM("2fv", ZERO2),
71
+ "mat3[]": __uniformM("3fv", ZERO3),
72
+ "mat4[]": __uniformM("4fv", ZERO4),
73
+ "sampler2D[]": __uniformV("1iv", Z1),
74
+ "sampler2DShadow[]": __uniformV("1iv", Z1),
75
+ "sampler3D[]": __uniformV("1iv", Z1),
76
+ "samplerCube[]": __uniformV("1iv", Z1),
77
+ "samplerCubeShadow[]": __uniformV("1iv", Z1)
78
78
  };
79
79
  export {
80
80
  UNIFORM_SETTERS