Skip to main content

WgpuRenderer

Struct WgpuRenderer 

Source
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

Source

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

Source

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)?;
Source

pub fn set_gamma_mode(&mut self, mode: GammaMode)

Set gamma mode

Source§

impl WgpuRenderer

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for WgpuRenderer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>