Skip to content

Commit 2e7fadc

Browse files
authored
WebGLRenderer: Fixed readRenderTargetPixelsAsync checking readability against incorrect render target (#30672)
* WebGLRenderer: Fixed readRenderTargetPixelsAsync checking readability against incorrect render target readRenderTargetPixelsAsync was checking if the render target was readable before binding the render target to active framebuffer. This resulted in the texture readability check occurring on the previously set framebuffer and not the render target we are reading pixels from. * lint fix * Removed redundant call to setRenderTarget
1 parent 537d396 commit 2e7fadc

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

examples/webgl_interactive_cubes_gpu.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@
254254
renderer.setClearColor( clearColor );
255255
renderer.render( pickingScene, camera );
256256

257+
// Restore active render target to canvas
258+
renderer.setRenderTarget( null );
259+
257260
// clear the view offset so rendering returns to normal
258261
camera.clearViewOffset();
259262

@@ -291,7 +294,6 @@
291294

292295
pick();
293296

294-
renderer.setRenderTarget( null );
295297
renderer.render( scene, camera );
296298

297299
}

src/renderers/WebGLRenderer.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -2931,27 +2931,27 @@ class WebGLRenderer {
29312931

29322932
if ( framebuffer ) {
29332933

2934-
const texture = renderTarget.texture;
2935-
const textureFormat = texture.format;
2936-
const textureType = texture.type;
2934+
// the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
2935+
if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
29372936

2938-
if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
2937+
// set the active frame buffer to the one we want to read
2938+
state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
29392939

2940-
throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
2940+
const texture = renderTarget.texture;
2941+
const textureFormat = texture.format;
2942+
const textureType = texture.type;
29412943

2942-
}
2944+
if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
29432945

2944-
if ( ! capabilities.textureTypeReadable( textureType ) ) {
2946+
throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
29452947

2946-
throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
2948+
}
29472949

2948-
}
2950+
if ( ! capabilities.textureTypeReadable( textureType ) ) {
29492951

2950-
// the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
2951-
if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
2952+
throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
29522953

2953-
// set the active frame buffer to the one we want to read
2954-
state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2954+
}
29552955

29562956
const glBuffer = _gl.createBuffer();
29572957
_gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );

0 commit comments

Comments
 (0)