pub struct Painter<'a> { /* private fields */ }
Expand description
Everything you need to paint egui with wgpu
on winit
.
Alternatively you can use crate::renderer
directly.
Implementations
sourceimpl<'a> Painter<'a>
impl<'a> Painter<'a>
sourcepub fn new(
backends: Backends,
power_preference: PowerPreference,
device_descriptor: DeviceDescriptor<'a>,
present_mode: PresentMode,
msaa_samples: u32
) -> Self
pub fn new(
backends: Backends,
power_preference: PowerPreference,
device_descriptor: DeviceDescriptor<'a>,
present_mode: PresentMode,
msaa_samples: u32
) -> Self
Manages wgpu
state, including surface state, required to render egui.
Only the wgpu::Instance
is initialized here. Device selection and the initialization
of render + surface state is deferred until the painter is given its first window target
via set_window()
. (Ensuring that a device that’s compatible with the
native window is chosen)
Before calling paint_and_update_textures()
a
wgpu::Surface
must be initialized (and corresponding render state) by calling
set_window()
once you have
a winit::window::Window
with a valid .raw_window_handle()
associated.
sourcepub fn render_state(&self) -> Option<RenderState>
pub fn render_state(&self) -> Option<RenderState>
Get the RenderState
.
Will return None
if the render state has not been initialized yet.
sourcepub unsafe fn set_window(&mut self, window: Option<&Window>)
pub unsafe fn set_window(&mut self, window: Option<&Window>)
Updates (or clears) the winit::window::Window
associated with the Painter
This creates a wgpu::Surface
for the given Window (as well as initializing render
state if needed) that is used for egui rendering.
This must be called before trying to render via
paint_and_update_textures
Portability
In particular it’s important to note that on Android a it’s only possible to create
a window surface between Resumed
and Paused
lifecycle events, and Winit will panic on
attempts to query the raw window handle while paused.
On Android set_window
should be called with Some(window)
for each
Resumed
event and None
for each Paused
event. Currently, on all other platforms
set_window
may be called with Some(window)
as soon as you have a
valid winit::window::Window
.
Safety
The raw Window handle associated with the given window
must be a valid object to create a
surface upon and must remain valid for the lifetime of the created surface. (The surface may
be cleared by passing None
).
sourcepub fn max_texture_side(&self) -> Option<usize>
pub fn max_texture_side(&self) -> Option<usize>
Returns the maximum texture dimension supported if known
This API will only return a known dimension after set_window()
has been called
at least once, since the underlying device and render state are initialized lazily
once we have a window (that may determine the choice of adapter/device).
pub fn on_window_resized(&mut self, width_in_pixels: u32, height_in_pixels: u32)
pub fn paint_and_update_textures(
&mut self,
pixels_per_point: f32,
clear_color: Rgba,
clipped_primitives: &[ClippedPrimitive],
textures_delta: &TexturesDelta
)
pub fn destroy(&mut self)
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Painter<'a>
impl<'a> Send for Painter<'a>
impl<'a> Sync for Painter<'a>
impl<'a> Unpin for Painter<'a>
impl<'a> !UnwindSafe for Painter<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more