Socket
Book a DemoInstallSign in
Socket

gl-texture2d-read-float

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gl-texture2d-read-float

Read out the contents of a floating-point gl-texture2d

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

gl-texture2d-read-float

experimental

Read out the contents of a floating-point gl-texture2d.

This will eventually be supported natively in WebGL (it's listed in the OpenGL ES 3 spec), but this fills that need until then!

Usage

NPM

read(glTex2d, done(err, data))

Reads out the contents of glTex2d, which should be an instance of gl-texture2d. When complete, done(err, data) will be called where data is a Float32Array containing the resulting floats in the texture.

const canvas    = document.createElement('canvas')
const gl        = require('gl-context')(canvas)

const read      = require('gl-texture2d-read-float')
const Texture2d = require('gl-texture2d')
const baboon    = require('baboon-image')
const assert    = require('assert')

const texture  = baboon(gl, baboon)

read(texture, function(err, data) {
  if (err) throw err

  assert.deepEqual(data, baboon.data)
})

A few things to note:

  • Right now, this is slow as it requires reading data back from the GPU. There's not much that can be done about this for the time being unfortunately.
  • The data is retrieved synchronously under the hood, but the API has been made asynchronous in preparation for WebGL's eventual async readPixels equivalent.
  • Only gl.RGBA/gl.FLOAT textures are currently supported. Pull requests are, however, very welcome! :)

Contributing

See stackgl/contributing for details.

License

MIT. See LICENSE.md for details.

Keywords

ecosystem:stackgl

FAQs

Package last updated on 12 Jun 2015

Did you know?

Socket

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