summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-13 14:52:46 +0800
committerKeuin <[email protected]>2022-04-13 14:52:46 +0800
commitd802e8367e7709966747efbe57c90f1b8a08f83b (patch)
tree6d5501d32bbb8a5375ac7ba119c72c601070f4be
parent3caba9694f6e6f0f8b51dcffd7619fa04fbe6c29 (diff)
Use basic_viewport8b if antialiasing is not enabled.
-rw-r--r--main_simple_scanner.cpp12
-rw-r--r--viewport.h1
2 files changed, 10 insertions, 3 deletions
diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp
index eaaa8b7..bd870d7 100644
--- a/main_simple_scanner.cpp
+++ b/main_simple_scanner.cpp
@@ -26,7 +26,12 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport
std::cerr << "Antialiasing Samples: " << samples << std::endl;
}
double r = 1.0 * image_width / image_height;
- aa_viewport8b vp{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}, samples};
+ viewport8b *vp;
+ if (samples == 1) {
+ vp = new basic_viewport8b{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}};
+ } else {
+ vp = new aa_viewport8b{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}, samples};
+ }
hitlist8b world;
world.add_object(std::make_shared<sphere>(
vec3d{0, -100.5, -1},
@@ -34,8 +39,8 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport
world.add_object(std::make_shared<sphere>(vec3d{0, 0, sphere_z}, sphere_r));
timer tm;
tm.start_measure();
- auto image = vp.render(world, vec3d::zero(),
- image_width, image_height); // camera position as the coordinate origin
+ auto image = vp->render(world, vec3d::zero(),
+ image_width, image_height); // camera position as the coordinate origin
tm.stop_measure();
if (!caption.empty()) {
image.print(caption,
@@ -47,6 +52,7 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport
} else {
std::cerr << "NOPRINT is defined. PPM Image won't be printed." << std::endl;
}
+ delete vp;
}
int main(int argc, char **argv) {
diff --git a/viewport.h b/viewport.h
index b4e4e56..74bdfcd 100644
--- a/viewport.h
+++ b/viewport.h
@@ -44,6 +44,7 @@ template<typename T>
class viewport {
public:
virtual bitmap<T> render(const hitlist<T> &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0;
+ virtual ~viewport() = default;
};
using viewport8b = viewport<uint8_t>;