comparison examples/eclrenderer.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 5016c09e5d7c
comparison
equal deleted inserted replaced
714:fcc8f736c746 715:2b2376811f46
135 135
136 // Open the image atlas matching this ANM. 136 // Open the image atlas matching this ANM.
137 let tex = load_anm_image(&mut surface, &anm0.borrow(), anm_filename); 137 let tex = load_anm_image(&mut surface, &anm0.borrow(), anm_filename);
138 138
139 // set the uniform interface to our type so that we can read textures from the shader 139 // set the uniform interface to our type so that we can read textures from the shader
140 let (program, _) = 140 let program =
141 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation"); 141 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings();
142 142
143 let mut tess = TessBuilder::new(&mut surface) 143 let mut tess = TessBuilder::new(&mut surface)
144 .add_vertices(vertices) 144 .add_vertices(vertices)
145 .set_mode(Mode::TriangleFan) 145 .set_mode(Mode::TriangleFan)
146 .build() 146 .build()
147 .unwrap(); 147 .unwrap();
148 148
149 let mut back_buffer = Framebuffer::back_buffer(surface.size()); 149 let mut back_buffer = surface.back_buffer().unwrap();
150 let mut resize = false;
150 151
151 'app: loop { 152 'app: loop {
152 for event in surface.poll_events() { 153 for event in surface.poll_events() {
153 match event { 154 match event {
154 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, 155 WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app,
155 156
156 WindowEvent::FramebufferSize(width, height) => { 157 WindowEvent::FramebufferSize(..) => {
157 back_buffer = Framebuffer::back_buffer([width as u32, height as u32]); 158 resize = true;
158 } 159 }
159 160
160 _ => (), 161 _ => (),
161 } 162 }
163 }
164
165 if resize {
166 back_buffer = surface.back_buffer().unwrap();
167 resize = false;
162 } 168 }
163 169
164 if ecl_runner.running == false { 170 if ecl_runner.running == false {
165 break; 171 break;
166 } 172 }
183 189
184 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU 190 // here, we need to bind the pipeline variable; it will enable us to bind the texture to the GPU
185 // and use it in the shader 191 // and use it in the shader
186 surface 192 surface
187 .pipeline_builder() 193 .pipeline_builder()
188 .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, shd_gate| { 194 .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| {
189 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader 195 // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader
190 let bound_tex = match &tex { 196 let bound_tex = match &tex {
191 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), 197 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex),
192 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), 198 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex),
193 }; 199 };
194 200
195 shd_gate.shade(&program, |rdr_gate, iface| { 201 shd_gate.shade(&program, |iface, mut rdr_gate| {
196 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU 202 // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU
197 // to use the texture passed as argument (no allocation or copy is performed) 203 // to use the texture passed as argument (no allocation or copy is performed)
198 iface.color_map.update(&bound_tex); 204 iface.color_map.update(&bound_tex);
199 //let mvp = ortho_2d(0., 384., 448., 0.); 205 //let mvp = ortho_2d(0., 384., 448., 0.);
200 let proj = perspective(0.5235987755982988, 384. / 448., 101010101./2010101., 101010101./10101.); 206 let proj = perspective(0.5235987755982988, 384. / 448., 101010101./2010101., 101010101./10101.);
205 iface.mvp.update(*mvp.borrow_inner()); 211 iface.mvp.update(*mvp.borrow_inner());
206 212
207 let render_state = RenderState::default() 213 let render_state = RenderState::default()
208 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); 214 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement));
209 215
210 rdr_gate.render(render_state, |tess_gate| { 216 rdr_gate.render(render_state, |mut tess_gate| {
211 // render the tessellation to the surface the regular way and let the vertex shader’s 217 // render the tessellation to the surface the regular way and let the vertex shader’s
212 // magic do the rest! 218 // magic do the rest!
213 tess_gate.render(&mut surface, (&tess).into()); 219 tess_gate.render(&tess);
214 }); 220 });
215 }); 221 });
216 }); 222 });
217 223
218 surface.swap_buffers(); 224 surface.swap_buffers();