stuff i forgor in earlier commits (state 4.1.25)
This commit is contained in:
parent
a5ea706744
commit
fdfc74c668
|
@ -70,15 +70,18 @@ impl WinitState {
|
||||||
window.demo_app.ui(&window.egui_platform.context());
|
window.demo_app.ui(&window.egui_platform.context());
|
||||||
let output = window.egui_platform.end_pass(Some(&window.window));
|
let output = window.egui_platform.end_pass(Some(&window.window));
|
||||||
|
|
||||||
self.renderer
|
// self.renderer
|
||||||
.draw_egui(&window.egui_platform.context(), output)
|
// .draw_egui(&window.egui_platform.context(), output)
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
self.renderer
|
self.renderer
|
||||||
.debug_draw(&window_id, || {
|
.debug_draw_egui(&window_id, &window.egui_platform.context(), output, || {
|
||||||
window.window.pre_present_notify();
|
window.window.pre_present_notify();
|
||||||
})
|
})
|
||||||
|
.inspect_err(|err| {
|
||||||
|
tracing::error!("error encountered while drawing: {err}");
|
||||||
|
})
|
||||||
.expect("drawing");
|
.expect("drawing");
|
||||||
window.window.request_redraw();
|
window.window.request_redraw();
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ mod texture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use render_graph::Access;
|
||||||
use util::Rgba;
|
use util::Rgba;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
@ -1295,7 +1296,7 @@ impl Vulkan {
|
||||||
)],
|
)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
tracing::debug!("pdev: {pdev:?}");
|
tracing::trace!("pdev: {pdev:?}");
|
||||||
let device = Device::new(instance.clone(), pdev, features)?;
|
let device = Device::new(instance.clone(), pdev, features)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
@ -2241,7 +2242,7 @@ impl<W> Renderer<W> {
|
||||||
);
|
);
|
||||||
self.texture_handler
|
self.texture_handler
|
||||||
.insert_image_with_id(id, texture.clone());
|
.insert_image_with_id(id, texture.clone());
|
||||||
tracing::debug!("new texture for egui: {egui_id:?} -> {id:?}");
|
tracing::trace!("new texture for egui: {egui_id:?} -> {id:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
(staging, texture)
|
(staging, texture)
|
||||||
|
@ -2501,6 +2502,85 @@ impl<W> Renderer<W> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn debug_draw_egui<K, F>(
|
||||||
|
&mut self,
|
||||||
|
window: &K,
|
||||||
|
egui_ctx: &egui::Context,
|
||||||
|
output: egui::FullOutput,
|
||||||
|
pre_present_cb: F,
|
||||||
|
) -> Result<()>
|
||||||
|
where
|
||||||
|
K: core::hash::Hash + Eq,
|
||||||
|
W: core::hash::Hash + Eq + Borrow<K>,
|
||||||
|
F: FnOnce(),
|
||||||
|
{
|
||||||
|
let dev = self.vulkan.device.clone();
|
||||||
|
|
||||||
|
if let Some(ctx) = self.window_contexts.get(window) {
|
||||||
|
let (frame, suboptimal) =
|
||||||
|
smol::block_on(ctx.current_swapchain.read().clone().acquire_image())?;
|
||||||
|
|
||||||
|
if suboptimal {
|
||||||
|
tracing::warn!(
|
||||||
|
"swapchain ({:?}) is suboptimal!",
|
||||||
|
ctx.current_swapchain.read().swapchain
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let [r, g, b] = rand::prelude::StdRng::seed_from_u64(ctx.surface.surface.as_raw())
|
||||||
|
.gen::<[f32; 3]>();
|
||||||
|
let clear_color = Rgba([r, g, b, 1.0]);
|
||||||
|
|
||||||
|
let mut rg = render_graph::RenderGraph::new();
|
||||||
|
let (textures_to_remove, cmds) = util::timed("record command buffer", || {
|
||||||
|
let framebuffer = rg.import_image(frame.image.clone(), Access::undefined());
|
||||||
|
rg.mark_as_output(framebuffer);
|
||||||
|
|
||||||
|
render_graph::clear_pass(&mut rg, clear_color, framebuffer);
|
||||||
|
egui_pass::egui_pre_pass(
|
||||||
|
&dev,
|
||||||
|
&mut rg,
|
||||||
|
&mut self.texture_handler,
|
||||||
|
&mut self.egui_state,
|
||||||
|
&output,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let textures_to_remove = egui_pass::egui_pass(
|
||||||
|
&dev,
|
||||||
|
&mut rg,
|
||||||
|
&mut self.texture_handler,
|
||||||
|
&mut self.vulkan.samplers,
|
||||||
|
&mut self.egui_state,
|
||||||
|
egui_ctx,
|
||||||
|
output,
|
||||||
|
framebuffer,
|
||||||
|
)?;
|
||||||
|
render_graph::present_pass(&mut rg, framebuffer);
|
||||||
|
|
||||||
|
Result::Ok((textures_to_remove, rg.resolve(dev.clone())?))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let future = cmds.submit(
|
||||||
|
Some((frame.acquire, vk::PipelineStageFlags::TRANSFER)),
|
||||||
|
Some(frame.release),
|
||||||
|
Arc::new(sync::Fence::create(dev.clone())?),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// call pre_present_notify
|
||||||
|
pre_present_cb();
|
||||||
|
|
||||||
|
let wait = Some(frame.release);
|
||||||
|
frame.present(wait)?;
|
||||||
|
future.block()?;
|
||||||
|
|
||||||
|
for id in textures_to_remove {
|
||||||
|
self.texture_handler.remove_texture(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn debug_draw<K, F: FnOnce()>(&mut self, window: &K, pre_present_cb: F) -> Result<()>
|
pub fn debug_draw<K, F: FnOnce()>(&mut self, window: &K, pre_present_cb: F) -> Result<()>
|
||||||
where
|
where
|
||||||
K: core::hash::Hash + Eq,
|
K: core::hash::Hash + Eq,
|
||||||
|
|
Loading…
Reference in a new issue