|
@@ -12,7 +12,7 @@ class WebGPUTextures {
|
|
|
this.defaultTexture = null;
|
|
|
this.defaultSampler = null;
|
|
|
|
|
|
- this.samplerCache = new WeakMap();
|
|
|
+ this.samplerCache = new Map();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -52,13 +52,13 @@ class WebGPUTextures {
|
|
|
|
|
|
const textureProperties = this.properties.get( texture );
|
|
|
|
|
|
- return textureProperties.sampler;
|
|
|
+ return textureProperties.samplerGPU;
|
|
|
|
|
|
}
|
|
|
|
|
|
updateTexture( texture ) {
|
|
|
|
|
|
- let updated = false;
|
|
|
+ let forceUpdate = false;
|
|
|
|
|
|
const textureProperties = this.properties.get( texture );
|
|
|
|
|
@@ -105,7 +105,7 @@ class WebGPUTextures {
|
|
|
|
|
|
textureProperties.textureGPU = this._createTexture( texture );
|
|
|
textureProperties.version = texture.version;
|
|
|
- updated = true;
|
|
|
+ forceUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -117,18 +117,16 @@ class WebGPUTextures {
|
|
|
if ( textureProperties.initializedRTT === false ) {
|
|
|
|
|
|
textureProperties.initializedRTT = true;
|
|
|
- updated = true;
|
|
|
+ forceUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
- return updated;
|
|
|
+ return forceUpdate;
|
|
|
|
|
|
}
|
|
|
|
|
|
updateSampler( texture ) {
|
|
|
|
|
|
- let updated = false;
|
|
|
-
|
|
|
const array = [];
|
|
|
|
|
|
array.push( texture.wrapS );
|
|
@@ -138,14 +136,12 @@ class WebGPUTextures {
|
|
|
array.push( texture.minFilter );
|
|
|
array.push( texture.anisotropy );
|
|
|
|
|
|
- const newKey = array.join();
|
|
|
- const key = this.samplerCache.get( texture );
|
|
|
-
|
|
|
- if ( key !== newKey ) {
|
|
|
+ const key = array.join();
|
|
|
+ let samplerGPU = this.samplerCache.get( key );
|
|
|
|
|
|
- this.samplerCache.set( texture, newKey );
|
|
|
+ if ( samplerGPU === undefined ) {
|
|
|
|
|
|
- const sampler = this.device.createSampler( {
|
|
|
+ samplerGPU = this.device.createSampler( {
|
|
|
addressModeU: this._convertAddressMode( texture.wrapS ),
|
|
|
addressModeV: this._convertAddressMode( texture.wrapT ),
|
|
|
addressModeW: this._convertAddressMode( texture.wrapR ),
|
|
@@ -155,15 +151,12 @@ class WebGPUTextures {
|
|
|
maxAnisotropy: texture.anisotropy
|
|
|
} );
|
|
|
|
|
|
- const textureProperties = this.properties.get( texture );
|
|
|
- textureProperties.sampler = sampler;
|
|
|
-
|
|
|
- updated = true;
|
|
|
+ this.samplerCache.set( key, samplerGPU );
|
|
|
|
|
|
}
|
|
|
|
|
|
- return updated;
|
|
|
-
|
|
|
+ const textureProperties = this.properties.get( texture );
|
|
|
+ textureProperties.samplerGPU = samplerGPU;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -230,6 +223,12 @@ class WebGPUTextures {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ dispose() {
|
|
|
+
|
|
|
+ this.samplerCache.clear();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
_convertAddressMode( value ) {
|
|
|
|
|
|
let addressMode = GPUAddressMode.ClampToEdge;
|