Saving off the glyph_cache and texture_cache for caching text on GPU
JakeCallery opened this issue · 1 comments
JakeCallery commented
Hi All,
I am trying to organize a bunch of the boiler plate stuff in my code.
I would like to save the glyph_cache and text_texture_cache into a struct:
pub struct App {
window: PistonWindow<Sdl2Window>,
ids: Ids,
ui: conrod_core::Ui,
image_map: conrod_core::image::Map<G2dTexture>,
glyph_cache: *can't seem to figure out type*,
text_texture_cache: *can't seem to figure out type*,
text_vertex_data: Vec<u8>,
pw_texture_context: G2dTextureContext,
}
In the examples glyph_cache and text_texture_cache are being defined as such:
// Create a texture to use for efficiently caching text on the GPU.
let mut text_vertex_data = Vec::new();
let (mut glyph_cache, mut text_texture_cache) = {
const SCALE_TOLERANCE: f32 = 0.1;
const POSITION_TOLERANCE: f32 = 0.1;
let cache = conrod_core::text::GlyphCache::builder()
.dimensions(win_w_32, win_h_32)
.scale_tolerance(SCALE_TOLERANCE)
.position_tolerance(POSITION_TOLERANCE)
.build();
let buffer_len = win_w_32 as usize * win_h_32 as usize;
let init = vec![128; buffer_len];
let settings = TextureSettings::new();
let texture =
G2dTexture::from_memory_alpha(&mut pw_texture_context, &init, win_w_32, win_h_32, &settings)
.unwrap();
(cache, texture)
};
So for glyph_cache, build() seems to return:
Cache<'font>
and for text_texture_cache it seems to return:
Texture<R> where R: gfx::Resources
Any chance someone could help me to figure out how to declare variables for those in a struct?
Thank you!
JakeCallery commented
I'm Sorry, I think I figured it out.
pub struct App<'a> {
window: PistonWindow<Sdl2Window>,
ids: Ids,
ui: conrod_core::Ui,
image_map: conrod_core::image::Map<G2dTexture>,
text_texture_cache: G2dTexture,
glyph_cache: text::GlyphCache<'a>,
text_vertex_data: Vec<u8>,
pw_texture_context: G2dTextureContext,
}