Skip to content

Commit d6d44ec

Browse files
committed
PMREMNode: Move texture cache into class scope.
1 parent 370b8ee commit d6d44ec

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/nodes/pmrem/PMREMNode.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { nodeProxy, vec3 } from '../tsl/TSLBase.js';
88
import { Texture } from '../../textures/Texture.js';
99
import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';
1010

11-
const _cache = new WeakMap();
12-
1311
/**
1412
* Generates the cubeUV size based on the given image height.
1513
*
@@ -35,11 +33,12 @@ function _generateCubeUVSize( imageHeight ) {
3533
* @private
3634
* @param {Texture} texture - The texture to create the PMREM for.
3735
* @param {PMREMGenerator} generator - The PMREM generator.
36+
* @param {WeakMap<Texture,Texture>} cache - The PMREM texture cache.
3837
* @return {Texture} The PMREM.
3938
*/
40-
function _getPMREMFromTexture( texture, generator ) {
39+
function _getPMREMFromTexture( texture, generator, cache ) {
4140

42-
let cacheTexture = _cache.get( texture );
41+
let cacheTexture = cache.get( texture );
4342

4443
const pmremVersion = cacheTexture !== undefined ? cacheTexture.pmremVersion : - 1;
4544

@@ -76,7 +75,7 @@ function _getPMREMFromTexture( texture, generator ) {
7675

7776
cacheTexture.pmremVersion = texture.pmremVersion;
7877

79-
_cache.set( texture, cacheTexture );
78+
cache.set( texture, cacheTexture );
8079

8180
}
8281

@@ -132,14 +131,14 @@ class PMREMNode extends TempNode {
132131
this._pmrem = null;
133132

134133
/**
135-
* The uv node.
134+
* The uv node.
136135
*
137136
* @type {Node<vec2>}
138137
*/
139138
this.uvNode = uvNode;
140139

141140
/**
142-
* The level node.
141+
* The level node.
143142
*
144143
* @type {Node<float>}
145144
*/
@@ -189,6 +188,14 @@ class PMREMNode extends TempNode {
189188
*/
190189
this._maxMip = uniform( 0 );
191190

191+
/**
192+
* The PMREM texture cache.
193+
*
194+
* @private
195+
* @type {WeakMap<Texture,Texture>}
196+
*/
197+
this._cache = new WeakMap();
198+
192199
/**
193200
* The `updateBeforeType` is set to `NodeUpdateType.RENDER`.
194201
*
@@ -248,7 +255,7 @@ class PMREMNode extends TempNode {
248255

249256
} else {
250257

251-
pmrem = _getPMREMFromTexture( texture, this._generator );
258+
pmrem = _getPMREMFromTexture( texture, this._generator, this._cache );
252259

253260
}
254261

0 commit comments

Comments
 (0)