Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsantell/gl-preserve-state
https://github.com/jsantell/gl-preserve-state
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jsantell/gl-preserve-state
- Owner: jsantell
- License: zlib
- Created: 2017-10-10T20:39:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-10T20:44:35.000Z (over 7 years ago)
- Last Synced: 2024-10-06T20:34:10.057Z (4 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gl-preserve-state
Caches specified GL state, runs a callback, and restores the cached state when
done.Modularized from Brandon Jones' [webgl-utils].
## Install
```
$ npm install --save gl-preserve-state
```## Example usage:
```js
var savedState = [
gl.ARRAY_BUFFER_BINDING,// TEXTURE_BINDING_2D or _CUBE_MAP must always be followed by the texure unit.
gl.TEXTURE_BINDING_2D, gl.TEXTURE0,gl.CLEAR_COLOR,
];
// After this call the array buffer, texture unit 0, active texture, and clear
// color will be restored. The viewport will remain changed, however, because
// gl.VIEWPORT was not included in the savedState list.
WGLUPreserveGLState(gl, savedState, function(gl) {
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, ....);gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, ...);gl.clearColor(1, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
});
```Note that this is not intended to be fast. Managing state in your own code to
avoid redundant state setting and querying will always be faster. This function
is most useful for cases where you may not have full control over the WebGL
calls being made, such as tooling or effect injectors.## License
Copyright (c) 2016 Brandon Jones
[webgl-utils]: https://github.com/toji/webgl-utils/