Socket
Socket
Sign inDemoInstall

gl-buffer-snoop

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gl-buffer-snoop

Intercepts uploads to WebGL buffers in order to keep track of their expected value on the GPU.


Version published
Weekly downloads
4
increased by100%
Maintainers
1
Install size
5.58 kB
Created
Weekly downloads
 

Readme

Source

gl-buffer-snoop

Intercepts uploads to WebGL buffers in order to keep track of their expected value on the GPU.

Designed solely with the intention of testing packages that interact with WebGL buffers. It's probably not something you should be using in an actual app/demo, so approach with caution.

Usage

NPM

snoop(gl)

Before using your WebGL context at all, you should let gl-buffer-snoop do its thing by passing it the context in question:

var canvas = document.createElement('canvas')
var gl = canvas.getContext('webgl')

require('gl-buffer-snoop')(gl)

This will override a few of the context's methods to keep track of outgoing data, along with providing a new method for you to use to retrieve a buffer's data:

gl.getBufferData(buffer)

Given an instance of a WebGLBuffer, returns our local copy of the data it should have stored on the GPU. This is returned as a Uint8Array, but you can easily convert it to other types too thanks to the magic of typed arrays. For example:

var buffer = gl.createBuffer()
// ...
var rawData = gl.getBufferData(buffer)
var floatData = new Float32Array(rawData.buffer)

If you're using this with gl-buffer, you can just use the handle property to access the underlying buffer instance:

var buffer = require('gl-buffer')(gl, [1, 2, 3])
var rawData = gl.getBufferData(buffer.handle)
var floatData = new Float32Array(rawData.buffer)

console.log(floatData) // [1, 2, 3]

License

MIT. See LICENSE.md for details.

Keywords

FAQs

Last updated on 03 Nov 2014

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc