Mercurial > touhou
changeset 715:2b2376811f46
examples: Update luminance.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 23 Sep 2019 00:22:08 +0200 |
parents | fcc8f736c746 |
children | 5016c09e5d7c |
files | Cargo.toml examples/anmrenderer.rs examples/common.rs examples/eclrenderer.rs examples/stdrenderer.rs |
diffstat | 5 files changed, 50 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ nom = "5" encoding_rs = "0.8" image = { version = "0.22", default-features = false, features = ["png_codec"] } bitflags = "1" -luminance = "0.32" -luminance-glfw = { version = "0.6", default-features = false } -luminance-derive = "0.1" +luminance = "0.36" +luminance-glfw = { version = "0.10", default-features = false, features = ["log-errors"] } +luminance-derive = "0.4" [profile.dev] panic = "abort"
--- a/examples/anmrenderer.rs +++ b/examples/anmrenderer.rs @@ -136,8 +136,8 @@ fn main() { let tex = load_anm_image(&mut surface, &anm0, anm_filename); // set the uniform interface to our type so that we can read textures from the shader - let (program, _) = - Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation"); + let program = + Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); let mut tess = TessBuilder::new(&mut surface) .add_vertices(vertices) @@ -145,21 +145,27 @@ fn main() { .build() .unwrap(); - let mut back_buffer = Framebuffer::back_buffer(surface.size()); + let mut back_buffer = surface.back_buffer().unwrap(); + let mut resize = false; 'app: loop { for event in surface.poll_events() { match event { WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, - WindowEvent::FramebufferSize(width, height) => { - back_buffer = Framebuffer::back_buffer([width as u32, height as u32]); + WindowEvent::FramebufferSize(..) => { + resize = true; } _ => (), } } + if resize { + back_buffer = surface.back_buffer().unwrap(); + resize = false; + } + { let mut slice = tess .as_slice_mut() @@ -173,14 +179,14 @@ fn main() { // and use it in the shader surface .pipeline_builder() - .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, shd_gate| { + .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader let bound_tex = match &tex { LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), }; - shd_gate.shade(&program, |rdr_gate, iface| { + shd_gate.shade(&program, |iface, mut rdr_gate| { // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU // to use the texture passed as argument (no allocation or copy is performed) iface.color_map.update(&bound_tex); @@ -195,10 +201,8 @@ fn main() { let render_state = RenderState::default() .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); - rdr_gate.render(render_state, |tess_gate| { - // render the tessellation to the surface the regular way and let the vertex shader’s - // magic do the rest! - tess_gate.render(&mut surface, (&tess).into()); + rdr_gate.render(render_state, |mut tess_gate| { + tess_gate.render(&tess); }); }); });
--- a/examples/common.rs +++ b/examples/common.rs @@ -34,7 +34,7 @@ fn load_rgb_png(surface: &mut GlfwSurfac // to 0 for now) and the latest is a the sampler to use when sampling the texels in the // shader (we’ll just use the default one) let tex = - Texture::new(surface, [width, height], 0, &Sampler::default()).expect("luminance texture creation"); + Texture::new(surface, [width, height], 0, Sampler::default()).expect("luminance texture creation"); // the first argument disables mipmap generation (we don’t care so far) tex.upload(GenMipmaps::No, &texels).unwrap(); @@ -78,7 +78,7 @@ fn load_rgb_a_pngs(surface: &mut GlfwSur // to 0 for now) and the latest is a the sampler to use when sampling the texels in the // shader (we’ll just use the default one) let tex = - Texture::new(surface, [width, height], 0, &Sampler::default()).expect("luminance texture creation"); + Texture::new(surface, [width, height], 0, Sampler::default()).expect("luminance texture creation"); // the first argument disables mipmap generation (we don’t care so far) tex.upload(GenMipmaps::No, &texels).unwrap();
--- a/examples/eclrenderer.rs +++ b/examples/eclrenderer.rs @@ -137,8 +137,8 @@ fn main() { let tex = load_anm_image(&mut surface, &anm0.borrow(), anm_filename); // set the uniform interface to our type so that we can read textures from the shader - let (program, _) = - Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation"); + let program = + Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); let mut tess = TessBuilder::new(&mut surface) .add_vertices(vertices) @@ -146,21 +146,27 @@ fn main() { .build() .unwrap(); - let mut back_buffer = Framebuffer::back_buffer(surface.size()); + let mut back_buffer = surface.back_buffer().unwrap(); + let mut resize = false; 'app: loop { for event in surface.poll_events() { match event { WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, - WindowEvent::FramebufferSize(width, height) => { - back_buffer = Framebuffer::back_buffer([width as u32, height as u32]); + WindowEvent::FramebufferSize(..) => { + resize = true; } _ => (), } } + if resize { + back_buffer = surface.back_buffer().unwrap(); + resize = false; + } + if ecl_runner.running == false { break; } @@ -185,14 +191,14 @@ fn main() { // and use it in the shader surface .pipeline_builder() - .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, shd_gate| { + .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader let bound_tex = match &tex { LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), }; - shd_gate.shade(&program, |rdr_gate, iface| { + shd_gate.shade(&program, |iface, mut rdr_gate| { // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU // to use the texture passed as argument (no allocation or copy is performed) iface.color_map.update(&bound_tex); @@ -207,10 +213,10 @@ fn main() { let render_state = RenderState::default() .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); - rdr_gate.render(render_state, |tess_gate| { + rdr_gate.render(render_state, |mut tess_gate| { // render the tessellation to the surface the regular way and let the vertex shader’s // magic do the rest! - tess_gate.render(&mut surface, (&tess).into()); + tess_gate.render(&tess); }); }); });
--- a/examples/stdrenderer.rs +++ b/examples/stdrenderer.rs @@ -1,6 +1,5 @@ use luminance::blending::{Equation, Factor}; use luminance::context::GraphicsContext; -use luminance::framebuffer::Framebuffer; use luminance::pipeline::BoundTexture; use luminance::pixel::NormUnsigned; use luminance::render_state::RenderState; @@ -163,8 +162,8 @@ fn main() { let tex = load_anm_image(&mut surface, &anm0, anm_filename); // set the uniform interface to our type so that we can read textures from the shader - let (program, _) = - Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation"); + let program = + Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); let tess = TessBuilder::new(&mut surface) .add_vertices(vertices) @@ -172,21 +171,27 @@ fn main() { .build() .unwrap(); - let mut back_buffer = Framebuffer::back_buffer(surface.size()); + let mut back_buffer = surface.back_buffer().unwrap(); + let mut resize = false; 'app: loop { for event in surface.poll_events() { match event { WindowEvent::Close | WindowEvent::Key(Key::Escape, _, Action::Release, _) => break 'app, - WindowEvent::FramebufferSize(width, height) => { - back_buffer = Framebuffer::back_buffer([width as u32, height as u32]); + WindowEvent::FramebufferSize(..) => { + resize = true; } _ => (), } } + if resize { + back_buffer = surface.back_buffer().unwrap(); + resize = false; + } + { stage_runner.run_frame(); //let sprites = stage.get_sprites(); @@ -197,14 +202,14 @@ fn main() { // and use it in the shader surface .pipeline_builder() - .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, shd_gate| { + .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { // bind our fancy texture to the GPU: it gives us a bound texture we can use with the shader let bound_tex = match &tex { LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), }; - shd_gate.shade(&program, |rdr_gate, iface| { + shd_gate.shade(&program, |iface, mut rdr_gate| { // update the texture; strictly speaking, this update doesn’t do much: it just tells the GPU // to use the texture passed as argument (no allocation or copy is performed) iface.color_map.update(&bound_tex); @@ -228,9 +233,9 @@ fn main() { for instance in stage.instances.iter() { iface.instance_position.update([instance.pos.x, instance.pos.y, instance.pos.z]); - rdr_gate.render(render_state, |tess_gate| { + rdr_gate.render(render_state, |mut tess_gate| { let (begin, end) = indices[instance.id as usize]; - tess_gate.render(&mut surface, tess.slice(begin..end)); + tess_gate.render(tess.slice(begin..end)); }); } });