Browse Source

textture 和 program 缓存

master
blobt 3 years ago
parent
commit
6bb1b3a8b3
  1. 60
      src/render/webgl/WebGLProgramCache.ts
  2. 57
      src/render/webgl/WebGLTextureCache.ts

60
src/render/webgl/WebGLProgramCache.ts

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

57
src/render/webgl/WebGLTextureCache.ts

@ -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);
}
}
Loading…
Cancel
Save