gl-preserve-state

WebJar for gl-preserve-state

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

gl-preserve-state
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

gl-preserve-state
WebJar for gl-preserve-state
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/jsantell/gl-preserve-state

Download gl-preserve-state

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/gl-preserve-state/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>gl-preserve-state</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/gl-preserve-state/
implementation 'org.webjars.npm:gl-preserve-state:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/gl-preserve-state/
implementation ("org.webjars.npm:gl-preserve-state:1.0.0")
'org.webjars.npm:gl-preserve-state:jar:1.0.0'
<dependency org="org.webjars.npm" name="gl-preserve-state" rev="1.0.0">
  <artifact name="gl-preserve-state" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='gl-preserve-state', version='1.0.0')
)
libraryDependencies += "org.webjars.npm" % "gl-preserve-state" % "1.0.0"
[org.webjars.npm/gl-preserve-state "1.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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:

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

Versions

Version
1.0.0