1212# %% Entrypoints (sync and async)
1313
1414
15- def setup_drawing_sync (canvas , power_preference = "high-performance" , limits = None ):
15+ def setup_drawing_sync (
16+ canvas , power_preference = "high-performance" , limits = None , format = None
17+ ):
1618 """Setup to draw a rotating cube on the given canvas.
1719
1820 The given canvas must implement WgpuCanvasInterface, but nothing more.
@@ -23,7 +25,9 @@ def setup_drawing_sync(canvas, power_preference="high-performance", limits=None)
2325 device = adapter .request_device_sync (required_limits = limits )
2426
2527 pipeline_layout , uniform_buffer , bind_groups = create_pipeline_layout (device )
26- pipeline_kwargs = get_render_pipeline_kwargs (canvas , device , pipeline_layout )
28+ pipeline_kwargs = get_render_pipeline_kwargs (
29+ canvas , device , pipeline_layout , format
30+ )
2731
2832 render_pipeline = device .create_render_pipeline (** pipeline_kwargs )
2933
@@ -32,7 +36,7 @@ def setup_drawing_sync(canvas, power_preference="high-performance", limits=None)
3236 )
3337
3438
35- async def setup_drawing_async (canvas , limits = None ):
39+ async def setup_drawing_async (canvas , limits = None , format = None ):
3640 """Setup to async-draw a rotating cube on the given canvas.
3741
3842 The given canvas must implement WgpuCanvasInterface, but nothing more.
@@ -43,7 +47,9 @@ async def setup_drawing_async(canvas, limits=None):
4347 device = await adapter .request_device_async (required_limits = limits )
4448
4549 pipeline_layout , uniform_buffer , bind_groups = create_pipeline_layout (device )
46- pipeline_kwargs = get_render_pipeline_kwargs (canvas , device , pipeline_layout )
50+ pipeline_kwargs = get_render_pipeline_kwargs (
51+ canvas , device , pipeline_layout , format
52+ )
4753
4854 render_pipeline = await device .create_render_pipeline_async (** pipeline_kwargs )
4955
@@ -55,9 +61,10 @@ async def setup_drawing_async(canvas, limits=None):
5561# %% Functions to create wgpu objects
5662
5763
58- def get_render_pipeline_kwargs (canvas , device , pipeline_layout ):
64+ def get_render_pipeline_kwargs (canvas , device , pipeline_layout , render_texture_format ):
5965 context = canvas .get_context ("wgpu" )
60- render_texture_format = context .get_preferred_format (device .adapter )
66+ if render_texture_format is None :
67+ render_texture_format = context .get_preferred_format (device .adapter )
6168 context .configure (device = device , format = render_texture_format )
6269
6370 shader = device .create_shader_module (code = shader_source )
0 commit comments