Mercurial > touhou
changeset 742:0a250ddfae79
examples: Update luminance.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 07 Jan 2020 00:23:15 +0100 |
parents | 3555845f8cf4 |
children | 0fed350d1778 |
files | Cargo.toml examples/anmrenderer.rs examples/eclrenderer.rs examples/stagerunner.rs examples/stdrenderer.rs src/th06/anm0_vm.rs |
diffstat | 6 files changed, 34 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ nom = "5" encoding_rs = "0.8" image = { version = "0.22", default-features = false, features = ["png_codec"] } bitflags = "1" -luminance = "0.37" -luminance-glfw = { version = "0.11", default-features = false, features = ["log-errors"] } +luminance = "0.38" +luminance-glfw = { version = "0.12", default-features = false, features = ["log-errors"] } luminance-derive = "0.5" [profile.dev]
--- a/examples/anmrenderer.rs +++ b/examples/anmrenderer.rs @@ -1,6 +1,6 @@ use luminance::blending::{Equation, Factor}; use luminance::context::GraphicsContext; -use luminance::pipeline::BoundTexture; +use luminance::pipeline::{BoundTexture, PipelineState}; use luminance::pixel::NormUnsigned; use luminance::render_state::RenderState; use luminance::shader::program::{Program, Uniform}; @@ -122,18 +122,19 @@ fn main() { // TODO: seed this PRNG with a valid seed. let prng = Rc::new(RefCell::new(Prng::new(0))); + let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); + + // Open the image atlas matching this ANM. + let tex = load_anm_image(&mut surface, &anm0, anm_filename).expect("image loading"); + // Create the AnmRunner from the ANM and the sprite. - let mut anm_runner = AnmRunner::new(&anm0, script, sprite.clone(), Rc::downgrade(&prng), 0); + let anms = Rc::new(RefCell::new([anm0])); + let mut anm_runner = AnmRunner::new(anms, script, sprite.clone(), Rc::downgrade(&prng), 0); assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); let mut vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() }; fill_vertices(sprite.clone(), &mut vertices); - let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); - - // Open the image atlas matching this ANM. - let tex = load_anm_image(&mut surface, &anm0, anm_filename).expect("image loading"); - // 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").ignore_warnings(); @@ -178,7 +179,7 @@ fn main() { // and use it in the shader surface .pipeline_builder() - .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { + .pipeline(&back_buffer, &PipelineState::default(), |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), @@ -200,7 +201,7 @@ fn main() { let render_state = RenderState::default() .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); - rdr_gate.render(render_state, |mut tess_gate| { + rdr_gate.render(&render_state, |mut tess_gate| { tess_gate.render(&tess); }); });
--- a/examples/eclrenderer.rs +++ b/examples/eclrenderer.rs @@ -1,6 +1,6 @@ use luminance::blending::{Equation, Factor}; use luminance::context::GraphicsContext; -use luminance::pipeline::BoundTexture; +use luminance::pipeline::{BoundTexture, PipelineState}; use luminance::pixel::NormUnsigned; use luminance::render_state::RenderState; use luminance::shader::program::{Program, Uniform}; @@ -108,7 +108,7 @@ fn main() { let buf = load_file_into_vec(anm_filename); let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); let anm0 = anms.pop().unwrap(); - let anm0 = Rc::new(RefCell::new(anm0)); + let anm0 = Rc::new(RefCell::new([anm0.clone(), anm0])); if ecl.subs.len() < sub as usize { eprintln!("This ecl doesn’t contain a sub named {}.", sub); @@ -124,7 +124,7 @@ fn main() { let game = Rc::new(RefCell::new(game)); // And the enemy object. - let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); + let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, false, Rc::downgrade(&anm0), Rc::downgrade(&game)); let mut ecl_runner = EclRunner::new(&ecl, enemy.clone(), sub); assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); @@ -133,7 +133,7 @@ fn main() { let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); // Open the image atlas matching this ANM. - let tex = load_anm_image(&mut surface, &anm0.borrow(), anm_filename).expect("image loading"); + let tex = load_anm_image(&mut surface, &anm0.borrow()[0], &anm_filename).expect("image loading"); // set the uniform interface to our type so that we can read textures from the shader let program = @@ -190,7 +190,7 @@ fn main() { // and use it in the shader surface .pipeline_builder() - .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { + .pipeline(&back_buffer, &PipelineState::default(), |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), @@ -212,7 +212,7 @@ fn main() { let render_state = RenderState::default() .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); - rdr_gate.render(render_state, |mut 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(&tess);
--- a/examples/stagerunner.rs +++ b/examples/stagerunner.rs @@ -1,6 +1,6 @@ use luminance::blending::{Equation, Factor}; use luminance::context::GraphicsContext; -use luminance::pipeline::BoundTexture; +use luminance::pipeline::{BoundTexture, PipelineState}; use luminance::pixel::NormUnsigned; use luminance::render_state::RenderState; use luminance::shader::program::{Program, Uniform}; @@ -203,7 +203,7 @@ fn main() { // and use it in the shader surface .pipeline_builder() - .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { + .pipeline(&back_buffer, &PipelineState::default(), |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), @@ -225,7 +225,7 @@ fn main() { let render_state = RenderState::default() .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); - rdr_gate.render(render_state, |mut tess_gate| { + rdr_gate.render(&render_state, |mut tess_gate| { let mut game = game.borrow_mut(); game.run_frame();
--- a/examples/stdrenderer.rs +++ b/examples/stdrenderer.rs @@ -1,6 +1,6 @@ use luminance::blending::{Equation, Factor}; use luminance::context::GraphicsContext; -use luminance::pipeline::BoundTexture; +use luminance::pipeline::{BoundTexture, PipelineState}; use luminance::pixel::NormUnsigned; use luminance::render_state::RenderState; use luminance::shader::program::{Program, Uniform}; @@ -129,11 +129,17 @@ fn main() { // TODO: seed this PRNG with a valid seed. let prng = Rc::new(RefCell::new(Prng::new(0))); + let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); + + // Open the image atlas matching this ANM. + let tex = load_anm_image(&mut surface, &anm0, anm_filename).expect("image loading"); + assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); let mut vertices: Vec<Vertex> = vec![]; let mut indices = vec![]; { + let anms = Rc::new(RefCell::new([anm0])); for model in stage.models.iter() { let begin = vertices.len(); for quad in model.quads.iter() { @@ -142,7 +148,7 @@ fn main() { // Create the AnmRunner from the ANM and the sprite. let sprite = Rc::new(RefCell::new(Sprite::with_size(width, height))); - let _anm_runner = AnmRunner::new(&anm0, quad.anm_script as u8, sprite.clone(), Rc::downgrade(&prng), 0); + let _anm_runner = AnmRunner::new(anms.clone(), quad.anm_script as u8, sprite.clone(), Rc::downgrade(&prng), 0); let mut new_vertices: [Vertex; 6] = unsafe { std::mem::uninitialized() }; fill_vertices(sprite.clone(), &mut new_vertices, x, y, z); new_vertices[4] = new_vertices[0]; @@ -156,11 +162,6 @@ fn main() { let mut stage_runner = StageRunner::new(Rc::new(RefCell::new(stage))); - let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); - - // Open the image atlas matching this ANM. - let tex = load_anm_image(&mut surface, &anm0, anm_filename).expect("image loading"); - // 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").ignore_warnings(); @@ -202,7 +203,7 @@ fn main() { // and use it in the shader surface .pipeline_builder() - .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { + .pipeline(&back_buffer, &PipelineState::default(), |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), @@ -233,7 +234,7 @@ 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, |mut tess_gate| { + rdr_gate.render(&render_state, |mut tess_gate| { let (begin, end) = indices[instance.id as usize]; tess_gate.render(tess.slice(begin..end)); });
--- a/src/th06/anm0_vm.rs +++ b/src/th06/anm0_vm.rs @@ -215,11 +215,11 @@ impl Sprite { } struct Anms { - inner: Rc<RefCell<[Anm0; 2]>>, + inner: Rc<RefCell<[Anm0]>>, } impl Anms { - fn new(anms: Rc<RefCell<[Anm0; 2]>>) -> Anms { + fn new(anms: Rc<RefCell<[Anm0]>>) -> Anms { Anms { inner: anms, } @@ -272,7 +272,7 @@ pub struct AnmRunner { impl AnmRunner { /// Create a new `AnmRunner`. - pub fn new(anms: Rc<RefCell<[Anm0; 2]>>, script_id: u8, sprite: Rc<RefCell<Sprite>>, prng: Weak<RefCell<Prng>>, sprite_index_offset: u32) -> AnmRunner { + pub fn new(anms: Rc<RefCell<[Anm0]>>, script_id: u8, sprite: Rc<RefCell<Sprite>>, prng: Weak<RefCell<Prng>>, sprite_index_offset: u32) -> AnmRunner { let anms = Anms::new(anms); let script = anms.get_script(script_id); let mut runner = AnmRunner {