From 4f0a70b6fd29da167e870b5ca699fc02d33e02c7 Mon Sep 17 00:00:00 2001 From: Daniil Ryabinin <70207219+dryabinin-actionengine@users.noreply.github.com> Date: Tue, 5 Apr 2022 19:33:10 +0300 Subject: [PATCH] chore(gltf-material-parser): add cleanup method (#1633) --- .../experimental/src/gltf/gltf-material-parser.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/experimental/src/gltf/gltf-material-parser.ts b/modules/experimental/src/gltf/gltf-material-parser.ts index 36f9b8c3e4..ab024dcd16 100644 --- a/modules/experimental/src/gltf/gltf-material-parser.ts +++ b/modules/experimental/src/gltf/gltf-material-parser.ts @@ -1,4 +1,6 @@ -import {Device, log} from '@luma.gl/api'; +import type {Device, Texture} from '@luma.gl/api'; +import {log} from '@luma.gl/api'; + import GL from '@luma.gl/constants'; import GLTFEnvironment from './gltf-environment'; @@ -16,7 +18,7 @@ export default class GLTFMaterialParser { readonly defines: Record; readonly uniforms: Record; readonly parameters: Record; - readonly generatedTextures: object[]; + readonly generatedTextures: Texture[]; constructor(device: Device, props: GLTFMaterialParserProps) { const {attributes, material, pbrDebug, imageBasedLightingEnvironment, lights, useTangents} = props; @@ -96,7 +98,7 @@ export default class GLTFMaterialParser { textureOptions = {data: image}; } - const texture = this.device.createTexture({ + const texture: Texture = this.device.createTexture({ id: gltfTexture.name || gltfTexture.id, parameters: { ...parameters, @@ -173,4 +175,11 @@ export default class GLTFMaterialParser { }); } } + + /** + * Destroy all generated resources to release memory. + */ + delete(): void { + this.generatedTextures.forEach(texture => texture.destroy()); + } }