1.0.2 • Published 10 years ago

gl-texture2d-pixels v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

gl-texture2d-pixels

experimental

Gets the RGBA pixels from a gl-texture2d as a Uint8Array. Same API as get-image-pixels.

var getPixels = require('gl-texture2d-pixels')

var array = getPixels(texture)
console.log(array.length === (texture.shape[0] * texture.shape[1] * 4)) //true

Note: This is a fairly expensive operation in WebGL.

Usage

NPM

getPixels(texture[, opts])

Gets the RGBA pixels from gl-texture2d object as a Uint8Array with some optional parameters.

  • x the x position to start clipping, default 0
  • y the y position to start clipping, default 0
  • width the width of the source to copy; this will change the returned array's shape. defaults to image width
  • height the height of the source to copy; this will change the returned array's shape. defaults to image height

The texture object can actually be any generic GL wrapper, as long as it has these fields:

{ 
	handle, //the WebGLTexture handle
	gl,     //the gl handle to WebGLRenderingContext
	shape   //an array of [width, height]
}

getPixels.dispose()

Release the shared canvas for GC. This is mainly useful if you need to minimize disruptive GC hitches, e.g. in a game loop.

License

MIT, see LICENSE.md for details.

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago