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

Implementations§

Source§

impl WgpuRenderer

Source

pub fn register_external_texture( &mut self, texture: &Texture, view: &TextureView, ) -> u64

Register an external WGPU texture + view and obtain a TextureId for ImGui usage.

Use this when you already have a wgpu::Texture (e.g., game view RT, video frame, atlas upload) and want to display it via legacy TextureId path: ui.image(TextureId::from(id), size).

Source

pub fn register_external_texture_with_sampler( &mut self, texture: &Texture, view: &TextureView, sampler: &Sampler, ) -> u64

Register an external WGPU texture + view with a custom sampler.

This lets you control sampling (e.g. nearest vs linear) per external texture. The sampler must be a filtering sampler compatible with the ImGui pipeline.

Source

pub fn update_external_texture_view( &mut self, texture_id: u64, view: &TextureView, ) -> bool

Update the view for an already-registered external texture.

Returns true if the texture existed and the view was replaced.

Source

pub fn update_external_texture_sampler( &mut self, texture_id: u64, sampler: &Sampler, ) -> bool

Update (or set) a custom sampler for an already-registered external texture.

Returns false if the texture_id is not registered.

Source

pub fn unregister_texture(&mut self, texture_id: u64)

Unregister (remove) a texture by id. Safe for both external and managed textures.

Source§

impl WgpuRenderer

Source

pub fn new( init_info: WgpuInitInfo, imgui_ctx: &mut Context, ) -> RendererResult<Self>

Create a new WGPU renderer with full initialization (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};

let init_info = WgpuInitInfo::new(device, queue, surface_format);
let mut renderer = WgpuRenderer::new(init_info, &mut imgui_context)?;
Source

pub fn empty() -> Self

Create an empty WGPU renderer for advanced usage

This creates an uninitialized renderer that must be initialized later using init_with_context(). Most users should use new() instead.

§Example
use dear_imgui_rs::Context;
use dear_imgui_wgpu::{WgpuRenderer, WgpuInitInfo};

let mut renderer = WgpuRenderer::empty();
let init_info = WgpuInitInfo::new(device, queue, surface_format);
renderer.init_with_context(init_info, &mut imgui_context)?;
Source

pub fn init(&mut self, init_info: WgpuInitInfo) -> RendererResult<()>

Initialize the renderer

This corresponds to ImGui_ImplWGPU_Init in the C++ implementation

Source

pub fn new_without_font_atlas( init_info: WgpuInitInfo, imgui_ctx: &mut Context, ) -> RendererResult<Self>

Initialize the renderer with ImGui context configuration (without font atlas for WASM)

This is a variant of init_with_context that skips font atlas preparation, useful for WASM builds where font atlas memory sharing is problematic.

Source

pub fn init_with_context( &mut self, init_info: WgpuInitInfo, imgui_ctx: &mut Context, ) -> RendererResult<()>

Initialize the renderer with ImGui context configuration

This is a convenience method that combines init() and configure_imgui_context() to ensure proper initialization order, similar to the glow backend approach.

Source

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

Set gamma mode

Source

pub fn configure_imgui_context(&self, imgui_context: &mut Context)

Configure Dear ImGui context with WGPU backend capabilities

Source

pub fn prepare_font_atlas( &mut self, imgui_ctx: &mut Context, ) -> RendererResult<()>

Prepare font atlas for rendering

Source

pub fn texture_manager(&self) -> &WgpuTextureManager

Load font texture from Dear ImGui context

With the new texture management system in Dear ImGui 1.92+, font textures are automatically managed through ImDrawData->Textures[] during rendering. However, we need to ensure the font atlas is built and ready before the first render. Legacy/fallback path: upload font atlas texture immediately and assign TexID. Returns Some(tex_id) on success, None if texdata is unavailable. Get the texture manager

Source

pub fn texture_manager_mut(&mut self) -> &mut WgpuTextureManager

Get the texture manager mutably

Source

pub fn is_initialized(&self) -> bool

Check if the renderer is initialized

Source

pub fn update_texture( &mut self, texture_data: &TextureData, ) -> RendererResult<TextureUpdateResult>

Update a single texture manually

This corresponds to ImGui_ImplWGPU_UpdateTexture in the C++ implementation. Use this when you need precise control over texture update timing.

§Returns

Returns a TextureUpdateResult that contains any status/ID updates that need to be applied to the texture data. This follows Rust’s principle of explicit state management.

§Example
let result = renderer.update_texture(&texture_data)?;
result.apply_to(&mut texture_data);
Source

pub fn new_frame(&mut self) -> RendererResult<()>

Called every frame to prepare for rendering

This corresponds to ImGui_ImplWGPU_NewFrame in the C++ implementation

Source

pub fn render_draw_data( &mut self, draw_data: &DrawData, render_pass: &mut RenderPass<'_>, ) -> RendererResult<()>

Render Dear ImGui draw data

This corresponds to ImGui_ImplWGPU_RenderDrawData in the C++ implementation

Source

pub fn render_draw_data_with_fb_size( &mut self, draw_data: &DrawData, render_pass: &mut RenderPass<'_>, fb_width: u32, fb_height: u32, ) -> RendererResult<()>

Source

pub fn invalidate_device_objects(&mut self) -> RendererResult<()>

Prepare frame resources (buffers) Setup render state

This corresponds to ImGui_ImplWGPU_SetupRenderState in the C++ implementation Render all draw lists Invalidate device objects

This corresponds to ImGui_ImplWGPU_InvalidateDeviceObjects in the C++ implementation

Source

pub fn shutdown(&mut self)

Shutdown the renderer

This corresponds to ImGui_ImplWGPU_Shutdown in the C++ implementation

Trait Implementations§

Source§

impl Default for WgpuRenderer

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,