npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gl-pixel-stream

v1.2.0

Published

streaming gl.readPixels from an FBO

Downloads

110

Readme

gl-pixel-stream

experimental

Streams chunks of gl.readPixels from the specified FrameBuffer Object. This is primarily useful for exporting WebGL scenes and textures to high resolution images (i.e. print-ready).

Before calling this method, ensure your FBO is populated with the content you wish to export. On each chunk, this will bind the given FBO, set the viewport, read the new pixels, and then unbind all FBOs.

The following image was generated with the demo.js in this module. This approach can render upwards of 10000x10000 images on a late 2013 MacBookPro.

earth

(download full 3200x1800 image)

Install

npm install gl-pixel-stream --save

Example

A simple example with gl-fbo might look like this:

var pixelStream = require('gl-pixel-stream')

// bind your FBO
fbo.bind()

// draw your scene to it
drawScene()

// get a pixel stream
var stream = pixelStream(gl, fbo.handle, fbo.shape)

// pipe it out somewhere
stream.pipe(output)

A more practical example involves streaming through png-stream/encoder to a write stream. See demo.js for an example of this, which uses Electron (through hihat) to merge the WebGL and Node.js APIs.

See Running From Source for details.

Usage

NPM

stream = glPixelStream(gl, fboHandle, shape, [opts])

Creates a new stream which streams the data from gl.readPixels, reading from the given FrameBuffer. It is assumed to already be populated with your scene/texture.

The stream emits a Buffer containing the uint8 pixels, default RGBA.

  • gl (required) the WebGL context
  • fboHandle (required) the handle for the WebGLFramebuffer instance
  • shape (required) an Array, the [width, height] of the output
  • opts (optional) additional settings

The additional settings can be:

  • chunkSize (Number) the number of rows to fetch from the GPU in a single call to gl.readPixels, defaults to 128
  • flipY (Boolean) whether to flip the output image on the Y axis (default false)
  • format a WebGL format like gl.RGBA or gl.RGB for reading, default gl.RGBA
  • stride (Number) the number of channels in a pixel, guessed from the specified format, or defaults to 4
  • onProgress (Function) a function that has an event parameter with current and total chunk count, as well as bounds array with [ x, y, width, height ] from readPixels

Running from Source

Clone and install:

git clone https://github.com/Jam3/gl-pixel-stream.git
cd gl-pixel-stream
npm install

To run the tests:

npm run test

To run the demo in "production" mode (no DevTools window). This will output an image.png in the current folder.

npm run start

To run the demo in "development" mode. This opens a DevTools window and reloads the bundle on demo.js file-save.

npm run dev

The output image.png should look like this, and be the size specified in the demo.js file:

earth

License

MIT, see LICENSE.md for details.