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
impl WgpuRenderer
Sourcepub fn register_external_texture(
&mut self,
texture: &Texture,
view: &TextureView,
) -> u64
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).
Sourcepub fn register_external_texture_with_sampler(
&mut self,
texture: &Texture,
view: &TextureView,
sampler: &Sampler,
) -> u64
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.
Sourcepub fn update_external_texture_view(
&mut self,
texture_id: u64,
view: &TextureView,
) -> bool
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.
Sourcepub fn update_external_texture_sampler(
&mut self,
texture_id: u64,
sampler: &Sampler,
) -> bool
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.
Sourcepub fn unregister_texture(&mut self, texture_id: u64)
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
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 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)?;Sourcepub fn empty() -> Self
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)?;Sourcepub fn init(&mut self, init_info: WgpuInitInfo) -> RendererResult<()>
pub fn init(&mut self, init_info: WgpuInitInfo) -> RendererResult<()>
Initialize the renderer
This corresponds to ImGui_ImplWGPU_Init in the C++ implementation
Sourcepub fn new_without_font_atlas(
init_info: WgpuInitInfo,
imgui_ctx: &mut Context,
) -> RendererResult<Self>
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.
Sourcepub fn init_with_context(
&mut self,
init_info: WgpuInitInfo,
imgui_ctx: &mut Context,
) -> RendererResult<()>
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.
Sourcepub fn set_gamma_mode(&mut self, mode: GammaMode)
pub fn set_gamma_mode(&mut self, mode: GammaMode)
Set gamma mode
Sourcepub fn configure_imgui_context(&self, imgui_context: &mut Context)
pub fn configure_imgui_context(&self, imgui_context: &mut Context)
Configure Dear ImGui context with WGPU backend capabilities
Sourcepub fn prepare_font_atlas(
&mut self,
imgui_ctx: &mut Context,
) -> RendererResult<()>
pub fn prepare_font_atlas( &mut self, imgui_ctx: &mut Context, ) -> RendererResult<()>
Prepare font atlas for rendering
Sourcepub fn texture_manager(&self) -> &WgpuTextureManager
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
Sourcepub fn texture_manager_mut(&mut self) -> &mut WgpuTextureManager
pub fn texture_manager_mut(&mut self) -> &mut WgpuTextureManager
Get the texture manager mutably
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check if the renderer is initialized
Sourcepub fn update_texture(
&mut self,
texture_data: &TextureData,
) -> RendererResult<TextureUpdateResult>
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);Sourcepub fn new_frame(&mut self) -> RendererResult<()>
pub fn new_frame(&mut self) -> RendererResult<()>
Called every frame to prepare for rendering
This corresponds to ImGui_ImplWGPU_NewFrame in the C++ implementation
Sourcepub fn render_draw_data(
&mut self,
draw_data: &DrawData,
render_pass: &mut RenderPass<'_>,
) -> RendererResult<()>
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
pub fn render_draw_data_with_fb_size( &mut self, draw_data: &DrawData, render_pass: &mut RenderPass<'_>, fb_width: u32, fb_height: u32, ) -> RendererResult<()>
Sourcepub fn invalidate_device_objects(&mut self) -> RendererResult<()>
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