@@ -3,13 +3,16 @@ extern crate gfx;
3
3
extern crate imgui;
4
4
5
5
mod im_texture;
6
+ pub use im_texture:: Texture ;
7
+
8
+ use std:: ops:: Deref ;
6
9
7
10
use gfx:: handle:: { Buffer , RenderTargetView } ;
8
11
use gfx:: memory:: Bind ;
9
12
use gfx:: texture:: { FilterMethod , SamplerInfo , WrapMode } ;
10
13
use gfx:: traits:: FactoryExt ;
11
14
use gfx:: { Bundle , CommandBuffer , Encoder , Factory , IntoIndexBuffer , Rect , Resources , Slice } ;
12
- use imgui:: { DrawList , FrameSize , ImDrawIdx , ImDrawVert , ImGui , Ui } ;
15
+ use imgui:: { DrawList , FrameSize , FromImTexture , ImDrawIdx , ImDrawVert , ImGui , Ui } ;
13
16
14
17
pub type RendererResult < T > = Result < T , RendererError > ;
15
18
@@ -99,8 +102,11 @@ impl Shaders {
99
102
pub struct Renderer < R : Resources > {
100
103
bundle : Bundle < R , pipe:: Data < R > > ,
101
104
index_buffer : Buffer < R , u16 > ,
105
+ font_texture : gfx:: handle:: ShaderResourceView < R , [ f32 ; 4 ] > ,
102
106
}
103
107
108
+ const FONT_TEXTURE_ID : usize = 0 ;
109
+
104
110
impl < R : Resources > Renderer < R > {
105
111
pub fn init < F : Factory < R > > (
106
112
imgui : & mut ImGui ,
@@ -133,7 +139,8 @@ impl<R: Resources> Renderer<R> {
133
139
& [ handle. pixels ] ,
134
140
)
135
141
} ) ?;
136
- // TODO: set texture id in imgui
142
+ imgui. set_texture_id ( FONT_TEXTURE_ID ) ;
143
+
137
144
let sampler =
138
145
factory. create_sampler ( SamplerInfo :: new ( FilterMethod :: Trilinear , WrapMode :: Clamp ) ) ;
139
146
let data = pipe:: Data {
@@ -144,7 +151,7 @@ impl<R: Resources> Renderer<R> {
144
151
[ 0.0 , 0.0 , -1.0 , 0.0 ] ,
145
152
[ -1.0 , 1.0 , 0.0 , 1.0 ] ,
146
153
] ,
147
- tex : ( texture, sampler) ,
154
+ tex : ( texture. clone ( ) , sampler) ,
148
155
out : out,
149
156
scissor : Rect {
150
157
x : 0 ,
@@ -163,6 +170,7 @@ impl<R: Resources> Renderer<R> {
163
170
Ok ( Renderer {
164
171
bundle : Bundle :: new ( slice, pso, data) ,
165
172
index_buffer : index_buffer,
173
+ font_texture : texture,
166
174
} )
167
175
}
168
176
pub fn update_render_target ( & mut self , out : RenderTargetView < R , gfx:: format:: Rgba8 > ) {
@@ -216,7 +224,13 @@ impl<R: Resources> Renderer<R> {
216
224
217
225
self . bundle . slice . start = 0 ;
218
226
for cmd in draw_list. cmd_buffer {
219
- // TODO: check cmd.texture_id
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
+ } ;
220
234
221
235
self . bundle . slice . end = self . bundle . slice . start + cmd. elem_count ;
222
236
self . bundle . data . scissor = Rect {
0 commit comments