Skip to content

Commit

Permalink
Re-implement PaintCallbacks With Support for WGPU
Browse files Browse the repository at this point in the history
This makes breaking changes to the PaintCallback system, but makes it
flexible enough to support both the WGPU and glow backends with custom
rendering.

Also adds a WGPU equivalent to the glow demo for custom painting.
  • Loading branch information
zicklag committed May 26, 2022
1 parent f5cca2a commit c83c281
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 253 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w
* Added opt-in feature `deadlock_detection` to detect double-lock of mutexes on the same thread ([#1619](https://github.com/emilk/egui/pull/1619)).
* Added `InputState::stable_dt`: a more stable estimate for the delta-time in reactive mode ([#1625](https://github.com/emilk/egui/pull/1625)).
* You can now specify a texture filter for your textures ([#1636](https://github.com/emilk/egui/pull/1636)).
* Added support for using `PaintCallback` shapes with the WGPU backend ([#1684](https://github.com/emilk/egui/pull/1684))

### Changed
* `PaintCallback` shapes now require the whole callback to be put in an `Arc<dyn Any>` with the value being a backend-specific callback type. ([#1684](https://github.com/emilk/egui/pull/1684))

### Fixed 🐛
* Fixed `ImageButton`'s changing background padding on hover ([#1595](https://github.com/emilk/egui/pull/1595)).
Expand Down
115 changes: 12 additions & 103 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [

"examples/confirm_exit",
"examples/custom_3d_glow",
"examples/custom_3d_three-d",
# "examples/custom_3d_three-d",
"examples/custom_font",
"examples/custom_font_style",
"examples/custom_window_frame",
Expand Down
42 changes: 21 additions & 21 deletions docs/egui_demo_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,21 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_28(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h0fd05312e5982956(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h517980ac832385bd(arg0, arg1);
}

function __wbg_adapter_31(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h67fa6b1a144b91cc(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h006a9139d694e1ca(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_34(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h67fa6b1a144b91cc(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h006a9139d694e1ca(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_37(arg0, arg1) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha165bf8c3b3285b8(retptr, arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2e68196b4392f7ca(retptr, arg0, arg1);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
if (r1) {
Expand Down Expand Up @@ -260,15 +260,15 @@ function makeClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_40(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbc9fd031a6ee69eb(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5a876099e8c37418(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_43(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbc9fd031a6ee69eb(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5a876099e8c37418(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_46(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha2f39f81315ed630(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd89f67ab5d72c155(arg0, arg1, addHeapObject(arg2));
}

/**
Expand Down Expand Up @@ -1537,32 +1537,32 @@ async function init(input) {
const ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1269 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_28);
imports.wbg.__wbindgen_closure_wrapper3052 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_28);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1270 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_31);
imports.wbg.__wbindgen_closure_wrapper3053 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_31);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1271 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_34);
imports.wbg.__wbindgen_closure_wrapper3054 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_34);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1280 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper3063 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1513 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 524, __wbg_adapter_40);
imports.wbg.__wbindgen_closure_wrapper3293 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 1235, __wbg_adapter_40);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1514 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 524, __wbg_adapter_43);
imports.wbg.__wbindgen_closure_wrapper3294 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 1235, __wbg_adapter_43);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1552 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 544, __wbg_adapter_46);
imports.wbg.__wbindgen_closure_wrapper3332 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1255, __wbg_adapter_46);
return addHeapObject(ret);
};

Expand Down
Binary file modified docs/egui_demo_app_bg.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub struct CreationContext<'s> {
/// you might want to use later from a [`egui::PaintCallback`].
#[cfg(feature = "glow")]
pub gl: Option<std::sync::Arc<glow::Context>>,
/// Can be used to manage GPU resources for custom rendering with WGPU using
/// [`egui::PaintCallback`]s.
#[cfg(feature = "wgpu")]
pub render_state: Option<egui_wgpu::RenderState>,
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -335,6 +339,11 @@ pub struct Frame {
#[cfg(feature = "glow")]
#[doc(hidden)]
pub gl: Option<std::sync::Arc<glow::Context>>,

/// Can be used to manage GPU resources for custom rendering with WGPU using
/// [`egui::PaintCallback`]s.
#[cfg(feature = "wgpu")]
pub render_state: Option<egui_wgpu::RenderState>,
}

impl Frame {
Expand Down
3 changes: 3 additions & 0 deletions eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pub use {egui, egui::emath, egui::epaint};
#[cfg(feature = "glow")]
pub use {egui_glow, glow};

#[cfg(feature = "wgpu")]
pub use {egui_wgpu, wgpu};

mod epi;

// Re-export everything in `epi` so `eframe` users don't have to care about what `epi` is:
Expand Down
3 changes: 3 additions & 0 deletions eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl EpiIntegration {
window: &winit::window::Window,
storage: Option<Box<dyn epi::Storage>>,
#[cfg(feature = "glow")] gl: Option<std::sync::Arc<glow::Context>>,
#[cfg(feature = "wgpu")] render_state: Option<egui_wgpu::RenderState>,
) -> Self {
let egui_ctx = egui::Context::default();

Expand All @@ -207,6 +208,8 @@ impl EpiIntegration {
storage,
#[cfg(feature = "glow")]
gl,
#[cfg(feature = "wgpu")]
render_state,
};

if prefer_dark_mode == Some(true) {
Expand Down
Loading

0 comments on commit c83c281

Please sign in to comment.