From 9c6b9af31abf4e2c2688db72912f8fb1f637082a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 29 Mar 2020 21:23:42 +0200 Subject: [PATCH] library: render: add Renderer trait --- pathtracer/src/render/mod.rs | 9 +++++++++ pathtracer/src/render/raytracer.rs | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/pathtracer/src/render/mod.rs b/pathtracer/src/render/mod.rs index dd37450..89cde0c 100644 --- a/pathtracer/src/render/mod.rs +++ b/pathtracer/src/render/mod.rs @@ -1,4 +1,13 @@ //! Define the different kinds of renderers for use on a given scene. +use image::RgbImage; + +/// Each renderer implements this trait, to be called after being built. +pub trait Renderer { + /// Render the [`Scene`] using the chosen rendering technique. + /// + /// [`Scene`]: ../scene/scene/struct.Scene.html + fn render(&self) -> RgbImage; +} mod raytracer; pub use raytracer::*; diff --git a/pathtracer/src/render/raytracer.rs b/pathtracer/src/render/raytracer.rs index f231189..b6c564d 100644 --- a/pathtracer/src/render/raytracer.rs +++ b/pathtracer/src/render/raytracer.rs @@ -1,4 +1,5 @@ use super::utils::*; +use super::Renderer; use crate::scene::{Object, Scene}; use crate::{ core::{LightProperties, LinearColor, ReflTransEnum}, @@ -247,3 +248,9 @@ impl Raytracer { .sum() } } + +impl Renderer for Raytracer { + fn render(&self) -> RgbImage { + self.render() + } +}