Skip to content

Commit

Permalink
pixels::PixelsBuilder::alpha_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
maki committed Oct 3, 2023
1 parent 705f22b commit fff7b99
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct PixelsBuilder<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplay
surface_texture_format: Option<wgpu::TextureFormat>,
clear_color: wgpu::Color,
blend_state: wgpu::BlendState,
alpha_mode: wgpu::CompositeAlphaMode,
}

impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fff7b99

Please sign in to comment.