forked from blender/blender
GPU: GLSL-C++ compilation stubs #4
@ -7,132 +7,144 @@
|
||||
#define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr
|
||||
#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test))
|
||||
|
||||
template<typename T, int Size, bool at_least_vec3 = Size >= 3, bool at_least_vec4 = Size >= 4>
|
||||
struct swizzle {
|
||||
T x;
|
||||
T y;
|
||||
std::enable_if_t<at_least_vec3, T> z;
|
||||
std::enable_if_t<at_least_vec4, T> w;
|
||||
};
|
||||
|
||||
template<typename T, int Size, bool at_least_vec3 = Size >= 3, bool at_least_vec4 = Size >= 4>
|
||||
struct VecBase : swizzle<T, Size> {
|
||||
|
||||
using swizzleT_vec2 = swizzle<T, 2>;
|
||||
using swizzleT_vec3 = swizzle<T, 3>;
|
||||
using swizzleT_vec4 = swizzle<T, 4>;
|
||||
|
||||
using swizzle2_vec3 = std::enable_if_t<at_least_vec3, swizzleT_vec2>;
|
||||
using swizzle3_vec3 = std::enable_if_t<at_least_vec3, swizzleT_vec3>;
|
||||
using swizzle4_vec3 = std::enable_if_t<at_least_vec3, swizzleT_vec4>;
|
||||
|
||||
using swizzle2_vec4 = std::enable_if_t<at_least_vec4, swizzleT_vec2>;
|
||||
using swizzle3_vec4 = std::enable_if_t<at_least_vec4, swizzleT_vec3>;
|
||||
using swizzle4_vec4 = std::enable_if_t<at_least_vec4, swizzleT_vec4>;
|
||||
|
||||
union {
|
||||
swizzleT_vec2 xx, xy, yx, yy;
|
||||
swizzleT_vec3 xxx, xxy, xyx, xyy, yxx, yxy, yyx, yyy;
|
||||
swizzleT_vec4 xxxx, xxxy, xxyx, xxyy, xyxx, xyxy, xyyx, xyyy, yxxx, yxxy, yxyx, yxyy, yyxx,
|
||||
yyxy, yyyx, yyyy;
|
||||
|
||||
swizzle2_vec3 xz, yz, zx, zy, zz, zw;
|
||||
swizzle3_vec3 xxz, xyz, xzx, xzy, xzz, yxz, yyz, yzx, yzy, yzz, zxx, zxy, zxz, zyx, zyy, zyz,
|
||||
zzx, zzy, zzz;
|
||||
swizzle4_vec3 xxxz, xxyz, xxzx, xxzy, xxzz, xyxz, xyyz, xyzx, xyzy, xyzz, xzxx, xzxy, xzxz,
|
||||
xzyx, xzyy, xzyz, xzzx, xzzy, xzzz, yxxz, yxyz, yxzx, yxzy, yxzz, yyxz, yyyz, yyzx, yyzy,
|
||||
yyzz, yzxx, yzxy, yzxz, yzyx, yzyy, yzyz, yzzx, yzzy, yzzz, zxxx, zxxy, zxxz, zxyx, zxyy,
|
||||
zxyz, zxzx, zxzy, zxzz, zyxx, zyxy, zyxz, zyyx, zyyy, zyyz, zyzx, zyzy, zyzz, zzxx, zzxy,
|
||||
zzxz, zzyx, zzyy, zzyz, zzzx, zzzy, zzzz;
|
||||
|
||||
swizzle2_vec4 xw, yw, wx, wy, wz, ww;
|
||||
swizzle3_vec4 xxw, xyw, xzw, xwx, xwy, xwz, xww, yxw, yyw, yzw, ywx, ywy, ywz, yww, zxw, zyw,
|
||||
zzw, zwx, zwy, zwz, zww, wxx, wxy, wxz, wxw, wyx, wyy, wyz, wyw, wzx, wzy, wzz, wzw, wwx,
|
||||
wwy, wwz, www;
|
||||
swizzle4_vec4 xxxw, xxyw, xxzw, xxwx, xxwy, xxwz, xxww, xyxw, xyyw, xyzw, xywx, xywy, xywz,
|
||||
xyww, xzxw, xzyw, xzzw, xzwx, xzwy, xzwz, xzww, xwxx, xwxy, xwxz, xwxw, xwyx, xwyy, xwyz,
|
||||
xwyw, xwzx, xwzy, xwzz, xwzw, xwwx, xwwy, xwwz, xwww, yxxw, yxyw, yxzw, yxwx, yxwy, yxwz,
|
||||
yxww, yyxw, yyyw, yyzw, yywx, yywy, yywz, yyww, yzxw, yzyw, yzzw, yzwx, yzwy, yzwz, yzww,
|
||||
ywxx, ywxy, ywxz, ywxw, ywyx, ywyy, ywyz, ywyw, ywzx, ywzy, ywzz, ywzw, ywwx, ywwy, ywwz,
|
||||
ywww, zxxw, zxyw, zxzw, zxwx, zxwy, zxwz, zxww, zyxw, zyyw, zyzw, zywx, zywy, zywz, zyww,
|
||||
zzxw, zzyw, zzzw, zzwx, zzwy, zzwz, zzww, zwxx, zwxy, zwxz, zwxw, zwyx, zwyy, zwyz, zwyw,
|
||||
zwzx, zwzy, zwzz, zwzw, zwwx, zwwy, zwwz, zwww, wxxx, wxxy, wxxz, wxxw, wxyx, wxyy, wxyz,
|
||||
wxyw, wxzx, wxzy, wxzz, wxzw, wxwx, wxwy, wxwz, wxww, wyxx, wyxy, wyxz, wyxw, wyyx, wyyy,
|
||||
wyyz, wyyw, wyzx, wyzy, wyzz, wyzw, wywx, wywy, wywz, wyww, wzxx, wzxy, wzxz, wzxw, wzyx,
|
||||
wzyy, wzyz, wzyw, wzzx, wzzy, wzzz, wzzw, wzwx, wzwy, wzwz, wzww, wwxx, wwxy, wwxz, wwxw,
|
||||
wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww;
|
||||
};
|
||||
|
||||
VecBase() {}
|
||||
VecBase(const VecBase &) {}
|
||||
|
||||
VecBase(T) {}
|
||||
VecBase(const swizzle<T, Size> &) {}
|
||||
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 2)> VecBase(T, T) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 3)> VecBase(T, T, T) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 4)> VecBase(T, T, T, T) {}
|
||||
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 3)> VecBase(swizzle<T, 2>, T) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 3)> VecBase(T, swizzle<T, 2>) {}
|
||||
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 4)> VecBase(swizzle<T, 2>, T, T) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 4)> VecBase(T, swizzle<T, 2>, T) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 4)> VecBase(T, T, swizzle<T, 2>) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 4)> VecBase(swizzle<T, 2>, swizzle<T, 2>) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 4)> VecBase(swizzle<T, 3>, T) {}
|
||||
template<BLI_ENABLE_IF_VEC(Size, == 4)> VecBase(T, swizzle<T, 3>) {}
|
||||
|
||||
template<typename T, int Sz> struct VecOp {
|
||||
T operator[](int) {}
|
||||
|
||||
VecOp operator+() const {}
|
||||
VecOp operator-() const {}
|
||||
|
||||
VecOp operator+(VecOp b) const {}
|
||||
VecOp operator-(VecOp b) const {}
|
||||
VecOp operator/(VecOp b) const {}
|
||||
VecOp operator*(VecOp b) const {}
|
||||
|
||||
VecOp operator+=(VecOp b) const {}
|
||||
VecOp operator-=(VecOp b) const {}
|
||||
VecOp operator/=(VecOp b) const {}
|
||||
VecOp operator*=(VecOp b) const {}
|
||||
|
||||
VecOp operator+(T b) const {}
|
||||
VecOp operator-(T b) const {}
|
||||
VecOp operator/(T b) const {}
|
||||
VecOp operator*(T b) const {}
|
||||
|
||||
VecOp operator+=(T b) const {}
|
||||
VecOp operator-=(T b) const {}
|
||||
VecOp operator/=(T b) const {}
|
||||
VecOp operator*=(T b) const {}
|
||||
|
||||
friend VecOp operator+(T a, VecOp b) {}
|
||||
friend VecOp operator-(T a, VecOp b) {}
|
||||
friend VecOp operator/(T a, VecOp b) {}
|
||||
friend VecOp operator*(T a, VecOp b) {}
|
||||
|
||||
#define BLI_INT_OP(_T) template<typename U = _T, BLI_ENABLE_IF((std::is_integral_v<U>))>
|
||||
|
||||
BLI_INT_OP(T) VecOp operator%(VecOp b) {}
|
||||
BLI_INT_OP(T) VecOp operator&(VecOp b) {}
|
||||
BLI_INT_OP(T) VecOp operator|(VecOp b) {}
|
||||
BLI_INT_OP(T) VecOp operator^(VecOp b) {}
|
||||
|
||||
BLI_INT_OP(T) VecOp operator%=(VecOp b) {}
|
||||
BLI_INT_OP(T) VecOp operator&=(VecOp b) {}
|
||||
BLI_INT_OP(T) VecOp operator|=(VecOp b) {}
|
||||
BLI_INT_OP(T) VecOp operator^=(VecOp b) {}
|
||||
|
||||
BLI_INT_OP(T) VecOp operator%(T b) {}
|
||||
BLI_INT_OP(T) VecOp operator&(T b) {}
|
||||
BLI_INT_OP(T) VecOp operator|(T b) {}
|
||||
BLI_INT_OP(T) VecOp operator^(T b) {}
|
||||
|
||||
BLI_INT_OP(T) VecOp operator%=(T b) {}
|
||||
BLI_INT_OP(T) VecOp operator&=(T b) {}
|
||||
BLI_INT_OP(T) VecOp operator|=(T b) {}
|
||||
BLI_INT_OP(T) VecOp operator^=(T b) {}
|
||||
|
||||
BLI_INT_OP(T) friend VecOp operator%(T a, VecOp<T, Sz> b) {}
|
||||
BLI_INT_OP(T) friend VecOp operator&(T a, VecOp<T, Sz> b) {}
|
||||
BLI_INT_OP(T) friend VecOp operator|(T a, VecOp<T, Sz> b) {}
|
||||
BLI_INT_OP(T) friend VecOp operator^(T a, VecOp<T, Sz> b) {}
|
||||
};
|
||||
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator+(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator-(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator/(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator*(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
template<typename T, int Sz> struct VecBase {};
|
||||
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator+(swizzle<T, Sz> a, T b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator-(swizzle<T, Sz> a, T b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator/(swizzle<T, Sz> a, T b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator*(swizzle<T, Sz> a, T b) {}
|
||||
template<typename T> struct VecSwizzle2 {
|
||||
static VecBase<T, 2> xx, xy, yx, yy;
|
||||
static VecBase<T, 3> xxx, xxy, xyx, xyy, yxx, yxy, yyx, yyy;
|
||||
static VecBase<T, 4> xxxx, xxxy, xxyx, xxyy, xyxx, xyxy, xyyx, xyyy, yxxx, yxxy, yxyx, yxyy,
|
||||
yyxx, yyxy, yyyx, yyyy;
|
||||
};
|
||||
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator+(T a, swizzle<T, Sz> b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator-(T a, swizzle<T, Sz> b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator/(T a, swizzle<T, Sz> b) {}
|
||||
template<typename T, int Sz> VecBase<T, Sz> operator*(T a, swizzle<T, Sz> b) {}
|
||||
template<typename T> struct VecSwizzle3 : VecSwizzle2<T> {
|
||||
static VecBase<T, 2> xz, yz, zx, zy, zz, zw;
|
||||
static VecBase<T, 3> xxz, xyz, xzx, xzy, xzz, yxz, yyz, yzx, yzy, yzz, zxx, zxy, zxz, zyx, zyy,
|
||||
zyz, zzx, zzy, zzz;
|
||||
static VecBase<T, 4> xxxz, xxyz, xxzx, xxzy, xxzz, xyxz, xyyz, xyzx, xyzy, xyzz, xzxx, xzxy,
|
||||
xzxz, xzyx, xzyy, xzyz, xzzx, xzzy, xzzz, yxxz, yxyz, yxzx, yxzy, yxzz, yyxz, yyyz, yyzx,
|
||||
yyzy, yyzz, yzxx, yzxy, yzxz, yzyx, yzyy, yzyz, yzzx, yzzy, yzzz, zxxx, zxxy, zxxz, zxyx,
|
||||
zxyy, zxyz, zxzx, zxzy, zxzz, zyxx, zyxy, zyxz, zyyx, zyyy, zyyz, zyzx, zyzy, zyzz, zzxx,
|
||||
zzxy, zzxz, zzyx, zzyy, zzyz, zzzx, zzzy, zzzz;
|
||||
};
|
||||
|
||||
/* Needed to support double literals. */
|
||||
template<int Sz> VecBase<float, Sz> operator+(swizzle<float, Sz> a, double b) {}
|
||||
template<int Sz> VecBase<float, Sz> operator-(swizzle<float, Sz> a, double b) {}
|
||||
template<int Sz> VecBase<float, Sz> operator/(swizzle<float, Sz> a, double b) {}
|
||||
template<int Sz> VecBase<float, Sz> operator*(swizzle<float, Sz> a, double b) {}
|
||||
template<typename T> struct VecSwizzle4 : VecSwizzle3<T> {
|
||||
static VecBase<T, 2> xw, yw, wx, wy, wz, ww;
|
||||
static VecBase<T, 3> xxw, xyw, xzw, xwx, xwy, xwz, xww, yxw, yyw, yzw, ywx, ywy, ywz, yww, zxw,
|
||||
zyw, zzw, zwx, zwy, zwz, zww, wxx, wxy, wxz, wxw, wyx, wyy, wyz, wyw, wzx, wzy, wzz, wzw,
|
||||
wwx, wwy, wwz, www;
|
||||
static VecBase<T, 4> xxxw, xxyw, xxzw, xxwx, xxwy, xxwz, xxww, xyxw, xyyw, xyzw, xywx, xywy,
|
||||
xywz, xyww, xzxw, xzyw, xzzw, xzwx, xzwy, xzwz, xzww, xwxx, xwxy, xwxz, xwxw, xwyx, xwyy,
|
||||
xwyz, xwyw, xwzx, xwzy, xwzz, xwzw, xwwx, xwwy, xwwz, xwww, yxxw, yxyw, yxzw, yxwx, yxwy,
|
||||
yxwz, yxww, yyxw, yyyw, yyzw, yywx, yywy, yywz, yyww, yzxw, yzyw, yzzw, yzwx, yzwy, yzwz,
|
||||
yzww, ywxx, ywxy, ywxz, ywxw, ywyx, ywyy, ywyz, ywyw, ywzx, ywzy, ywzz, ywzw, ywwx, ywwy,
|
||||
ywwz, ywww, zxxw, zxyw, zxzw, zxwx, zxwy, zxwz, zxww, zyxw, zyyw, zyzw, zywx, zywy, zywz,
|
||||
zyww, zzxw, zzyw, zzzw, zzwx, zzwy, zzwz, zzww, zwxx, zwxy, zwxz, zwxw, zwyx, zwyy, zwyz,
|
||||
zwyw, zwzx, zwzy, zwzz, zwzw, zwwx, zwwy, zwwz, zwww, wxxx, wxxy, wxxz, wxxw, wxyx, wxyy,
|
||||
wxyz, wxyw, wxzx, wxzy, wxzz, wxzw, wxwx, wxwy, wxwz, wxww, wyxx, wyxy, wyxz, wyxw, wyyx,
|
||||
wyyy, wyyz, wyyw, wyzx, wyzy, wyzz, wyzw, wywx, wywy, wywz, wyww, wzxx, wzxy, wzxz, wzxw,
|
||||
wzyx, wzyy, wzyz, wzyw, wzzx, wzzy, wzzz, wzzw, wzwx, wzwy, wzwz, wzww, wwxx, wwxy, wwxz,
|
||||
wwxw, wwyx, wwyy, wwyz, wwyw, wwzx, wwzy, wwzz, wwzw, wwwx, wwwy, wwwz, wwww;
|
||||
};
|
||||
|
||||
template<int Sz> VecBase<float, Sz> operator+(double a, swizzle<float, Sz> b) {}
|
||||
template<int Sz> VecBase<float, Sz> operator-(double a, swizzle<float, Sz> b) {}
|
||||
template<int Sz> VecBase<float, Sz> operator/(double a, swizzle<float, Sz> b) {}
|
||||
template<int Sz> VecBase<float, Sz> operator*(double a, swizzle<float, Sz> b) {}
|
||||
template<typename T> struct VecBase<T, 2> : VecOp<T, 2>, VecSwizzle2<T> {
|
||||
T x, y;
|
||||
|
||||
#define BLI_INT_OP template<typename T, int Sz, BLI_ENABLE_IF((std::is_integral_v<T>))>
|
||||
BLI_INT_OP VecBase<T, Sz> operator%(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator&(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator|(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator^(swizzle<T, Sz> a, swizzle<T, Sz> b) {}
|
||||
VecBase() = default;
|
||||
VecBase(VecOp<T, 2>) {}
|
||||
explicit VecBase(T) {}
|
||||
explicit VecBase(T, T) {}
|
||||
};
|
||||
|
||||
BLI_INT_OP VecBase<T, Sz> operator%(swizzle<T, Sz> a, T b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator&(swizzle<T, Sz> a, T b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator|(swizzle<T, Sz> a, T b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator^(swizzle<T, Sz> a, T b) {}
|
||||
template<typename T> struct VecBase<T, 3> : VecOp<T, 2>, VecSwizzle3<T> {
|
||||
T x, y, z;
|
||||
|
||||
BLI_INT_OP VecBase<T, Sz> operator%(T a, swizzle<T, Sz> b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator&(T a, swizzle<T, Sz> b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator|(T a, swizzle<T, Sz> b) {}
|
||||
BLI_INT_OP VecBase<T, Sz> operator^(T a, swizzle<T, Sz> b) {}
|
||||
VecBase() = default;
|
||||
VecBase(VecOp<T, 3>) {}
|
||||
explicit VecBase(T) {}
|
||||
explicit VecBase(T, T, T) {}
|
||||
explicit VecBase(VecBase<T, 2>, T) {}
|
||||
explicit VecBase(T, VecBase<T, 2>) {}
|
||||
};
|
||||
|
||||
template<typename T> struct VecBase<T, 4> : VecOp<T, 3>, VecSwizzle4<T> {
|
||||
T x, y, z, w;
|
||||
|
||||
VecBase() = default;
|
||||
VecBase(VecOp<T, 4>) {}
|
||||
explicit VecBase(T) {}
|
||||
explicit VecBase(T, T, T, T) {}
|
||||
explicit VecBase(VecBase<T, 2>, T, T) {}
|
||||
explicit VecBase(T, VecBase<T, 2>, T) {}
|
||||
explicit VecBase(T, T, VecBase<T, 2>) {}
|
||||
explicit VecBase(VecBase<T, 2>, VecBase<T, 2>) {}
|
||||
explicit VecBase(VecBase<T, 3>, T) {}
|
||||
explicit VecBase(T, VecBase<T, 3>) {}
|
||||
};
|
||||
|
||||
using uint = unsigned int;
|
||||
|
||||
using float2 = VecBase<float, 2>;
|
||||
using float3 = VecBase<float, 3>;
|
||||
using float4 = VecBase<float, 4>;
|
||||
using float2 = VecBase<double, 2>;
|
||||
using float3 = VecBase<double, 3>;
|
||||
using float4 = VecBase<double, 4>;
|
||||
|
||||
using uint2 = VecBase<uint, 2>;
|
||||
using uint3 = VecBase<uint, 3>;
|
||||
|
Loading…
Reference in New Issue
Block a user