add support for resetting the imgui renderer's texture map
This commit is contained in:
parent
457aa757cf
commit
f6ef1ee22e
|
@ -2,6 +2,26 @@ use ggdt::graphics::{BlendFunction, RgbaBitmap, RgbaPixelFormat, RGBA};
|
||||||
use ggdt::math::{Rect, Vector2};
|
use ggdt::math::{Rect, Vector2};
|
||||||
use imgui::internal::RawWrapper;
|
use imgui::internal::RawWrapper;
|
||||||
|
|
||||||
|
fn create_default_texture_map(context: &mut imgui::Context) -> imgui::Textures<RgbaBitmap> {
|
||||||
|
let mut texture_map = imgui::Textures::new();
|
||||||
|
|
||||||
|
// set up a bitmap with the imgui font atlas texture pixels and register a bitmap->texture mapping for it
|
||||||
|
// with imgui
|
||||||
|
let mut font = context.fonts();
|
||||||
|
let mut font_atlas_texture = font.build_rgba32_texture();
|
||||||
|
font.tex_id = texture_map.insert(
|
||||||
|
RgbaBitmap::from_bytes(
|
||||||
|
font_atlas_texture.width,
|
||||||
|
font_atlas_texture.height,
|
||||||
|
RgbaPixelFormat::RGBA,
|
||||||
|
&mut font_atlas_texture.data,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
texture_map
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
pub texture_map: imgui::Textures<RgbaBitmap>,
|
pub texture_map: imgui::Textures<RgbaBitmap>,
|
||||||
|
@ -9,23 +29,7 @@ pub struct Renderer {
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
pub fn new(context: &mut imgui::Context) -> Self {
|
pub fn new(context: &mut imgui::Context) -> Self {
|
||||||
let mut texture_map = imgui::Textures::new();
|
Renderer { texture_map: create_default_texture_map(context) }
|
||||||
|
|
||||||
// set up a bitmap with the imgui font atlas texture pixels and register a bitmap->texture mapping for it
|
|
||||||
// with imgui
|
|
||||||
let mut font = context.fonts();
|
|
||||||
let mut font_atlas_texture = font.build_rgba32_texture();
|
|
||||||
font.tex_id = texture_map.insert(
|
|
||||||
RgbaBitmap::from_bytes(
|
|
||||||
font_atlas_texture.width,
|
|
||||||
font_atlas_texture.height,
|
|
||||||
RgbaPixelFormat::RGBA,
|
|
||||||
&mut font_atlas_texture.data,
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Renderer { texture_map }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, draw_data: &imgui::DrawData, dest: &mut RgbaBitmap) {
|
pub fn render(&mut self, draw_data: &imgui::DrawData, dest: &mut RgbaBitmap) {
|
||||||
|
@ -81,4 +85,8 @@ impl Renderer {
|
||||||
}
|
}
|
||||||
dest.set_clip_region(&original_clip_rect);
|
dest.set_clip_region(&original_clip_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset_textures(&mut self, context: &mut imgui::Context) {
|
||||||
|
self.texture_map = create_default_texture_map(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue