Skip to content

Commit

Permalink
chore(gltf-material-parser): add cleanup method (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
dryabinin94 authored Apr 5, 2022
1 parent d4ed9ed commit 4f0a70b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/experimental/src/gltf/gltf-material-parser.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,7 +18,7 @@ export default class GLTFMaterialParser {
readonly defines: Record<string, number | boolean>;
readonly uniforms: Record<string, any>;
readonly parameters: Record<string, any>;
readonly generatedTextures: object[];
readonly generatedTextures: Texture[];

constructor(device: Device, props: GLTFMaterialParserProps) {
const {attributes, material, pbrDebug, imageBasedLightingEnvironment, lights, useTangents} = props;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -173,4 +175,11 @@ export default class GLTFMaterialParser {
});
}
}

/**
* Destroy all generated resources to release memory.
*/
delete(): void {
this.generatedTextures.forEach(texture => texture.destroy());
}
}

0 comments on commit 4f0a70b

Please sign in to comment.