3 个不稳定版本
| 0.6.1 | 2021年2月22日 |
|---|---|
| 0.5.1 | 2021年2月4日 |
| 0.5.0 | 2021年2月2日 |
#147 in 渲染
在 game_kernel 中使用
1MB
601 行
imgui-vulkano-renderer
注意:我仅在几个示例和一些项目中使用过此渲染器,因此可能存在一些问题,但它似乎与基本的 ImGui 使用兼容。
支持 imgui-rs 版本 0.6.0 和 vulkano 版本 0.19.0。
注意:目前 vulkano-win,即 vulkano 的 winit 集成,仅支持 winit 0.22.2,而 imgui-winit-support 默认使用 winit 0.23.0。要使它们兼容,请在 imgui-winit-support 包中启用 winit-22 功能。
使用方法
Renderer 结构旨在作为 imgui-glium-renderer 和 imgui-gfx-renderer(来自 imgui-rs 仓库)中相应功能的直接替换,除了 API 特定的上下文参数(Vulkano 的 Device 和 Queue 结构)。
设置
use imgui_vulkano_renderer::Renderer;
let mut renderer = Renderer::init(
&mut imgui_ctx,
device.clone(),
graphics_queue.clone(),
Format::R8G8B8A8Srgb
).unwrap();
渲染
使用 Renderer::draw_commands 函数来更新缓冲区
let ui = imgui_ctx.frame();
// ... UI elements created here
let draw_data = ui.render();
let mut cmd_buf_builder = AutoCommandBufferBuilder::new(device.clone(), graphics_queue.family()).unwrap();
// add Vulkan commands to a command buffer. Here a new command buffer is used, but you can also append to an existing one.
renderer.draw_commands(&mut cmd_buf_builder, graphics_queue.clone(), target_image.clone(), draw_data).unwrap();
let cmd_buf = cmd_buf_builder.build().unwrap();
其他
字体图集纹理通过以下方式重新加载
renderer.reupload_font_texture(&mut imgui_ctx, device.clone(), queue.clone());
您 UI 中使用的纹理在 imgui::Textures 结构中查找,可以使用 Renderer::textures 访问。
示例
我将来自 imgui-rs 的几个示例进行了重写,以展示基本用法(其中大多数只需对 examples/support/mod.rs 中的 System 结构体进行设置更改)。它们可以用以下方式运行:
cargo run --example hello_world
cargo run --example custom_textures
依赖项
~48MB
~1M SLoC