https://github.com/stackgl/gl-reset
Completely reset the state of a WebGL context, deleting any allocated resources
https://github.com/stackgl/gl-reset
Last synced: 4 months ago
JSON representation
Completely reset the state of a WebGL context, deleting any allocated resources
- Host: GitHub
- URL: https://github.com/stackgl/gl-reset
- Owner: stackgl
- License: other
- Created: 2014-10-26T06:32:53.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-26T06:33:03.000Z (over 11 years ago)
- Last Synced: 2025-10-02T03:35:28.637Z (9 months ago)
- Language: JavaScript
- Size: 102 KB
- Stars: 19
- Watchers: 11
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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
[](https://nodei.co/npm/gl-reset/)
### `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.
``` javascript
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](http://github.com/hughsk/gl-reset/blob/master/LICENSE.md) for details.