@luma.gl/engine 9.0.0-alpha.35 → 9.0.0-alpha.36

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 (47) hide show
  1. package/dist/animation/timeline.d.ts +4 -4
  2. package/dist/animation/timeline.d.ts.map +1 -1
  3. package/dist/animation/timeline.js +13 -13
  4. package/dist/animation/timeline.js.map +1 -1
  5. package/dist/animation-loop/animation-loop.d.ts +2 -2
  6. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  7. package/dist/animation-loop/animation-loop.js +5 -6
  8. package/dist/animation-loop/animation-loop.js.map +1 -1
  9. package/dist/animation-loop/animation-props.d.ts +1 -2
  10. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  11. package/dist/animation-loop/animation-props.js.map +1 -1
  12. package/dist/dist.dev.js +991 -9124
  13. package/dist/index.cjs +269 -130
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/lib/clip-space.d.ts +1 -1
  19. package/dist/lib/clip-space.d.ts.map +1 -1
  20. package/dist/lib/clip-space.js +1 -2
  21. package/dist/lib/clip-space.js.map +1 -1
  22. package/dist/model/model.d.ts +43 -22
  23. package/dist/model/model.d.ts.map +1 -1
  24. package/dist/model/model.js +72 -19
  25. package/dist/model/model.js.map +1 -1
  26. package/dist/scenegraph/scenegraph-node.d.ts +5 -5
  27. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  28. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  29. package/dist/shadertools/shader-module-uniforms.d.ts +36 -0
  30. package/dist/shadertools/shader-module-uniforms.d.ts.map +1 -0
  31. package/dist/shadertools/shader-module-uniforms.js +87 -0
  32. package/dist/shadertools/shader-module-uniforms.js.map +1 -0
  33. package/dist/transform/transform.d.ts +2 -2
  34. package/dist/transform/transform.d.ts.map +1 -1
  35. package/dist/transform/transform.js +0 -18
  36. package/dist/transform/transform.js.map +1 -1
  37. package/dist.min.js +107 -165
  38. package/package.json +5 -6
  39. package/src/animation/timeline.ts +13 -13
  40. package/src/animation-loop/animation-loop.ts +6 -8
  41. package/src/animation-loop/animation-props.ts +1 -2
  42. package/src/index.ts +3 -0
  43. package/src/lib/clip-space.ts +2 -3
  44. package/src/model/model.ts +154 -60
  45. package/src/scenegraph/scenegraph-node.ts +5 -5
  46. package/src/shadertools/shader-module-uniforms.ts +178 -0
  47. package/src/transform/transform.ts +8 -6
