9#include <Common/assertion.h>
25template<
typename OperatorType,
typename InputTypeA,
typename InputTypeB,
typename OutputType>
26concept CBinaryOperator =
requires (OperatorType op, InputTypeA inputA, InputTypeB inputB)
28 { op(inputA, inputB) } -> std::same_as<OutputType>;
31template<
typename InputTypeA,
typename InputTypeB,
typename OutputType>
35 OutputType
operator () (
const InputTypeA& inputValueA,
const InputTypeB& inputValueB)
const
38 "Must have addition operator for `OutputType` = `InputTypeA` + `InputTypeB`");
40 return inputValueA + inputValueB;
44template<
typename InputTypeA,
typename InputTypeB,
typename OutputType>
48 OutputType
operator () (
const InputTypeA& inputValueA,
const InputTypeB& inputValueB)
const
51 "Must have subtraction operator for `OutputType` = `InputTypeA` - `InputTypeB`");
53 return inputValueA - inputValueB;
57template<
typename InputTypeA,
typename InputTypeB,
typename OutputType>
61 OutputType
operator () (
const InputTypeA& inputValueA,
const InputTypeB& inputValueB)
const
64 "Must have multiplication operator for `OutputType` = `InputTypeA` * `InputTypeB`");
66 return inputValueA * inputValueB;
70template<
typename InputTypeA,
typename InputTypeB,
typename OutputType>
74 OutputType
operator () (
const InputTypeA& inputValueA,
const InputTypeB& inputValueB)
const
77 "Must have multiplication operator for `OutputType` = `InputTypeA` / `InputTypeB`");
79 return inputValueA / inputValueB;
83template<
typename InputTypeA,
typename InputTypeB,
typename OutputType>
87 OutputType
operator () (
const InputTypeA& inputValueA,
const InputTypeB& inputValueB)
const
89 constexpr bool canCallPowMethod =
requires (InputTypeA a, InputTypeB b)
91 { a.pow(b) } -> std::convertible_to<OutputType>;
94 constexpr bool canCallStdPow =
requires (InputTypeA a, InputTypeB b)
96 { std::pow(a, b) } -> std::convertible_to<OutputType>;
99 if constexpr(canCallPowMethod)
101 return inputValueA.pow(inputValueB);
103 else if constexpr(canCallStdPow)
105 return std::pow(inputValueA, inputValueB);
109 PH_STATIC_ASSERT_DEPENDENT_FALSE(OutputType,
110 "Cannot perform power operation for the specified types.");
141 : m_inputA (
std::move(inputA))
142 , m_inputB (
std::move(inputB))
143 , m_operator(
std::move(op))
150 PH_ASSERT(out_value);
152 InputTypeA inputValueA;
153 m_inputA->sample(sampleLocation, &inputValueA);
155 InputTypeB inputValueB;
156 m_inputB->sample(sampleLocation, &inputValueB);
158 *out_value = m_operator(inputValueA, inputValueB);
164 OperatorType m_operator;
Definition SampleLocation.h:22
Definition binary_texture_operators.h:131
TBinaryTextureOperator(InputTexResA inputA, InputTexResB inputB, OperatorType op)
Definition binary_texture_operators.h:140
std::shared_ptr< TTexture< InputTypeA > > InputTexResA
Definition binary_texture_operators.h:133
std::shared_ptr< TTexture< InputTypeB > > InputTexResB
Definition binary_texture_operators.h:134
void sample(const SampleLocation &sampleLocation, OutputType *const out_value) const override
Definition binary_texture_operators.h:146
TBinaryTextureOperator(InputTexResA inputA, InputTexResB inputB)
Definition binary_texture_operators.h:136
Definition binary_texture_operators.h:33
OutputType operator()(const InputTypeA &inputValueA, const InputTypeB &inputValueB) const
Definition binary_texture_operators.h:35
Definition binary_texture_operators.h:72
OutputType operator()(const InputTypeA &inputValueA, const InputTypeB &inputValueB) const
Definition binary_texture_operators.h:74
Definition binary_texture_operators.h:59
OutputType operator()(const InputTypeA &inputValueA, const InputTypeB &inputValueB) const
Definition binary_texture_operators.h:61
Definition binary_texture_operators.h:85
OutputType operator()(const InputTypeA &inputValueA, const InputTypeB &inputValueB) const
Definition binary_texture_operators.h:87
Definition binary_texture_operators.h:46
OutputType operator()(const InputTypeA &inputValueA, const InputTypeB &inputValueB) const
Definition binary_texture_operators.h:48
Check if instances of types can be added together.
Definition traits.h:19
Check if instances of types can be divided.
Definition traits.h:55
Check if instances of types can be multiplied together.
Definition traits.h:43
Check if instances of types can be subtracted.
Definition traits.h:31
Definition binary_texture_operators.h:26
The root for all renderer implementations.
Definition EEngineProject.h:6