import { IndexBuffer } from './Buffers' ; import { DrawMode } from './_constants' ; export class RendererState { public lastDrawTime ! : number ; public drawBuffer ! : IndexBuffer ; public drawMode : DrawMode ; public animationEnabled : boolean ; public drawBufferNeedsUpdate : boolean ; public attributeBuffersNeedUpdate : boolean ; private currentlyEnabledVertexAttributes : Set < number > ; private previouslyEnabledVertexAttributes : Set < number > ; private gl : WebGLRenderingContext ; constructor ( gl ) { this . gl = gl ; this . currentlyEnabledVertexAttributes = new Set ( ) ; this . previouslyEnabledVertexAttributes = new Set ( ) ; this . drawMode = DrawMode . Lines ; this . drawBufferNeedsUpdate = true ; this . attributeBuffersNeedUpdate = true ; this . animationEnabled = true ; this . gl . clearColor ( 0 , 0 , 0 , 0 ) ; this . gl . pixelStorei ( this . gl . UNPACK_FLIP_Y_WEBGL , 1 ) ; this . gl . enable ( this . gl . DEPTH_TEST ) ; this . gl . enable ( this . gl . CULL_FACE ) ; } public clearEnabledVertexAttributes ( ) { this . previouslyEnabledVertexAttributes = this . currentlyEnabledVertexAttributes ; this . currentlyEnabledVertexAttributes = new Set ( ) ; } public enableVertexAttribute ( location ) { if ( ! this . currentlyEnabledVertexAttributes . has ( location ) ) { this . currentlyEnabledVertexAttributes . add ( location ) ; if ( ! this . previouslyEnabledVertexAttributes . has ( location ) ) { this . gl . enableVertexAttribArray ( location ) ; } } } public disableUnusedVertexAttributes ( ) { for ( const location of this . previouslyEnabledVertexAttributes ) { if ( ! this . currentlyEnabledVertexAttributes . has ( location ) ) { this . gl . disableVertexAttribArray ( location ) ; } } } public clearBuffers ( ) { this . gl . clear ( this . gl . COLOR_BUFFER_BIT | this . gl . DEPTH_BUFFER_BIT ) ; } public setViewport ( width , height ) { this . gl . viewport ( 0 , 0 , width , height ) ; } }