@@ -235,11 +235,16 @@ class Canvas:
235235 device : Device
236236 depth_format : TextureFormat
237237 depth_texture : Texture = None
238+ depth_texture_view = None
238239 multisample_texture : Texture = None
240+ multisample_texture_view = None
239241 multisample : MultisampleState = None
240242 target_texture : Texture = None
243+ target_texture_view = None
241244 select_depth_texture : Texture = None
245+ select_depth_texture_view = None
242246 select_texture : Texture = None
247+ select_texture_view = None
243248
244249 width : int = 0
245250 height : int = 0
@@ -389,6 +394,11 @@ def destroy_textures(self):
389394 ]:
390395 if tex is not None :
391396 tex .destroy ()
397+ self .target_texture_view = None
398+ self .multisample_texture_view = None
399+ self .depth_texture_view = None
400+ self .select_texture_view = None
401+ self .select_depth_texture_view = None
392402
393403 @debounce (5 )
394404 def resize (self ):
@@ -434,6 +444,9 @@ def resize(self):
434444 usage = TextureUsage .RENDER_ATTACHMENT ,
435445 label = "multisample" ,
436446 )
447+ self .multisample_texture_view = self .multisample_texture .createView ()
448+ else :
449+ self .multisample_texture_view = None
437450
438451 self .depth_texture = device .createTexture (
439452 size = [width , height , 1 ],
@@ -442,6 +455,7 @@ def resize(self):
442455 label = "depth_texture" ,
443456 sampleCount = self .multisample .count ,
444457 )
458+ self .depth_texture_view = self .depth_texture .createView ()
445459
446460 self .target_texture_view = self .target_texture .createView ()
447461
@@ -458,6 +472,7 @@ def resize(self):
458472 label = "select_depth" ,
459473 )
460474 self .select_texture_view = self .select_texture .createView ()
475+ self .select_depth_texture_view = self .select_depth_texture .createView ()
461476
462477 self .width = width
463478 self .height = height
@@ -470,7 +485,7 @@ def color_attachments(self, loadOp: LoadOp):
470485 return [
471486 RenderPassColorAttachment (
472487 view = (
473- self .multisample_texture . createView ()
488+ self .multisample_texture_view
474489 if have_multisample
475490 else self .target_texture_view
476491 ),
@@ -491,14 +506,14 @@ def select_attachments(self, loadOp: LoadOp):
491506
492507 def select_depth_stencil_attachment (self , loadOp : LoadOp ):
493508 return RenderPassDepthStencilAttachment (
494- self .select_depth_texture . createView () ,
509+ self .select_depth_texture_view ,
495510 depthClearValue = 1.0 ,
496511 depthLoadOp = loadOp ,
497512 )
498513
499514 def depth_stencil_attachment (self , loadOp : LoadOp ):
500515 return RenderPassDepthStencilAttachment (
501- self .depth_texture . createView () ,
516+ self .depth_texture_view ,
502517 depthClearValue = 1.0 ,
503518 depthLoadOp = loadOp ,
504519 )
0 commit comments