Skip to content

Commit ebd9792

Browse files
authored
WebGLRenderer: bugfix when reading pixel in MRT (mrdoob#32506)
1 parent 0f580fc commit ebd9792

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/renderers/WebGLRenderer.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,10 @@ class WebGLRenderer {
29882988
const textureFormat = texture.format;
29892989
const textureType = texture.type;
29902990

2991+
// when using MRT, select the correct color buffer for the subsequent read command
2992+
2993+
if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
2994+
29912995
if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
29922996

29932997
error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
@@ -3006,10 +3010,6 @@ class WebGLRenderer {
30063010

30073011
if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
30083012

3009-
// when using MRT, select the correct color buffer for the subsequent read command
3010-
3011-
if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
3012-
30133013
_gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
30143014

30153015
}
@@ -3070,6 +3070,11 @@ class WebGLRenderer {
30703070
const textureFormat = texture.format;
30713071
const textureType = texture.type;
30723072

3073+
// when using MRT, select the correct color buffer for the subsequent read command
3074+
3075+
if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
3076+
3077+
30733078
if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
30743079

30753080
throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
@@ -3086,10 +3091,6 @@ class WebGLRenderer {
30863091
_gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
30873092
_gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
30883093

3089-
// when using MRT, select the correct color buffer for the subsequent read command
3090-
3091-
if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
3092-
30933094
_gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
30943095

30953096
// reset the frame buffer to the currently set buffer before waiting

0 commit comments

Comments
 (0)