@@ -146,6 +146,7 @@ class WebGPURenderer {
146146 this . _animation = new WebGPUAnimation ( ) ;
147147
148148 this . _currentRenderState = null ;
149+ this . _lastRenderState = null ;
149150
150151 this . _opaqueSort = null ;
151152 this . _transparentSort = null ;
@@ -434,6 +435,8 @@ class WebGPURenderer {
434435 nodeFrame . renderId = previousRenderId ;
435436 this . _currentRenderState = previousRenderState ;
436437
438+ this . _lastRenderState = renderState ;
439+
437440 }
438441
439442 setAnimationLoop ( callback ) {
@@ -688,9 +691,77 @@ class WebGPURenderer {
688691
689692 }
690693
691- clear ( ) {
694+ clear ( color = true , depth = true , stencil = true ) {
695+
696+ const renderState = this . _currentRenderState || this . _lastRenderState ;
697+ if ( renderState === null ) return ;
698+
699+ depth = depth && renderState . depth ;
700+ stencil = stencil && renderState . stencil ;
701+
702+ const descriptorGPU = renderState . descriptorGPU ;
703+ const colorAttachment = descriptorGPU . colorAttachments [ 0 ] ;
704+
705+ // @TODO : Include render target in clear operation.
706+ if ( this . _parameters . antialias === true ) {
707+
708+ colorAttachment . view = this . _colorBuffer . createView ( ) ;
709+ colorAttachment . resolveTarget = this . _context . getCurrentTexture ( ) . createView ( ) ;
710+
711+ } else {
712+
713+ colorAttachment . view = this . _context . getCurrentTexture ( ) . createView ( ) ;
714+ colorAttachment . resolveTarget = undefined ;
715+
716+ }
717+
718+ descriptorGPU . depthStencilAttachment . view = this . _depthBuffer . createView ( ) ;
719+
720+ if ( color ) {
721+
722+ colorAttachment . loadOp = GPULoadOp . Clear ;
723+ colorAttachment . clearValue = { r : this . _clearColor . r , g : this . _clearColor . g , b : this . _clearColor . b , a : this . _clearAlpha } ;
724+
725+ }
726+
727+ if ( depth ) {
728+
729+ descriptorGPU . depthStencilAttachment . depthLoadOp = GPULoadOp . Clear ;
730+ descriptorGPU . depthStencilAttachment . depthClearValue = this . _clearDepth ;
731+
732+ }
733+
734+ if ( stencil ) {
735+
736+ descriptorGPU . depthStencilAttachment . stencilLoadOp = GPULoadOp . Clear ;
737+ descriptorGPU . depthStencilAttachment . stencilClearValue = this . _clearStencil ;
738+
739+ }
740+
741+ renderState . encoderGPU = this . _device . createCommandEncoder ( { } ) ;
742+ renderState . currentPassGPU = renderState . encoderGPU . beginRenderPass ( renderState . descriptorGPU ) ;
743+
744+ renderState . currentPassGPU . end ( ) ;
745+
746+ this . _device . queue . submit ( [ renderState . encoderGPU . finish ( ) ] ) ;
747+
748+ }
749+
750+ clearColor ( ) {
751+
752+ this . clear ( true , false , false ) ;
753+
754+ }
755+
756+ clearDepth ( ) {
757+
758+ this . clear ( false , true , false ) ;
759+
760+ }
761+
762+ clearStencil ( ) {
692763
693- if ( this . _background ) this . _background . clear ( ) ;
764+ this . clear ( false , false , true ) ;
694765
695766 }
696767
0 commit comments