@luma.gl/engine 9.2.6 → 9.3.0-alpha.11

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 (198) hide show
  1. package/dist/animation-loop/animation-loop.d.ts +11 -5
  2. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  3. package/dist/animation-loop/animation-loop.js +83 -47
  4. package/dist/animation-loop/animation-loop.js.map +1 -1
  5. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  6. package/dist/animation-loop/make-animation-loop.js +8 -1
  7. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  8. package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
  9. package/dist/animation-loop/request-animation-frame.js +23 -6
  10. package/dist/animation-loop/request-animation-frame.js.map +1 -1
  11. package/dist/compute/computation.d.ts +3 -7
  12. package/dist/compute/computation.d.ts.map +1 -1
  13. package/dist/compute/computation.js +16 -13
  14. package/dist/compute/computation.js.map +1 -1
  15. package/dist/compute/swap.d.ts +2 -0
  16. package/dist/compute/swap.d.ts.map +1 -1
  17. package/dist/compute/swap.js +10 -5
  18. package/dist/compute/swap.js.map +1 -1
  19. package/dist/debug/debug-framebuffer.d.ts +9 -4
  20. package/dist/debug/debug-framebuffer.d.ts.map +1 -1
  21. package/dist/debug/debug-framebuffer.js +91 -45
  22. package/dist/debug/debug-framebuffer.js.map +1 -1
  23. package/dist/dist.dev.js +2767 -1344
  24. package/dist/dist.min.js +326 -211
  25. package/dist/dynamic-texture/dynamic-texture.d.ts +102 -0
  26. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -0
  27. package/dist/dynamic-texture/dynamic-texture.js +558 -0
  28. package/dist/dynamic-texture/dynamic-texture.js.map +1 -0
  29. package/dist/dynamic-texture/texture-data.d.ts +144 -0
  30. package/dist/dynamic-texture/texture-data.d.ts.map +1 -0
  31. package/dist/dynamic-texture/texture-data.js +208 -0
  32. package/dist/dynamic-texture/texture-data.js.map +1 -0
  33. package/dist/geometries/cone-geometry.d.ts +3 -1
  34. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  35. package/dist/geometries/cone-geometry.js.map +1 -1
  36. package/dist/geometries/cube-geometry.js +7 -7
  37. package/dist/geometries/cube-geometry.js.map +1 -1
  38. package/dist/geometries/cylinder-geometry.d.ts +2 -1
  39. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  40. package/dist/geometries/cylinder-geometry.js.map +1 -1
  41. package/dist/geometries/ico-sphere-geometry.js +3 -1
  42. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  43. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  44. package/dist/geometry/gpu-geometry.js +11 -3
  45. package/dist/geometry/gpu-geometry.js.map +1 -1
  46. package/dist/index.cjs +2620 -1267
  47. package/dist/index.cjs.map +4 -4
  48. package/dist/index.d.ts +20 -6
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +12 -4
  51. package/dist/index.js.map +1 -1
  52. package/dist/material/material-factory.d.ts +73 -0
  53. package/dist/material/material-factory.d.ts.map +1 -0
  54. package/dist/material/material-factory.js +111 -0
  55. package/dist/material/material-factory.js.map +1 -0
  56. package/dist/material/material.d.ts +84 -0
  57. package/dist/material/material.d.ts.map +1 -0
  58. package/dist/material/material.js +176 -0
  59. package/dist/material/material.js.map +1 -0
  60. package/dist/model/model.d.ts +47 -16
  61. package/dist/model/model.d.ts.map +1 -1
  62. package/dist/model/model.js +148 -71
  63. package/dist/model/model.js.map +1 -1
  64. package/dist/model/split-uniforms-and-bindings.d.ts +4 -3
  65. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  66. package/dist/model/split-uniforms-and-bindings.js +2 -2
  67. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  68. package/dist/models/billboard-texture-model.d.ts +8 -5
  69. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  70. package/dist/models/billboard-texture-model.js +79 -25
  71. package/dist/models/billboard-texture-model.js.map +1 -1
  72. package/dist/models/billboard-texture-module.d.ts +1 -1
  73. package/dist/models/billboard-texture-module.js +1 -1
  74. package/dist/models/clip-space.js +7 -7
  75. package/dist/models/directional-light-model.d.ts +7 -0
  76. package/dist/models/directional-light-model.d.ts.map +1 -0
  77. package/dist/models/directional-light-model.js +23 -0
  78. package/dist/models/directional-light-model.js.map +1 -0
  79. package/dist/models/light-model-utils.d.ts +69 -0
  80. package/dist/models/light-model-utils.d.ts.map +1 -0
  81. package/dist/models/light-model-utils.js +395 -0
  82. package/dist/models/light-model-utils.js.map +1 -0
  83. package/dist/models/point-light-model.d.ts +7 -0
  84. package/dist/models/point-light-model.d.ts.map +1 -0
  85. package/dist/models/point-light-model.js +22 -0
  86. package/dist/models/point-light-model.js.map +1 -0
  87. package/dist/models/spot-light-model.d.ts +7 -0
  88. package/dist/models/spot-light-model.d.ts.map +1 -0
  89. package/dist/models/spot-light-model.js +23 -0
  90. package/dist/models/spot-light-model.js.map +1 -0
  91. package/dist/modules/picking/color-picking.d.ts +5 -9
  92. package/dist/modules/picking/color-picking.d.ts.map +1 -1
  93. package/dist/modules/picking/color-picking.js +122 -115
  94. package/dist/modules/picking/color-picking.js.map +1 -1
  95. package/dist/modules/picking/index-picking.d.ts +4 -4
  96. package/dist/modules/picking/index-picking.d.ts.map +1 -1
  97. package/dist/modules/picking/index-picking.js +36 -16
  98. package/dist/modules/picking/index-picking.js.map +1 -1
  99. package/dist/modules/picking/legacy-color-picking.d.ts +26 -0
  100. package/dist/modules/picking/legacy-color-picking.d.ts.map +1 -0
  101. package/dist/modules/picking/legacy-color-picking.js +7 -0
  102. package/dist/modules/picking/legacy-color-picking.js.map +1 -0
  103. package/dist/modules/picking/picking-manager.d.ts +29 -3
  104. package/dist/modules/picking/picking-manager.d.ts.map +1 -1
  105. package/dist/modules/picking/picking-manager.js +188 -41
  106. package/dist/modules/picking/picking-manager.js.map +1 -1
  107. package/dist/modules/picking/picking-uniforms.d.ts +13 -12
  108. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
  109. package/dist/modules/picking/picking-uniforms.js +27 -14
  110. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  111. package/dist/modules/picking/picking.d.ts +25 -0
  112. package/dist/modules/picking/picking.d.ts.map +1 -0
  113. package/dist/modules/picking/picking.js +18 -0
  114. package/dist/modules/picking/picking.js.map +1 -0
  115. package/dist/passes/get-fragment-shader.js +12 -27
  116. package/dist/passes/get-fragment-shader.js.map +1 -1
  117. package/dist/passes/shader-pass-renderer.d.ts +5 -7
  118. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  119. package/dist/passes/shader-pass-renderer.js +16 -42
  120. package/dist/passes/shader-pass-renderer.js.map +1 -1
  121. package/dist/scenegraph/group-node.d.ts +5 -0
  122. package/dist/scenegraph/group-node.d.ts.map +1 -1
  123. package/dist/scenegraph/group-node.js +12 -0
  124. package/dist/scenegraph/group-node.js.map +1 -1
  125. package/dist/scenegraph/model-node.d.ts +2 -2
  126. package/dist/scenegraph/model-node.d.ts.map +1 -1
  127. package/dist/scenegraph/model-node.js.map +1 -1
  128. package/dist/scenegraph/scenegraph-node.d.ts +1 -1
  129. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  130. package/dist/scenegraph/scenegraph-node.js +23 -15
  131. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  132. package/dist/shader-inputs.d.ts +9 -7
  133. package/dist/shader-inputs.d.ts.map +1 -1
  134. package/dist/shader-inputs.js +90 -13
  135. package/dist/shader-inputs.js.map +1 -1
  136. package/dist/utils/buffer-layout-order.d.ts.map +1 -1
  137. package/dist/utils/buffer-layout-order.js +12 -2
  138. package/dist/utils/buffer-layout-order.js.map +1 -1
  139. package/dist/utils/shader-module-utils.d.ts +7 -0
  140. package/dist/utils/shader-module-utils.d.ts.map +1 -0
  141. package/dist/utils/shader-module-utils.js +46 -0
  142. package/dist/utils/shader-module-utils.js.map +1 -0
  143. package/package.json +6 -6
  144. package/src/animation-loop/animation-loop.ts +89 -50
  145. package/src/animation-loop/make-animation-loop.ts +14 -5
  146. package/src/animation-loop/request-animation-frame.ts +32 -6
  147. package/src/compute/computation.ts +32 -17
  148. package/src/compute/swap.ts +13 -7
  149. package/src/debug/debug-framebuffer.ts +139 -61
  150. package/src/dynamic-texture/dynamic-texture.ts +730 -0
  151. package/src/dynamic-texture/texture-data.ts +336 -0
  152. package/src/{async-texture/texture-setters.ts.disabled → dynamic-texture/texture-data.ts.disabled} +1 -1
  153. package/src/geometries/cone-geometry.ts +6 -1
  154. package/src/geometries/cube-geometry.ts +7 -7
  155. package/src/geometries/cylinder-geometry.ts +5 -1
  156. package/src/geometries/ico-sphere-geometry.ts +3 -1
  157. package/src/geometry/gpu-geometry.ts +11 -3
  158. package/src/index.ts +38 -8
  159. package/src/material/material-factory.ts +157 -0
  160. package/src/material/material.ts +254 -0
  161. package/src/model/model.ts +196 -93
  162. package/src/model/split-uniforms-and-bindings.ts +8 -6
  163. package/src/models/billboard-texture-model.ts +90 -29
  164. package/src/models/billboard-texture-module.ts +1 -1
  165. package/src/models/clip-space.ts +7 -7
  166. package/src/models/directional-light-model.ts +32 -0
  167. package/src/models/light-model-utils.ts +587 -0
  168. package/src/models/point-light-model.ts +31 -0
  169. package/src/models/spot-light-model.ts +32 -0
  170. package/src/modules/picking/color-picking.ts +123 -122
  171. package/src/modules/picking/index-picking.ts +36 -16
  172. package/src/modules/picking/legacy-color-picking.ts +8 -0
  173. package/src/modules/picking/picking-manager.ts +252 -50
  174. package/src/modules/picking/picking-uniforms.ts +39 -24
  175. package/src/modules/picking/picking.ts +22 -0
  176. package/src/passes/get-fragment-shader.ts +12 -27
  177. package/src/passes/shader-pass-renderer.ts +25 -48
  178. package/src/scenegraph/group-node.ts +16 -0
  179. package/src/scenegraph/model-node.ts +2 -2
  180. package/src/scenegraph/scenegraph-node.ts +27 -16
  181. package/src/shader-inputs.ts +167 -26
  182. package/src/utils/buffer-layout-order.ts +18 -2
  183. package/src/utils/shader-module-utils.ts +65 -0
  184. package/dist/async-texture/async-texture.d.ts +0 -166
  185. package/dist/async-texture/async-texture.d.ts.map +0 -1
  186. package/dist/async-texture/async-texture.js +0 -386
  187. package/dist/async-texture/async-texture.js.map +0 -1
  188. package/dist/factories/pipeline-factory.d.ts +0 -37
  189. package/dist/factories/pipeline-factory.d.ts.map +0 -1
  190. package/dist/factories/pipeline-factory.js +0 -181
  191. package/dist/factories/pipeline-factory.js.map +0 -1
  192. package/dist/factories/shader-factory.d.ts +0 -22
  193. package/dist/factories/shader-factory.d.ts.map +0 -1
  194. package/dist/factories/shader-factory.js +0 -88
  195. package/dist/factories/shader-factory.js.map +0 -1
  196. package/src/async-texture/async-texture.ts +0 -551
  197. package/src/factories/pipeline-factory.ts +0 -224
  198. package/src/factories/shader-factory.ts +0 -103
@@ -1,224 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import type {RenderPipelineProps, ComputePipelineProps} from '@luma.gl/core';
6
- import {Device, RenderPipeline, ComputePipeline, log} from '@luma.gl/core';
7
- import {uid} from '../utils/uid';
8
-
9
- export type PipelineFactoryProps = RenderPipelineProps;
10
-
11
- type RenderPipelineCacheItem = {pipeline: RenderPipeline; useCount: number};
12
- type ComputePipelineCacheItem = {pipeline: ComputePipeline; useCount: number};
13
-
14
- /**
15
- * Efficiently creates / caches pipelines
16
- */
17
- export class PipelineFactory {
18
- static defaultProps: Required<PipelineFactoryProps> = {...RenderPipeline.defaultProps};
19
-
20
- /** Get the singleton default pipeline factory for the specified device */
21
- static getDefaultPipelineFactory(device: Device): PipelineFactory {
22
- device._lumaData['defaultPipelineFactory'] =
23
- device._lumaData['defaultPipelineFactory'] || new PipelineFactory(device);
24
- return device._lumaData['defaultPipelineFactory'] as PipelineFactory;
25
- }
26
-
27
- readonly device: Device;
28
- readonly cachingEnabled: boolean;
29
- readonly destroyPolicy: 'unused' | 'never';
30
- readonly debug: boolean;
31
-
32
- private _hashCounter: number = 0;
33
- private readonly _hashes: Record<string, number> = {};
34
- private readonly _renderPipelineCache: Record<string, RenderPipelineCacheItem> = {};
35
- private readonly _computePipelineCache: Record<string, ComputePipelineCacheItem> = {};
36
-
37
- get [Symbol.toStringTag](): string {
38
- return 'PipelineFactory';
39
- }
40
-
41
- toString(): string {
42
- return `PipelineFactory(${this.device.id})`;
43
- }
44
-
45
- constructor(device: Device) {
46
- this.device = device;
47
- this.cachingEnabled = device.props._cachePipelines;
48
- this.destroyPolicy = device.props._cacheDestroyPolicy;
49
- this.debug = device.props.debugFactories;
50
- }
51
-
52
- /** Return a RenderPipeline matching supplied props. Reuses an equivalent pipeline if already created. */
53
- createRenderPipeline(props: RenderPipelineProps): RenderPipeline {
54
- if (!this.cachingEnabled) {
55
- return this.device.createRenderPipeline(props);
56
- }
57
-
58
- const allProps: Required<RenderPipelineProps> = {...RenderPipeline.defaultProps, ...props};
59
-
60
- const cache = this._renderPipelineCache;
61
- const hash = this._hashRenderPipeline(allProps);
62
-
63
- let pipeline: RenderPipeline = cache[hash]?.pipeline;
64
- if (!pipeline) {
65
- pipeline = this.device.createRenderPipeline({
66
- ...allProps,
67
- id: allProps.id ? `${allProps.id}-cached` : uid('unnamed-cached')
68
- });
69
- pipeline.hash = hash;
70
- cache[hash] = {pipeline, useCount: 1};
71
- if (this.debug) {
72
- log.log(3, `${this}: ${pipeline} created, count=${cache[hash].useCount}`)();
73
- }
74
- } else {
75
- cache[hash].useCount++;
76
- if (this.debug) {
77
- log.log(
78
- 3,
79
- `${this}: ${cache[hash].pipeline} reused, count=${cache[hash].useCount}, (id=${props.id})`
80
- )();
81
- }
82
- }
83
-
84
- return pipeline;
85
- }
86
-
87
- /** Return a ComputePipeline matching supplied props. Reuses an equivalent pipeline if already created. */
88
- createComputePipeline(props: ComputePipelineProps): ComputePipeline {
89
- if (!this.cachingEnabled) {
90
- return this.device.createComputePipeline(props);
91
- }
92
-
93
- const allProps: Required<ComputePipelineProps> = {...ComputePipeline.defaultProps, ...props};
94
-
95
- const cache = this._computePipelineCache;
96
- const hash = this._hashComputePipeline(allProps);
97
-
98
- let pipeline: ComputePipeline = cache[hash]?.pipeline;
99
- if (!pipeline) {
100
- pipeline = this.device.createComputePipeline({
101
- ...allProps,
102
- id: allProps.id ? `${allProps.id}-cached` : undefined
103
- });
104
- pipeline.hash = hash;
105
- cache[hash] = {pipeline, useCount: 1};
106
- if (this.debug) {
107
- log.log(3, `${this}: ${pipeline} created, count=${cache[hash].useCount}`)();
108
- }
109
- } else {
110
- cache[hash].useCount++;
111
- if (this.debug) {
112
- log.log(
113
- 3,
114
- `${this}: ${cache[hash].pipeline} reused, count=${cache[hash].useCount}, (id=${props.id})`
115
- )();
116
- }
117
- }
118
-
119
- return pipeline;
120
- }
121
-
122
- release(pipeline: RenderPipeline | ComputePipeline): void {
123
- if (!this.cachingEnabled) {
124
- pipeline.destroy();
125
- return;
126
- }
127
-
128
- const cache = this._getCache(pipeline);
129
- const hash = pipeline.hash;
130
-
131
- cache[hash].useCount--;
132
- if (cache[hash].useCount === 0) {
133
- this._destroyPipeline(pipeline);
134
- if (this.debug) {
135
- log.log(3, `${this}: ${pipeline} released and destroyed`)();
136
- }
137
- } else if (cache[hash].useCount < 0) {
138
- log.error(`${this}: ${pipeline} released, useCount < 0, resetting`)();
139
- cache[hash].useCount = 0;
140
- } else if (this.debug) {
141
- log.log(3, `${this}: ${pipeline} released, count=${cache[hash].useCount}`)();
142
- }
143
- }
144
-
145
- // PRIVATE
146
-
147
- /** Destroy a cached pipeline, removing it from the cache (depending on destroy policy) */
148
- private _destroyPipeline(pipeline: RenderPipeline | ComputePipeline): boolean {
149
- const cache = this._getCache(pipeline);
150
-
151
- switch (this.destroyPolicy) {
152
- case 'never':
153
- return false;
154
- case 'unused':
155
- delete cache[pipeline.hash];
156
- pipeline.destroy();
157
- return true;
158
- }
159
- }
160
-
161
- /** Get the appropriate cache for the type of pipeline */
162
- private _getCache(
163
- pipeline: RenderPipeline | ComputePipeline
164
- ): Record<string, RenderPipelineCacheItem> | Record<string, ComputePipelineCacheItem> {
165
- let cache:
166
- | Record<string, RenderPipelineCacheItem>
167
- | Record<string, ComputePipelineCacheItem>
168
- | undefined;
169
- if (pipeline instanceof ComputePipeline) {
170
- cache = this._computePipelineCache;
171
- }
172
- if (pipeline instanceof RenderPipeline) {
173
- cache = this._renderPipelineCache;
174
- }
175
- if (!cache) {
176
- throw new Error(`${this}`);
177
- }
178
- if (!cache[pipeline.hash]) {
179
- throw new Error(`${this}: ${pipeline} matched incorrect entry`);
180
- }
181
- return cache;
182
- }
183
-
184
- /** Calculate a hash based on all the inputs for a compute pipeline */
185
- private _hashComputePipeline(props: ComputePipelineProps): string {
186
- const {type} = this.device;
187
- const shaderHash = this._getHash(props.shader.source);
188
- return `${type}/C/${shaderHash}`;
189
- }
190
-
191
- /** Calculate a hash based on all the inputs for a render pipeline */
192
- private _hashRenderPipeline(props: RenderPipelineProps): string {
193
- const vsHash = props.vs ? this._getHash(props.vs.source) : 0;
194
- const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
195
-
196
- // WebGL specific
197
- // const {varyings = [], bufferMode = {}} = props;
198
- // const varyingHashes = varyings.map((v) => this._getHash(v));
199
- const varyingHash = '-'; // `${varyingHashes.join('/')}B${bufferMode}`
200
- const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
201
-
202
- const {type} = this.device;
203
- switch (type) {
204
- case 'webgl':
205
- // WebGL is more dynamic
206
- return `${type}/R/${vsHash}/${fsHash}V${varyingHash}BL${bufferLayoutHash}`;
207
-
208
- case 'webgpu':
209
- default:
210
- // On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change
211
- const parameterHash = this._getHash(JSON.stringify(props.parameters));
212
- // TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?
213
- // create a deepHash() to deduplicate?
214
- return `${type}/R/${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}`;
215
- }
216
- }
217
-
218
- private _getHash(key: string): number {
219
- if (this._hashes[key] === undefined) {
220
- this._hashes[key] = this._hashCounter++;
221
- }
222
- return this._hashes[key];
223
- }
224
- }
@@ -1,103 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {Device, Shader, ShaderProps, log} from '@luma.gl/core';
6
-
7
- /** Manages a cached pool of Shaders for reuse. */
8
- export class ShaderFactory {
9
- static readonly defaultProps: Required<ShaderProps> = {...Shader.defaultProps};
10
-
11
- /** Returns the default ShaderFactory for the given {@link Device}, creating one if necessary. */
12
- static getDefaultShaderFactory(device: Device): ShaderFactory {
13
- device._lumaData['defaultShaderFactory'] ||= new ShaderFactory(device);
14
- return device._lumaData['defaultShaderFactory'] as ShaderFactory;
15
- }
16
-
17
- public readonly device: Device;
18
- readonly cachingEnabled: boolean;
19
- readonly destroyPolicy: 'unused' | 'never';
20
- readonly debug: boolean;
21
-
22
- private readonly _cache: Record<string, {shader: Shader; useCount: number}> = {};
23
-
24
- get [Symbol.toStringTag](): string {
25
- return 'ShaderFactory';
26
- }
27
-
28
- toString(): string {
29
- return `${this[Symbol.toStringTag]}(${this.device.id})`;
30
- }
31
-
32
- /** @internal */
33
- constructor(device: Device) {
34
- this.device = device;
35
- this.cachingEnabled = device.props._cacheShaders;
36
- this.destroyPolicy = device.props._cacheDestroyPolicy;
37
- this.debug = true; // device.props.debugFactories;
38
- }
39
-
40
- /** Requests a {@link Shader} from the cache, creating a new Shader only if necessary. */
41
- createShader(props: ShaderProps): Shader {
42
- if (!this.cachingEnabled) {
43
- return this.device.createShader(props);
44
- }
45
-
46
- const key = this._hashShader(props);
47
-
48
- let cacheEntry = this._cache[key];
49
- if (!cacheEntry) {
50
- const shader = this.device.createShader({
51
- ...props,
52
- id: props.id ? `${props.id}-cached` : undefined
53
- });
54
- this._cache[key] = cacheEntry = {shader, useCount: 1};
55
- if (this.debug) {
56
- log.log(3, `${this}: Created new shader ${shader.id}`)();
57
- }
58
- } else {
59
- cacheEntry.useCount++;
60
- if (this.debug) {
61
- log.log(
62
- 3,
63
- `${this}: Reusing shader ${cacheEntry.shader.id} count=${cacheEntry.useCount}`
64
- )();
65
- }
66
- }
67
-
68
- return cacheEntry.shader;
69
- }
70
-
71
- /** Releases a previously-requested {@link Shader}, destroying it if no users remain. */
72
- release(shader: Shader): void {
73
- if (!this.cachingEnabled) {
74
- shader.destroy();
75
- return;
76
- }
77
-
78
- const key = this._hashShader(shader);
79
- const cacheEntry = this._cache[key];
80
- if (cacheEntry) {
81
- cacheEntry.useCount--;
82
- if (cacheEntry.useCount === 0) {
83
- if (this.destroyPolicy === 'unused') {
84
- delete this._cache[key];
85
- cacheEntry.shader.destroy();
86
- if (this.debug) {
87
- log.log(3, `${this}: Releasing shader ${shader.id}, destroyed`)();
88
- }
89
- }
90
- } else if (cacheEntry.useCount < 0) {
91
- throw new Error(`ShaderFactory: Shader ${shader.id} released too many times`);
92
- } else if (this.debug) {
93
- log.log(3, `${this}: Releasing shader ${shader.id} count=${cacheEntry.useCount}`)();
94
- }
95
- }
96
- }
97
-
98
- // PRIVATE
99
-
100
- protected _hashShader(value: Shader | ShaderProps): string {
101
- return `${value.stage}:${value.source}`;
102
- }
103
- }