@@ -48,6 +48,7 @@ internal sealed unsafe class WebGPUSurfaceResources : IDisposable
4848 private FramePacingSignal ? previousFrameWorkDone ;
4949 private readonly FeatureName requiredFeature ;
5050 private readonly Configuration configuration ;
51+ private readonly WebGPUCompositeAlphaMode alphaMode ;
5152
5253 // Mutable because the device-owned portion of the stack is replaced on device-loss recovery.
5354 private WebGPUDeviceContext deviceContext ;
@@ -69,6 +70,7 @@ internal sealed unsafe class WebGPUSurfaceResources : IDisposable
6970 /// <param name="queueHandle">The owned default queue handle paired with <paramref name="deviceHandle"/>.</param>
7071 /// <param name="deviceContext">The device context bound to <paramref name="deviceHandle"/> and <paramref name="queueHandle"/>.</param>
7172 /// <param name="format">The negotiated swapchain texture format.</param>
73+ /// <param name="alphaMode">How the native compositor interprets the swapchain alpha channel.</param>
7274 /// <param name="requiredFeature">The optional WebGPU feature required by the selected texture format.</param>
7375 private WebGPUSurfaceResources (
7476 WebGPU api ,
@@ -80,6 +82,7 @@ private WebGPUSurfaceResources(
8082 WebGPUQueueHandle queueHandle ,
8183 WebGPUDeviceContext deviceContext ,
8284 WebGPUTextureFormat format ,
85+ WebGPUCompositeAlphaMode alphaMode ,
8386 FeatureName requiredFeature )
8487 {
8588 this . Api = api ;
@@ -91,6 +94,7 @@ private WebGPUSurfaceResources(
9194 this . QueueHandle = queueHandle ;
9295 this . deviceContext = deviceContext ;
9396 this . Format = format ;
97+ this . alphaMode = alphaMode ;
9498 this . requiredFeature = requiredFeature ;
9599 }
96100
@@ -138,6 +142,7 @@ private WebGPUSurfaceResources(
138142 /// <param name="configuration">The ImageSharp configuration the device context will use for its rendering backend.</param>
139143 /// <param name="nativeSource">The native surface source that provides the platform handles for surface creation.</param>
140144 /// <param name="format">The swapchain texture format.</param>
145+ /// <param name="alphaMode">How the native compositor interprets the swapchain alpha channel.</param>
141146 /// <param name="initialPresentMode">The present mode to apply to the first surface configuration.</param>
142147 /// <param name="initialFramebufferSize">The framebuffer size to apply to the first surface configuration. Zero-area
143148 /// sizes are permitted and leave the surface unconfigured until the caller invokes <see cref="ConfigureSurface"/>
@@ -152,6 +157,7 @@ public static WebGPUSurfaceResources Create(
152157 Configuration configuration ,
153158 INativeWindowSource nativeSource ,
154159 WebGPUTextureFormat format ,
160+ WebGPUCompositeAlphaMode alphaMode ,
155161 WebGPUPresentMode initialPresentMode ,
156162 Size initialFramebufferSize )
157163 {
@@ -191,6 +197,7 @@ public static WebGPUSurfaceResources Create(
191197 deviceResources . QueueHandle ,
192198 deviceResources . DeviceContext ,
193199 format ,
200+ alphaMode ,
194201 requiredFeature ) ;
195202
196203 resources . ConfigureSurface ( initialPresentMode , initialFramebufferSize ) ;
@@ -250,6 +257,7 @@ private void ConfigureSurfaceCore(WebGPUPresentMode presentMode, Size framebuffe
250257 {
251258 Usage = TextureUsage . RenderAttachment | TextureUsage . CopySrc | TextureUsage . CopyDst | TextureUsage . TextureBinding ,
252259 Format = WebGPUTextureFormatMapper . ToNative ( this . Format ) ,
260+ AlphaMode = ToNative ( this . alphaMode ) ,
253261 PresentMode = ToNative ( presentMode ) ,
254262 Width = ( uint ) framebufferSize . Width ,
255263 Height = ( uint ) framebufferSize . Height ,
@@ -275,6 +283,19 @@ private static SilkPresentMode ToNative(WebGPUPresentMode presentMode)
275283 _ => throw new InvalidOperationException ( "The WebGPU present mode mapping is incomplete." )
276284 } ;
277285
286+ /// <summary>
287+ /// Maps the public composite-alpha enumeration to the native Silk.NET value.
288+ /// </summary>
289+ /// <param name="alphaMode">The composite-alpha mode to map.</param>
290+ /// <returns>The native composite-alpha mode.</returns>
291+ private static CompositeAlphaMode ToNative ( WebGPUCompositeAlphaMode alphaMode )
292+ => alphaMode switch
293+ {
294+ WebGPUCompositeAlphaMode . Auto => CompositeAlphaMode . Auto ,
295+ WebGPUCompositeAlphaMode . Opaque => CompositeAlphaMode . Opaque ,
296+ _ => throw new InvalidOperationException ( "The WebGPU composite alpha mode mapping is incomplete." )
297+ } ;
298+
278299 /// <summary>
279300 /// Acquires the next presentable frame from <see cref="SurfaceHandle"/> and wraps it as a
280301 /// <see cref="WebGPUSurfaceFrame"/> with a ready-to-use <see cref="DrawingCanvas"/>.
0 commit comments