[oden] Memoize textures by path
This commit is contained in:
parent
043a3ee183
commit
c7ea93f972
1 changed files with 10 additions and 3 deletions
|
|
@ -1,7 +1,14 @@
|
|||
import * as io from "./io.ts";
|
||||
import * as gfx from "./graphics.ts";
|
||||
|
||||
export async function load_texture(path: string): Promise<gfx.Texture> {
|
||||
const buffer = await io.load(path);
|
||||
return gfx.create_texture(buffer, path);
|
||||
const LOADED_TEXTURES = new Map<string, Promise<gfx.Texture>>();
|
||||
|
||||
export function load_texture(path: string): Promise<gfx.Texture> {
|
||||
let promise = LOADED_TEXTURES.get(path);
|
||||
if (!promise) {
|
||||
promise = io.load(path).then((buffer) => gfx.create_texture(buffer, path));
|
||||
LOADED_TEXTURES.set(path, promise);
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue