gl-buffer-snoop

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i gl-buffer-snoop

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • mikolalysenko
  • wwwtyro
  • thibauts
  • mikkoh
  • yoshuawuyts
  • mattdesl
  • hughsk
  • chrisdickinson
  • tatumcreative
  • rezaali