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