@@ -105,8 +105,6 @@ pub struct Renderer<R: Resources> {
105
105
font_texture : gfx:: handle:: ShaderResourceView < R , [ f32 ; 4 ] > ,
106
106
}
107
107
108
- const FONT_TEXTURE_ID : usize = 0 ;
109
-
110
108
impl < R : Resources > Renderer < R > {
111
109
pub fn init < F : Factory < R > > (
112
110
imgui : & mut ImGui ,
@@ -128,18 +126,16 @@ impl<R: Resources> Renderer<R> {
128
126
gfx:: memory:: Usage :: Dynamic ,
129
127
Bind :: empty ( ) ,
130
128
) ?;
131
- let ( _, texture) = imgui. prepare_texture ( |handle| {
132
- factory. create_texture_immutable_u8 :: < gfx:: format:: Rgba8 > (
133
- gfx:: texture:: Kind :: D2 (
134
- handle. width as u16 ,
135
- handle. height as u16 ,
136
- gfx:: texture:: AaMode :: Single ,
137
- ) ,
138
- gfx:: texture:: Mipmap :: Provided ,
139
- & [ handle. pixels ] ,
129
+ let texture = imgui. register_font_texture ( |handle| {
130
+ Texture :: from_raw (
131
+ factory,
132
+ handle. width as u16 ,
133
+ handle. height as u16 ,
134
+ handle. pixels ,
140
135
)
141
136
} ) ?;
142
- imgui. set_texture_id ( FONT_TEXTURE_ID ) ;
137
+ imgui. set_texture_id ( texture. get_id ( ) as usize ) ;
138
+ let texture = <Texture < R > as FromImTexture >:: from_im_texture ( & texture) . deref ( ) ;
143
139
144
140
let sampler =
145
141
factory. create_sampler ( SamplerInfo :: new ( FilterMethod :: Trilinear , WrapMode :: Clamp ) ) ;
@@ -170,7 +166,7 @@ impl<R: Resources> Renderer<R> {
170
166
Ok ( Renderer {
171
167
bundle : Bundle :: new ( slice, pso, data) ,
172
168
index_buffer : index_buffer,
173
- font_texture : texture,
169
+ font_texture : texture. clone ( ) ,
174
170
} )
175
171
}
176
172
pub fn update_render_target ( & mut self , out : RenderTargetView < R , gfx:: format:: Rgba8 > ) {
@@ -224,13 +220,9 @@ impl<R: Resources> Renderer<R> {
224
220
225
221
self . bundle . slice . start = 0 ;
226
222
for cmd in draw_list. cmd_buffer {
227
- self . bundle . data . tex . 0 = if cmd. texture_id as usize == FONT_TEXTURE_ID {
228
- self . font_texture . clone ( )
229
- } else {
230
- <Texture < R > as FromImTexture >:: from_id ( cmd. texture_id )
231
- . deref ( )
232
- . clone ( )
233
- } ;
223
+ self . bundle . data . tex . 0 = <Texture < R > as FromImTexture >:: from_id ( cmd. texture_id )
224
+ . deref ( )
225
+ . clone ( ) ;
234
226
235
227
self . bundle . slice . end = self . bundle . slice . start + cmd. elem_count ;
236
228
self . bundle . data . scissor = Rect {
0 commit comments