1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Wrap tesselated output in struct ClippedMesh(Rect, Mesh)

This commit is contained in:
Emil Ernerfeldt
2021-01-25 21:43:17 +01:00
parent 75fa77e040
commit b493bc6efc
16 changed files with 89 additions and 71 deletions

View File

@@ -42,30 +42,30 @@ impl WebBackend {
self.ctx.begin_frame(raw_input)
}
pub fn end_frame(&mut self) -> Result<(egui::Output, egui::PaintJobs), JsValue> {
pub fn end_frame(&mut self) -> Result<(egui::Output, Vec<egui::ClippedMesh>), JsValue> {
let frame_start = self
.frame_start
.take()
.expect("unmatched calls to begin_frame/end_frame");
let (output, shapes) = self.ctx.end_frame();
let paint_jobs = self.ctx.tessellate(shapes);
let clipped_meshes = self.ctx.tessellate(shapes);
let now = now_sec();
self.previous_frame_time = Some((now - frame_start) as f32);
Ok((output, paint_jobs))
Ok((output, clipped_meshes))
}
pub fn paint(
&mut self,
clear_color: egui::Rgba,
paint_jobs: egui::PaintJobs,
clipped_meshes: Vec<egui::ClippedMesh>,
) -> Result<(), JsValue> {
self.painter.upload_egui_texture(&self.ctx.texture());
self.painter.clear(clear_color);
self.painter
.paint_meshes(paint_jobs, self.ctx.pixels_per_point())
.paint_meshes(clipped_meshes, self.ctx.pixels_per_point())
}
pub fn painter_debug_info(&self) -> String {
@@ -190,7 +190,7 @@ impl AppRunner {
Ok(())
}
pub fn logic(&mut self) -> Result<(egui::Output, egui::PaintJobs), JsValue> {
pub fn logic(&mut self) -> Result<(egui::Output, Vec<egui::ClippedMesh>), JsValue> {
resize_canvas_to_screen_size(self.web_backend.canvas_id());
let canvas_size = canvas_size_in_points(self.web_backend.canvas_id());
let raw_input = self.input.new_frame(canvas_size);
@@ -216,7 +216,7 @@ impl AppRunner {
let egui_ctx = &self.web_backend.ctx;
self.app.update(egui_ctx, &mut frame);
let (egui_output, paint_jobs) = self.web_backend.end_frame()?;
let (egui_output, clipped_meshes) = self.web_backend.end_frame()?;
handle_output(&egui_output);
{
@@ -227,11 +227,12 @@ impl AppRunner {
} = app_output;
}
Ok((egui_output, paint_jobs))
Ok((egui_output, clipped_meshes))
}
pub fn paint(&mut self, paint_jobs: egui::PaintJobs) -> Result<(), JsValue> {
self.web_backend.paint(self.app.clear_color(), paint_jobs)
pub fn paint(&mut self, clipped_meshes: Vec<egui::ClippedMesh>) -> Result<(), JsValue> {
self.web_backend
.paint(self.app.clear_color(), clipped_meshes)
}
}

View File

@@ -405,8 +405,8 @@ fn paint_and_schedule(runner_ref: AppRunnerRef) -> Result<(), JsValue> {
fn paint_if_needed(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
let mut runner_lock = runner_ref.0.lock();
if runner_lock.needs_repaint.fetch_and_clear() {
let (output, paint_jobs) = runner_lock.logic()?;
runner_lock.paint(paint_jobs)?;
let (output, clipped_meshes) = runner_lock.logic()?;
runner_lock.paint(clipped_meshes)?;
if output.needs_repaint {
runner_lock.needs_repaint.set_true();
}

View File

@@ -10,8 +10,11 @@ pub trait Painter {
fn upload_egui_texture(&mut self, texture: &egui::Texture);
fn clear(&mut self, lear_color: egui::Rgba);
fn clear(&mut self, clear_color: egui::Rgba);
fn paint_meshes(&mut self, jobs: egui::PaintJobs, pixels_per_point: f32)
-> Result<(), JsValue>;
fn paint_meshes(
&mut self,
clipped_meshes: Vec<egui::ClippedMesh>,
pixels_per_point: f32,
) -> Result<(), JsValue>;
}

View File

@@ -6,7 +6,7 @@ use {
use egui::{
math::clamp,
paint::{Color32, Mesh, PaintJobs, Texture},
paint::{Color32, Mesh, Texture},
vec2,
};
@@ -478,7 +478,11 @@ impl crate::Painter for WebGlPainter {
gl.clear(Gl::COLOR_BUFFER_BIT);
}
fn paint_meshes(&mut self, jobs: PaintJobs, pixels_per_point: f32) -> Result<(), JsValue> {
fn paint_meshes(
&mut self,
clipped_meshes: Vec<egui::ClippedMesh>,
pixels_per_point: f32,
) -> Result<(), JsValue> {
self.upload_user_textures();
let gl = &self.gl;
@@ -504,7 +508,7 @@ impl crate::Painter for WebGlPainter {
let u_sampler_loc = gl.get_uniform_location(&self.program, "u_sampler").unwrap();
gl.uniform1i(Some(&u_sampler_loc), 0);
for (clip_rect, mesh) in jobs {
for egui::ClippedMesh(clip_rect, mesh) in clipped_meshes {
if let Some(gl_texture) = self.get_texture(mesh.texture_id) {
gl.bind_texture(Gl::TEXTURE_2D, Some(gl_texture));

View File

@@ -8,7 +8,7 @@ use {
use egui::{
math::clamp,
paint::{Color32, Mesh, PaintJobs, Texture},
paint::{Color32, Mesh, Texture},
vec2,
};
@@ -467,7 +467,11 @@ impl crate::Painter for WebGl2Painter {
gl.clear(Gl::COLOR_BUFFER_BIT);
}
fn paint_meshes(&mut self, jobs: PaintJobs, pixels_per_point: f32) -> Result<(), JsValue> {
fn paint_meshes(
&mut self,
clipped_meshes: Vec<egui::ClippedMesh>,
pixels_per_point: f32,
) -> Result<(), JsValue> {
self.upload_user_textures();
let gl = &self.gl;
@@ -493,7 +497,7 @@ impl crate::Painter for WebGl2Painter {
let u_sampler_loc = gl.get_uniform_location(&self.program, "u_sampler").unwrap();
gl.uniform1i(Some(&u_sampler_loc), 0);
for (clip_rect, mesh) in jobs {
for egui::ClippedMesh(clip_rect, mesh) in clipped_meshes {
if let Some(gl_texture) = self.get_texture(mesh.texture_id) {
gl.bind_texture(Gl::TEXTURE_2D, Some(gl_texture));