Skip to content

Commit a4525f2

Browse files
committed
WebGLRenderer: Support MRT for 2d array textures
1 parent 250c5f6 commit a4525f2

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/renderers/WebGLRenderer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,9 +2811,15 @@ class WebGLRenderer {
28112811

28122812
} else if ( isRenderTarget3D ) {
28132813

2814-
const textureProperties = properties.get( renderTarget.texture );
28152814
const layer = activeCubeFace;
2816-
_gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel, layer );
2815+
2816+
for ( let i = 0; i < renderTarget.textures.length; i ++ ) {
2817+
2818+
const textureProperties = properties.get( renderTarget.textures[ i ] );
2819+
2820+
_gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, textureProperties.__webglTexture, activeMipmapLevel, layer );
2821+
2822+
}
28172823

28182824
} else if ( renderTarget !== null && activeMipmapLevel !== 0 ) {
28192825

src/renderers/webgl/WebGLTextures.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
544544

545545
const textureProperties = properties.get( texture );
546546

547-
if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
547+
if ( texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version ) {
548548

549549
uploadTexture( textureProperties, texture, slot );
550550
return;
@@ -559,7 +559,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
559559

560560
const textureProperties = properties.get( texture );
561561

562-
if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
562+
if ( texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version ) {
563563

564564
uploadTexture( textureProperties, texture, slot );
565565
return;
@@ -2002,13 +2002,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
20022002
const attachment = textures[ i ];
20032003
const attachmentProperties = properties.get( attachment );
20042004

2005-
state.bindTexture( _gl.TEXTURE_2D, attachmentProperties.__webglTexture );
2006-
setTextureParameters( _gl.TEXTURE_2D, attachment );
2007-
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, 0 );
2005+
let glTextureType = _gl.TEXTURE_2D;
2006+
2007+
if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget ) {
2008+
2009+
glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY;
2010+
2011+
}
2012+
2013+
state.bindTexture( glTextureType, attachmentProperties.__webglTexture );
2014+
setTextureParameters( glTextureType, attachment );
2015+
setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, glTextureType, 0 );
20082016

20092017
if ( textureNeedsGenerateMipmaps( attachment ) ) {
20102018

2011-
generateMipmap( _gl.TEXTURE_2D );
2019+
generateMipmap( glTextureType );
20122020

20132021
}
20142022

0 commit comments

Comments
 (0)