Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TUrbg32x2.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/primitive_type.h>
6
7#include <type_traits>
8#include <utility>
9
10namespace ph::math
11{
12
17template<CURBG URBG1, CURBG URBG2 = URBG1>
18class TUrbg32x2 final : public TUniformRandomBitGenerator<TUrbg32x2<URBG1, URBG2>, uint64>
19{
20 static_assert(
21 std::is_same_v<typename URBG1::BitsType, uint32> ||
22 std::is_same_v<typename URBG1::BitsType, uint64>,
23 "URBG1 must have `uint32` or `uint64` bits type.");
24
25 static_assert(
26 std::is_same_v<typename URBG2::BitsType, uint32> ||
27 std::is_same_v<typename URBG2::BitsType, uint64>,
28 "URBG2 must have `uint32` or `uint64` bits type.");
29
30public:
32
33 TUrbg32x2(URBG1 urbg1, URBG2 urbg2);
34
35 uint64 impl_generate();
36 void impl_jumpAhead(uint64 distance);
37
38private:
39 URBG1 m_urbg1;
40 URBG2 m_urbg2;
41};
42
43template<CURBG URBG1, CURBG URBG2>
44inline TUrbg32x2<URBG1, URBG2>::TUrbg32x2(URBG1 urbg1, URBG2 urbg2)
45 : m_urbg1(std::move(urbg1))
46 , m_urbg2(std::move(urbg2))
47{}
48
49template<CURBG URBG1, CURBG URBG2>
51{
52 // Generate 8-byte bits by combining two 4-byte bits
53 // (prefer `URGB1` by placing it in the higher bits, since some algorithm consider higher bits
54 // may be of better quality by default)
55 const auto higher4B = uint64(m_urbg1.template generate<uint32>()) << 32;
56 const auto lower4B = uint64(m_urbg2.template generate<uint32>());
57 return higher4B | lower4B;
58}
59
60template<CURBG URBG1, CURBG URBG2>
61inline void TUrbg32x2<URBG1, URBG2>::impl_jumpAhead(const uint64 distance)
62{
63 m_urbg1.jumpAhead(distance);
64 m_urbg2.jumpAhead(distance);
65}
66
67}// end namespace ph::math
Definition TUniformRandomBitGenerator.h:30
Combining two 32-bit RNGs to form a new 64-bit RNG. If any of the input RNG is not a 32-bit type,...
Definition TUrbg32x2.h:19
uint64 impl_generate()
Definition TUrbg32x2.h:50
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TUrbg32x2)
TUrbg32x2(URBG1 urbg1, URBG2 urbg2)
Definition TUrbg32x2.h:44
void impl_jumpAhead(uint64 distance)
Definition TUrbg32x2.h:61
Math functions and utilities.
Definition TransformInfo.h:10
Definition TAABB2D.h:96