@@ -0,0 +1,178 @@
1
+ // luma.gl, MIT license
2
+ import {NumberArray, isNumberArray} from '@luma.gl/core';
3
+ import {Device, Buffer, UniformBufferLayout, ShaderUniformType} from '@luma.gl/core';
4
+ import {ShaderModule} from '@luma.gl/shadertools';
5
+
6
+ /** Duplicates definition in core module to avoid cross dependencies */
7
+ export type UniformValue = number | boolean | Readonly<NumberArray>; // Float32Array> | Readonly<Int32Array> | Readonly<Uint32Array> | Readonly<number[]>;
8
+
9
+ /** A uniform store holds a number of uniform values and does some book keeping on what has changes */
10
+ export class ShaderModuleUniforms<TUniforms extends Record<string, UniformValue>> {
11
+ device: Device;
12
+ shaderModule: ShaderModule<TUniforms>;
13
+
14
+ useUniformBuffers: boolean;
15
+ uniformBufferLayout: UniformBufferLayout;
16
+ uniformBuffer: Buffer | null = null;
17
+
18
+ uniforms: Record<string, UniformValue> = {};
19
+ modifiedUniforms: Record<string, boolean> = {};
20
+ modified: boolean = true;
21
+
22
+ needsRedraw: string | false = 'initialized';
23
+
24
+ constructor(props?: {
25
+ device: Device;
26
+ shaderModule: ShaderModule<TUniforms>
27
+ }) {
28
+ this.device = props.device;
29
+ this.shaderModule = props.shaderModule;
30
+ this.useUniformBuffers = this.device.info.type !== 'webgl';
31
+
32
+ // extract uniform formats and create a uniform buffer layout
33
+ const uniformTypes: Record<string, ShaderUniformType> = {};
34
+ for (const [name, {format}] of Object.entries(props.shaderModule.uniforms)) {
35
+ uniformTypes[name] = format;
36
+ }
37
+ this.uniformBufferLayout = new UniformBufferLayout(uniformTypes);
38
+
39
+ // create a uniform buffer
40
+ if (this.useUniformBuffers) {
41
+ this.uniformBuffer = this.device.createBuffer({
42
+ usage: Buffer.UNIFORM,
43
+ byteLength: this.uniformBufferLayout.byteLength
44
+ });
45
+ }
46
+ }
47
+
48
+ /** Set a map of uniforms */
49
+ setUniforms(uniforms: TUniforms): void {
50
+ for (const [key, value] of Object.entries(uniforms)) {
51
+ this._setUniform(key, value);
52
+ this.setNeedsRedraw(key);
53
+ }
54
+ }
55
+
56
+ setNeedsRedraw(reason: string): void {
57
+ this.needsRedraw = this.needsRedraw || reason;
58
+ }
59
+
60
+ /**
61
+ * Updates the uniform buffer if needed.
62
+ * Clears the dirty flag.
63
+ */
64
+ getUniformBuffer(): Buffer {
65
+ if (this.needsRedraw) {
66
+ const modifiedUniforms = this.getModifiedUniforms();
67
+ const data = this.uniformBufferLayout.getData(modifiedUniforms);
68
+ this.uniformBuffer.write(data);
69
+ }
70
+ return this.uniformBuffer;
71
+ }
72
+
73
+ /** Returns all uniforms */
74
+ getUniforms(groupName: string): Record<string, UniformValue> {
75
+ this.modifiedUniforms = {};
76
+ this.needsRedraw = false;
77
+ return (this.uniforms[groupName] || {}) as Record<string, UniformValue>;
78
+ }
79
+
80
+ /** Returns modified uniforms */
81
+ getModifiedUniforms() {
82
+ const modifiedUniforms = this.modifiedUniforms;
83
+ this.modifiedUniforms = {};
84
+ this.needsRedraw = false;
85
+ return modifiedUniforms;
86
+ }
87
+
88
+ /** Set a single uniform */
89
+ private _setUniform(key: string, value: UniformValue) {
90
+ // if (this.layout[key] !== undefined) {
91
+ // this.uniforms[key] = value;
92
+ // this.modifiedUniforms[key] = true;
93
+ // this.modified = true;
94
+ // } else {
95
+ // log.warn(`Unknown uniform ${key}`)
96
+ // }
97
+ if (arrayEqual(this.uniforms[key], value)) {
98
+ return;
99
+ }
100
+ this.uniforms[key] = value;
101
+ this.modifiedUniforms[key] = true;
102
+ this.modified = true;
103
+ }
104
+ }
105
+
106
+ function arrayEqual(a: unknown, b: unknown, limit: number = 16) {
107
+ if (a !== b) {
108
+ return false;
109
+ }
110
+ const arrayA = isNumberArray(a);
111
+ if (!arrayA) {
112
+ return false;
113
+ }
114
+ const arrayB = isNumberArray(b);
115
+ if (arrayB && arrayA.length === arrayB.length) {
116
+ for (let i = 0; i < arrayA.length; ++i) {
117
+ if (arrayB[i] !== arrayA[i]) {
118
+ return false;
119
+ }
120
+ }
121
+ }
122
+ return true;
123
+ }
124
+
125
+
126
+ // export function makeUniformStore<I extends Record<string, Record<string, unknown>>>(name: string, uniforms: I): UniformStore<{ [P in keyof I]: I[P] }> {
127
+ // return new UniformStore<{ [P in keyof I]: I[P] }>({name, uniforms});
128
+ // }
129
+
130
+ // type ShaderModule<Uniforms extends Record<string, unknown> = {}> = {
131
+ // uniformTypes: Record<keyof Uniforms, string>;
132
+ // };
133
+
134
+ // type Module1Uniforms = {
135
+ // uniform1?: number;
136
+ // uniform2?: [number, number];
137
+ // }
138
+
139
+ // type Module2Uniforms = {
140
+ // uniform3: number;
141
+ // uniform4: [number, number];
142
+ // }
143
+
144
+ // const shaderModule: ShaderModule<Module1Uniforms> = {
145
+ // uniformTypes: {
146
+ // uniform1: 'aaa',
147
+ // uniform2: 'aaa'
148
+ // }
149
+ // }
150
+
151
+
152
+ // const module1Uniforms = new ShaderModuleUniforms<Module1Uniforms>();
153
+
154
+ // module1Uniforms.setUniforms({
155
+ // uniform1: 1,
156
+ // uniform2: [1, 1]
157
+ // });
158
+
159
+
160
+
161
+ // setUniformStore(pipeline, blockIndex, block);
162
+
163
+ // GLSL utilities
164
+
165
+
166
+ // TYPE TESTS
167
+
168
+ /*
169
+ new UniformStore<ModuleUniforms>().setUniforms({
170
+ uniform1: 1,
171
+ uniform2: 1,
172
+ });
173
+
174
+ new UniformStore<ModuleUniforms>().setUniforms({
175
+ three: 1,
176
+ uniform1: 1,
177
+ });
178
+ */
@@ -1,10 +1,11 @@
1
+
1
2
  // luma.gl, MIT license
