mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 07:03:14 -04:00
Pass out pixels_per_point in output for use in tesselation
This commit is contained in:
@@ -562,6 +562,7 @@ mod glow_integration {
|
||||
platform_output,
|
||||
textures_delta,
|
||||
shapes,
|
||||
pixels_per_point,
|
||||
viewports: viewports_out,
|
||||
viewport_commands,
|
||||
} = full_output;
|
||||
@@ -580,10 +581,6 @@ mod glow_integration {
|
||||
integration.post_update(app.as_mut(), window);
|
||||
integration.handle_platform_output(window, viewport_id, platform_output, egui_winit);
|
||||
|
||||
let pixels_per_point = integration
|
||||
.egui_ctx
|
||||
.input_for(viewport_id, |i| i.pixels_per_point());
|
||||
|
||||
let clipped_primitives = integration.egui_ctx.tessellate(shapes, pixels_per_point);
|
||||
|
||||
*current_gl_context = Some(
|
||||
@@ -1581,7 +1578,7 @@ mod glow_integration {
|
||||
let screen_size_in_pixels: [u32; 2] = window.inner_size().into();
|
||||
|
||||
let pixels_per_point = egui_ctx.input_for(ids.this, |i| i.pixels_per_point());
|
||||
let clipped_primitives = egui_ctx.tessellate(output.shapes, pixels_per_point);
|
||||
let clipped_primitives = egui_ctx.tessellate(output.shapes, output.pixels_per_point);
|
||||
|
||||
let mut painter = painter.borrow_mut();
|
||||
|
||||
@@ -2181,7 +2178,7 @@ mod wgpu_integration {
|
||||
}
|
||||
|
||||
let pixels_per_point = egui_ctx.input_for(ids.this, |i| i.pixels_per_point());
|
||||
let clipped_primitives = egui_ctx.tessellate(output.shapes, pixels_per_point);
|
||||
let clipped_primitives = egui_ctx.tessellate(output.shapes, output.pixels_per_point);
|
||||
painter.paint_and_update_textures(
|
||||
ids.this,
|
||||
pixels_per_point,
|
||||
@@ -2504,6 +2501,7 @@ mod wgpu_integration {
|
||||
platform_output,
|
||||
textures_delta,
|
||||
shapes,
|
||||
pixels_per_point,
|
||||
viewports: out_viewports,
|
||||
viewport_commands,
|
||||
} = full_output;
|
||||
@@ -2511,10 +2509,6 @@ mod wgpu_integration {
|
||||
integration.handle_platform_output(window, viewport_id, platform_output, egui_winit);
|
||||
|
||||
{
|
||||
let pixels_per_point = integration
|
||||
.egui_ctx
|
||||
.input_for(viewport_id, |i| i.pixels_per_point());
|
||||
|
||||
let clipped_primitives = integration.egui_ctx.tessellate(shapes, pixels_per_point);
|
||||
|
||||
let screenshot_requested = &mut integration.frame.output.screenshot_requested;
|
||||
|
||||
@@ -429,7 +429,7 @@ impl ContextImpl {
|
||||
/// });
|
||||
/// });
|
||||
/// handle_platform_output(full_output.platform_output);
|
||||
/// let clipped_primitives = ctx.tessellate(full_output.shapes); // create triangles to paint
|
||||
/// let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
|
||||
/// paint(full_output.textures_delta, clipped_primitives);
|
||||
/// }
|
||||
/// ```
|
||||
@@ -1486,6 +1486,7 @@ impl ContextImpl {
|
||||
fn end_frame(&mut self) -> FullOutput {
|
||||
let ended_viewport_id = self.viewport_id();
|
||||
let viewport = self.viewports.entry(ended_viewport_id).or_default();
|
||||
let pixels_per_point = viewport.input.pixels_per_point;
|
||||
|
||||
if viewport.input.wants_repaint() {
|
||||
self.repaint.requested_repaint(&ended_viewport_id);
|
||||
@@ -1607,6 +1608,7 @@ impl ContextImpl {
|
||||
platform_output,
|
||||
textures_delta,
|
||||
shapes,
|
||||
pixels_per_point,
|
||||
viewports: out_viewports,
|
||||
// We should not process viewport commands when we are a sync viewport, because that will cause a deadlock for egui backend
|
||||
viewport_commands: if is_last {
|
||||
|
||||
@@ -21,6 +21,11 @@ pub struct FullOutput {
|
||||
/// You can use [`crate::Context::tessellate`] to turn this into triangles.
|
||||
pub shapes: Vec<epaint::ClippedShape>,
|
||||
|
||||
/// The number of physical pixels per logical ui point, for the viewport that was updated.
|
||||
///
|
||||
/// You can pass this to [`Context::tesselate`] together with [`Self::shapes`].
|
||||
pub pixels_per_point: f32,
|
||||
|
||||
/// All the active viewports, excluding the root.
|
||||
pub viewports: Vec<ViewportOutput>,
|
||||
|
||||
@@ -35,6 +40,7 @@ impl FullOutput {
|
||||
platform_output,
|
||||
textures_delta,
|
||||
shapes,
|
||||
pixels_per_point,
|
||||
mut viewports,
|
||||
mut viewport_commands,
|
||||
} = newer;
|
||||
@@ -42,6 +48,7 @@ impl FullOutput {
|
||||
self.platform_output.append(platform_output);
|
||||
self.textures_delta.append(textures_delta);
|
||||
self.shapes = shapes; // Only paint the latest
|
||||
self.pixels_per_point = pixels_per_point; // Use latest
|
||||
self.viewports.append(&mut viewports);
|
||||
self.viewport_commands.append(&mut viewport_commands);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
//! });
|
||||
//! });
|
||||
//! handle_platform_output(full_output.platform_output);
|
||||
//! let clipped_primitives = ctx.tessellate(full_output.shapes); // create triangles to paint
|
||||
//! let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
|
||||
//! paint(full_output.textures_delta, clipped_primitives);
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
@@ -9,7 +9,6 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
{
|
||||
let ctx = egui::Context::default();
|
||||
let mut demo_windows = egui_demo_lib::DemoWindows::default();
|
||||
let pixels_per_point = 1.0;
|
||||
|
||||
// The most end-to-end benchmark.
|
||||
c.bench_function("demo_with_tessellate__realistic", |b| {
|
||||
@@ -17,7 +16,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
let full_output = ctx.run(RawInput::default(), |ctx| {
|
||||
demo_windows.ui(ctx);
|
||||
});
|
||||
ctx.tessellate(full_output.shapes, pixels_per_point)
|
||||
ctx.tessellate(full_output.shapes, full_output.pixels_per_point)
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,7 +32,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
demo_windows.ui(ctx);
|
||||
});
|
||||
c.bench_function("demo_only_tessellate", |b| {
|
||||
b.iter(|| ctx.tessellate(full_output.shapes.clone(), pixels_per_point));
|
||||
b.iter(|| ctx.tessellate(full_output.shapes.clone(), full_output.pixels_per_point));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -71,14 +71,13 @@ fn test_egui_e2e() {
|
||||
let mut demo_windows = crate::DemoWindows::default();
|
||||
let ctx = egui::Context::default();
|
||||
let raw_input = egui::RawInput::default();
|
||||
let pixels_per_point = 1.0;
|
||||
|
||||
const NUM_FRAMES: usize = 5;
|
||||
for _ in 0..NUM_FRAMES {
|
||||
let full_output = ctx.run(raw_input.clone(), |ctx| {
|
||||
demo_windows.ui(ctx);
|
||||
});
|
||||
let clipped_primitives = ctx.tessellate(full_output.shapes, pixels_per_point);
|
||||
let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
|
||||
assert!(!clipped_primitives.is_empty());
|
||||
}
|
||||
}
|
||||
@@ -91,14 +90,13 @@ fn test_egui_zero_window_size() {
|
||||
screen_rect: Some(egui::Rect::from_min_max(egui::Pos2::ZERO, egui::Pos2::ZERO)),
|
||||
..Default::default()
|
||||
};
|
||||
let pixels_per_point = 1.0;
|
||||
|
||||
const NUM_FRAMES: usize = 5;
|
||||
for _ in 0..NUM_FRAMES {
|
||||
let full_output = ctx.run(raw_input.clone(), |ctx| {
|
||||
demo_windows.ui(ctx);
|
||||
});
|
||||
let clipped_primitives = ctx.tessellate(full_output.shapes, pixels_per_point);
|
||||
let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
|
||||
assert!(
|
||||
clipped_primitives.is_empty(),
|
||||
"There should be nothing to show, has at least one primitive with clip_rect: {:?}",
|
||||
|
||||
@@ -10,7 +10,9 @@ pub struct EguiGlow {
|
||||
pub egui_winit: egui_winit::State,
|
||||
pub painter: crate::Painter,
|
||||
|
||||
// output from the last update:
|
||||
shapes: Vec<egui::epaint::ClippedShape>,
|
||||
pixels_per_point: f32,
|
||||
textures_delta: egui::TexturesDelta,
|
||||
}
|
||||
|
||||
@@ -28,15 +30,19 @@ impl EguiGlow {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let egui_winit = egui_winit::State::new(
|
||||
event_loop,
|
||||
native_pixels_per_point,
|
||||
Some(painter.max_texture_side()),
|
||||
);
|
||||
let pixels_per_point = egui_winit.pixels_per_point();
|
||||
|
||||
Self {
|
||||
egui_ctx: Default::default(),
|
||||
egui_winit: egui_winit::State::new(
|
||||
event_loop,
|
||||
native_pixels_per_point,
|
||||
Some(painter.max_texture_side()),
|
||||
),
|
||||
egui_winit,
|
||||
painter,
|
||||
shapes: Default::default(),
|
||||
pixels_per_point,
|
||||
textures_delta: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -55,6 +61,7 @@ impl EguiGlow {
|
||||
platform_output,
|
||||
textures_delta,
|
||||
shapes,
|
||||
pixels_per_point,
|
||||
viewports,
|
||||
viewport_commands,
|
||||
} = self.egui_ctx.run(raw_input, run_ui);
|
||||
@@ -76,6 +83,7 @@ impl EguiGlow {
|
||||
);
|
||||
|
||||
self.shapes = shapes;
|
||||
self.pixels_per_point = pixels_per_point;
|
||||
self.textures_delta.append(textures_delta);
|
||||
}
|
||||
|
||||
@@ -88,7 +96,7 @@ impl EguiGlow {
|
||||
self.painter.set_texture(id, &image_delta);
|
||||
}
|
||||
|
||||
let pixels_per_point = self.egui_ctx.pixels_per_point();
|
||||
let pixels_per_point = self.pixels_per_point;
|
||||
let clipped_primitives = self.egui_ctx.tessellate(shapes, pixels_per_point);
|
||||
let dimensions: [u32; 2] = window.inner_size().into();
|
||||
self.painter
|
||||
|
||||
Reference in New Issue
Block a user