(gl, framebuffer, x, y, format, type, flipY)
| 85 | * @returns {Number[]} pixels The channel data for the pixel at that location |
| 86 | */ |
| 87 | export 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 | |
| 105 | export function setWebGLTextureParams(texture, gl, webglVersion) { |
| 106 | texture.bindTexture(); |
no test coverage detected