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 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
Source§impl WgpuRenderer
impl WgpuRenderer
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 invalidate_device_objects(&mut self) -> RendererResult<()>
pub fn invalidate_device_objects(&mut self) -> RendererResult<()>
Invalidate device objects
This corresponds to ImGui_ImplWGPU_InvalidateDeviceObjects in the C++ implementation
Sourcepub fn shutdown(&mut self)
pub fn shutdown(&mut self)
Shutdown the renderer
This corresponds to ImGui_ImplWGPU_Shutdown in the C++ implementation.
If multi-viewport support was enabled, this also makes renderer callbacks no-op for this renderer. Call the matching multi-viewport shutdown helper when you also need to uninstall callbacks from the ImGui context and destroy platform windows.
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn render_draw_data(
&mut self,
draw_data: &mut DrawData,
render_pass: &mut RenderPass<'_>,
) -> RendererResult<()>
pub fn render_draw_data( &mut self, draw_data: &mut DrawData, render_pass: &mut RenderPass<'_>, ) -> RendererResult<()>
Render Dear ImGui draw data
This corresponds to ImGui_ImplWGPU_RenderDrawData in the C++ implementation
Sourcepub fn render_context(
&mut self,
ctx: &mut Context,
render_pass: &mut RenderPass<'_>,
) -> RendererResult<()>
pub fn render_context( &mut self, ctx: &mut Context, render_pass: &mut RenderPass<'_>, ) -> RendererResult<()>
Finalize and render the frame for an explicit ImGui context.
This is the preferred entry point for multi-context applications because the temporary
PlatformIO.Renderer_RenderState pointer used by draw callbacks is written to the
provided context instead of whichever Dear ImGui context is current.
pub fn render_draw_data_with_fb_size( &mut self, draw_data: &mut DrawData, render_pass: &mut RenderPass<'_>, fb_width: u32, fb_height: u32, ) -> RendererResult<()>
Sourcepub fn render_context_with_fb_size(
&mut self,
ctx: &mut Context,
render_pass: &mut RenderPass<'_>,
fb_width: u32,
fb_height: u32,
) -> RendererResult<()>
pub fn render_context_with_fb_size( &mut self, ctx: &mut Context, render_pass: &mut RenderPass<'_>, fb_width: u32, fb_height: u32, ) -> RendererResult<()>
Finalize and render the frame for an explicit ImGui context and framebuffer size.
Use this variant in multi-context applications when overriding framebuffer dimensions.
Draw callbacks read the render state through the matching context’s PlatformIO.
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn texture_manager(&self) -> &WgpuTextureManager
pub fn texture_manager(&self) -> &WgpuTextureManager
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);Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn register_external_texture(
&mut self,
texture: &Texture,
view: &TextureView,
) -> TextureId
pub fn register_external_texture( &mut self, texture: &Texture, view: &TextureView, ) -> TextureId
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(texture_id, size).
Sourcepub fn register_external_texture_with_sampler(
&mut self,
texture: &Texture,
view: &TextureView,
sampler: &Sampler,
) -> TextureId
pub fn register_external_texture_with_sampler( &mut self, texture: &Texture, view: &TextureView, sampler: &Sampler, ) -> TextureId
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: TextureId,
view: &TextureView,
) -> bool
pub fn update_external_texture_view( &mut self, texture_id: TextureId, 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: TextureId,
sampler: &Sampler,
) -> bool
pub fn update_external_texture_sampler( &mut self, texture_id: TextureId, 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: TextureId)
pub fn unregister_texture(&mut self, texture_id: TextureId)
Unregister (remove) a texture by id. Safe for both external and managed textures.