pub struct WgpuRenderer { /* private fields */ }Expand description
Main WGPU renderer for Dear ImGui
This corresponds to the main renderer functionality in imgui_impl_wgpu.cpp
An initialized renderer owns the renderer state of exactly one Context. Create a separate
renderer for every Dear ImGui context. Call Self::shutdown with
the matching context when GPU resources must be released before Context teardown or before
that live Context can accept a replacement renderer. Dropping a bound renderer without that
call is safe but defers its renderer resources and consumer to Context teardown, so it does
not make the Context available for reuse. The retained context binding makes this renderer
UI-thread-bound.
Implementations§
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn renderer_consumer(&self) -> RendererResult<&SynchronousRendererConsumer>
pub fn renderer_consumer(&self) -> RendererResult<&SynchronousRendererConsumer>
Returns the synchronous consumer capability owned by this renderer.
Use it with Context::render when application code needs to reconcile a frame before
platform-window callbacks or other renderer-managed work.
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn new(
init_info: WgpuInitInfo,
imgui_ctx: &mut Context,
) -> RendererResult<Self>
pub fn new( init_info: WgpuInitInfo, imgui_ctx: &mut Context, ) -> RendererResult<Self>
Create a WGPU renderer bound to one Dear ImGui context (recommended)
This is the preferred way to create a WGPU renderer as it ensures proper initialization order and is consistent with other backends.
§Arguments
init_info- WGPU initialization information (device, queue, format)imgui_ctx- Dear ImGui context to configure
§Example
use dear_imgui_rs::Context;
use dear_imgui_wgpu::{WgpuRenderer, WgpuInitInfo, wgpu};
let init_info = WgpuInitInfo::new(device, queue, surface_format);
let mut renderer = WgpuRenderer::new(init_info, &mut imgui_context)?;Sourcepub fn set_gamma_mode(&mut self, mode: GammaMode)
pub fn set_gamma_mode(&mut self, mode: GammaMode)
Set gamma mode
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn invalidate_device_objects(
&mut self,
imgui_context: &mut Context,
) -> RendererResult<()>
pub fn invalidate_device_objects( &mut self, imgui_context: &mut Context, ) -> RendererResult<()>
Invalidate renderer-owned device objects and reset managed texture bindings.
This corresponds to ImGui_ImplWGPU_InvalidateDeviceObjects. Passing the context makes
destroying renderer-owned GPU textures and requeueing Context-owned uploads one operation.
Application-owned external texture handles remain registered; after device loss, replace
their views through Self::update_external_texture before drawing them again.
Sourcepub fn shutdown(&mut self, imgui_context: &mut Context) -> RendererResult<()>
pub fn shutdown(&mut self, imgui_context: &mut Context) -> RendererResult<()>
Shutdown the renderer and detach its Dear ImGui state.
This corresponds to ImGui_ImplWGPU_Shutdown in the C++ implementation.
The matching context is required so managed texture IDs, backend flags, the renderer name, and standard draw callbacks cannot outlive the GPU resources they describe. An initialized renderer consumed by a multi-viewport runtime is intentionally unavailable through this method until that owning runtime completes teardown.
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn render(
&mut self,
frame: PendingFrame<'_>,
render_pass: &mut RenderPass<'_>,
framebuffer_extent: FramebufferExtent,
) -> RendererResult<()>
pub fn render( &mut self, frame: PendingFrame<'_>, render_pass: &mut RenderPass<'_>, framebuffer_extent: FramebufferExtent, ) -> RendererResult<()>
Renders one Context-borrowed Dear ImGui frame into an explicit framebuffer extent.
Managed texture requests are reconciled before draw commands resolve renderer texture IDs. WGPU render passes do not expose their attachment dimensions, so callers must pass the physical width and height of the target being rendered.
Sourcepub fn render_reconciled(
&mut self,
frame: ReconciledFrame<'_>,
render_pass: &mut RenderPass<'_>,
framebuffer_extent: FramebufferExtent,
) -> RendererResult<()>
pub fn render_reconciled( &mut self, frame: ReconciledFrame<'_>, render_pass: &mut RenderPass<'_>, framebuffer_extent: FramebufferExtent, ) -> RendererResult<()>
Renders an already reconciled frame into an explicit framebuffer extent.
Recording consumes the reconciled capability. Command submission and presentation remain the application’s responsibility.
Sourcepub fn reconcile_frame<'frame>(
&mut self,
frame: PendingFrame<'frame>,
) -> RendererResult<ReconciledFrame<'frame>>
pub fn reconcile_frame<'frame>( &mut self, frame: PendingFrame<'frame>, ) -> RendererResult<ReconciledFrame<'frame>>
Applies managed-texture requests without drawing or acquiring a surface.
Callback capability is checked before texture reconciliation, so an unsupported callback-bearing frame is not consumed partially.
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn register_external_texture(
&mut self,
view: &TextureView,
) -> RendererResult<ExternalTextureId>
pub fn register_external_texture( &mut self, view: &TextureView, ) -> RendererResult<ExternalTextureId>
Registers an application-owned WGPU texture view for Dear ImGui rendering.
The renderer clones the view handle. The application retains ownership of the texture contents and must not explicitly destroy the underlying GPU resource while it is registered.
Sourcepub fn update_external_texture(
&mut self,
texture: ExternalTextureId,
view: &TextureView,
) -> RendererResult<()>
pub fn update_external_texture( &mut self, texture: ExternalTextureId, view: &TextureView, ) -> RendererResult<()>
Replaces the WGPU view associated with an external texture handle.
Stale handles, handles from another renderer, and already-unregistered handles are rejected without changing renderer state.
Sourcepub fn unregister_external_texture(
&mut self,
texture: ExternalTextureId,
) -> RendererResult<()>
pub fn unregister_external_texture( &mut self, texture: ExternalTextureId, ) -> RendererResult<()>
Unregisters an application-owned external texture view.
The underlying WGPU texture remains application-owned and is not destroyed by this call.