2022-05-12 07:02:28 +00:00
|
|
|
//! This crates provides bindings between [`egui`](https://github.com/emilk/egui) and [wgpu](https://crates.io/crates/wgpu).
|
2022-06-09 13:27:22 +00:00
|
|
|
//!
|
|
|
|
//! ## Feature flags
|
2022-06-09 15:41:37 +00:00
|
|
|
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
|
2022-06-09 13:27:22 +00:00
|
|
|
//!
|
2022-05-12 07:02:28 +00:00
|
|
|
|
|
|
|
#![allow(unsafe_code)]
|
|
|
|
|
|
|
|
pub use wgpu;
|
|
|
|
|
|
|
|
/// Low-level painting of [`egui`] on [`wgpu`].
|
|
|
|
pub mod renderer;
|
2022-05-28 15:52:36 +00:00
|
|
|
pub use renderer::CallbackFn;
|
2022-09-07 12:20:21 +00:00
|
|
|
pub use renderer::Renderer;
|
2022-05-12 07:02:28 +00:00
|
|
|
|
|
|
|
/// Module for painting [`egui`] with [`wgpu`] on [`winit`].
|
|
|
|
#[cfg(feature = "winit")]
|
|
|
|
pub mod winit;
|
2022-08-02 15:26:33 +00:00
|
|
|
|
2022-10-05 18:14:18 +00:00
|
|
|
use egui::mutex::RwLock;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
/// Access to the render state for egui, which can be useful in combination with
|
|
|
|
/// [`egui::PaintCallback`]s for custom rendering using WGPU.
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct RenderState {
|
|
|
|
pub device: Arc<wgpu::Device>,
|
|
|
|
pub queue: Arc<wgpu::Queue>,
|
|
|
|
pub target_format: wgpu::TextureFormat,
|
|
|
|
pub renderer: Arc<RwLock<Renderer>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Find the framebuffer format that egui prefers
|
|
|
|
pub fn preferred_framebuffer_format(formats: &[wgpu::TextureFormat]) -> wgpu::TextureFormat {
|
|
|
|
for &format in formats {
|
|
|
|
if matches!(
|
|
|
|
format,
|
|
|
|
wgpu::TextureFormat::Rgba8Unorm | wgpu::TextureFormat::Bgra8Unorm
|
|
|
|
) {
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
formats[0] // take the first
|
|
|
|
}
|