2
3
 
3
4
  import {Device, Buffer, Texture, Framebuffer} from '@luma.gl/core';
4
- import {getShaderInfo, getPassthroughFS} from '@luma.gl/shadertools';
5
- import {GL} from '@luma.gl/constants';
6
- import {WebGLDevice, GLParameters} from '@luma.gl/webgl';
7
- import {Model} from '../model/model';
5
+ import {GLParameters} from '@luma.gl/constants';
6
+ // import {getShaderInfo, getPassthroughFS} from '@luma.gl/shadertools';
7
+ // import {GL} from '@luma.gl/constants';
8
+ // import {Model} from '../model/model';
8
9
 
9
10
  // import {AccessorObject} from '@luma.gl/webgl';
10
11
  // import {default as TransformFeedback} from '../classic/transform-feedback';
@@ -86,7 +87,7 @@ export class Transform {
86
87
  return false;
87
88
  }
88
89
 
89
- readonly device: WebGLDevice;
90
+ readonly device: Device;
90
91
  readonly gl: WebGL2RenderingContext;
91
92
  // model: Model;
92
93
  elementCount = 0;
@@ -95,6 +96,7 @@ export class Transform {
95
96
  elementIDBuffer: Buffer | null = null;
96
97
 
97
98
  constructor(device: Device | WebGLRenderingContext, props: TransformProps = {}) {
99
+ /*
98
100
  this.device = WebGLDevice.attach(device);
99
101
  // TODO assert webgl2?
100
102
  this.gl = this.device.gl2;
@@ -106,7 +108,6 @@ export class Transform {
106
108
  ...props,
107
109
  fs: props.fs || getPassthroughFS({version: getShaderInfo(props.vs).version}),
108
110
  id: props.id || 'transform-model',
109
- // @ts-expect-error
110
111
  drawMode: props.drawMode || GL.POINTS,
111
112
  vertexCount: props.elementCount
112
113
  });
@@ -115,6 +116,7 @@ export class Transform {
115
116
  // this.bufferTransform.setupResources({model: this.model});
116
117
  // }
117
118
  Object.seal(this);
119
+ */
118
120
  }
119
121
 
120
122
  /** Delete owned resources. */