[oden] Memoize textures by path

This commit is contained in:
John Doty 2023-08-19 21:16:11 -07:00
parent 043a3ee183
commit c7ea93f972

View file

@ -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;
}