diff --git a/imgui-gfx-renderer/src/lib.rs b/imgui-gfx-renderer/src/lib.rs index c82f06e6d..99f153b0b 100644 --- a/imgui-gfx-renderer/src/lib.rs +++ b/imgui-gfx-renderer/src/lib.rs @@ -105,8 +105,6 @@ pub struct Renderer { font_texture: gfx::handle::ShaderResourceView, } -const FONT_TEXTURE_ID: usize = 0; - impl Renderer { pub fn init>( imgui: &mut ImGui, @@ -128,18 +126,16 @@ impl Renderer { gfx::memory::Usage::Dynamic, Bind::empty(), )?; - let (_, texture) = imgui.prepare_texture(|handle| { - factory.create_texture_immutable_u8::( - gfx::texture::Kind::D2( - handle.width as u16, - handle.height as u16, - gfx::texture::AaMode::Single, - ), - gfx::texture::Mipmap::Provided, - &[handle.pixels], + let texture = imgui.register_font_texture(|handle| { + Texture::from_raw( + factory, + handle.width as u16, + handle.height as u16, + handle.pixels, ) })?; - imgui.set_texture_id(FONT_TEXTURE_ID); + imgui.set_texture_id(texture.get_id() as usize); + let texture = as FromImTexture>::from_im_texture(&texture).deref(); let sampler = factory.create_sampler(SamplerInfo::new(FilterMethod::Trilinear, WrapMode::Clamp)); @@ -170,7 +166,7 @@ impl Renderer { Ok(Renderer { bundle: Bundle::new(slice, pso, data), index_buffer: index_buffer, - font_texture: texture, + font_texture: texture.clone(), }) } pub fn update_render_target(&mut self, out: RenderTargetView) { @@ -224,13 +220,9 @@ impl Renderer { self.bundle.slice.start = 0; for cmd in draw_list.cmd_buffer { - self.bundle.data.tex.0 = if cmd.texture_id as usize == FONT_TEXTURE_ID { - self.font_texture.clone() - } else { - as FromImTexture>::from_id(cmd.texture_id) - .deref() - .clone() - }; + self.bundle.data.tex.0 = as FromImTexture>::from_id(cmd.texture_id) + .deref() + .clone(); self.bundle.slice.end = self.bundle.slice.start + cmd.elem_count; self.bundle.data.scissor = Rect {