1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Removed Context::set_current_rendering_viewport

Now we always need to say what viewport we rendering in Context::beagin or Context::run
This commit is contained in:
Konkitoman
2023-07-30 20:03:56 +03:00
parent 1f5d17cfcc
commit fd1c01cf1f
6 changed files with 22 additions and 21 deletions

View File

@@ -515,7 +515,7 @@ impl EpiIntegration {
self.frame.info.parent_viewport = parent_id; self.frame.info.parent_viewport = parent_id;
// Run user code: // Run user code:
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| { let full_output = self.egui_ctx.run(raw_input, viewport_id, |egui_ctx| {
crate::profile_scope!("App::update"); crate::profile_scope!("App::update");
app.update(egui_ctx, &mut self.frame, render.as_ref().map(|r| &***r)); app.update(egui_ctx, &mut self.frame, render.as_ref().map(|r| &***r));
}); });

View File

@@ -1062,7 +1062,6 @@ mod glow_integration {
app.clear_color(&integration.egui_ctx.style().visuals), app.clear_color(&integration.egui_ctx.style().visuals),
); );
integration.egui_ctx.set_current_viewport_id(win.window_id);
egui::FullOutput { egui::FullOutput {
platform_output, platform_output,
repaint_after, repaint_after,
@@ -1786,7 +1785,6 @@ mod wgpu_integration {
}; };
{ {
let Some((viewport_id, (Some(window), Some(state), render, parent_viewport_id, _))) = windows_id.get(&window_id).and_then(|id|(windows.get_mut(id).map(|w|(*id, w)))) else{return vec![]}; let Some((viewport_id, (Some(window), Some(state), render, parent_viewport_id, _))) = windows_id.get(&window_id).and_then(|id|(windows.get_mut(id).map(|w|(*id, w)))) else{return vec![]};
integration.egui_ctx.set_current_viewport_id(viewport_id);
let _ = pollster::block_on(painter.set_window(viewport_id, Some(window))); let _ = pollster::block_on(painter.set_window(viewport_id, Some(window)));

View File

@@ -219,7 +219,8 @@ struct ContextImpl {
} }
impl ContextImpl { impl ContextImpl {
fn begin_frame_mut(&mut self, mut new_raw_input: RawInput) { fn begin_frame_mut(&mut self, mut new_raw_input: RawInput, viewport_id: u64) {
self.current_rendering_viewport = viewport_id;
self.repaint.start_frame(self.current_rendering_viewport); self.repaint.start_frame(self.current_rendering_viewport);
if let Some(new_pixels_per_point) = self.memory.new_pixels_per_point.take() { if let Some(new_pixels_per_point) = self.memory.new_pixels_per_point.take() {
@@ -420,8 +421,13 @@ impl Context {
/// // handle full_output /// // handle full_output
/// ``` /// ```
#[must_use] #[must_use]
pub fn run(&self, new_input: RawInput, run_ui: impl FnOnce(&Context)) -> FullOutput { pub fn run(
self.begin_frame(new_input); &self,
new_input: RawInput,
viewport_id: u64,
run_ui: impl FnOnce(&Context),
) -> FullOutput {
self.begin_frame(new_input, viewport_id);
run_ui(self); run_ui(self);
self.end_frame() self.end_frame()
} }
@@ -443,8 +449,8 @@ impl Context {
/// let full_output = ctx.end_frame(); /// let full_output = ctx.end_frame();
/// // handle full_output /// // handle full_output
/// ``` /// ```
pub fn begin_frame(&self, new_input: RawInput) { pub fn begin_frame(&self, new_input: RawInput, viewport_id: u64) {
self.write(|ctx| ctx.begin_frame_mut(new_input)); self.write(|ctx| ctx.begin_frame_mut(new_input, viewport_id));
} }
} }
@@ -1973,9 +1979,6 @@ impl Context {
use containers::window::ViewportBuilder; use containers::window::ViewportBuilder;
/// # Windows /// # Windows
impl Context { impl Context {
pub fn set_current_viewport_id(&self, viewport_id: u64) {
self.write(|ctx| ctx.current_rendering_viewport = viewport_id);
}
pub fn current_rendering_viewport(&self) -> u64 { pub fn current_rendering_viewport(&self) -> u64 {
self.read(|ctx| ctx.current_rendering_viewport) self.read(|ctx| ctx.current_rendering_viewport)
} }

View File

@@ -555,7 +555,7 @@ pub type ViewportRender = dyn Fn(&Context, u64, u64) + Sync + Send;
pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) { pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
let ctx = Context::default(); let ctx = Context::default();
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time) ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
let _ = ctx.run(Default::default(), |ctx| { let _ = ctx.run(Default::default(), 0, |ctx| {
run_ui(ctx); run_ui(ctx);
}); });
} }
@@ -564,7 +564,7 @@ pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) { pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
let ctx = Context::default(); let ctx = Context::default();
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time) ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
let _ = ctx.run(Default::default(), |ctx| { let _ = ctx.run(Default::default(), 0, |ctx| {
crate::CentralPanel::default().show(ctx, |ui| { crate::CentralPanel::default().show(ctx, |ui| {
add_contents(ui); add_contents(ui);
}); });

View File

@@ -13,7 +13,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
// The most end-to-end benchmark. // The most end-to-end benchmark.
c.bench_function("demo_with_tessellate__realistic", |b| { c.bench_function("demo_with_tessellate__realistic", |b| {
b.iter(|| { b.iter(|| {
let full_output = ctx.run(RawInput::default(), |ctx| { let full_output = ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx); demo_windows.ui(ctx);
}); });
ctx.tessellate(full_output.shapes) ctx.tessellate(full_output.shapes)
@@ -22,13 +22,13 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("demo_no_tessellate", |b| { c.bench_function("demo_no_tessellate", |b| {
b.iter(|| { b.iter(|| {
ctx.run(RawInput::default(), |ctx| { ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx); demo_windows.ui(ctx);
}) })
}); });
}); });
let full_output = ctx.run(RawInput::default(), |ctx| { let full_output = ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx); demo_windows.ui(ctx);
}); });
c.bench_function("demo_only_tessellate", |b| { c.bench_function("demo_only_tessellate", |b| {
@@ -42,7 +42,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let mut demo_windows = egui_demo_lib::DemoWindows::default(); let mut demo_windows = egui_demo_lib::DemoWindows::default();
c.bench_function("demo_full_no_tessellate", |b| { c.bench_function("demo_full_no_tessellate", |b| {
b.iter(|| { b.iter(|| {
ctx.run(RawInput::default(), |ctx| { ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx); demo_windows.ui(ctx);
}) })
}); });
@@ -51,7 +51,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
{ {
let ctx = egui::Context::default(); let ctx = egui::Context::default();
let _ = ctx.run(RawInput::default(), |ctx| { let _ = ctx.run(RawInput::default(), 0, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
c.bench_function("label &str", |b| { c.bench_function("label &str", |b| {
b.iter(|| { b.iter(|| {
@@ -69,7 +69,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
{ {
let ctx = egui::Context::default(); let ctx = egui::Context::default();
ctx.begin_frame(RawInput::default()); ctx.begin_frame(RawInput::default(), 0);
egui::CentralPanel::default().show(&ctx, |ui| { egui::CentralPanel::default().show(&ctx, |ui| {
c.bench_function("Painter::rect", |b| { c.bench_function("Painter::rect", |b| {

View File

@@ -68,7 +68,7 @@ fn test_egui_e2e() {
const NUM_FRAMES: usize = 5; const NUM_FRAMES: usize = 5;
for _ in 0..NUM_FRAMES { for _ in 0..NUM_FRAMES {
let full_output = ctx.run(raw_input.clone(), |ctx| { let full_output = ctx.run(raw_input.clone(), 0, |ctx| {
demo_windows.ui(ctx); demo_windows.ui(ctx);
}); });
let clipped_primitives = ctx.tessellate(full_output.shapes); let clipped_primitives = ctx.tessellate(full_output.shapes);
@@ -87,7 +87,7 @@ fn test_egui_zero_window_size() {
const NUM_FRAMES: usize = 5; const NUM_FRAMES: usize = 5;
for _ in 0..NUM_FRAMES { for _ in 0..NUM_FRAMES {
let full_output = ctx.run(raw_input.clone(), |ctx| { let full_output = ctx.run(raw_input.clone(), 0, |ctx| {
demo_windows.ui(ctx); demo_windows.ui(ctx);
}); });
let clipped_primitives = ctx.tessellate(full_output.shapes); let clipped_primitives = ctx.tessellate(full_output.shapes);