Skip to content

Commit

Permalink
gfx: No special use of font texture
Browse files Browse the repository at this point in the history
  • Loading branch information
malikolivier committed Aug 13, 2018
1 parent 34b9460 commit fc4d0a9
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions imgui-gfx-renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ pub struct Renderer<R: Resources> {
font_texture: gfx::handle::ShaderResourceView<R, [f32; 4]>,
}

const FONT_TEXTURE_ID: usize = 0;

impl<R: Resources> Renderer<R> {
pub fn init<F: Factory<R>>(
imgui: &mut ImGui,
Expand All @@ -128,18 +126,16 @@ impl<R: Resources> Renderer<R> {
gfx::memory::Usage::Dynamic,
Bind::empty(),
)?;
let (_, texture) = imgui.prepare_texture(|handle| {
factory.create_texture_immutable_u8::<gfx::format::Rgba8>(
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 = <Texture<R> as FromImTexture>::from_im_texture(&texture).deref();

let sampler =
factory.create_sampler(SamplerInfo::new(FilterMethod::Trilinear, WrapMode::Clamp));
Expand Down Expand Up @@ -170,7 +166,7 @@ impl<R: Resources> Renderer<R> {
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<R, gfx::format::Rgba8>) {
Expand Down Expand Up @@ -224,13 +220,9 @@ impl<R: Resources> Renderer<R> {

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 {
<Texture<R> as FromImTexture>::from_id(cmd.texture_id)
.deref()
.clone()
};
self.bundle.data.tex.0 = <Texture<R> 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 {
Expand Down

0 comments on commit fc4d0a9

Please sign in to comment.