@@ -75658,8 +75658,9 @@ class WebGLRenderer {
7565875658 * @param {number} height - The height of the copy region.
7565975659 * @param {TypedArray} buffer - The result buffer.
7566075660 * @param {number} [activeCubeFaceIndex] - The active cube face index.
75661+ * @param {number} [textureIndex=0] - The texture index of an MRT render target.
7566175662 */
75662- this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
75663+ this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex, textureIndex = 0 ) {
7566375664
7566475665 if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
7566575666
@@ -75682,7 +75683,7 @@ class WebGLRenderer {
7568275683
7568375684 try {
7568475685
75685- const texture = renderTarget.texture ;
75686+ const texture = renderTarget.textures[ textureIndex ] ;
7568675687 const textureFormat = texture.format;
7568775688 const textureType = texture.type;
7568875689
@@ -75704,6 +75705,10 @@ class WebGLRenderer {
7570475705
7570575706 if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
7570675707
75708+ // when using MRT, select the corect color buffer for the subsequent read command
75709+
75710+ if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
75711+
7570775712 _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
7570875713
7570975714 }
@@ -75734,9 +75739,10 @@ class WebGLRenderer {
7573475739 * @param {number} height - The height of the copy region.
7573575740 * @param {TypedArray} buffer - The result buffer.
7573675741 * @param {number} [activeCubeFaceIndex] - The active cube face index.
75742+ * @param {number} [textureIndex=0] - The texture index of an MRT render target.
7573775743 * @return {Promise<TypedArray>} A Promise that resolves when the read has been finished. The resolve provides the read data as a typed array.
7573875744 */
75739- this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
75745+ this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex, textureIndex = 0 ) {
7574075746
7574175747 if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
7574275748
@@ -75759,7 +75765,7 @@ class WebGLRenderer {
7575975765 // set the active frame buffer to the one we want to read
7576075766 state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
7576175767
75762- const texture = renderTarget.texture ;
75768+ const texture = renderTarget.textures[ textureIndex ] ;
7576375769 const textureFormat = texture.format;
7576475770 const textureType = texture.type;
7576575771
@@ -75778,6 +75784,11 @@ class WebGLRenderer {
7577875784 const glBuffer = _gl.createBuffer();
7577975785 _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
7578075786 _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
75787+
75788+ // when using MRT, select the corect color buffer for the subsequent read command
75789+
75790+ if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
75791+
7578175792 _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
7578275793
7578375794 // reset the frame buffer to the currently set buffer before waiting
0 commit comments