|
|
@@ -692,20 +692,22 @@ class WebGLTextureUtils {
|
|
|
|
|
|
}
|
|
|
|
|
|
- copyFramebufferToTexture( texture, renderContext ) {
|
|
|
+ copyFramebufferToTexture( texture, renderContext, rectangle ) {
|
|
|
|
|
|
const { gl } = this;
|
|
|
const { state } = this.backend;
|
|
|
|
|
|
const { textureGPU } = this.backend.get( texture );
|
|
|
|
|
|
- const width = texture.image.width;
|
|
|
- const height = texture.image.height;
|
|
|
+ const { x, y, z: width, w: height } = rectangle;
|
|
|
|
|
|
const requireDrawFrameBuffer = texture.isDepthTexture === true || ( renderContext.renderTarget && renderContext.renderTarget.samples > 0 );
|
|
|
|
|
|
+ const srcHeight = renderContext.renderTarget ? renderContext.renderTarget.height : this.backend.gerDrawingBufferSize().y;
|
|
|
+
|
|
|
if ( requireDrawFrameBuffer ) {
|
|
|
|
|
|
+ const partial = ( x !== 0 || y !== 0 );
|
|
|
let mask;
|
|
|
let attachment;
|
|
|
|
|
|
@@ -727,19 +729,45 @@ class WebGLTextureUtils {
|
|
|
|
|
|
}
|
|
|
|
|
|
- const fb = gl.createFramebuffer();
|
|
|
- state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
|
+ if ( partial ) {
|
|
|
+
|
|
|
+ const renderTargetContextData = this.backend.get( renderContext.renderTarget );
|
|
|
+
|
|
|
+ const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ];
|
|
|
+ const msaaFrameBuffer = renderTargetContextData.msaaFrameBuffer;
|
|
|
+
|
|
|
+ state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
|
+ state.bindFramebuffer( gl.READ_FRAMEBUFFER, msaaFrameBuffer );
|
|
|
+
|
|
|
+ const flippedY = srcHeight - y - height;
|
|
|
+
|
|
|
+ gl.blitFramebuffer( x, flippedY, x + width, flippedY + height, x, flippedY, x + width, flippedY + height, mask, gl.NEAREST );
|
|
|
+
|
|
|
+ state.bindFramebuffer( gl.READ_FRAMEBUFFER, fb );
|
|
|
+
|
|
|
+ state.bindTexture( gl.TEXTURE_2D, textureGPU );
|
|
|
|
|
|
- gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 );
|
|
|
+ gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, x, flippedY, width, height );
|
|
|
|
|
|
- gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST );
|
|
|
+ state.unbindTexture();
|
|
|
|
|
|
- gl.deleteFramebuffer( fb );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ const fb = gl.createFramebuffer();
|
|
|
+
|
|
|
+ state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
|
+
|
|
|
+ gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 );
|
|
|
+ gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST );
|
|
|
+
|
|
|
+ gl.deleteFramebuffer( fb );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.bindTexture( gl.TEXTURE_2D, textureGPU );
|
|
|
- gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, 0, 0, width, height );
|
|
|
+ gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, x, srcHeight - height - y, width, height );
|
|
|
|
|
|
state.unbindTexture();
|
|
|
|