6
6
#define _NBL_BUILTIN_HLSL_COMPLEX_INCLUDED_
7
7
8
8
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
9
+ #include <nbl/builtin/hlsl/functional.hlsl>
10
+
11
+ using namespace nbl::hlsl;
9
12
10
13
// -------------------------------------- CPP VERSION ------------------------------------
11
14
#ifndef __HLSL_VERSION
@@ -44,8 +47,6 @@ complex_t<Scalar> rotateRight(NBL_CONST_REF_ARG(complex_t<Scalar>) value)
44
47
// -------------------------------------- HLSL VERSION ---------------------------------------
45
48
#else
46
49
47
- #include "nbl/builtin/hlsl/functional.hlsl"
48
-
49
50
namespace nbl
50
51
{
51
52
namespace hlsl
@@ -164,6 +165,8 @@ struct complex_t
164
165
template<typename Scalar>
165
166
struct plus< complex_t<Scalar> >
166
167
{
168
+ using type_t = complex_t<Scalar>;
169
+
167
170
complex_t<Scalar> operator ()(NBL_CONST_REF_ARG (complex_t<Scalar>) lhs, NBL_CONST_REF_ARG (complex_t<Scalar>) rhs)
168
171
{
169
172
return lhs + rhs;
@@ -175,6 +178,8 @@ struct plus< complex_t<Scalar> >
175
178
template<typename Scalar>
176
179
struct minus< complex_t<Scalar> >
177
180
{
181
+ using type_t = complex_t<Scalar>;
182
+
178
183
complex_t<Scalar> operator ()(NBL_CONST_REF_ARG (complex_t<Scalar>) lhs, NBL_CONST_REF_ARG (complex_t<Scalar>) rhs)
179
184
{
180
185
return lhs - rhs;
@@ -186,6 +191,8 @@ struct minus< complex_t<Scalar> >
186
191
template<typename Scalar>
187
192
struct multiplies< complex_t<Scalar> >
188
193
{
194
+ using type_t = complex_t<Scalar>;
195
+
189
196
complex_t<Scalar> operator ()(NBL_CONST_REF_ARG (complex_t<Scalar>) lhs, NBL_CONST_REF_ARG (complex_t<Scalar>) rhs)
190
197
{
191
198
return lhs * rhs;
@@ -202,6 +209,8 @@ struct multiplies< complex_t<Scalar> >
202
209
template<typename Scalar>
203
210
struct divides< complex_t<Scalar> >
204
211
{
212
+ using type_t = complex_t<Scalar>;
213
+
205
214
complex_t<Scalar> operator ()(NBL_CONST_REF_ARG (complex_t<Scalar>) lhs, NBL_CONST_REF_ARG (complex_t<Scalar>) rhs)
206
215
{
207
216
return lhs / rhs;
@@ -417,17 +426,20 @@ complex_t<Scalar> rotateRight(NBL_CONST_REF_ARG(complex_t<Scalar>) value)
417
426
return retVal;
418
427
}
419
428
420
- // Annoyed at having to write a lot of boilerplate to do a select
421
- // Essentially returns what you'd expect from doing `condition ? a : b`
422
429
template<typename Scalar>
423
- complex_t<Scalar> ternaryOperator ( bool condition, NBL_CONST_REF_ARG (complex_t<Scalar>) a, NBL_CONST_REF_ARG ( complex_t<Scalar>) b)
430
+ struct ternary_operator< complex_t<Scalar> >
424
431
{
425
- const vector <Scalar, 2 > aVector = vector <Scalar, 2 >(a.real (), a.imag ());
426
- const vector <Scalar, 2 > bVector = vector <Scalar, 2 >(b.real (), b.imag ());
427
- const vector <Scalar, 2 > resultVector = condition ? aVector : bVector;
428
- const complex_t<Scalar> result = { resultVector.x, resultVector.y };
429
- return result;
430
- }
432
+ using type_t = complex_t<Scalar>;
433
+
434
+ complex_t<Scalar> operator ()(bool condition, NBL_CONST_REF_ARG (complex_t<Scalar>) lhs, NBL_CONST_REF_ARG (complex_t<Scalar>) rhs)
435
+ {
436
+ const vector <Scalar, 2 > lhsVector = vector <Scalar, 2 >(lhs.real (), lhs.imag ());
437
+ const vector <Scalar, 2 > rhsVector = vector <Scalar, 2 >(rhs.real (), rhs.imag ());
438
+ const vector <Scalar, 2 > resultVector = condition ? lhsVector : rhsVector;
439
+ const complex_t<Scalar> result = { resultVector.x, resultVector.y };
440
+ return result;
441
+ }
442
+ };
431
443
432
444
433
445
}
0 commit comments