Mercurial > touhou
comparison examples/anmrenderer.rs @ 742:0a250ddfae79
examples: Update luminance.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 07 Jan 2020 00:23:15 +0100 |
parents | d5d5496e4e53 |
children | 0fed350d1778 |
comparison
equal
deleted
inserted
replaced
741:3555845f8cf4 | 742:0a250ddfae79 |
---|---|
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::pipeline::BoundTexture; | 3 use luminance::pipeline::{BoundTexture, PipelineState}; |
4 use luminance::pixel::NormUnsigned; | 4 use luminance::pixel::NormUnsigned; |
5 use luminance::render_state::RenderState; | 5 use luminance::render_state::RenderState; |
6 use luminance::shader::program::{Program, Uniform}; | 6 use luminance::shader::program::{Program, Uniform}; |
7 use luminance::tess::{Mode, TessBuilder}; | 7 use luminance::tess::{Mode, TessBuilder}; |
8 use luminance::texture::{Dim2, Flat}; | 8 use luminance::texture::{Dim2, Flat}; |
120 let sprite = Rc::new(RefCell::new(Sprite::new())); | 120 let sprite = Rc::new(RefCell::new(Sprite::new())); |
121 | 121 |
122 // TODO: seed this PRNG with a valid seed. | 122 // TODO: seed this PRNG with a valid seed. |
123 let prng = Rc::new(RefCell::new(Prng::new(0))); | 123 let prng = Rc::new(RefCell::new(Prng::new(0))); |
124 | 124 |
125 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); | |
126 | |
127 // Open the image atlas matching this ANM. | |
128 let tex = load_anm_image(&mut surface, &anm0, anm_filename).expect("image loading"); | |
129 | |
125 // Create the AnmRunner from the ANM and the sprite. | 130 // Create the AnmRunner from the ANM and the sprite. |
126 let mut anm_runner = AnmRunner::new(&anm0, script, sprite.clone(), Rc::downgrade(&prng), 0); | 131 let anms = Rc::new(RefCell::new([anm0])); |
132 let mut anm_runner = AnmRunner::new(anms, script, sprite.clone(), Rc::downgrade(&prng), 0); | |
127 | 133 |
128 assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); | 134 assert_eq!(std::mem::size_of::<Vertex>(), std::mem::size_of::<FakeVertex>()); |
129 let mut vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() }; | 135 let mut vertices: [Vertex; 4] = unsafe { std::mem::uninitialized() }; |
130 fill_vertices(sprite.clone(), &mut vertices); | 136 fill_vertices(sprite.clone(), &mut vertices); |
131 | |
132 let mut surface = GlfwSurface::new(WindowDim::Windowed(384, 448), "Touhou", WindowOpt::default()).unwrap(); | |
133 | |
134 // Open the image atlas matching this ANM. | |
135 let tex = load_anm_image(&mut surface, &anm0, anm_filename).expect("image loading"); | |
136 | 137 |
137 // 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 |
138 let program = | 139 let program = |
139 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); | 140 Program::<Semantics, (), ShaderInterface>::from_strings(None, VS, None, FS).expect("program creation").ignore_warnings(); |
140 | 141 |
176 | 177 |
177 // 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 |
178 // and use it in the shader | 179 // and use it in the shader |
179 surface | 180 surface |
180 .pipeline_builder() | 181 .pipeline_builder() |
181 .pipeline(&back_buffer, [0., 0., 0., 0.], |pipeline, mut shd_gate| { | 182 .pipeline(&back_buffer, &PipelineState::default(), |pipeline, mut shd_gate| { |
182 // 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 |
183 let bound_tex = match &tex { | 184 let bound_tex = match &tex { |
184 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), | 185 LoadedTexture::Rgb(tex) => pipeline.bind_texture(tex), |
185 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), | 186 LoadedTexture::Rgba(tex) => pipeline.bind_texture(tex), |
186 }; | 187 }; |
198 iface.mvp.update(*mvp.borrow_inner()); | 199 iface.mvp.update(*mvp.borrow_inner()); |
199 | 200 |
200 let render_state = RenderState::default() | 201 let render_state = RenderState::default() |
201 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); | 202 .set_blending((Equation::Additive, Factor::SrcAlpha, Factor::SrcAlphaComplement)); |
202 | 203 |
203 rdr_gate.render(render_state, |mut tess_gate| { | 204 rdr_gate.render(&render_state, |mut tess_gate| { |
204 tess_gate.render(&tess); | 205 tess_gate.render(&tess); |
205 }); | 206 }); |
206 }); | 207 }); |
207 }); | 208 }); |
208 | 209 |