namespace GStats { export class GLHook { public drawPasses : number = 0 ; public isInit : boolean = false ; private realGLDrawElements : Function = function ( ) { } ; private gl : any ; constructor ( _gl ? ) { if ( _gl ) { if ( _gl . __proto__ . drawElements ) { this . gl = _gl ; this . realGLDrawElements = _gl . __proto__ . drawElements ; _gl . __proto__ . drawElements = this . fakeGLdrawElements . bind ( this ) ; this . isInit = true ; console . log ( "[GLHook] GL was Hooked!" ) ; } } else { console . error ( "[GLHook] GL can't be NULL" ) ; } } private fakeGLdrawElements ( mode , count , type , offset ) { this . drawPasses ++ ; this . realGLDrawElements . call ( this . gl , mode , count , type , offset ) ; } public reset ( ) { this . drawPasses = 0 ; } public release ( ) { if ( this . isInit ) { this . gl . __proto__ . drawElements = this . realGLDrawElements ; console . log ( "[GLHook] Hook was removed!" ) ; } this . isInit = false ; } } }