# HG changeset patch # User Emmanuel Gil Peyrot # Date 1564770285 -7200 # Node ID 01849ffd0180dcbd74d85c4069f22e2b513644d8 # Parent 9e40bd5cc26d9ec270c3d0f23de986c2eea6a6df Add an anmrenderer binary. diff --git a/Cargo.toml b/Cargo.toml --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,10 @@ license = "GPL-3.0-or-later" [dependencies] nom = "5" +image = { version = "0.22", default-features = false, features = ["png_codec"] } +luminance = { version = "*", path = "../luminance/luminance" } +luminance-glfw = { version = "*", path = "../luminance/luminance-glfw", default-features = false } +luminance-derive = { version = "*", path = "../luminance/luminance-derive" } + +[profile.dev] +panic = "abort" diff --git a/examples/anmrenderer.rs b/examples/anmrenderer.rs new file mode 100644 --- /dev/null +++ b/examples/anmrenderer.rs @@ -0,0 +1,231 @@ +use image::GenericImageView; +use luminance::context::GraphicsContext; +use luminance::framebuffer::Framebuffer; +use luminance::pipeline::BoundTexture; +use luminance::pixel::{RGB, Floating}; +use luminance::render_state::RenderState; +use luminance::shader::program::{Program, Uniform}; +use luminance::tess::{Mode, TessBuilder}; +use luminance::texture::{Dim2, Flat, Sampler, Texture, GenMipmaps}; +use luminance_derive::{Semantics, Vertex, UniformInterface}; +use luminance_glfw::event::{Action, Key, WindowEvent}; +use luminance_glfw::surface::{GlfwSurface, Surface, WindowDim, WindowOpt}; +use touhou::th06::anm0::Anm0; +use touhou::th06::anm0_vm::{AnmRunner, Sprite, Vertex as FakeVertex}; +use touhou::util::math::{perspective, setup_camera}; +use std::cell::RefCell; +use std::fs::File; +use std::io::{BufReader, Read}; +use std::rc::Rc; +use std::env; +use std::path::Path; + +const VS: &str = r#" +in ivec3 in_position; +in vec2 in_texcoord; +in uvec4 in_color; + +uniform mat4 mvp; + +out vec2 texcoord; +out vec4 color; + +void main() +{ + gl_Position = mvp * vec4(vec3(in_position), 1.0); + texcoord = vec2(in_texcoord); + + // Normalized from the u8 being passed. + color = vec4(in_color) / 255.; +} +"#; + +const FS: &str = r#" +in vec2 texcoord; +in vec4 color; + +uniform sampler2D color_map; + +out vec4 frag_color; + +void main() +{ + frag_color = texture(color_map, texcoord) * color; +} +"#; + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Semantics)] +pub enum Semantics { + #[sem(name = "in_position", repr = "[i16; 3]", wrapper = "VertexPosition")] + Position, + + #[sem(name = "in_texcoord", repr = "[f32; 2]", wrapper = "VertexTexcoord")] + Texcoord, + + #[sem(name = "in_color", repr = "[u8; 4]", wrapper = "VertexColor")] + Color, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug, PartialEq, Vertex)] +#[vertex(sem = "Semantics")] +struct Vertex { + pos: VertexPosition, + uv: VertexTexcoord, + rgba: VertexColor, +} + +#[derive(UniformInterface)] +struct ShaderInterface { + // the 'static lifetime acts as “anything” here + color_map: Uniform<&'static BoundTexture<'static, Flat, Dim2, Floating>>, + + #[uniform(name = "mvp")] + mvp: Uniform<[[f32; 4]; 4]>, +} + +fn main() { + // Parse arguments. + let args: Vec<_> = env::args().collect(); + if args.len() != 4 { + eprintln!("Usage: {}