Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multistate

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multistate

**Save** and **restore** the entire state of WebGL easily like in a 2D canvas. Multistate manages the global state only and is not concerned with any properties or content of any textures, buffers, VAOs etc. It also adds cache checks for all the global-st

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Multistate

Save and restore the entire state of WebGL easily like in a 2D canvas. Multistate manages the global state only and is not concerned with any properties or content of any textures, buffers, VAOs etc. It also adds cache checks for all the global-state-setting functions to prevent redundant WebGL API calls.

Handles

  1. Global settings including viewport, culling, blending, and stencil.
  2. State toggles managed by gl.enable and gl.disable.
  3. Options configured with pixelStorei.
  4. Currently bound textures.
  5. Currently bound framebuffers with their read/draw buffers settings.
  6. Current VAO and UBO.
  7. Current program.

Is not concerned with

  1. Uniforms and attributes.
  2. Any individual buffer settings or content.
  3. Any individual texture settings or content.

Quick start

Installation

npm install multistate

Basic usage

import { enhanceWebGLContext } from 'multistate'

gl = canvas.getContext('webgl2')
enhanceWebGLContext(gl)

// .. run your setup here

// set any global params
gl.viewport(0, 0, 500, 500)

gl.saveState()

// make some changes
gl.viewport(0, 0, 200, 200)
gl.enable(gl.CULL_FACE)

gl.restoreState()

// the viewport is now [0, 0, 500, 500]
console.log(gl.getParameter(gl.VIEWPORT))
// the face culling is now disabled
console.log(gl.isEnabled(gl.CULL_FACE))


Multiple state containers

// save the container once
const stateContainerA = gl.createState()
const stateContainerB = gl.createState()

// pass the container as a paramter to write to it
gl.saveState(stateContainerA)
gl.restoreState(stateContainerB)
gl.restoreState(stateContainerA)

FAQs

Package last updated on 23 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc