summaryrefslogtreecommitdiff
path: root/aa.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-17 18:21:41 +0800
committerKeuin <[email protected]>2022-04-17 18:21:41 +0800
commit23b2d8939528bd44a40702482ef50d7b8c063254 (patch)
treedd6bf823193cc074a31eddee2b1d1cbe7d9651be /aa.h
parent82c24472a4bf9463d39cbb2db0d06cbbf151fe2f (diff)
Configurable thread count.
Diffstat (limited to 'aa.h')
-rw-r--r--aa.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/aa.h b/aa.h
index acdbc88..769eb31 100644
--- a/aa.h
+++ b/aa.h
@@ -18,9 +18,11 @@ template<typename T>
class aa_viewport : public viewport<T> {
unsigned samples;
std::vector<basic_viewport<T>> *subviews;
+ int threads;
public:
- aa_viewport(double width, double height, vec3d viewport_center, unsigned samples) : samples(samples) {
+ aa_viewport(double width, double height, vec3d viewport_center, unsigned samples, int threads = -1)
+ : samples(samples), threads{(threads > 0) ? threads : (int)std::thread::hardware_concurrency()} {
assert(samples >= 1);
subviews = new std::vector<basic_viewport<T>>{samples, {width, height, viewport_center}};
}
@@ -31,9 +33,9 @@ public:
virtual bitmap<T> render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) {
static constexpr auto seed = 123456789012345678ULL;
- const unsigned thread_count = std::min(std::thread::hardware_concurrency(), samples);
+ const unsigned thread_count = std::min((unsigned)threads, samples);
std::cerr << "Preparing tasks..." << std::endl;
- std::vector<bitmap<T>> images{samples, {0,0}};
+ std::vector<bitmap<T>> images{samples, {0, 0}};
std::mt19937_64 seedgen{seed}; // generates seeds for workers
const struct s_render_shared {