pub struct Graphics {
pub camera: Camera2D,
pub camera3d: Camera3D,
/* private fields */
}Fields§
§camera: Camera2D§camera3d: Camera3DPerspective camera for 3D meshes. Set its fields to move the view.
Implementations§
Source§impl Graphics
impl Graphics
pub async fn new( window: Arc<Window>, vsync: bool, depth_format: Option<TextureFormat>, msaa_samples: u32, ) -> Result<Graphics, Error>
pub fn resize(&mut self, width: u32, height: u32)
pub fn window(&self) -> &Arc<Window> ⓘ
pub fn size(&self) -> (u32, u32)
Sourcepub fn surface_format(&self) -> TextureFormat
pub fn surface_format(&self) -> TextureFormat
The color format the frame is rendered in: always an sRGB format, possibly a view of a
non-sRGB surface. Build render pipelines that draw into a Frame with this.
pub fn device(&self) -> &Device
pub fn queue(&self) -> &Queue
Sourcepub fn load_texture(
&mut self,
path: impl AsRef<Path>,
) -> Result<TextureId, Error>
pub fn load_texture( &mut self, path: impl AsRef<Path>, ) -> Result<TextureId, Error>
Load a PNG from disk and remember its path for Graphics::refresh_textures. Not
available on the web; use Graphics::load_texture_bytes (or ctx.load_texture,
which picks the right one per platform).
Sourcepub fn measure_text(&mut self, s: &str, size_px: f32) -> [f32; 2]
pub fn measure_text(&mut self, s: &str, size_px: f32) -> [f32; 2]
Size [width, height] in pixels that s takes up drawn at size_px (the widest line,
and the height of all lines), for aligning text or sizing a box to fit. Uses the same
layout as drawing, so the result matches Painter::text exactly; measuring and then
drawing the same string shapes it once.
Sourcepub fn load_font_bytes(&mut self, bytes: Vec<u8>)
pub fn load_font_bytes(&mut self, bytes: Vec<u8>)
Register an extra font face (TTF/OTF bytes) as a glyph fallback for text rendering.
Sourcepub fn load_texture_bytes(
&mut self,
bytes: &[u8],
label: Option<&str>,
) -> Result<TextureId, Error>
pub fn load_texture_bytes( &mut self, bytes: &[u8], label: Option<&str>, ) -> Result<TextureId, Error>
Decode a PNG held in memory and upload it. label names the texture in GPU debuggers
and error messages.
Sourcepub fn refresh_textures<I, P>(&mut self, changed_paths: I) -> usize
pub fn refresh_textures<I, P>(&mut self, changed_paths: I) -> usize
Re-decode any texture whose backing file is in changed_paths and update its bind
group in place. Returns the number of textures actually reloaded.
pub fn create_texture_rgba( &mut self, width: u32, height: u32, rgba: &[u8], label: Option<&str>, ) -> TextureId
Sourcepub fn update_texture_rgba(&mut self, id: TextureId, rgba: &[u8])
pub fn update_texture_rgba(&mut self, id: TextureId, rgba: &[u8])
Overwrite the pixels of an existing texture without reallocating it, for content that
changes every frame (a software-rendered framebuffer, a video frame). rgba must hold
width * height * 4 bytes for the texture’s size; create the texture once with
Self::create_texture_rgba. Unknown ids and size mismatches are logged and ignored.
pub fn white_texture(&self) -> TextureId
Sourcepub fn set_texture_wrap(&mut self, id: TextureId, wrap: TextureWrap)
pub fn set_texture_wrap(&mut self, id: TextureId, wrap: TextureWrap)
Choose what id shows for UVs outside 0..1: TextureWrap::Clamp (the default for
every texture) stretches the edge texels, TextureWrap::Repeat and
TextureWrap::MirrorRepeat tile. Set Repeat on a texture to tile it across one
quad (Painter::quad_textured with UVs up to [4.0, 10.0], a sprite with
crate::SpriteInstance::with_uv beyond 1.0) instead of drawing a quad per tile.
Keep atlases on Clamp: their regions sample right up to the edge, and with wrapping
a UV of exactly 1.0 bleeds in the opposite edge. The mode survives hot-reloads.
Unknown ids are ignored.
Sourcepub fn texture_wrap(&self, id: TextureId) -> Option<TextureWrap>
pub fn texture_wrap(&self, id: TextureId) -> Option<TextureWrap>
The TextureWrap mode of id, or None for an unknown id.
Sourcepub fn texture_size(&self, id: TextureId) -> Option<[u32; 2]>
pub fn texture_size(&self, id: TextureId) -> Option<[u32; 2]>
Pixel size [width, height] of a loaded texture, or None for an unknown id. Follows
hot-reloads, so it reports the size of the current contents.
Sourcepub fn create_mesh(
&mut self,
vertices: &[MeshVertex],
indices: &[u16],
) -> MeshId
pub fn create_mesh( &mut self, vertices: &[MeshVertex], indices: &[u16], ) -> MeshId
Upload a static mesh (positions + normals, indexed) and return its handle. Meshes are
drawn depth-tested via Graphics::draw_mesh using the perspective Self::camera3d.
Sourcepub fn draw_mesh(&mut self, mesh: MeshId, instance: MeshInstance)
pub fn draw_mesh(&mut self, mesh: MeshId, instance: MeshInstance)
Queue one instance of mesh for this frame. Meshes render before the 2D layers, so
2D sprites, primitives and text draw on top of them.
Sourcepub fn request_screenshot(&mut self, path: impl Into<PathBuf>)
pub fn request_screenshot(&mut self, path: impl Into<PathBuf>)
Save a PNG of the next presented frame to path. The read-back stalls that frame, so
this is for debug/dev use. A no-op (with a warning) if the surface lacks COPY_SRC,
and on the web, where there is neither a blocking read-back nor a filesystem.
pub fn begin_frame(&mut self) -> Result<Frame, Error>
pub fn present(&mut self, frame: Frame)
Sourcepub fn flush_pending(&mut self, frame: &mut Frame)
pub fn flush_pending(&mut self, frame: &mut Frame)
Flush all queued 2D layers (sprites + shapes + primitives + text) into the current frame.
Called automatically when a crate::Painter is dropped; call manually before
stacking other passes (e.g. egui) when no painter was created.
Auto Trait Implementations§
impl !Freeze for Graphics
impl !RefUnwindSafe for Graphics
impl !UnwindSafe for Graphics
impl Send for Graphics
impl Sync for Graphics
impl Unpin for Graphics
impl UnsafeUnpin for Graphics
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.