MCPcopy Index your code
hub / github.com/processing/p5.js / readPixelWebGL

Function readPixelWebGL

src/webgl/utils.js:87–103  ·  view source on GitHub ↗
(gl, framebuffer, x, y, format, type, flipY)

Source from the content-addressed store, hash-verified

85 * @returns {Number[]} pixels The channel data for the pixel at that location
86 */
87export function readPixelWebGL(gl, framebuffer, x, y, format, type, flipY) {
88 // Record the currently bound framebuffer so we can go back to it after, and
89 // bind the framebuffer we want to read from
90 const prevFramebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
91 gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
92
93 const channels = format === gl.RGBA ? 4 : 3;
94 const TypedArrayClass = type === gl.UNSIGNED_BYTE ? Uint8Array : Float32Array;
95 const pixels = new TypedArrayClass(channels);
96
97 gl.readPixels(x, flipY ? flipY - y - 1 : y, 1, 1, format, type, pixels);
98
99 // Re-bind whatever was previously bound
100 gl.bindFramebuffer(gl.FRAMEBUFFER, prevFramebuffer);
101
102 return Array.from(pixels);
103}
104
105export function setWebGLTextureParams(texture, gl, webglVersion) {
106 texture.bindTexture();

Callers 2

_getPixelMethod · 0.90
readFramebufferPixelMethod · 0.90

Calls 1

bindFramebufferMethod · 0.45

Tested by

no test coverage detected