blobt
4 years ago
2 changed files with 117 additions and 0 deletions
@ -0,0 +1,60 @@ |
|||
import { GLProgram } from "./WebGLProgram"; |
|||
import { Dictionary } from "../ds/Dictionary"; |
|||
|
|||
export class GLProgramCache { |
|||
/** |
|||
* @var 单例 |
|||
*/ |
|||
public static readonly instance: GLProgramCache = new GLProgramCache(); |
|||
|
|||
/** |
|||
* @var 字典 |
|||
*/ |
|||
private _dict: Dictionary<GLProgram>; |
|||
|
|||
private constructor() { |
|||
this._dict = new Dictionary<GLProgram>(); |
|||
} |
|||
|
|||
/** |
|||
* 添加program |
|||
* @param key |
|||
* @param value |
|||
*/ |
|||
public set(key: string, value: GLProgram) { |
|||
this._dict.insert(key, value); |
|||
} |
|||
|
|||
/** |
|||
* 获取program不验证 |
|||
* @param key |
|||
* @returns |
|||
*/ |
|||
public getMaybe(key: string): GLProgram | undefined { |
|||
let ret: GLProgram | undefined = this._dict.find(key); |
|||
return ret; |
|||
} |
|||
|
|||
/** |
|||
* 获取program |
|||
* @param key |
|||
* @returns |
|||
*/ |
|||
public getMust(key: string): GLProgram { |
|||
let ret: GLProgram | undefined = this._dict.find(key); |
|||
if (ret === undefined) { |
|||
throw new Error(key + " is not exist."); |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
/** |
|||
* 删除program |
|||
* @param key |
|||
* @returns |
|||
*/ |
|||
public remove(key: string): boolean { |
|||
return this._dict.remove(key); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,57 @@ |
|||
import { GLTexture } from "./WebGLTexture"; |
|||
import { Dictionary } from "../ds/Dictionary"; |
|||
|
|||
export class GLtextureCache { |
|||
/** |
|||
* @var 单例 |
|||
*/ |
|||
public static readonly instance: GLtextureCache = new GLtextureCache(); |
|||
|
|||
/** |
|||
* @var 字典 |
|||
*/ |
|||
private _dict: Dictionary<GLTexture>; |
|||
|
|||
private constructor() { |
|||
this._dict = new Dictionary<GLTexture>(); |
|||
} |
|||
|
|||
/** |
|||
* 添加贴图 |
|||
* @param key |
|||
* @param value |
|||
*/ |
|||
public set(key: string, value: GLTexture) { |
|||
this._dict.insert(key, value); |
|||
} |
|||
|
|||
/** |
|||
* 获取贴图,不作检测 |
|||
* @param key |
|||
*/ |
|||
public getMaybe(key: string): GLTexture | undefined { |
|||
let ret: GLTexture | undefined = this._dict.find(key); |
|||
return ret; |
|||
} |
|||
|
|||
/** |
|||
* 获取贴图,作检测 |
|||
* @param key |
|||
*/ |
|||
public getMust(key: string): GLTexture { |
|||
let ret: GLTexture | undefined = this._dict.find(key); |
|||
if (ret === undefined) { |
|||
throw new Error(key + " is not exist."); |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
/** |
|||
* 删除贴图 |
|||
* @param key |
|||
* @returns |
|||
*/ |
|||
public remove(key: string) { |
|||
return this._dict.remove(key); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue