Skip to content

Commit 34f4d8d

Browse files
committed
egui-wgpu renderer renaming
- `RenderPass` -> `Renderer` - `RenderPass::execute` -> `Renderer::render` - `RenderPass::execute_with_renderpass` -> `Renderer::render_onto_renderpass` - reexport `Renderer` in `lib.rs`
1 parent 0e62c0e commit 34f4d8d

File tree

5 files changed

+61
-55
lines changed

5 files changed

+61
-55
lines changed

crates/egui-wgpu/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to the `egui-wgpu` integration will be noted in this file.
33

44

55
## Unreleased
6+
* Rename `RenderPass` to `Renderer`
7+
* Rename `RenderPass::execute` to `RenderPass::render`
8+
* Rename `RenderPass::execute_with_renderpass` to `Renderer::render_onto_renderpass`
9+
* Reexport `Renderer`
610

711

812
## 0.19.0 - 2022-08-20

crates/egui-wgpu/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub use wgpu;
1111
/// Low-level painting of [`egui`] on [`wgpu`].
1212
pub mod renderer;
1313
pub use renderer::CallbackFn;
14+
pub use renderer::Renderer;
1415

1516
/// Module for painting [`egui`] with [`wgpu`] on [`winit`].
1617
#[cfg(feature = "winit")]

crates/egui-wgpu/src/renderer.rs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ struct SizedBuffer {
118118
size: usize,
119119
}
120120

121-
/// Render pass to render a egui based GUI.
122-
pub struct RenderPass {
123-
render_pipeline: wgpu::RenderPipeline,
121+
/// Renderer for a egui based GUI.
122+
pub struct Renderer {
123+
pipeline: wgpu::RenderPipeline,
124124
depth_texture: Option<(wgpu::Texture, wgpu::TextureView)>,
125125
index_buffers: Vec<SizedBuffer>,
126126
vertex_buffers: Vec<SizedBuffer>,
@@ -137,8 +137,8 @@ pub struct RenderPass {
137137
pub paint_callback_resources: TypeMap,
138138
}
139139

140-
impl RenderPass {
141-
/// Creates a new render pass to render a egui UI.
140+
impl Renderer {
141+
/// Creates a renderer for a egui UI.
142142
///
143143
/// If the format passed is not a *Srgb format, the shader will automatically convert to `sRGB` colors in the shader.
144144
pub fn new(
@@ -231,7 +231,7 @@ impl RenderPass {
231231
bias: wgpu::DepthBiasState::default(),
232232
});
233233

234-
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
234+
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
235235
label: Some("egui_pipeline"),
236236
layout: Some(&pipeline_layout),
237237
vertex: wgpu::VertexState {
@@ -290,7 +290,7 @@ impl RenderPass {
290290
});
291291

292292
Self {
293-
render_pipeline,
293+
pipeline,
294294
vertex_buffers: Vec::with_capacity(64),
295295
index_buffers: Vec::with_capacity(64),
296296
uniform_buffer,
@@ -323,8 +323,8 @@ impl RenderPass {
323323
self.depth_texture = Some((texture, view));
324324
}
325325

326-
/// Executes the egui render pass.
327-
pub fn execute(
326+
/// Executes the renderer on it's own render pass.
327+
pub fn render(
328328
&self,
329329
encoder: &mut wgpu::CommandEncoder,
330330
color_attachment: &wgpu::TextureView,
@@ -349,7 +349,7 @@ impl RenderPass {
349349
}
350350
});
351351

352-
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
352+
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
353353
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
354354
view: color_attachment,
355355
resolve_target: None,
@@ -359,26 +359,23 @@ impl RenderPass {
359359
},
360360
})],
361361
depth_stencil_attachment,
362-
label: Some("egui main render pass"),
362+
label: Some("egui_render_pass"),
363363
});
364-
rpass.push_debug_group("egui_pass");
365364

366-
self.execute_with_renderpass(&mut rpass, paint_jobs, screen_descriptor);
367-
368-
rpass.pop_debug_group();
365+
self.render_onto_renderpass(&mut render_pass, paint_jobs, screen_descriptor);
369366
}
370367

