Expand description
CPU software render backend for egui
§Basic example usage:
use egui_software_backend::{BufferMutRef, ColorFieldOrder, EguiSoftwareRender};
let buffer = &mut vec![[0u8; 4]; 512 * 512];
let mut buffer_ref = BufferMutRef::new(buffer, 512, 512);
let ctx = egui::Context::default();
let mut demo = egui_demo_lib::DemoWindows::default();
let mut sw_render = EguiSoftwareRender::new(ColorFieldOrder::Bgra);
let out = ctx.run(egui::RawInput::default(), |ctx| {
demo.ui(ctx);
});
let primitives = ctx.tessellate(out.shapes, out.pixels_per_point);
sw_render.render(
&mut buffer_ref,
&primitives,
&out.textures_delta,
out.pixels_per_point,
);§Usage with optional winit backend:
#[cfg(all(feature = "std", feature = "winit"))]
mod example {
use egui::vec2;
use egui_software_backend::{SoftwareBackend, SoftwareBackendAppConfiguration};
struct EguiApp {}
impl EguiApp {
fn new(context: egui::Context) -> Self {
egui_extras::install_image_loaders(&context);
EguiApp {}
}
}
impl egui_software_backend::App for EguiApp {
fn update(&mut self, ctx: &egui::Context, _backend: &mut SoftwareBackend) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("Hello World!");
});
}
}
fn main() {
let settings = SoftwareBackendAppConfiguration::new()
.inner_size(Some(vec2(500.0, 300.0)))
.title(Some("Simple example".to_string()));
egui_software_backend::run_app_with_software_backend(settings, EguiApp::new)
//Can fail if winit fails to create the window
.expect("Failed to run app")
}
}Performance will be very poor without compiler optimizations. Run in release or use (Cargo.toml):
# Enable high optimizations for dependencies
[profile.dev.package."*"]
opt-level = 3Structs§
- Buffer
MutRef - A mutable reference to a slice of image buffer data and corresponding image extents.
- Buffer
Ref - A reference to a slice of image buffer data and corresponding image extents.
- Cached
Primitive - A region of cached rendered image data that corresponds to a ClippedPrimitive.
- Egui
Software Render - Software render backend for egui.
- Software
Backend - This struct contains statistics as well as possible interactions with the software renderer.
- Software
Backend AppConfiguration - Used to initialize the software render backend app, renderer, and winit configuration.
Enums§
- Color
Field Order - Used to define the color swizzle order. Some backends require Rgba and others require Bgra. The renderer swizzles textures as they are loaded so they can later be rasterized directly onto the frame buffer.
Traits§
- App
- Implement this trait to write apps using the optional winit backend similarly to eframe’s App.
Functions§
- run_
app_ with_ software_ backend - Starts the app.