Dawn/ts/asset/AssetManager.ts

41 lines
1.1 KiB
TypeScript

import { Shader } from "../display/Shader";
export interface IAssetOwner {
}
export class AssetManager {
private owners:{ [key:string]:IAssetOwner[] };
private textures:{ [key:string]:CTexture };
private shaders:{ [key:string]:Shader };
constructor() {
this.owners = {};
this.textures = {};
this.shaders = {};
}
private addOwner(name:string, owner:IAssetOwner) {
this.owners[name] = this.owners[name] || [];
this.owners[name].push(owner);
}
public textureLoad(name:string, owner:IAssetOwner):CTexture {
this.addOwner(name, owner);
if(this.textures[name]) return this.textures[name];
this.textures[name] = textureCreate();
assetTextureLoad(this.textures[name], name);
return this.textures[name];
}
public shaderLoad(vert:string, frag:string, owner:IAssetOwner):Shader {
this.addOwner(vert, owner);
if(this.shaders[vert]) return this.shaders[vert];
this.shaders[vert] = new Shader();
assetShaderLoad(this.shaders[vert]._shader, vert, frag);
return this.shaders[vert];
}
public releaseOwner(owner:IAssetOwner) {
}
}