Ver código fonte

WebGPURenderer: Fix `copyFramebufferToTexture` wrong framebuffer binding in WebGLBackend (#27593)

* fix framebuffer binding

* fix stencil

* fix webgl warning with unecessary READ_FRAMEBUFFER null binding
Renaud Rohlinger 1 ano atrás
pai
commit
6c1e2c0a2d

+ 10 - 6
examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js

@@ -486,21 +486,25 @@ class WebGLTextureUtils {
 		const width = texture.image.width;
 		const height = texture.image.height;
 
-		state.bindFramebuffer( gl.READ_FRAMEBUFFER, null );
-
 		if ( texture.isDepthTexture ) {
 
-			const fb = gl.createFramebuffer();
+			let mask = gl.DEPTH_BUFFER_BIT;
+
+			if ( renderContext.stencil ) {
+
+				mask |= gl.STENCIL_BUFFER_BIT;
 
-			gl.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
+			}
+
+			const fb = gl.createFramebuffer();
+			state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
 
 			gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureGPU, 0 );
 
-			gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, gl.DEPTH_BUFFER_BIT, gl.NEAREST );
+			gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST );
 
 			gl.deleteFramebuffer( fb );
 
-
 		} else {
 
 			state.bindTexture( gl.TEXTURE_2D, textureGPU );