|
@@ -223,8 +223,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
deallocateRenderTarget( renderTarget );
|
|
|
|
|
|
- info.memory.textures --;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//
|
|
@@ -254,6 +252,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
_gl.deleteTexture( textureProperties.__webglTexture );
|
|
|
|
|
|
+ info.memory.textures --;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if ( renderTarget.depthTexture ) {
|
|
@@ -281,6 +281,26 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if ( renderTarget.isWebGLMultipleRenderTargets ) {
|
|
|
+
|
|
|
+ for ( let i = 0, il = texture.length; i < il; i ++ ) {
|
|
|
+
|
|
|
+ const attachmentProperties = properties.get( texture[ i ] );
|
|
|
+
|
|
|
+ if ( attachmentProperties.__webglTexture ) {
|
|
|
+
|
|
|
+ _gl.deleteTexture( attachmentProperties.__webglTexture );
|
|
|
+
|
|
|
+ info.memory.textures --;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ properties.remove( texture[ i ] );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
properties.remove( texture );
|
|
|
properties.remove( renderTarget );
|
|
|
|
|
@@ -833,9 +853,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
// Render targets
|
|
|
|
|
|
// Setup storage for target texture and bind it to correct framebuffer
|
|
|
- function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
|
|
|
-
|
|
|
- const texture = renderTarget.texture;
|
|
|
+ function setupFrameBufferTexture( framebuffer, renderTarget, texture, attachment, textureTarget ) {
|
|
|
|
|
|
const glFormat = utils.convert( texture.format );
|
|
|
const glType = utils.convert( texture.type );
|
|
@@ -915,7 +933,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- const texture = renderTarget.texture;
|
|
|
+ // Use the first texture for MRT so far
|
|
|
+ const texture = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture[ 0 ] : renderTarget.texture;
|
|
|
|
|
|
const glFormat = utils.convert( texture.format );
|
|
|
const glType = utils.convert( texture.type );
|
|
@@ -1035,12 +1054,16 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
|
|
|
|
|
|
- textureProperties.__webglTexture = _gl.createTexture();
|
|
|
- textureProperties.__version = texture.version;
|
|
|
+ if ( renderTarget.isWebGLMultipleRenderTargets !== true ) {
|
|
|
|
|
|
- info.memory.textures ++;
|
|
|
+ textureProperties.__webglTexture = _gl.createTexture();
|
|
|
+ textureProperties.__version = texture.version;
|
|
|
+ info.memory.textures ++;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
|
|
|
+ const isMultiRenderTarget = ( renderTarget.isWebGLMultipleRenderTargets === true );
|
|
|
const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
|
|
|
const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
|
|
|
const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
@@ -1071,7 +1094,31 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
|
|
|
|
|
|
- if ( isMultisample ) {
|
|
|
+ if ( isMultiRenderTarget ) {
|
|
|
+
|
|
|
+ if ( capabilities.multiRenderTarget ) {
|
|
|
+
|
|
|
+ for ( let i = 0, il = renderTarget.texture.length; i < il; i ++ ) {
|
|
|
+
|
|
|
+ const attachmentProperties = properties.get( renderTarget.texture[ i ] );
|
|
|
+
|
|
|
+ if ( attachmentProperties.__webglTexture === undefined ) {
|
|
|
+
|
|
|
+ attachmentProperties.__webglTexture = _gl.createTexture();
|
|
|
+
|
|
|
+ info.memory.textures ++;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ console.warn( 'THREE.WebGLRenderer: WebGLMultipleRenderTargets can only be used with WebGL2 or WEBGL_draw_buffers extension.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ( isMultisample ) {
|
|
|
|
|
|
if ( isWebGL2 ) {
|
|
|
|
|
@@ -1119,7 +1166,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
for ( let i = 0; i < 6; i ++ ) {
|
|
|
|
|
|
- setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
|
|
|
+ setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1131,6 +1178,29 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
|
|
|
|
|
|
+ } else if ( isMultiRenderTarget ) {
|
|
|
+
|
|
|
+ const texture = renderTarget.texture;
|
|
|
+
|
|
|
+ for ( let i = 0, il = texture.length; i < il; i ++ ) {
|
|
|
+
|
|
|
+ const attachment = texture[ i ];
|
|
|
+ const attachmentProperties = properties.get( attachment );
|
|
|
+
|
|
|
+ state.bindTexture( _gl.TEXTURE_2D, attachmentProperties.__webglTexture );
|
|
|
+ setTextureParameters( _gl.TEXTURE_2D, attachment, supportsMips );
|
|
|
+ setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D );
|
|
|
+
|
|
|
+ if ( textureNeedsGenerateMipmaps( attachment, supportsMips ) ) {
|
|
|
+
|
|
|
+ generateMipmap( _gl.TEXTURE_2D, attachment, renderTarget.width, renderTarget.height );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ state.bindTexture( _gl.TEXTURE_2D, null );
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
let glTextureType = _gl.TEXTURE_2D;
|
|
@@ -1154,7 +1224,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
state.bindTexture( glTextureType, textureProperties.__webglTexture );
|
|
|
setTextureParameters( glTextureType, texture, supportsMips );
|
|
|
- setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, glTextureType );
|
|
|
+ setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType );
|
|
|
|
|
|
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
|
|
@@ -1178,18 +1248,24 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
|
|
|
|
|
|
function updateRenderTargetMipmap( renderTarget ) {
|
|
|
|
|
|
- const texture = renderTarget.texture;
|
|
|
-
|
|
|
const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
|
|
|
|
|
|
- if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
+ const textures = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture : [ renderTarget.texture ];
|
|
|
+
|
|
|
+ for ( let i = 0, il = textures.length; i < il; i ++ ) {
|
|
|
+
|
|
|
+ const texture = textures[ i ];
|
|
|
|
|
|
- const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
|
|
|
- const webglTexture = properties.get( texture ).__webglTexture;
|
|
|
+ if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
|
|
|
+
|
|
|
+ const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
|
|
|
+ const webglTexture = properties.get( texture ).__webglTexture;
|
|
|
|
|
|
- state.bindTexture( target, webglTexture );
|
|
|
- generateMipmap( target, texture, renderTarget.width, renderTarget.height );
|
|
|
- state.bindTexture( target, null );
|
|
|
+ state.bindTexture( target, webglTexture );
|
|
|
+ generateMipmap( target, texture, renderTarget.width, renderTarget.height );
|
|
|
+ state.bindTexture( target, null );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|