Add glow::Painter::intermediate_fbo()

This allow callbacks to restore to the correct framebuffer
after using their own temporary FBO.

See discussion in https://github.com/emilk/egui/issues/1744
This commit is contained in:
Emil Ernerfeldt 2022-08-03 09:38:46 +02:00
parent 53249d36df
commit a827c3e033
3 changed files with 19 additions and 0 deletions

View file

@ -7,6 +7,7 @@ All notable changes to the `egui_glow` integration will be noted in this file.
* `EguiGlow::new` now takes an `EventLoopWindowTarget<E>` instead of a `winit::Window` ([#1634](https://github.com/emilk/egui/pull/1634)).
* Use `Arc` for `glow::Context` instead of `Rc` ([#1640](https://github.com/emilk/egui/pull/1640)).
* Fixed `glClear` on WebGL1 ([#1658](https://github.com/emilk/egui/pull/1658)).
* Add `Painter::intermediate_fbo` which tells callbacks where to render. This is only needed if the callbacks use their own FBO:s and need to know what to restore to.
## 0.18.1 - 2022-05-05

View file

@ -248,6 +248,19 @@ impl Painter {
self.max_texture_side
}
/// The framebuffer we use as an intermediate render target,
/// or `None` if we are painting to the screen framebuffer directly.
///
/// This is the framebuffer that is bound when [`egui::Shape::Callback`] is called,
/// and is where any callbacks should ultimately render onto.
///
/// So if in a [`egui::Shape::Callback`] you need to use an offscreen FBO, you should
/// then restore to this afterwards with
/// `gl.bind_framebuffer(glow::FRAMEBUFFER, painter.intermediate_fbo());`
pub fn intermediate_fbo(&self) -> Option<glow::Framebuffer> {
self.post_process.as_ref().map(|pp| pp.fbo())
}
unsafe fn prepare_painting(
&mut self,
[width_in_pixels, height_in_pixels]: [u32; 2],

View file

@ -176,6 +176,11 @@ impl PostProcess {
})
}
/// What we render to.
pub(crate) fn fbo(&self) -> glow::Framebuffer {
self.fbo
}
pub(crate) unsafe fn begin(&mut self, width: i32, height: i32) {
if (width, height) != self.texture_size {
self.gl