mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 21:00:03 -04:00
Add glow::Context to epi::Frame (#1425)
This can be used, for instance, to: * Render things to offscreen buffers. * Read the pixel buffer from the previous frame (glow::Context::read_pixels). * Render things behind the egui windows.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use crate::*;
|
||||
use egui_winit::winit;
|
||||
|
||||
struct RequestRepaintEvent;
|
||||
@@ -50,6 +49,7 @@ pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi
|
||||
|
||||
let mut integration = egui_winit::epi::EpiIntegration::new(
|
||||
"egui_glow",
|
||||
gl.clone(),
|
||||
painter.max_texture_side(),
|
||||
gl_window.window(),
|
||||
storage,
|
||||
@@ -86,6 +86,10 @@ pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
|
||||
let screen_size_in_pixels: [u32; 2] = gl_window.window().inner_size().into();
|
||||
|
||||
crate::painter::clear(&gl, screen_size_in_pixels, app.clear_color());
|
||||
|
||||
let egui::FullOutput {
|
||||
platform_output,
|
||||
needs_repaint,
|
||||
@@ -97,24 +101,14 @@ pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi
|
||||
|
||||
let clipped_primitives = integration.egui_ctx.tessellate(shapes);
|
||||
|
||||
// paint:
|
||||
{
|
||||
let color = app.clear_color();
|
||||
unsafe {
|
||||
use glow::HasContext as _;
|
||||
gl.disable(glow::SCISSOR_TEST);
|
||||
gl.clear_color(color[0], color[1], color[2], color[3]);
|
||||
gl.clear(glow::COLOR_BUFFER_BIT);
|
||||
}
|
||||
painter.paint_and_update_textures(
|
||||
gl_window.window().inner_size().into(),
|
||||
integration.egui_ctx.pixels_per_point(),
|
||||
&clipped_primitives,
|
||||
&textures_delta,
|
||||
);
|
||||
painter.paint_and_update_textures(
|
||||
screen_size_in_pixels,
|
||||
integration.egui_ctx.pixels_per_point(),
|
||||
&clipped_primitives,
|
||||
&textures_delta,
|
||||
);
|
||||
|
||||
gl_window.swap_buffers().unwrap();
|
||||
}
|
||||
gl_window.swap_buffers().unwrap();
|
||||
|
||||
{
|
||||
*control_flow = if integration.should_quit() {
|
||||
|
||||
@@ -627,11 +627,16 @@ impl Painter {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear(gl: &glow::Context, dimension: [u32; 2], clear_color: egui::Rgba) {
|
||||
pub fn clear(gl: &glow::Context, screen_size_in_pixels: [u32; 2], clear_color: egui::Rgba) {
|
||||
unsafe {
|
||||
gl.disable(glow::SCISSOR_TEST);
|
||||
|
||||
gl.viewport(0, 0, dimension[0] as i32, dimension[1] as i32);
|
||||
gl.viewport(
|
||||
0,
|
||||
0,
|
||||
screen_size_in_pixels[0] as i32,
|
||||
screen_size_in_pixels[1] as i32,
|
||||
);
|
||||
|
||||
let clear_color: Color32 = clear_color.into();
|
||||
gl.clear_color(
|
||||
|
||||
Reference in New Issue
Block a user