node package manager



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.




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')

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:


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] 


MIT. See for details.