import { log , errorLog } from "../log" ; class export default class ShaderHook { public shaders : number = 0 ; private realAttachShader : any ; private realDetachShader : any ; private hooked : boolean ; private gl : WebGLRenderingContext | WebGL2RenderingContext ; constructor ( gl ) { this . realAttachShader = gl . attachShader ; this . realDetachShader = gl . detachShader ; gl . attachShader = this . hookedAttachShader . bind ( this ) ; gl . detachShader = this . hookedDetachShader . bind ( this ) ; this . hooked = true ; this . gl = gl ; log ( `Shader is hooked.` ) ; } private hookedAttachShader ( program , shader ) { this . realAttachShader . call ( this . gl , program , shader ) ; this . shaders ++ ; log ( `AttachShader:` , shader , `shaders: ${ this . shaders }` ) ; } private hookedDetachShader ( program , shader ) { this . realDetachShader . call ( this . gl , program , shader ) ; this . shaders -- ; log ( `DetachShader. shaders: ${ this . shaders }` ) ; } public reset ( ) { this . shaders = 0 ; } public release ( ) { if ( this . hooked ) { this . gl . attachShader = this . realAttachShader ; this . gl . detachShader = this . realDetachShader ; } this . hooked = false ; } }