Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support remote rendering #3323

Draft
wants to merge 42 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8e2be10
Implement basic remote client
linguini11 Jul 18, 2023
e4db352
Working remote methods
linguini11 Jul 21, 2023
a42b563
Remove unnecessary code
linguini11 Jul 25, 2023
0b0efc6
Refactoring into existing methods
linguini11 Jul 25, 2023
6b976a9
Remove unnecessary code
linguini11 Jul 25, 2023
c776a73
Add debugging lines
linguini11 Jul 25, 2023
956bc4e
Savae before debugging
linguini11 Jul 26, 2023
d6fac65
Add serde_diff
linguini11 Jul 28, 2023
0957fc0
Save before debugging
linguini11 Jul 31, 2023
32b1bbe
Save before debugging
linguini11 Jul 31, 2023
b34a59f
Changing opaque structs to skipping specific fields
linguini11 Jul 31, 2023
911742e
Remove serde diff for debugging
linguini11 Jul 31, 2023
8c7f41d
Finalise serde_diff
linguini11 Aug 8, 2023
617b8ab
Fix merge conflicts
linguini11 Aug 8, 2023
c6f9410
Add serde_diff back in
linguini11 Aug 8, 2023
010752e
Clean up code
linguini11 Aug 8, 2023
a544cb4
Remove reset_repaint_after method
linguini11 Aug 8, 2023
ae26adb
Fix serializing infinity bug
linguini11 Aug 11, 2023
7ee42df
Remove code no longer needed
linguini11 Aug 11, 2023
0ff3170
Update serde-diff dependency
linguini11 Aug 16, 2023
fc8f33c
Pass frame to update_remote
linguini11 Aug 30, 2023
f627ef8
Add message type enum
linguini11 Sep 6, 2023
201061b
Add back optional for serde
linguini11 Sep 6, 2023
888397b
Fix deriving traits
linguini11 Sep 6, 2023
4372b3a
Remove copy trait
linguini11 Sep 6, 2023
b1ebaf1
Remove unnecessary traits
linguini11 Sep 6, 2023
a30a52e
Add wgpu remote rendering
linguini11 Sep 7, 2023
2b5adca
Switch to wgpu renderer
linguini11 Sep 7, 2023
f8e057a
Use different serde-diff version
linguini11 Sep 7, 2023
2191571
Add local serde-diff copy
linguini11 Sep 7, 2023
5fd403b
Local serde-diff copy
linguini11 Sep 7, 2023
0df61ab
Add examples
linguini11 Sep 7, 2023
9d8018d
Update examples
linguini11 Sep 7, 2023
60ee8d2
Add serde-diff feature flag
linguini11 Sep 7, 2023
12afefe
Fix epaint serde-diff feature
linguini11 Sep 7, 2023
cfafab8
Fix serde_diff feature
linguini11 Sep 7, 2023
553fade
Add serde-diff as default feature
linguini11 Sep 7, 2023
c24a062
Re-add wgpu remote_rendering
linguini11 Sep 7, 2023
d82828b
Put serde-diff behind a feature flag
linguini11 Sep 8, 2023
9005a75
Update documentation description of serde-diff
linguini11 Oct 8, 2023
a106b46
Use multiple features for serde-diff feature flag
linguini11 Oct 8, 2023
d3124b3
Address pull request comments
linguini11 Oct 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitmodules
Empty file.
132 changes: 127 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/ecolor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ document-features = { version = "0.2", optional = true }

## Allow serialization using [`serde`](https://docs.rs/serde).
serde = { version = "1", optional = true, features = ["derive"] }

## Allow diffing with serialization using [`serde-diff`](https://docs.rs/serde-diff/latest/serde_diff/) .
#serde-diff = { version = "0.4.1", optional = true }
serde-diff = { git = "https://github.com/linguini11/serde-diff.git", optional = true }
4 changes: 4 additions & 0 deletions crates/ecolor/src/color32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use crate::{gamma_u8_from_linear_f32, linear_f32_from_gamma_u8, linear_f32_from_
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(
all(feature = "serde-diff", feature = "serde"),
derive(serde_diff::SerdeDiff)
)]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct Color32(pub(crate) [u8; 4]);

Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]


[features]
default = ["accesskit", "default_fonts", "glow"]
default = ["accesskit", "default_fonts", "glow", "serde"]

## Enable platform accessibility API implementations through [AccessKit](https://accesskit.dev/).
accesskit = ["egui/accesskit", "egui-winit/accesskit"]
Expand Down
23 changes: 23 additions & 0 deletions crates/eframe/src/epi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ unsafe impl HasRawDisplayHandle for CreationContext<'_> {
}
}

