From fff7b99a25ec0ff2fff34116690e2900e15479c6 Mon Sep 17 00:00:00 2001 From: maki Date: Tue, 3 Oct 2023 18:29:20 +0200 Subject: [PATCH] pixels::PixelsBuilder::alpha_mode --- src/builder.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 7b86e1f7..156444f5 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -17,6 +17,7 @@ pub struct PixelsBuilder<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplay surface_texture_format: Option, clear_color: wgpu::Color, blend_state: wgpu::BlendState, + alpha_mode: wgpu::CompositeAlphaMode, } impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle> @@ -64,6 +65,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle> surface_texture_format: None, clear_color: wgpu::Color::BLACK, blend_state: wgpu::BlendState::ALPHA_BLENDING, + alpha_mode: wgpu::CompositeAlphaMode::Auto, } } @@ -235,6 +237,22 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle> self } + /// Sets the alpha mode. + /// + /// Default value is `Auto`. + /// + ///``` + ///use pixels::wgpu::CompositeAlphaMode; + /// + ///let mut pixels = PixelsBuilder::new(320, 240, surface_texture) + /// .alpha_mode(CompositeAlphaMode::PostMultiplied) + /// .build()?; + ///``` + pub fn alpha_mode(mut self, alpha_mode: wgpu::CompositeAlphaMode) -> Self { + self.alpha_mode = alpha_mode; + self + } + /// Create a pixel buffer from the options builder. /// /// This is the private implementation shared by [`PixelsBuilder::build`] and @@ -319,7 +337,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle> let mut pixels = Vec::with_capacity(pixels_buffer_size); pixels.resize_with(pixels_buffer_size, Default::default); - let alpha_mode = surface_capabilities.alpha_modes[0]; + let alpha_mode = self.alpha_mode; // Instantiate the Pixels struct let context = PixelsContext {