-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pixels::PixelsBuilder::alpha_mode #376
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably check whether the selected alpha mode is supported by the surface. Return an error if it is not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the same be done for Pixels::surface_texture_format and Pixels::render_texture_format then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that is the case. |
||
|
||
// Instantiate the Pixels struct | ||
let context = PixelsContext { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not passing in CI.