From d883ff94342f418b87ac2333b3fdf779bd2dfa0f Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 13 Apr 2022 13:34:50 +0800 Subject: Generalize hitlist and basic_viewport. (HDR in the future) --- viewport.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'viewport.h') diff --git a/viewport.h b/viewport.h index 2610ff5..72e938e 100644 --- a/viewport.h +++ b/viewport.h @@ -43,13 +43,14 @@ public: template class viewport { public: - virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0; + virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0; }; using viewport8b = viewport; // Single sampled viewport which supports bias sampling -class basic_viewport : public viewport8b { +template +class basic_viewport : public viewport { const double half_width, half_height; // viewport size const vec3d center; // coordinate of the viewport center point @@ -59,22 +60,22 @@ public: basic_viewport(double width, double height, vec3d viewport_center) : half_width(width / 2.0), half_height(height / 2.0), center(viewport_center) {} - virtual bitmap8b - render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) override { + virtual bitmap + render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) override { bias_ctx bc{}; return render(world, viewpoint, image_width, image_height, bc); } - virtual /** + /** * Generate the image seen on given viewpoint. * @param bx bias on x axis (0.0 <= bx < 1.0) * @param by bias on y axis (0.0 <= by < 1.0) * @return */ - bitmap8b render(const hitlist &world, vec3d viewpoint, - uint16_t image_width, uint16_t image_height, - bias_ctx &bias) const { - bitmap8b image{image_width, image_height}; + virtual bitmap render(const hitlist &world, vec3d viewpoint, + uint16_t image_width, uint16_t image_height, + bias_ctx &bias) const { + bitmap image{image_width, image_height}; double bx, by; const auto r = center - viewpoint; const int img_hw = image_width / 2, img_hh = image_height / 2; @@ -101,4 +102,6 @@ public: } }; +using basic_viewport8b = basic_viewport; + #endif //RT_VIEWPORT_H -- cgit v1.2.3