Skip to content

Commit

Permalink
Apply More Code Review Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed May 27, 2022
1 parent d5d8cab commit 7aee50b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 31 deletions.
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__h517980ac832385bd(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h0fd05312e5982956(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__h006a9139d694e1ca(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h67fa6b1a144b91cc(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__h006a9139d694e1ca(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h67fa6b1a144b91cc(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__h2e68196b4392f7ca(retptr, arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha165bf8c3b3285b8(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__h5a876099e8c37418(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbc9fd031a6ee69eb(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__h5a876099e8c37418(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__Fn__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbc9fd031a6ee69eb(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__hd89f67ab5d72c155(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha2f39f81315ed630(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_wrapper3052 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_28);
imports.wbg.__wbindgen_closure_wrapper1269 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_28);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper3053 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_31);
imports.wbg.__wbindgen_closure_wrapper1270 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_31);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper3054 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_34);
imports.wbg.__wbindgen_closure_wrapper1271 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_34);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper3063 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1094, __wbg_adapter_37);
imports.wbg.__wbindgen_closure_wrapper1280 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 371, __wbg_adapter_37);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper3293 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 1235, __wbg_adapter_40);
imports.wbg.__wbindgen_closure_wrapper1513 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 524, __wbg_adapter_40);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper3294 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 1235, __wbg_adapter_43);
imports.wbg.__wbindgen_closure_wrapper1514 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 524, __wbg_adapter_43);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper3332 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1255, __wbg_adapter_46);
imports.wbg.__wbindgen_closure_wrapper1552 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 544, __wbg_adapter_46);
return addHeapObject(ret);
};

Expand Down
Binary file modified docs/egui_demo_app_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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")]
Expand Down
28 changes: 25 additions & 3 deletions egui-wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ use wgpu::util::DeviceExt as _;

/// A callback function that can be used to compose an [`egui::PaintCallback`] for custom WGPU
/// rendering.
///
/// The callback is composed of two functions: `prepare` and `paint`.
///
/// `prepare` is called every frame before `paint`, and can use the passed-in [`wgpu::Device`] and
/// [`wgpu::Buffer`] to allocate or modify GPU resources such as buffers.
///
/// `paint` is called after `prepare` and is given access to the the [`wgpu::RenderPass`] so that it
/// can issue draw commands.
///
/// The final argument of both the `prepare` and `paint` callbacks is a the
/// [`paint_callback_resources`][crate::renderer::RenderPass::paint_callback_resources].
/// `paint_callback_resources` has the same lifetime as the Egui render pass, so it can be used to
/// store buffers, pipelines, and other information that needs to be accessed during the render
/// pass.
///
/// # Example
///
/// See the [custom3d_wgpu] demo source for a detailed usage example.
///
/// [custom3d_wgpu]:
/// https://github.com/emilk/egui/blob/master/egui_demo_app/src/apps/custom3d_wgpu.rs
pub struct CallbackFn {
prepare: Box<PrepareCallback>,
paint: Box<PaintCallback>,
Expand All @@ -32,6 +53,7 @@ impl CallbackFn {
Self::default()
}

/// Set the prepare callback
pub fn prepare<F>(mut self, prepare: F) -> Self
where
F: Fn(&wgpu::Device, &wgpu::Queue, &mut TypeMap) + Sync + Send + 'static,
Expand All @@ -40,6 +62,7 @@ impl CallbackFn {
self
}

/// Set the paint callback
pub fn paint<F>(mut self, paint: F) -> Self
where
F: for<'a, 'b> Fn(PaintCallbackInfo, &'a mut wgpu::RenderPass<'b>, &'b TypeMap)
Expand Down Expand Up @@ -375,6 +398,7 @@ impl RenderPass {
let cbfn = if let Some(c) = callback.callback.downcast_ref::<CallbackFn>() {
c
} else {
// We already warned in the `prepare` callback
continue;
};

Expand Down Expand Up @@ -539,7 +563,6 @@ impl RenderPass {
};
}

/// Should be called before `execute()`.
pub fn free_texture(&mut self, id: &egui::TextureId) {
self.textures.remove(id);
}
Expand Down Expand Up @@ -682,8 +705,7 @@ impl RenderPass {
let cbfn = if let Some(c) = callback.callback.downcast_ref::<CallbackFn>() {
c
} else {
// TODO: Should we warn in the console about this, or provide some other way to
// debug ignored paint callbacks?
tracing::warn!("Unknown paint callback: expected `egui_gpu::CallbackFn`");
continue;
};

Expand Down
10 changes: 7 additions & 3 deletions egui-wgpu/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ impl<'a> Painter<'a> {
for (id, image_delta) in &textures_delta.set {
rpass.update_texture(&render_state.device, &render_state.queue, *id, image_delta);
}
for id in &textures_delta.free {
rpass.free_texture(id);
}

rpass.update_buffers(
&render_state.device,
Expand All @@ -290,6 +287,13 @@ impl<'a> Painter<'a> {
}),
);

{
let mut rpass = render_state.egui_rpass.write();
for id in &textures_delta.free {
rpass.free_texture(id);
}
}

// Submit the commands.
render_state.queue.submit(std::iter::once(encoder.finish()));

Expand Down
4 changes: 2 additions & 2 deletions egui_demo_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ chrono = { version = "0.4", features = ["js-sys", "wasmbind"] }
eframe = { version = "0.18.0", path = "../eframe", default-features = false }
egui = { version = "0.18.0", path = "../egui", features = ["extra_debug_asserts"] }
egui_demo_lib = { version = "0.18.0", path = "../egui_demo_lib", features = ["chrono"] }
bytemuck = { version = "1.9.1", optional = true }
pollster = { version = "0.2.5", optional = true }

# Optional dependencies:

bytemuck = { version = "1.9.1", optional = true }
egui_extras = { version = "0.18.0", optional = true, path = "../egui_extras" }

# feature "http":
Expand All @@ -56,6 +55,7 @@ image = { version = "0.24", optional = true, default-features = false, features
"png",
] }
poll-promise = { version = "0.1", optional = true, default-features = false }
pollster = { version = "0.2.5", optional = true }

# feature "persistence":
serde = { version = "1", optional = true, features = ["derive"] }
Expand Down
13 changes: 12 additions & 1 deletion egui_glow/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ pub struct Painter {
destroyed: bool,
}

// TODO: Documentation
/// A callback function that can be used to compose an [`egui::PaintCallback`] for custom rendering
/// with [`glow`].
///
/// The callback is passed, the [`egui::PaintCallbackInfo`] and the [`Painter`] which can be used to
/// access the OpenGL context.
///
/// # Example
///
/// See the [custom3d_glow] demo source for a detailed usage example.
///
/// [custom3d_glow]:
/// https://github.com/emilk/egui/blob/master/egui_demo_app/src/apps/custom3d_wgpu.rs
pub struct CallbackFn {
f: Box<dyn Fn(PaintCallbackInfo, &Painter) + Sync + Send>,
}
Expand Down

0 comments on commit 7aee50b

Please sign in to comment.