use std::time::Duration;
pub use egui;
pub use crate::render_benchmark::SampledRectModulatedWorkload;
pub use crate::renderer::{RenderFrame, RenderOutcome, RenderTimings, TextureEvidence};
use crate::texture::TextureId;
#[must_use]
pub const fn egui_texture_id(texture: TextureId) -> egui::TextureId {
texture.to_egui()
}
const _: () = {
use std::mem::{align_of, offset_of, size_of};
use egui::epaint::Vertex as EguiVertex;
use crate::{Color, Vertex};
assert!(size_of::<EguiVertex>() == size_of::<Vertex>());
assert!(align_of::<Vertex>() <= align_of::<EguiVertex>());
assert!(offset_of!(EguiVertex, pos) == offset_of!(Vertex, pos));
assert!(offset_of!(EguiVertex, uv) == offset_of!(Vertex, uv));
assert!(offset_of!(EguiVertex, color) == offset_of!(Vertex, color));
assert!(size_of::<egui::Pos2>() == size_of::<[f32; 2]>());
assert!(offset_of!(egui::Pos2, x) == 0 && offset_of!(egui::Pos2, y) == size_of::<f32>());
assert!(size_of::<egui::Color32>() == size_of::<Color>());
assert!(offset_of!(Color, r) == 0 && offset_of!(Color, g) == 1);
assert!(offset_of!(Color, b) == 2 && offset_of!(Color, a) == 3);
let bytes = unsafe {
std::mem::transmute::<egui::Color32, [u8; 4]>(egui::Color32::from_rgba_premultiplied(
1, 2, 3, 4,
))
};
assert!(bytes[0] == 1 && bytes[1] == 2 && bytes[2] == 3 && bytes[3] == 4);
};
pub(crate) const fn vertices_from_egui(vertices: &[egui::epaint::Vertex]) -> &[crate::Vertex] {
unsafe { std::slice::from_raw_parts(vertices.as_ptr().cast::<crate::Vertex>(), vertices.len()) }
}
pub(crate) fn raster_mesh_from_egui(mesh: &egui::Mesh) -> crate::geometry::RasterMesh<'_> {
crate::geometry::RasterMesh {
vertices: vertices_from_egui(&mesh.vertices),
indices: &mesh.indices,
}
}
#[must_use]
pub fn format_repaint_delay(repaint_delay: Duration) -> String {
if repaint_delay == Duration::MAX {
"none".to_owned()
} else {
format!("{repaint_delay:?}")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn format_repaint_delay_names_missing_repaint() {
assert_eq!(format_repaint_delay(Duration::MAX), "none");
assert_eq!(format_repaint_delay(Duration::from_millis(16)), "16ms");
}
}