Skip to content

Commit

Permalink
Expose egui WGPU Textures and Limit Exposed API
Browse files Browse the repository at this point in the history
This allows paint callbacks to access textures allocated by egui, and
also hides the functions on the `RenderPass` that users should not need
to call.
  • Loading branch information
zicklag committed Jun 2, 2022
1 parent e2bfdbe commit 2d009c5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions egui-wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl RenderPass {
/// Creates a new render pass to render a egui UI.
///
/// If the format passed is not a *Srgb format, the shader will automatically convert to `sRGB` colors in the shader.
pub fn new(
pub(crate) fn new(
device: &wgpu::Device,
output_format: wgpu::TextureFormat,
msaa_samples: u32,
Expand Down Expand Up @@ -292,7 +292,7 @@ impl RenderPass {
}

/// Executes the egui render pass.
pub fn execute(
pub(crate) fn execute(
&self,
encoder: &mut wgpu::CommandEncoder,
color_attachment: &wgpu::TextureView,
Expand Down Expand Up @@ -326,7 +326,7 @@ impl RenderPass {
}

/// Executes the egui render pass onto an existing wgpu renderpass.
pub fn execute_with_renderpass<'rpass>(
pub(crate) fn execute_with_renderpass<'rpass>(
&'rpass self,
rpass: &mut wgpu::RenderPass<'rpass>,
paint_jobs: &[egui::epaint::ClippedPrimitive],
Expand Down Expand Up @@ -452,7 +452,7 @@ impl RenderPass {
}

/// Should be called before `execute()`.
pub fn update_texture(
pub(crate) fn update_texture(
&mut self,
device: &wgpu::Device,
queue: &wgpu::Queue,
Expand Down Expand Up @@ -564,10 +564,22 @@ impl RenderPass {
};
}

pub fn free_texture(&mut self, id: &egui::TextureId) {
pub(crate) fn free_texture(&mut self, id: &egui::TextureId) {
self.textures.remove(id);
}

/// Get the WGPU texture and bind group associated to a texture that has been allocated by egui.
///
/// This could be used by custom paint hooks to render images that have been added through with
/// [`egui_extras::RetainedImage`](https://docs.rs/egui_extras/latest/egui_extras/image/struct.RetainedImage.html)
/// or [`egui::Context::load_texture`].
pub fn get_texture(
&self,
id: &egui::TextureId,
) -> Option<&(Option<wgpu::Texture>, wgpu::BindGroup)> {
self.textures.get(id)
}

/// Registers a `wgpu::Texture` with a `egui::TextureId`.
///
/// This enables the application to reference the texture inside an image ui element.
Expand Down Expand Up @@ -649,7 +661,7 @@ impl RenderPass {

/// Uploads the uniform, vertex and index data used by the render pass.
/// Should be called before `execute()`.
pub fn update_buffers(
pub(crate) fn update_buffers(
&mut self,
device: &wgpu::Device,
queue: &wgpu::Queue,
Expand Down

0 comments on commit 2d009c5

Please sign in to comment.