|
@@ -3,12 +3,11 @@ import { Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinear
|
|
|
|
|
|
class WebGPUTextures {
|
|
|
|
|
|
- constructor( device, properties ) {
|
|
|
+ constructor( device, properties, info ) {
|
|
|
|
|
|
this.device = device;
|
|
|
this.properties = properties;
|
|
|
-
|
|
|
- this.textures = new WeakMap();
|
|
|
+ this.info = info;
|
|
|
|
|
|
this.defaultTexture = null;
|
|
|
this.defaultSampler = null;
|
|
@@ -77,6 +76,23 @@ class WebGPUTextures {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
+ // texture init
|
|
|
+
|
|
|
+ if ( textureProperties.initialized === undefined ) {
|
|
|
+
|
|
|
+ textureProperties.initialized = true;
|
|
|
+
|
|
|
+ const disposeCallback = onTextureDispose.bind( this );
|
|
|
+ textureProperties.disposeCallback = disposeCallback;
|
|
|
+
|
|
|
+ texture.addEventListener( 'dispose', disposeCallback );
|
|
|
+
|
|
|
+ this.info.memory.textures ++;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // texture creation
|
|
|
+
|
|
|
if ( textureProperties.textureGPU !== undefined ) {
|
|
|
|
|
|
// TODO: Avoid calling of destroy() in certain scenarios. When only the contents of a texture
|
|
@@ -316,4 +332,19 @@ class WebGPUTextures {
|
|
|
|
|
|
}
|
|
|
|
|
|
+function onTextureDispose( event ) {
|
|
|
+
|
|
|
+ const texture = event.target;
|
|
|
+
|
|
|
+ const textureProperties = this.properties.get( texture );
|
|
|
+ textureProperties.textureGPU.destroy();
|
|
|
+
|
|
|
+ texture.removeEventListener( 'dispose', textureProperties.disposeCallback );
|
|
|
+
|
|
|
+ this.properties.remove( texture );
|
|
|
+
|
|
|
+ this.info.memory.textures --;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
export default WebGPUTextures;
|