Skip to main content

SoftwareRenderer

Struct SoftwareRenderer 

Source
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

Source

pub 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.

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.

Source

pub const fn set_skip_unchanged_frames(&mut self, skip: bool)

Available on crate feature 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

Source

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.

Source

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.

Source

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.

Source

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

Source

pub const fn surface(&self) -> &SoftwareSurface

The surface holding the most recently rendered frame.

Trait Implementations§

Source§

impl Debug for SoftwareRenderer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SoftwareRenderer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.