pub struct SoftwareRenderer { /* private fields */ }Expand description
A CPU rasterizer that owns an RGBA8 SoftwareSurface and a texture store.
Draw with SoftwareRenderer::begin_frame, or, with the egui feature, run egui frames
through SoftwareRenderer::render_egui. Both write the same surface.
Implementations§
Source§impl SoftwareRenderer
impl SoftwareRenderer
Sourcepub fn render_egui(
&mut self,
width: usize,
height: usize,
frame: &RenderFrame<'_>,
run_ui: impl FnMut(&mut Ui),
) -> Result<RenderOutcome>
Available on crate feature egui only.
pub fn render_egui( &mut self, width: usize, height: usize, frame: &RenderFrame<'_>, run_ui: impl FnMut(&mut Ui), ) -> Result<RenderOutcome>
egui only.Runs run_ui for one egui frame sized widthxheight, applies egui’s texture
changes, tessellates the output, and rasterizes it into the surface.
egui meshes can show textures made with SoftwareRenderer::create_texture through
crate::egui_adapter::egui_texture_id.
§Errors
Returns an error if the surface cannot be sized, a texture delta is malformed or would
exceed MAX_TEXTURE_BYTES, a mesh’s index count is not a
multiple of three or an index is past its vertices, a clip rectangle is not finite, or
egui emits a paint callback. Mesh errors carry the Error that
Frame::mesh would return for the same indices.
Sourcepub const fn set_skip_unchanged_frames(&mut self, skip: bool)
Available on crate feature egui only.
pub const fn set_skip_unchanged_frames(&mut self, skip: bool)
egui only.Whether egui frames whose tessellated output is bit-identical to the previous frame, with no texture uploads, skip rasterization and keep the previous surface. Enabled by default.
Source§impl SoftwareRenderer
impl SoftwareRenderer
Sourcepub fn create_texture(
&mut self,
width: usize,
height: usize,
pixels: &[u8],
) -> Result<TextureId, Error>
pub fn create_texture( &mut self, width: usize, height: usize, pixels: &[u8], ) -> Result<TextureId, Error>
Stores a texture from premultiplied RGBA8 pixels, width * height * 4 bytes, top
row first.
§Errors
Error::TextureSize for a zero or overflowing size or a side longer than 65536
texels, Error::PixelDataLength if pixels is the wrong length,
Error::TextureBudget if the renderer’s texture storage would exceed
MAX_TEXTURE_BYTES, and Error::TextureIdsExhausted once
the process has issued every possible handle.
Sourcepub fn update_texture(
&mut self,
texture: TextureId,
x: usize,
y: usize,
width: usize,
height: usize,
pixels: &[u8],
) -> Result<(), Error>
pub fn update_texture( &mut self, texture: TextureId, x: usize, y: usize, width: usize, height: usize, pixels: &[u8], ) -> Result<(), Error>
Replaces the widthxheight region of texture whose top-left texel is (x, y)
with premultiplied RGBA8 pixels, top row first.
§Errors
Error::UnknownTexture for a freed or foreign handle, Error::PixelDataLength if
pixels is the wrong length, and Error::TextureUpdateOutOfBounds if the region does
not fit inside the texture.
Sourcepub fn free_texture(&mut self, texture: TextureId) -> Result<(), Error>
pub fn free_texture(&mut self, texture: TextureId) -> Result<(), Error>
Releases a texture’s storage. The handle is invalid afterwards.
§Errors
Error::UnknownTexture if the handle was already freed or never belonged to this
renderer.
Sourcepub fn begin_frame(
&mut self,
width: usize,
height: usize,
) -> Result<Frame<'_>, Error>
pub fn begin_frame( &mut self, width: usize, height: usize, ) -> Result<Frame<'_>, Error>
Starts drawing into a widthxheight surface.
Nothing is cleared implicitly: the surface keeps the previous frame’s pixels, unless its
size changed, in which case it starts transparent black. Call Frame::clear to set a
background.
§Errors
Error::SurfaceSize if the pixel count overflows or exceeds
MAX_SURFACE_PIXELS, or either side is longer than 65535
pixels.
Source§impl SoftwareRenderer
impl SoftwareRenderer
Sourcepub const fn surface(&self) -> &SoftwareSurface
pub const fn surface(&self) -> &SoftwareSurface
The surface holding the most recently rendered frame.
Trait Implementations§
Source§impl Debug for SoftwareRenderer
impl Debug for SoftwareRenderer
Auto Trait Implementations§
impl !RefUnwindSafe for SoftwareRenderer
impl !UnwindSafe for SoftwareRenderer
impl Freeze for SoftwareRenderer
impl Send for SoftwareRenderer
impl Sync for SoftwareRenderer
impl Unpin for SoftwareRenderer
impl UnsafeUnpin for SoftwareRenderer
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more