comparison examples/stdrenderer.rs @ 715:2b2376811f46

examples: Update luminance.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 23 Sep 2019 00:22:08 +0200
parents 3954801b6299
children d5d5496e4e53
comparison
equal deleted inserted replaced
714:fcc8f736c746 715:2b2376811f46
1 use luminance::blending::{Equation, Factor}; 1 use luminance::blending::{Equation, Factor};
2 use luminance::context::GraphicsContext; 2 use luminance::context::GraphicsContext;
3 use luminance::framebuffer::Framebuffer;
4 use luminance::pipeline::BoundTexture; 3 use luminance::pipeline::BoundTexture;
5 use luminance::pixel::NormUnsigned; 4 use luminance::pixel::NormUnsigned;
6 use luminance::render_state::RenderState; 5 use luminance::render_state::RenderState;
7 use luminance::shader::program::{Program, Uniform}; 6 use luminance::shader::program::{Program, Uniform};
8 use luminance::tess::{Mode, TessBuilder, TessSliceIndex}; 7 use luminance::tess::{Mode, TessBuilder, TessSliceIndex};
161 160
162 // Open the image atlas matching this ANM. 161 // Open the image atlas matching this ANM.
163 let tex = load_anm_image(&mut surface, &anm0, anm_filename); 162 let tex = load_anm_image(&mut surface, &anm0, anm_filename);
164 163
165 // set the uniform interface to our type so that we can read textures from the shader 164 // set the uniform interface to our type so that we can read textures from the shader
166 let (program, _) = 165 let program =
167 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation"); 166 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings();
168 167
169 let tess = TessBuilder::new(&mut surface) 168 let tess = TessBuilder::new(&mut surface)
170 .add_vertices(vertices) 169 .add_vertices(vertices)
171 .set_mode(Mode::Triangle) 170 .set_mode(Mode::Triangle)
172 .build() 171 .build()
173 .unwrap(); 172 .unwrap();
174 173
175 let mut back_buffer = Framebuffer::back_buffer(surface.size()); 174 let mut back_buffer = surface.back_buffer().unwrap();
175 let mut resize = false;
176 176
177 'app: loop { 177 'app: loop {
178 for event in surface.poll_events() { 178 for event in surface.poll_events() {
179 match event { 179 match event {
180 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, 180 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app,
181 181
182 WindowEvent::FramebufferSize(width, height) => { 182 WindowEvent::FramebufferSize(..) => {
183 back_buffer = Framebuffer::back_buffer([width as u32, height as u32]); 183 resize = true;
184 } 184 }
185 185
186 _ => (), 186 _ => (),
187 } 187 }
188 }
189
190 if resize {
191 back_buffer = surface.back_buffer().unwrap();
192 resize = false;
188 } 193 }
189 194
190 { 195 {
191 stage_runner.run_frame(); 196 stage_runner.run_frame();
192 //let sprites = stage.get_sprites(); 197 //let sprites = stage.get_sprites();
195 200
196 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU 201 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU
197 // and use it in the shader 202 // and use it in the shader
198 surface 203 surface
199 .pipeline_builder() 204 .pipeline_builder()
200 .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, shd_gate| { 205 .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| {
201 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader 206 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader
202 let bound_tex = match &tex { 207 let bound_tex = match &tex {
203 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), 208 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex),
204 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), 209 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex),
205 }; 210 };
206 211
207 shd_gate.shade(&program, |rdr_gate, iface| { 212 shd_gate.shade(&program, |iface, mut rdr_gate| {
208 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU 213 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU
209 // to use the texture passed as argument (no allocation or copy is performed) 214 // to use the texture passed as argument (no allocation or copy is performed)
210 iface.color_map.update(&bound_tex); 215 iface.color_map.update(&bound_tex);
211 216
212 let proj = perspective(0.5235987755982988, 384. / 448., 101010101./2010101., 101010101./10101.); 217 let proj = perspective(0.5235987755982988, 384. / 448., 101010101./2010101., 101010101./10101.);
226 231
227 let stage = stage_runner.stage.borrow(); 232 let stage = stage_runner.stage.borrow();
228 for instance in stage.instances.iter() { 233 for instance in stage.instances.iter() {
229 iface.instance_position.update([instance.pos.x, instance.pos.y, instance.pos.z]); 234 iface.instance_position.update([instance.pos.x, instance.pos.y, instance.pos.z]);
230 235
231 rdr_gate.render(render_state, |tess_gate| { 236 rdr_gate.render(render_state, |mut tess_gate| {
232 let (begin, end) = indices[instance.id as usize]; 237 let (begin, end) = indices[instance.id as usize];
233 tess_gate.render(&mut surface, tess.slice(begin..end)); 238 tess_gate.render(tess.slice(begin..end));
234 }); 239 });
235 } 240 }
236 }); 241 });
237 }); 242 });
238 243