pub struct MyDeviceImpl<'a> { /* private fields */ }Expand description
An abstraction of the wgpu::Surface<’lifetime>
to create from a given winit Window.
Following is an example to create the surface using a given Window
§Examples
use wgpu_quick_start::{MyDevice, create_new_device};
use winit::{event::WindowEvent, window::WindowAttributes};
use winit_app::{AppWindowEvent, Application};
fn launch() -> Result<(), Box<dyn std::error::Error>> {
let winit_app = Application::new();
let mut opt_device: Option<Box<dyn MyDevice>> = None;
winit_app.run(
WindowAttributes::default().with_title("wgpu starter app"),
move |app_window_event| match app_window_event {
AppWindowEvent::NewWindow(window) => match create_new_device(window) {
Ok(value) => {
opt_device = Some(value);
}
Err(err) => {
// warning - Error creating new surface from the window
}
},
AppWindowEvent::OnWindowEvent(event, event_loop) => {
if let Some(local_device) = opt_device.as_mut() {
// Handle those events
}
}
},
)?;
Ok(())
}§Lifetimes
The lifetime of this struct refers to the underlying lifetime of the wgpu::Surface<'lifetime> inside the same.
Implementations§
Source§impl<'a> MyDeviceImpl<'a>
impl<'a> MyDeviceImpl<'a>
Sourcepub async fn new(
window: impl Into<SurfaceTarget<'a>>,
dimensions: (u32, u32),
) -> GPUStarterResult<Self>
pub async fn new( window: impl Into<SurfaceTarget<'a>>, dimensions: (u32, u32), ) -> GPUStarterResult<Self>
Create a new surface from the given window for the given dimensions (width, height) tuple
Sourcepub async fn new_without_window() -> GPUStarterResult<Self>
pub async fn new_without_window() -> GPUStarterResult<Self>
Create a new device without a ‘window’ reference. Useful for unit testing
Trait Implementations§
Source§impl<'a> MyDevice for MyDeviceImpl<'a>
impl<'a> MyDevice for MyDeviceImpl<'a>
Source§fn get_device(&self) -> &Device
fn get_device(&self) -> &Device
Retrieve the device associated with this surface
Source§fn get_adapter(&self) -> &Adapter
fn get_adapter(&self) -> &Adapter
Retrieve the adapter
Source§fn get_current_texture(&self) -> GPUStarterResult<SurfaceTexture>
fn get_current_texture(&self) -> GPUStarterResult<SurfaceTexture>
Retrieve the current texture
Source§fn get_texture_format(&self) -> GPUStarterResult<TextureFormat>
fn get_texture_format(&self) -> GPUStarterResult<TextureFormat>
Retrieve the texture format
Auto Trait Implementations§
impl<'a> !Freeze for MyDeviceImpl<'a>
impl<'a> !RefUnwindSafe for MyDeviceImpl<'a>
impl<'a> Send for MyDeviceImpl<'a>
impl<'a> Sync for MyDeviceImpl<'a>
impl<'a> Unpin for MyDeviceImpl<'a>
impl<'a> !UnwindSafe for MyDeviceImpl<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.