5 个版本 (3 个重大更新)
0.4.0 | 2024年1月14日 |
---|---|
0.3.0 | 2024年1月5日 |
0.2.0 | 2024年1月1日 |
0.1.1 | 2023年12月14日 |
0.1.0 | 2023年12月14日 |
#574 in GUI
每月53次下载
165KB
3.5K SLoC
egui-ash
此crate原生支持自egui 0.24版本开始添加的多视口功能。
您可以通过gpu-allocator
功能将gpu_allocator
用作默认分配器。您也可以通过实现Allocator
特质来使用自己的分配器。
示例
简单
cargo run --release --example egui_ash_simple
vulkan
cargo run --release --example egui_ash_vulkan
图像
cargo run --release --example images
多视口
cargo run --release --example multi_viewports
本地图像
cargo run --release --example native_image
场景视图
cargo run --release --example scene_view
瓦片
cargo run --release --example tiles
使用方法
// (1) Create a App struct that implements the `egui_ash::App` trait.
struct MyApp;
impl egui_ash::App for MyApp {
fn ui(
&mut self,
ctx: &egui::CtxRef,
integration_context: &mut egui_ash::IntegrationContext,
) {
// (2) draw ui here
egui::Window::new("Hello world").show(ctx, |ui| {
ui.label("Hello world!");
});
}
fn request_redraw(&mut self, _viewport_id: egui::ViewportId) -> HandleRedraw {
// (3) return `HandleRedraw::Auto` if you want to draw only egui.
HandleRedraw::Auto
// (4) ...or return `HandleRedraw::Handle` if you want to draw with ash.
// NOTE: You must call `egui_cmd.update_swapchain` inside render function
// when you first render and when you recreate the swapchain.
HandleRedraw::Handle(Box::new(|size, egui_cmd| render(size, egui_cmd)))
}
}
// (5) Create a AppCreator struct that implements the `egui_ash::AppCreator` trait.
struct MyAppCreator;
impl egui_ash::AppCreator for MyAppCreator {
type App = MyApp;
// (6) new method receives `egui_ash::CreationContext` and
// returns `Self::App` and `egui_ash::AshRenderState`.
fn new(&self, cc: CreationContext) -> (Self::App, AshRenderState<Arc<Mutex<Allocator>>>) {
// create vk objects
let entry = create_entry();
let (instance, debug_utils_loader, debug_messenger) =
create_instance(&cc.required_instance_extensions, &entry);
let surface_loader = create_surface_loader(&entry, &instance);
let surface = create_surface(&entry, &instance, cc.main_window);
let (physical_device, _physical_device_memory_properties, queue_family_index) =
create_physical_device(
&instance,
&surface_loader,
surface,
&cc.required_device_extensions,
);
let (device, queue) = create_device(
&instance,
physical_device,
queue_family_index,
&cc.required_device_extensions,
);
let swapchain_loader = create_swapchain_loader(&instance, &device);
let command_pool = create_command_pool(&device, queue_family_index);
// create allocator
let allocator = {
Allocator::new(&AllocatorCreateDesc {
instance: instance.clone(),
device: device.clone(),
physical_device,
debug_settings: Default::default(),
buffer_device_address: false,
allocation_sizes: Default::default(),
})
.expect("Failed to create allocator")
};
let allocator = Arc::new(Mutex::new(allocator));
let ash_render_state = AshRenderState {
entry,
instance,
physical_device,
device,
surface_loader,
swapchain_loader,
queue,
queue_family_index,
command_pool,
allocator,
};
(Self, ash_render_state)
}
}
// (7) Call `egui_ash::run` with `AppCreator` struct.
fn main() {
egui_ash::run(
MyAppCreator,
RunOption {
viewport_builder: Some(egui::ViewportBuilder::default().with_title("egui-ash")),
..Default::default()
},
)
}
功能标志
gpu-allocator
- 启用gpu-allocator crate。
此功能允许使用Arc<Mutex<gpu_allocator::vulkan::Allocator>>
作为egui-ash的分配器。
persistence
- 启用egui的持久化功能。
使用此功能,将persistent_windows
和persistent_egui_memory
在RunOption中设置为true
将保留窗口大小和位置,以及缩放因子等。
其他功能
其他功能直接控制底层的egui_winit功能
许可证
MIT OR Apache-2.0
依赖
~12–46MB
~779K SLoC