|
@@ -864,20 +864,42 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- copyFramebufferToTexture( texture /*, renderContext */ ) {
|
|
|
|
|
|
+ copyFramebufferToTexture( texture, renderContext ) {
|
|
|
|
|
|
const { gl } = this;
|
|
const { gl } = this;
|
|
|
|
|
|
const { textureGPU } = this.get( texture );
|
|
const { textureGPU } = this.get( texture );
|
|
|
|
|
|
- gl.bindFramebuffer( gl.FRAMEBUFFER, null );
|
|
|
|
- gl.bindTexture( gl.TEXTURE_2D, textureGPU );
|
|
|
|
|
|
+ const width = texture.image.width;
|
|
|
|
+ const height = texture.image.height;
|
|
|
|
|
|
- gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, 0, 0, texture.image.width, texture.image.height );
|
|
|
|
|
|
+ gl.bindFramebuffer( gl.READ_FRAMEBUFFER, null );
|
|
|
|
|
|
- if ( texture.generateMipmaps ) gl.generateMipmap( gl.TEXTURE_2D );
|
|
|
|
|
|
+ if ( texture.isDepthTexture ) {
|
|
|
|
|
|
- gl.bindTexture( gl.TEXTURE_2D, null );
|
|
|
|
|
|
+ const fb = gl.createFramebuffer();
|
|
|
|
+
|
|
|
|
+ gl.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.deleteFramebuffer( fb );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ gl.bindTexture( gl.TEXTURE_2D, textureGPU );
|
|
|
|
+ gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, 0, 0, width, height );
|
|
|
|
+
|
|
|
|
+ gl.bindTexture( gl.TEXTURE_2D, null );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( texture.generateMipmaps ) this.generateMipmaps( texture );
|
|
|
|
+
|
|
|
|
+ this._setFramebuffer( renderContext );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|