|
|
@@ -31070,61 +31070,53 @@ class WebGLRenderer {
|
|
|
|
|
|
if ( framebuffer ) {
|
|
|
|
|
|
- state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- const texture = renderTarget.texture;
|
|
|
- const textureFormat = texture.format;
|
|
|
- const textureType = texture.type;
|
|
|
-
|
|
|
- if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
|
|
|
-
|
|
|
- throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ( ! capabilities.textureTypeReadable( textureType ) ) {
|
|
|
+ const texture = renderTarget.texture;
|
|
|
+ const textureFormat = texture.format;
|
|
|
+ const textureType = texture.type;
|
|
|
|
|
|
- throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
|
|
|
+ if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
|
|
|
|
|
|
- }
|
|
|
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
|
|
|
|
|
|
- // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
|
|
|
- if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
|
|
|
+ }
|
|
|
|
|
|
- const glBuffer = _gl.createBuffer();
|
|
|
- _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
|
|
|
- _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
|
|
|
- _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
|
|
|
- _gl.flush();
|
|
|
+ if ( ! capabilities.textureTypeReadable( textureType ) ) {
|
|
|
|
|
|
- // check if the commands have finished every 8 ms
|
|
|
- const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 );
|
|
|
- await probeAsync( _gl, sync, 4 );
|
|
|
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
|
|
|
|
|
|
- try {
|
|
|
+ }
|
|
|
|
|
|
- _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
|
|
|
- _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer );
|
|
|
+ // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
|
|
|
+ if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
|
|
|
|
|
|
- } finally {
|
|
|
+ // set the active frame buffer to the one we want to read
|
|
|
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
|
|
|
|
|
|
- _gl.deleteBuffer( glBuffer );
|
|
|
- _gl.deleteSync( sync );
|
|
|
+ const glBuffer = _gl.createBuffer();
|
|
|
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
|
|
|
+ _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
|
|
|
+ _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
|
|
|
+ _gl.flush();
|
|
|
|
|
|
- }
|
|
|
+ // reset the frame buffer to the currently set buffer before waiting
|
|
|
+ const currFramebuffer = _currentRenderTarget !== null ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
|
|
|
+ state.bindFramebuffer( _gl.FRAMEBUFFER, currFramebuffer );
|
|
|
|
|
|
- return buffer;
|
|
|
+ // check if the commands have finished every 8 ms
|
|
|
+ const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 );
|
|
|
+ await probeAsync( _gl, sync, 4 );
|
|
|
|
|
|
- }
|
|
|
+ // read the data and delete the buffer
|
|
|
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
|
|
|
+ _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer );
|
|
|
+ _gl.deleteBuffer( glBuffer );
|
|
|
+ _gl.deleteSync( sync );
|
|
|
|
|
|
- } finally {
|
|
|
+ return buffer;
|
|
|
|
|
|
- // restore framebuffer of current render target if necessary
|
|
|
+ } else {
|
|
|
|
|
|
- const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
|
|
|
- state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
|
|
|
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.' );
|
|
|
|
|
|
}
|
|
|
|