@@ -87,21 +87,22 @@ class WebGPUTextureUtils {
8787 */
8888 this . defaultVideoFrame = null ;
8989
90- /**
91- * Represents the color attachment of the default framebuffer.
92- *
93- * @type {?GPUTexture }
94- * @default null
95- */
96- this . colorBuffer = null ;
97-
98- /**
99- * Represents the depth attachment of the default framebuffer.
100- *
101- * @type {DepthTexture }
102- */
103- this . depthTexture = new DepthTexture ( ) ;
104- this . depthTexture . name = 'depthBuffer' ;
90+ this . frameBufferData = {
91+ color : {
92+ buffer : null , // TODO: Move to FramebufferTexture
93+ width : 0 ,
94+ height : 0 ,
95+ samples : 0
96+ } ,
97+ depth : {
98+ texture : new DepthTexture ( ) ,
99+ width : 0 ,
100+ height : 0 ,
101+ samples : 0 ,
102+ depth : false ,
103+ stencil : false
104+ }
105+ } ;
105106
106107 /**
107108 * A cache of shared texture samplers.
@@ -396,24 +397,44 @@ class WebGPUTextureUtils {
396397 */
397398 getColorBuffer ( ) {
398399
399- if ( this . colorBuffer ) this . colorBuffer . destroy ( ) ;
400-
401400 const backend = this . backend ;
402401 const { width, height } = backend . getDrawingBufferSize ( ) ;
402+ const samples = backend . renderer . currentSamples ;
403403
404- this . colorBuffer = backend . device . createTexture ( {
404+ const frameBufferColor = this . frameBufferData . color ;
405+
406+ if ( frameBufferColor . width === width && frameBufferColor . height === height && frameBufferColor . samples === samples ) {
407+
408+ return frameBufferColor . buffer ;
409+
410+ }
411+
412+ // recreate
413+
414+ let colorBuffer = frameBufferColor . buffer ;
415+
416+ if ( colorBuffer ) colorBuffer . destroy ( ) ;
417+
418+ colorBuffer = backend . device . createTexture ( {
405419 label : 'colorBuffer' ,
406420 size : {
407421 width : width ,
408422 height : height ,
409423 depthOrArrayLayers : 1
410424 } ,
411- sampleCount : backend . utils . getSampleCount ( backend . renderer . samples ) ,
425+ sampleCount : backend . utils . getSampleCount ( backend . renderer . currentSamples ) ,
412426 format : backend . utils . getPreferredCanvasFormat ( ) ,
413427 usage : GPUTextureUsage . RENDER_ATTACHMENT | GPUTextureUsage . COPY_SRC
414428 } ) ;
415429
416- return this . colorBuffer ;
430+ //
431+
432+ frameBufferColor . buffer = colorBuffer ;
433+ frameBufferColor . width = width ;
434+ frameBufferColor . height = height ;
435+ frameBufferColor . samples = samples ;
436+
437+ return colorBuffer ;
417438
418439 }
419440
@@ -429,8 +450,23 @@ class WebGPUTextureUtils {
429450
430451 const backend = this . backend ;
431452 const { width, height } = backend . getDrawingBufferSize ( ) ;
453+ const samples = backend . renderer . currentSamples ;
454+
455+ const frameBufferDepth = this . frameBufferData . depth ;
456+ const depthTexture = frameBufferDepth . texture ;
457+
458+ if ( depthTexture . width === width &&
459+ depthTexture . height === height &&
460+ depthTexture . samples === samples &&
461+ depthTexture . depth === depth &&
462+ depthTexture . stencil === stencil ) {
463+
464+ return backend . get ( depthTexture ) . texture ;
465+
466+ }
467+
468+ //
432469
433- const depthTexture = this . depthTexture ;
434470 const depthTextureGPU = backend . get ( depthTexture ) . texture ;
435471
436472 let format , type ;
@@ -459,6 +495,8 @@ class WebGPUTextureUtils {
459495
460496 }
461497
498+ // recreate
499+
462500 depthTexture . name = 'depthBuffer' ;
463501 depthTexture . format = format ;
464502 depthTexture . type = type ;
0 commit comments