-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(texture): dispose of textures when no longer in use (#16)
- Loading branch information
Showing
5 changed files
with
165 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as THREE from 'three'; | ||
import TextureManager from './TextureManager.js'; | ||
|
||
class ManagedCompressedTexture extends THREE.CompressedTexture { | ||
#manager: TextureManager; | ||
#refId: string; | ||
|
||
constructor( | ||
manager: TextureManager, | ||
refId: string, | ||
mipmaps: ImageData[], | ||
width: number, | ||
height: number, | ||
format: THREE.CompressedPixelFormat, | ||
type?: THREE.TextureDataType, | ||
mapping?: THREE.Mapping, | ||
wrapS?: THREE.Wrapping, | ||
wrapT?: THREE.Wrapping, | ||
magFilter?: THREE.MagnificationTextureFilter, | ||
minFilter?: THREE.MinificationTextureFilter, | ||
anisotropy?: number, | ||
colorSpace?: THREE.ColorSpace, | ||
) { | ||
super( | ||
mipmaps, | ||
width, | ||
height, | ||
format, | ||
type, | ||
mapping, | ||
wrapS, | ||
wrapT, | ||
magFilter, | ||
minFilter, | ||
anisotropy, | ||
colorSpace, | ||
); | ||
|
||
this.#manager = manager; | ||
this.#refId = refId; | ||
} | ||
|
||
dispose() { | ||
if (this.#manager.deref(this.#refId) === 0) { | ||
super.dispose(); | ||
} | ||
} | ||
} | ||
|
||
export default ManagedCompressedTexture; | ||
export { ManagedCompressedTexture }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as THREE from 'three'; | ||
import TextureManager from './TextureManager.js'; | ||
|
||
class ManagedDataTexture extends THREE.DataTexture { | ||
#manager: TextureManager; | ||
#refId: string; | ||
|
||
constructor( | ||
manager: TextureManager, | ||
refId: string, | ||
data?: BufferSource | null, | ||
width?: number, | ||
height?: number, | ||
format?: THREE.PixelFormat, | ||
type?: THREE.TextureDataType, | ||
mapping?: THREE.Mapping, | ||
wrapS?: THREE.Wrapping, | ||
wrapT?: THREE.Wrapping, | ||
magFilter?: THREE.MagnificationTextureFilter, | ||
minFilter?: THREE.MinificationTextureFilter, | ||
anisotropy?: number, | ||
colorSpace?: THREE.ColorSpace, | ||
) { | ||
super( | ||
data, | ||
width, | ||
height, | ||
format, | ||
type, | ||
mapping, | ||
wrapS, | ||
wrapT, | ||
magFilter, | ||
minFilter, | ||
anisotropy, | ||
colorSpace, | ||
); | ||
|
||
this.#manager = manager; | ||
this.#refId = refId; | ||
} | ||
|
||
dispose() { | ||
if (this.#manager.deref(this.#refId) === 0) { | ||
super.dispose(); | ||
} | ||
} | ||
} | ||
|
||
export default ManagedDataTexture; | ||
export { ManagedDataTexture }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters