MCPcopy
hub / github.com/processing/p5.js / clear

Method clear

src/webgpu/p5.RendererWebGPU.js:632–705  ·  view source on GitHub ↗
(...args)

Source from the content-addressed store, hash-verified

630 }
631
632 clear(...args) {
633 if (!this.device || !this.drawingContext) return;
634 const _r = args[0] || 0;
635 const _g = args[1] || 0;
636 const _b = args[2] || 0;
637 const _a = args[3] || 0;
638
639 // If PENDING and no custom framebuffer, clear means stay UNPROMOTED.
640 // However, if we are still in setup (frameCount == 0), we must promote
641 // so that mainFramebuffer gets the cleared content. This ensures that if
642 // draw() later promotes without a copy, it starts from the correct state
643 // rather than a stale mainFramebuffer.
644 // Note: a mid-draw-loop transition from UNPROMOTED back to PROMOTED
645 // (i.e. calling background() some frames but not others) will still
646 // lose intermediate UNPROMOTED frame content.
647 if (this._frameState !== FRAME_STATE.PROMOTED && !this.activeFramebuffer()) {
648 if (this._pInst.frameCount > 0) {
649 this._frameState = FRAME_STATE.UNPROMOTED;
650 } else {
651 this._promoteToFramebufferWithoutCopy();
652 // clear() then targets mainFramebuffer via activeFramebuffer()
653 }
654 }
655
656 this._finishActiveRenderPass();
657
658 const commandEncoder = this.device.createCommandEncoder();
659
660 // Use framebuffer texture if active, otherwise use canvas texture
661 const activeFramebuffer = this.activeFramebuffer();
662
663 const colorAttachment = {
664 view: activeFramebuffer
665 ? (activeFramebuffer.aaColorTexture
666 ? activeFramebuffer.aaColorTextureView
667 : activeFramebuffer.colorTextureView)
668 : this._getCanvasColorTextureView(),
669 clearValue: { r: _r * _a, g: _g * _a, b: _b * _a, a: _a },
670 loadOp: 'clear',
671 storeOp: 'store',
672 // If using multisampled texture, resolve to non-multisampled texture
673 resolveTarget: activeFramebuffer && activeFramebuffer.aaColorTexture
674 ? activeFramebuffer.colorTextureView
675 : undefined,
676 };
677
678 // Use framebuffer depth texture if active, otherwise use canvas depth texture
679 const depthTextureView = activeFramebuffer
680 ? (activeFramebuffer.aaDepthTexture
681 ? activeFramebuffer.aaDepthTextureView
682 : activeFramebuffer.depthTextureView)
683 : this.depthTextureView;
684 const depthAttachment = depthTextureView
685 ? {
686 view: depthTextureView,
687 depthClearValue: 1.0,
688 depthLoadOp: 'clear',
689 depthStoreOp: 'store',

Callers 2

_updateSizeMethod · 0.95

Calls 7

activeFramebufferMethod · 0.80
endMethod · 0.80
finishMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected