Skip to content

Completely reset the state of a WebGL context, deleting any allocated resources

License

Notifications You must be signed in to change notification settings

stackgl/gl-reset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gl-reset

Completely reset the state of a WebGL context, deleting any allocated resources.

Resetting is slow and instrumentation introduces a very slight overhead on creating new resources. However, this is useful:

  • If you want to safely recycle a WebGL context without state leaking between renders.
  • To capture and remove any generated resources during a render.

There's a limit on the number of contexts you can have running simultaneously on a page, and (at least on Chrome) when hitting the threshold you simply lose the least recently created one. To work around this limit, you can instead reset and reuse a single WebGL context between multiple renders.

Usage

NPM

reset = require('gl-reset')(gl)

Returns a function that, when called, will remove any existing resources and reset the current WebGL state.

Note: this function must be created before creating any resources, as it instruments several WebGL methods to do its thing.

var reset = require('gl-reset')(gl)

function render() {
  // Triggers a context reset
  reset()
}

require('gl-reset/state')(gl)

Resets the state, without instrumenting the context and without removing any allocated resources.

License

MIT. See LICENSE.md for details.

About

Completely reset the state of a WebGL context, deleting any allocated resources

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published