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_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_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
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
Sourcepub fn render_draw_data_with_fb_size(
&mut self,
draw_data: &DrawData,
render_pass: &mut RenderPass<'_>,
fb_width: u32,
fb_height: u32,
) -> RendererResult<()>
pub fn render_draw_data_with_fb_size( &mut self, draw_data: &DrawData, render_pass: &mut RenderPass<'_>, fb_width: u32, fb_height: u32, ) -> RendererResult<()>
Render Dear ImGui draw data with explicit framebuffer size override
This clones the logic of render_draw_data but clamps scissor to the provided
fb_width/fb_height instead of deriving it from DrawData.
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