Skip to content

Instantly share code, notes, and snippets.

@davschne
Created August 23, 2019 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davschne/663b744abd5522b7f5dc67a22fa85783 to your computer and use it in GitHub Desktop.
Save davschne/663b744abd5522b7f5dc67a22fa85783 to your computer and use it in GitHub Desktop.
// construct the pixel data
const floatArray = new Float32Array([ /* pixels */ ]);
const uintArray = new Uint8Array(floatArray.buffer);
// bind the pixel data to a WebGL texture
gl.texImage2D(
gl.TEXTURE_2D, // target
0, // mipmap level
gl.RGBA, // internal format: 4 color channels
width, // width of texture in pixels
height, // height of texture in pixels
0, // border: must be 0
gl.RGBA, // format: must be the same as internal format
gl.UNSIGNED_BYTE, // type: 8 bits per channel
uintArray, // pixels
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment