Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TPhoton.h
Go to the documentation of this file.
1#pragma once
2
3#include "Utility/utility.h"
4#include "Utility/traits.h"
5#include "Math/TVector3.h"
7
8#include <utility>
9#include <type_traits>
10
11namespace ph
12{
13
14enum class EPhotonData
15{
17 Pos,
18 FromDir,
21};
22
23template<typename T>
24concept CPhoton = std::is_trivially_copyable_v<T> && requires
25{
26 typename T::PMPhotonTag;
27};
28
29template<typename Derived>
31{
32public:
33 using PMPhotonTag = void;
34
35 template<EPhotonData TYPE>
36 static constexpr bool has();
37
38 template<EPhotonData TYPE>
39 decltype(auto) get() const;
40
41 template<EPhotonData TYPE, typename T>
42 void set(const T& value);
43
44// Hide special members as this class is not intended to be used polymorphically.
45// It is derived class's choice to expose them (by defining them in public) or not.
46protected:
48};
49
50template<typename Derived>
51template<EPhotonData TYPE>
52inline constexpr bool TPhoton<Derived>::has()
53{
54 static_assert(requires
55 {
56 { Derived::template impl_has<TYPE>() } -> CSame<bool>;
57 },
58 "A photon mapping photon type must implement a static method callable as "
59 "`impl_has<EPhotonData{}>() -> bool`.");
60
61 return Derived::template impl_has<TYPE>();
62}
63
64template<typename Derived>
65template<EPhotonData TYPE>
66inline decltype(auto) TPhoton<Derived>::get() const
67{
68 static_assert(requires (const Derived derived)
69 {
70 { derived.template impl_get<TYPE>() } -> CNotSame<void>;
71 },
72 "A photon mapping photon type must implement a method callable as "
73 "`impl_get<EPhotonData{}>() const -> (any type)`.");
74
75 return static_cast<const Derived&>(*this).template impl_get<TYPE>();
76}
77
78template<typename Derived>
79template<EPhotonData TYPE, typename T>
80inline void TPhoton<Derived>::set(const T& value)
81{
82 static_assert(requires (Derived derived, T value)
83 {
84 { derived.template impl_set<TYPE>(value) } -> CSame<void>;
85 },
86 "A photon mapping photon type must implement a method callable as "
87 "`impl_set<EPhotonData{}, T{}>(T{}) -> void`.");
88
89 static_cast<Derived&>(*this).template impl_set<TYPE>(value);
90}
91
92}// end namespace ph
Definition TPhoton.h:31
static constexpr bool has()
Definition TPhoton.h:52
decltype(auto) get() const
Definition TPhoton.h:66
void set(const T &value)
Definition TPhoton.h:80
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TPhoton)
void PMPhotonTag
Definition TPhoton.h:33
Definition traits.h:116
Definition TPhoton.h:24
Definition traits.h:113
The root for all renderer implementations.
Definition EEngineProject.h:6
EPhotonData
Definition TPhoton.h:15