(framebuffer)
| 1835 | } |
| 1836 | |
| 1837 | updateFramebufferPixels(framebuffer) { |
| 1838 | const gl = this.GL; |
| 1839 | framebuffer.colorP5Texture.bindTexture(); |
| 1840 | const colorFormat = this._getFramebufferColorFormat(framebuffer); |
| 1841 | |
| 1842 | const channels = colorFormat.format === gl.RGBA ? 4 : 3; |
| 1843 | const len = framebuffer.width * framebuffer.height * framebuffer.density * framebuffer.density * channels; |
| 1844 | const TypedArrayClass = colorFormat.type === gl.UNSIGNED_BYTE ? Uint8Array : Float32Array; |
| 1845 | |
| 1846 | if (!(framebuffer.pixels instanceof TypedArrayClass) || framebuffer.pixels.length !== len) { |
| 1847 | throw new Error( |
| 1848 | 'The pixels array has not been set correctly. Please call loadPixels() before updatePixels().' |
| 1849 | ); |
| 1850 | } |
| 1851 | |
| 1852 | gl.texImage2D( |
| 1853 | gl.TEXTURE_2D, |
| 1854 | 0, |
| 1855 | colorFormat.internalFormat, |
| 1856 | framebuffer.width * framebuffer.density, |
| 1857 | framebuffer.height * framebuffer.density, |
| 1858 | 0, |
| 1859 | colorFormat.format, |
| 1860 | colorFormat.type, |
| 1861 | framebuffer.pixels |
| 1862 | ); |
| 1863 | framebuffer.colorP5Texture.unbindTexture(); |
| 1864 | framebuffer.dirty.colorTexture = false; |
| 1865 | |
| 1866 | const prevFramebuffer = this.activeFramebuffer(); |
| 1867 | if (framebuffer.antialias) { |
| 1868 | // We need to make sure the antialiased framebuffer also has the updated |
| 1869 | // pixels so that if more is drawn to it, it goes on top of the updated |
| 1870 | // pixels instead of replacing them. |
| 1871 | // We can't blit the framebuffer to the multisampled antialias |
| 1872 | // framebuffer to leave both in the same state, so instead we have |
| 1873 | // to use image() to put the framebuffer texture onto the antialiased |
| 1874 | // framebuffer. |
| 1875 | framebuffer.begin(); |
| 1876 | this.push(); |
| 1877 | this.states.setValue('imageMode', constants.CORNER); |
| 1878 | this.setCamera(framebuffer.filterCamera); |
| 1879 | this.resetMatrix(); |
| 1880 | this.states.setValue('strokeColor', null); |
| 1881 | this.clear(); |
| 1882 | this._drawingFilter = true; |
| 1883 | this.image( |
| 1884 | framebuffer, |
| 1885 | 0, 0, |
| 1886 | framebuffer.width, framebuffer.height, |
| 1887 | -this.width / 2, -this.height / 2, |
| 1888 | this.width, this.height |
| 1889 | ); |
| 1890 | this._drawingFilter = false; |
| 1891 | this.pop(); |
| 1892 | if (framebuffer.useDepth) { |
| 1893 | gl.clearDepth(1); |
| 1894 | gl.clear(gl.DEPTH_BUFFER_BIT); |
no test coverage detected