From 83ed6406ac5c2f2fcf55f6e2daa884777ebe2d17 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 29 Mar 2020 21:04:24 +0200 Subject: [PATCH] executable: allow the choice of renderer --- pathtracer/src/main.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pathtracer/src/main.rs b/pathtracer/src/main.rs index f8601a7..aa10c72 100644 --- a/pathtracer/src/main.rs +++ b/pathtracer/src/main.rs @@ -1,8 +1,18 @@ use pathtracer::render::Raytracer; use pathtracer::scene::Scene; use std::path::PathBuf; +use std::str; +use structopt::clap::arg_enum; use structopt::StructOpt; +arg_enum! { + #[derive(Debug)] + enum RenderOption { + Raytracer, + Pathtracer, + } +} + #[derive(StructOpt, Debug)] struct Options { /// Input description for the scene to be rendered. @@ -11,6 +21,15 @@ struct Options { /// Output image for the rendered scene. #[structopt(short, long, parse(from_os_str), default_value = "scene.png")] output: PathBuf, + /// Which renderer should be used on the input scene. + #[structopt( + short, + long, + possible_values = &RenderOption::variants(), + case_insensitive = true, + default_value = "Raytracer" + )] + renderer: RenderOption, } fn main() -> Result<(), Box> { @@ -18,7 +37,10 @@ fn main() -> Result<(), Box> { let f = std::fs::File::open(options.input)?; let scene: Scene = serde_yaml::from_reader(f)?; - let image = Raytracer::new(scene).render(); + let image = match options.renderer { + RenderOption::Raytracer => Raytracer::new(scene).render(), + RenderOption::Pathtracer => todo!(), + }; image.save(options.output)?; Ok(())