import { GFX_MAX_TEXTURE_UNITS, GFX_MAX_VERTEX_ATTRIBUTES, IGFXRect, IGFXViewport } from '../define'; import { GFXBlendState, GFXDepthStencilState, GFXRasterizerState } from '../pipeline-state'; export interface IWebGLTexUnit { glTexture: WebGLTexture; } export class WebGLStateCache { public glArrayBuffer: WebGLBuffer = 0; public glElementArrayBuffer: WebGLBuffer = 0; public glVAO: WebGLVertexArrayObjectOES = 0; public texUnit: number = 0; public glTex2DUnits: IWebGLTexUnit[]; public glTexCubeUnits: IWebGLTexUnit[]; public glRenderbuffer: WebGLRenderbuffer = 0; public glFramebuffer: WebGLFramebuffer = 0; public viewport: IGFXViewport; public scissorRect: IGFXRect; public rs: GFXRasterizerState; public dss: GFXDepthStencilState; public bs: GFXBlendState; public glProgram: WebGLProgram = 0; public glEnabledAttribLocs: boolean[]; public glCurrentAttribLocs: boolean[]; constructor () { this.glTex2DUnits = new Array(GFX_MAX_TEXTURE_UNITS); this.glTexCubeUnits = new Array(GFX_MAX_TEXTURE_UNITS); this.viewport = { left: 0.0, top: 0.0, width: 0.0, height: 0.0, minDepth: 0.0, maxDepth: 0.0 }; this.scissorRect = { x: 0.0, y: 0.0, width: 0.0, height: 0.0 }; this.rs = new GFXRasterizerState(); this.dss = new GFXDepthStencilState(); this.bs = new GFXBlendState(); this.glEnabledAttribLocs = new Array(GFX_MAX_VERTEX_ATTRIBUTES); this.glCurrentAttribLocs = new Array(GFX_MAX_VERTEX_ATTRIBUTES); for (let i = 0; i < GFX_MAX_TEXTURE_UNITS; ++i) { this.glTex2DUnits[i] = { glTexture: 0, }; this.glTexCubeUnits[i] = { glTexture: 0, }; } for (let i = 0; i < GFX_MAX_VERTEX_ATTRIBUTES; ++i) { this.glEnabledAttribLocs[i] = false; this.glCurrentAttribLocs[i] = false; } } }