371-
/// Executes the egui render pass onto an existing wgpu renderpass.
372-
pub fn execute_with_renderpass<'rpass>(
373-
&'rpass self,
374-
rpass: &mut wgpu::RenderPass<'rpass>,
368+
/// Executes the egui renderer onto an existing wgpu renderpass.
369+
pub fn render_onto_renderpass<'rp>(
370+
&'rp self,
371+
render_pass: &mut wgpu::RenderPass<'rp>,
375372
paint_jobs: &[egui::epaint::ClippedPrimitive],
376373
screen_descriptor: &ScreenDescriptor,
377374
) {
378375
let pixels_per_point = screen_descriptor.pixels_per_point;
379376
let size_in_pixels = screen_descriptor.size_in_pixels;
380377

381-
// Whether or not we need to reset the renderpass state because a paint callback has just
378+
// Whether or not we need to reset the render pass because a paint callback has just
382379
// run.
383380
let mut needs_reset = true;
384381

@@ -391,16 +388,16 @@ impl RenderPass {
391388
} in paint_jobs
392389
{
393390
if needs_reset {
394-
rpass.set_viewport(
391+
render_pass.set_viewport(
395392
0.0,
396393
0.0,
397394
size_in_pixels[0] as f32,
398395
size_in_pixels[1] as f32,
399396
0.0,
400397
1.0,
401398
);
402-
rpass.set_pipeline(&self.render_pipeline);
403-
rpass.set_bind_group(0, &self.uniform_bind_group, &[]);
399+
render_pass.set_pipeline(&self.pipeline);
400+
render_pass.set_bind_group(0, &self.uniform_bind_group, &[]);
404401
needs_reset = false;
405402
}
406403

@@ -417,7 +414,7 @@ impl RenderPass {
417414
continue;
418415
}
419416

420-
rpass.set_scissor_rect(rect.x, rect.y, rect.width, rect.height);
417+
render_pass.set_scissor_rect(rect.x, rect.y, rect.width, rect.height);
421418
}
422419

423420
match primitive {
@@ -426,13 +423,13 @@ impl RenderPass {
426423
let vertex_buffer = vertex_buffers.next().unwrap();
427424

428425
if let Some((_texture, bind_group)) = self.textures.get(&mesh.texture_id) {
429-
rpass.set_bind_group(1, bind_group, &[]);
430-
rpass.set_index_buffer(
426+
render_pass.set_bind_group(1, bind_group, &[]);
427+
render_pass.set_index_buffer(
431428
index_buffer.buffer.slice(..),
432429
wgpu::IndexFormat::Uint32,
433430
);
434-
rpass.set_vertex_buffer(0, vertex_buffer.buffer.slice(..));
435-
rpass.draw_indexed(0..mesh.indices.len() as u32, 0, 0..1);
431+
render_pass.set_vertex_buffer(0, vertex_buffer.buffer.slice(..));
432+
render_pass.draw_indexed(0..mesh.indices.len() as u32, 0, 0..1);
436433
} else {
437434
tracing::warn!("Missing texture: {:?}", mesh.texture_id);
438435
}
@@ -461,7 +458,7 @@ impl RenderPass {
461458
let rect_max_x = rect_max_x.round();
462459
let rect_max_y = rect_max_y.round();
463460

464-
rpass.set_viewport(
461+
render_pass.set_viewport(
465462
rect_min_x,
466463
rect_min_y,
467464
rect_max_x - rect_min_x,
@@ -478,18 +475,18 @@ impl RenderPass {
478475
pixels_per_point,
479476
screen_size_px: size_in_pixels,
480477
},
481-
rpass,
478+
render_pass,
482479
&self.paint_callback_resources,
483480
);
484481
}
485482
}
486483
}
487484
}
488485

489-
rpass.set_scissor_rect(0, 0, size_in_pixels[0], size_in_pixels[1]);
486+
render_pass.set_scissor_rect(0, 0, size_in_pixels[0], size_in_pixels[1]);
490487
}
491488

492-
/// Should be called before `execute()`.
489+
/// Should be called before `render()`.
493490
pub fn update_texture(
494491
&mut self,
495492
device: &wgpu::Device,
@@ -768,8 +765,8 @@ impl RenderPass {
768765
*user_texture_binding = bind_group;
769766
}
770767

771-
/// Uploads the uniform, vertex and index data used by the render pass.
772-
/// Should be called before `execute()`.
768+
/// Uploads the uniform, vertex and index data used by the renderer.
769+
/// Should be called before `render()`.
773770
pub fn update_buffers(
774771
&mut self,
775772
device: &wgpu::Device,
@@ -922,7 +919,7 @@ impl ScissorRect {
922919
}
923920

924921
#[test]
925-
fn render_pass_impl_send_sync() {
922+
fn renderer_impl_send_sync() {
926923
fn assert_send_sync<T: Send + Sync>() {}
927-
assert_send_sync::<RenderPass>();
924+
assert_send_sync::<Renderer>();
928925
}

crates/egui-wgpu/src/winit.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use egui::mutex::RwLock;
44
use tracing::error;
55
use wgpu::{Adapter, Instance, Surface};
66

7-
use crate::renderer;
7+
use crate::{renderer, Renderer};
88

99
/// Access to the render state for egui, which can be useful in combination with
1010
/// [`egui::PaintCallback`]s for custom rendering using WGPU.
@@ -13,7 +13,7 @@ pub struct RenderState {
1313
pub device: Arc<wgpu::Device>,
1414
pub queue: Arc<wgpu::Queue>,
1515
pub target_format: wgpu::TextureFormat,
16-
pub egui_rpass: Arc<RwLock<renderer::RenderPass>>,
16+
pub renderer: Arc<RwLock<Renderer>>,
1717
}
1818

1919
struct SurfaceState {
@@ -90,14 +90,13 @@ impl<'a> Painter<'a> {
9090
let (device, queue) =
9191
pollster::block_on(adapter.request_device(&self.device_descriptor, None)).unwrap();
9292

93-
let rpass =
94-
renderer::RenderPass::new(&device, target_format, self.msaa_samples, self.depth_bits);
93+
let renderer = Renderer::new(&device, target_format, self.msaa_samples, self.depth_bits);
9594

9695
RenderState {
9796
device: Arc::new(device),
9897
queue: Arc::new(queue),
9998
target_format,
100-
egui_rpass: Arc::new(RwLock::new(rpass)),
99+
renderer: Arc::new(RwLock::new(renderer)),
101100
}
102101
}
103102

@@ -151,7 +150,7 @@ impl<'a> Painter<'a> {
151150
surface_state.height = height_in_pixels;
152151

153152
if self.depth_bits > 0 {
154-
render_state.egui_rpass.write().update_depth_texture(
153+
render_state.renderer.write().update_depth_texture(
155154
&render_state.device,
156155
width_in_pixels,
157156
height_in_pixels,
@@ -272,12 +271,17 @@ impl<'a> Painter<'a> {
272271
};
273272

274273
{
275-
let mut rpass = render_state.egui_rpass.write();
274+
let mut renderer = render_state.renderer.write();
276275
for (id, image_delta) in &textures_delta.set {
277-
rpass.update_texture(&render_state.device, &render_state.queue, *id, image_delta);
276+
renderer.update_texture(
277+
&render_state.device,
278+
&render_state.queue,
279+
*id,
280+
image_delta,
281+
);
278282
}
279283

280-
rpass.update_buffers(
284+
renderer.update_buffers(
281285
&render_state.device,
282286
&render_state.queue,
283287
clipped_primitives,
@@ -286,7 +290,7 @@ impl<'a> Painter<'a> {
286290
}
287291

288292
// Record all render passes.
289-
render_state.egui_rpass.read().execute(
293+
render_state.renderer.read().render(
290294
&mut encoder,
291295
&output_view,
292296
clipped_primitives,
@@ -300,9 +304,9 @@ impl<'a> Painter<'a> {
300304
);
301305

302306
{
303-
let mut rpass = render_state.egui_rpass.write();
307+
let mut renderer = render_state.renderer.write();
304308
for id in &textures_delta.free {
305-
rpass.free_texture(id);
309+
renderer.free_texture(id);
306310
}
307311
}
308312

crates/egui_demo_app/src/apps/custom3d_wgpu.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Custom3d {
8282
// instead of storing the pipeline in our `Custom3D` struct, we insert it into the
8383
// `paint_callback_resources` type map, which is stored alongside the render pass.
8484
wgpu_render_state
85-
.egui_rpass
85+
.renderer
8686
.write()
8787
.paint_callback_resources
8888
.insert(TriangleRenderResources {
@@ -142,9 +142,9 @@ impl Custom3d {
142142
let resources: &TriangleRenderResources = paint_callback_resources.get().unwrap();
143143
resources.prepare(device, queue, angle);
144144
})
145-
.paint(move |_info, rpass, paint_callback_resources| {
145+
.paint(move |_info, render_pass, paint_callback_resources| {
146146
let resources: &TriangleRenderResources = paint_callback_resources.get().unwrap();
147-
resources.paint(rpass);
147+
resources.paint(render_pass);
148148
});
149149

150150
let callback = egui::PaintCallback {
@@ -168,10 +168,10 @@ impl TriangleRenderResources {
168168
queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[angle]));
169169
}
170170

171-
fn paint<'rpass>(&'rpass self, rpass: &mut wgpu::RenderPass<'rpass>) {
171+
fn paint<'rp>(&'rp self, render_pass: &mut wgpu::RenderPass<'rp>) {
172172
// Draw our triangle!
173-
rpass.set_pipeline(&self.pipeline);
174-
rpass.set_bind_group(0, &self.bind_group, &[]);
175-
rpass.draw(0..3, 0..1);
173+
render_pass.set_pipeline(&self.pipeline);
174+
render_pass.set_bind_group(0, &self.bind_group, &[]);
175+
render_pass.draw(0..3, 0..1);
176176
}
177177
}

0 commit comments

Comments
 (0)