/// Message types for client to server communication for remote rendering
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum RemoteRenderingMessageType {
/// Initial connection, specifying pixels_per_point as the content
Connect(f32),
/// Request to update pixels_per_point
PixelsPerPoint(f32),
/// Send input events to server
RawInput(egui::RawInput),
}

// ----------------------------------------------------------------------------

/// Implement this trait to write apps that can be compiled for both web/wasm and desktop/native using [`eframe`](https://github.com/emilk/egui/tree/master/crates/eframe).
Expand All @@ -114,6 +126,17 @@ pub trait App {
/// To force a repaint, call [`egui::Context::request_repaint`] at any time (e.g. from another thread).
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame);

/// Called each time the UI needs repainting when rendering on a remote client, which may be many times per second.
///
/// Retrieves the `FullOutput` from the client rather than constructing it internally
fn update_remote(
&mut self,
_raw_input: egui::RawInput,
_frame: &Frame,
) -> (egui::output::FullOutput, f32) {
(egui::output::FullOutput::default(), 2.0)
}

/// Get a handle to the app.
///
/// Can be used from web to interact or other external context.
Expand Down
10 changes: 6 additions & 4 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!
//! fn main() {
//! let native_options = eframe::NativeOptions::default();
//! eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))));
//! eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))), false);
//! }
//!
//! #[derive(Default)]
Expand Down Expand Up @@ -170,7 +170,7 @@ mod native;
///
/// fn main() -> eframe::Result<()> {
/// let native_options = eframe::NativeOptions::default();
/// eframe::run_native("MyApp", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))))
/// eframe::run_native("MyApp", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))), false)
/// }
///
/// #[derive(Default)]
Expand Down Expand Up @@ -204,6 +204,7 @@ pub fn run_native(
app_name: &str,
native_options: NativeOptions,
app_creator: AppCreator,
remote_rendering: bool,
) -> Result<()> {
let renderer = native_options.renderer;

Expand All @@ -217,13 +218,13 @@ pub fn run_native(
#[cfg(feature = "glow")]
Renderer::Glow => {
log::debug!("Using the glow renderer");
native::run::run_glow(app_name, native_options, app_creator)
native::run::run_glow(app_name, native_options, app_creator, remote_rendering)
}

#[cfg(feature = "wgpu")]
Renderer::Wgpu => {
log::debug!("Using the wgpu renderer");
native::run::run_wgpu(app_name, native_options, app_creator)
native::run::run_wgpu(app_name, native_options, app_creator, remote_rendering)
}
}
}
Expand Down Expand Up @@ -282,6 +283,7 @@ pub fn run_simple_native(
app_name,
native_options,
Box::new(|_cc| Box::new(SimpleApp { update_fun })),
false,
)
}

Expand Down
24 changes: 18 additions & 6 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl EpiIntegration {
let saved_memory: egui::Memory = self.egui_ctx.memory(|mem| mem.clone());
self.egui_ctx
.memory_mut(|mem| mem.set_everything_is_visible(true));
let full_output = self.update(app, window);
let full_output = self.update(app, window, false);
self.pending_full_output.append(full_output); // Handle it next frame
self.egui_ctx.memory_mut(|mem| *mem = saved_memory); // We don't want to remember that windows were huge.
self.egui_ctx.clear_animations();
Expand Down Expand Up @@ -489,6 +489,7 @@ impl EpiIntegration {
&mut self,
app: &mut dyn epi::App,
window: &winit::window::Window,
remote_rendering: bool,
) -> egui::FullOutput {
let frame_start = std::time::Instant::now();

Expand All @@ -499,12 +500,23 @@ impl EpiIntegration {
let raw_input = self.egui_winit.take_egui_input(window);

// Run user code:
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
crate::profile_scope!("App::update");
app.update(egui_ctx, &mut self.frame);
});
if remote_rendering {
let (full_output, pixels_per_point) = app.update_remote(raw_input, &self.frame);
// Tessellate throws error if 'run' hasn't been called, so run and ignore result
let raw_input = egui::RawInput {
pixels_per_point: Some(pixels_per_point),
..Default::default()
};
let _ = self.egui_ctx.run(raw_input, |_egui_ctx| {});
self.pending_full_output.append(full_output);
} else {
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
crate::profile_scope!("App::update");
app.update(egui_ctx, &mut self.frame);
});
self.pending_full_output.append(full_output);
}

self.pending_full_output.append(full_output);
let full_output = std::mem::take(&mut self.pending_full_output);

{
Expand Down
Loading