* Promotes the current frame to use mainFramebuffer. * Copies current canvas content to mainFramebuffer, then switches to rendering there. * @private
()
| 1381 | * @private |
| 1382 | */ |
| 1383 | _promoteToFramebuffer() { |
| 1384 | // Already promoted this frame |
| 1385 | if (this._frameState === FRAME_STATE.PROMOTED) { |
| 1386 | return; |
| 1387 | } |
| 1388 | |
| 1389 | // Already drawing to a custom framebuffer, no promotion needed |
| 1390 | if (this.activeFramebuffer()) { |
| 1391 | return; |
| 1392 | } |
| 1393 | |
| 1394 | // Flush any pending draws to canvas first |
| 1395 | this.flushDraw(); |
| 1396 | |
| 1397 | // Mark as promoted |
| 1398 | this._frameState = FRAME_STATE.PROMOTED; |
| 1399 | |
| 1400 | // Get current canvas texture |
| 1401 | const canvasTexture = this.drawingContext.getCurrentTexture(); |
| 1402 | |
| 1403 | // Ensure mainFramebuffer matches canvas size |
| 1404 | if (this.mainFramebuffer.width !== this.width || |
| 1405 | this.mainFramebuffer.height !== this.height) { |
| 1406 | this.mainFramebuffer.resize(this.width, this.height); |
| 1407 | } |
| 1408 | |
| 1409 | // Copy canvas textures to mainFramebuffer |
| 1410 | const commandEncoder = this.device.createCommandEncoder(); |
| 1411 | |
| 1412 | // Copy color texture |
| 1413 | commandEncoder.copyTextureToTexture( |
| 1414 | { |
| 1415 | texture: canvasTexture, |
| 1416 | origin: { x: 0, y: 0, z: 0 }, |
| 1417 | mipLevel: 0, |
| 1418 | }, |
| 1419 | { |
| 1420 | texture: this.mainFramebuffer.colorTexture, |
| 1421 | origin: { x: 0, y: 0, z: 0 }, |
| 1422 | mipLevel: 0, |
| 1423 | }, |
| 1424 | { |
| 1425 | width: Math.ceil(this.width * this._pixelDensity), |
| 1426 | height: Math.ceil(this.height * this._pixelDensity), |
| 1427 | depthOrArrayLayers: 1, |
| 1428 | } |
| 1429 | ); |
| 1430 | |
| 1431 | // Copy depth texture |
| 1432 | commandEncoder.copyTextureToTexture( |
| 1433 | { |
| 1434 | texture: this.depthTexture, |
| 1435 | origin: { x: 0, y: 0, z: 0 }, |
| 1436 | mipLevel: 0, |
| 1437 | }, |
| 1438 | { |
| 1439 | texture: this.mainFramebuffer.depthTexture, |
| 1440 | origin: { x: 0, y: 0, z: 0 }, |