Ver Fonte

MRT clean up (#21792)

* MRT clean up

* Updated files.json

* Added mrt tag for webgl2_multiple_rendertargets
Mr.doob há 4 anos atrás
pai
commit
5dd3e7c36d

+ 1 - 1
examples/files.json

@@ -309,7 +309,7 @@
 		"webgl2_materials_texture2darray",
 		"webgl2_materials_texture3d",
 		"webgl2_materials_texture3d_partialupdate",
-		"webgl2_mrt",
+		"webgl2_multiple_rendertargets",
 		"webgl2_multisampled_renderbuffers",
 		"webgl2_rendertarget_texture2darray",
 		"webgl2_volume_cloud",

+ 0 - 0
examples/screenshots/webgl2_mrt.jpg → examples/screenshots/webgl2_multiple_rendertargets.jpg


+ 1 - 0
examples/tags.json

@@ -90,6 +90,7 @@
 	"webgl_shadowmap_pcss": [ "soft" ],
 	"webgl_simple_gi": [ "global illumination" ],
 	"webgl_tiled_forward": [ "derivatives" ],
+	"webgl2_multiple_rendertargets": [ "mrt" ],
 	"webgl2_multisampled_renderbuffers": [ "msaa" ],
 	"physics_ammo_cloth": [ "integration" ],
 	"misc_controls_deviceorientation": [ "accelerometer", "sensors" ],

+ 0 - 0
examples/webgl2_mrt.html → examples/webgl2_multiple_rendertargets.html


+ 24 - 13
src/renderers/WebGLRenderer.js

@@ -1852,32 +1852,42 @@ function WebGLRenderer( parameters ) {
 
 		}
 
-		if ( state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ) && capabilities.multiRenderTarget ) {
+		const framebufferBound = state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
+
+		if ( framebufferBound && capabilities.drawBuffers ) {
 
 			let needsUpdate = false;
 
-			if ( renderTarget && renderTarget.isWebGLMultipleRenderTargets ) {
+			if ( renderTarget ) {
+
+				if ( renderTarget.isWebGLMultipleRenderTargets ) {
+
+					const textures = renderTarget.texture;
+
+					if ( _currentDrawBuffers.length !== textures.length || _currentDrawBuffers[ 0 ] !== _gl.COLOR_ATTACHMENT0 ) {
 
-				if ( _currentDrawBuffers.length !== renderTarget.texture.length || _currentDrawBuffers[ 0 ] !== _gl.COLOR_ATTACHMENT0 ) {
+						for ( let i = 0, il = textures.length; i < il; i ++ ) {
+
+							_currentDrawBuffers[ i ] = _gl.COLOR_ATTACHMENT0 + i;
+
+						}
 
-					for ( let i = 0, il = renderTarget.texture.length; i < il; i ++ ) {
+						_currentDrawBuffers.length = textures.length;
 
-						_currentDrawBuffers[ i ] = _gl.COLOR_ATTACHMENT0 + i;
+						needsUpdate = true;
 
 					}
 
-					_currentDrawBuffers.length = renderTarget.texture.length;
-					needsUpdate = true;
+				} else {
 
-				}
+					if ( _currentDrawBuffers.length !== 1 || _currentDrawBuffers[ 0 ] !== _gl.COLOR_ATTACHMENT0 ) {
 
-			} else if ( renderTarget ) {
+						_currentDrawBuffers[ 0 ] = _gl.COLOR_ATTACHMENT0;
+						_currentDrawBuffers.length = 1;
 
-				if ( _currentDrawBuffers.length !== 1 || _currentDrawBuffers[ 0 ] !== _gl.COLOR_ATTACHMENT0 ) {
+						needsUpdate = true;
 
-					_currentDrawBuffers[ 0 ] = _gl.COLOR_ATTACHMENT0;
-					_currentDrawBuffers.length = 1;
-					needsUpdate = true;
+					}
 
 				}
 
@@ -1887,6 +1897,7 @@ function WebGLRenderer( parameters ) {
 
 					_currentDrawBuffers[ 0 ] = _gl.BACK;
 					_currentDrawBuffers.length = 1;
+
 					needsUpdate = true;
 
 				}

+ 5 - 3
src/renderers/webgl/WebGLCapabilities.js

@@ -67,6 +67,8 @@ function WebGLCapabilities( gl, extensions, parameters ) {
 
 	}
 
+	const drawBuffers = isWebGL2 || extensions.has( 'WEBGL_draw_buffers' );
+
 	const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
 
 	const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
@@ -84,12 +86,13 @@ function WebGLCapabilities( gl, extensions, parameters ) {
 	const floatVertexTextures = vertexTextures && floatFragmentTextures;
 
 	const maxSamples = isWebGL2 ? gl.getParameter( gl.MAX_SAMPLES ) : 0;
-	const multiRenderTarget = isWebGL2 || extensions.has( 'WEBGL_draw_buffers' );
 
 	return {
 
 		isWebGL2: isWebGL2,
 
+		drawBuffers: drawBuffers,
+
 		getMaxAnisotropy: getMaxAnisotropy,
 		getMaxPrecision: getMaxPrecision,
 
@@ -110,8 +113,7 @@ function WebGLCapabilities( gl, extensions, parameters ) {
 		floatFragmentTextures: floatFragmentTextures,
 		floatVertexTextures: floatVertexTextures,
 
-		maxSamples: maxSamples,
-		multiRenderTarget: multiRenderTarget
+		maxSamples: maxSamples
 
 	};
 

+ 11 - 9
src/renderers/webgl/WebGLTextures.js

@@ -1063,7 +1063,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 		}
 
 		const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
-		const isMultiRenderTarget = ( renderTarget.isWebGLMultipleRenderTargets === true );
+		const isMultipleRenderTargets = ( renderTarget.isWebGLMultipleRenderTargets === true );
 		const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
 		const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
 		const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
@@ -1094,13 +1094,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 			renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
 
-			if ( isMultiRenderTarget ) {
+			if ( isMultipleRenderTargets ) {
 
-				if ( capabilities.multiRenderTarget ) {
+				if ( capabilities.drawBuffers ) {
 
-					for ( let i = 0, il = renderTarget.texture.length; i < il; i ++ ) {
+					const textures = renderTarget.texture;
 
-						const attachmentProperties = properties.get( renderTarget.texture[ i ] );
+					for ( let i = 0, il = textures.length; i < il; i ++ ) {
+
+						const attachmentProperties = properties.get( textures[ i ] );
 
 						if ( attachmentProperties.__webglTexture === undefined ) {
 
@@ -1178,13 +1180,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 			state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
 
-		} else if ( isMultiRenderTarget ) {
+		} else if ( isMultipleRenderTargets ) {
 
-			const texture = renderTarget.texture;
+			const textures = renderTarget.texture;
 
-			for ( let i = 0, il = texture.length; i < il; i ++ ) {
+			for ( let i = 0, il = textures.length; i < il; i ++ ) {
 
-				const attachment = texture[ i ];
+				const attachment = textures[ i ];
 				const attachmentProperties = properties.get( attachment );
 
 				state.bindTexture( _gl.TEXTURE_2D, attachmentProperties.__webglTexture );