Skip to content

Commit 1fc062b

Browse files
authored
Additional comments to grab pass functionality (playcanvas#2610)
* Additional comments to grab pass functionality
1 parent c70461d commit 1fc062b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/graphics/device.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,10 @@ Object.assign(GraphicsDevice.prototype, {
10721072
return false;
10731073
}
10741074

1075+
// render target currently being rendered to (these are null if default framebuffer is active)
10751076
var renderTarget = this.renderTarget;
10761077
var resolveRenderTarget = renderTarget && renderTarget._glResolveFrameBuffer;
1078+
10771079
var grabPassTexture = this.grabPassTexture;
10781080
var width = this.width;
10791081
var height = this.height;
@@ -1087,16 +1089,22 @@ Object.assign(GraphicsDevice.prototype, {
10871089
renderTarget.resolve(true);
10881090
}
10891091

1092+
// these are null if rendering to default framebuffer
10901093
var currentFrameBuffer = renderTarget ? renderTarget._glFrameBuffer : null;
10911094
var resolvedFrameBuffer = renderTarget ? renderTarget._glResolveFrameBuffer || renderTarget._glFrameBuffer : null;
10921095

1096+
// init grab pass framebuffer (only does it once)
10931097
this.initRenderTarget(this.grabPassRenderTarget);
10941098
var grabPassFrameBuffer = this.grabPassRenderTarget._glFrameBuffer;
10951099

1100+
// blit from currently used render target (or default framebuffer if null)
10961101
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, resolvedFrameBuffer);
1102+
1103+
// blit to grab pass framebuffer
10971104
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, grabPassFrameBuffer);
10981105

10991106
// Note: This fails on Chromium Mac when Antialasing is On and Alpha is off
1107+
// blit color from current framebuffer's color attachment to grab pass color attachment
11001108
gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
11011109

11021110
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, currentFrameBuffer);
@@ -1107,6 +1115,7 @@ Object.assign(GraphicsDevice.prototype, {
11071115
gl.bindFramebuffer(gl.FRAMEBUFFER, renderTarget._glResolveFrameBuffer);
11081116
}
11091117

1118+
// this allocates texture (grabPassTexture was already bound to gl)
11101119
var format = grabPassTexture._glFormat;
11111120
gl.copyTexImage2D(gl.TEXTURE_2D, 0, format, 0, 0, width, height, 0);
11121121
grabPassTexture._width = width;

0 commit comments

Comments
 (0)