Add wgpu adapter getter API (#340)

Co-authored-by: Jay Oster <jay@kodewerx.org>
This commit is contained in:
Aggelos Tselios 2023-03-08 03:39:02 +02:00 committed by GitHub
parent 860559272a
commit bbfd49deba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -345,6 +345,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
let pixels = Pixels {
context,
adapter,
surface_size,
present_mode,
render_texture_format,

View file

@ -100,6 +100,7 @@ pub struct Pixels {
surface_texture_format: wgpu::TextureFormat,
blend_state: wgpu::BlendState,
alpha_mode: wgpu::CompositeAlphaMode,
adapter: wgpu::Adapter,
// Pixel buffer
pixels: Vec<u8>,
@ -275,6 +276,24 @@ impl Pixels {
self.context.scaling_renderer.clear_color = color;
}
/// Returns a reference of the `wgpu` adapter used by the crate.
///
/// The adapter can be used to retrieve runtime information about the host system
/// or the WGPU backend.
///
/// ```no_run
/// # use pixels::Pixels;
/// # let window = pixels_mocks::Rwh;
/// # let surface_texture = pixels::SurfaceTexture::new(320, 240, &window);
/// let mut pixels = Pixels::new(320, 240, surface_texture)?;
/// let adapter = pixels.adapter();
/// // Do something with the adapter.
/// # Ok::<(), pixels::Error>(())
/// ```
pub fn adapter(&self) -> &wgpu::Adapter {
&self.adapter
}
/// Resize the pixel buffer and zero its contents.
///
/// This does not resize the surface upon which the pixel buffer texture is rendered. Use