Skip to content

Commit

Permalink
Add [ ] operator to other vector types for consistency with floatN
Browse files Browse the repository at this point in the history
  • Loading branch information
redorav committed Aug 21, 2022
1 parent bf7df71 commit dfabd70
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 6 deletions.
12 changes: 12 additions & 0 deletions include/hlsl++_vector_float8.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,18 @@ namespace hlslpp
hlslpp_inline float8(float8&& f) hlslpp_noexcept : vec(f.vec) {}
hlslpp_inline float8& operator = (float8&& f) hlslpp_noexcept { vec = f.vec; return *this; }

float& operator[](int N)
{
hlslpp_assert(N >= 0 && N <= 7);
return f32[N];
}

const float& operator[](int N) const
{
hlslpp_assert(N >= 0 && N <= 7);
return f32[N];
}

union
{
n256 vec;
Expand Down
54 changes: 51 additions & 3 deletions include/hlsl++_vector_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,22 @@ namespace hlslpp

hlslpp_inline operator int32_t() const { return i32[0]; }

int32_t& operator[](int N)
{
hlslpp_assert(N == 0);
return i32[N];
}

const int32_t& operator[](int N) const
{
hlslpp_assert(N == 0);
return i32[N];
}

union
{
n128i vec;
int32_t i32[4];
int32_t i32[1];
#include "swizzle/hlsl++_vector_int_x.h"
};
};
Expand Down Expand Up @@ -371,10 +383,22 @@ namespace hlslpp
hlslpp_inline int2(int2&& i) hlslpp_noexcept : vec(i.vec) {}
hlslpp_inline int2& operator = (int2&& i) hlslpp_noexcept { vec = i.vec; return *this; }

int32_t& operator[](int N)
{
hlslpp_assert(N >= 0 && N <= 1);
return i32[N];
}

const int32_t& operator[](int N) const
{
hlslpp_assert(N >= 0 && N <= 1);
return i32[N];
}

union
{
n128i vec;
int32_t i32[4];
int32_t i32[2];
#include "swizzle/hlsl++_vector_int_x.h"
#include "swizzle/hlsl++_vector_int_y.h"
};
Expand Down Expand Up @@ -410,10 +434,22 @@ namespace hlslpp
hlslpp_inline int3(int3&& i) hlslpp_noexcept : vec(i.vec) {}
hlslpp_inline int3& operator = (int3&& i) hlslpp_noexcept { vec = i.vec; return *this; }

int32_t& operator[](int N)
{
hlslpp_assert(N >= 0 && N <= 2);
return i32[N];
}

const int32_t& operator[](int N) const
{
hlslpp_assert(N >= 0 && N <= 2);
return i32[N];
}

union
{
n128i vec;
int32_t i32[4];
int32_t i32[3];
#include "swizzle/hlsl++_vector_int_x.h"
#include "swizzle/hlsl++_vector_int_y.h"
#include "swizzle/hlsl++_vector_int_z.h"
Expand Down Expand Up @@ -460,6 +496,18 @@ namespace hlslpp
hlslpp_inline int4(int4&& i) hlslpp_noexcept : vec(i.vec) {}
hlslpp_inline int4& operator = (int4&& i) hlslpp_noexcept { vec = i.vec; return *this; }

int32_t& operator[](int N)
{
hlslpp_assert(N >= 0 && N <= 3);
return i32[N];
}

const int32_t& operator[](int N) const
{
hlslpp_assert(N >= 0 && N <= 3);
return i32[N];
}

union
{
n128i vec;
Expand Down
54 changes: 51 additions & 3 deletions include/hlsl++_vector_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,22 @@ namespace hlslpp

hlslpp_inline operator uint32_t() const { return u32[0]; }

uint32_t& operator[](int N)
{
hlslpp_assert(N == 0);
return u32[N];
}

const uint32_t& operator[](int N) const
{
hlslpp_assert(N == 0);
return u32[N];
}

union
{
n128u vec;
uint32_t u32[4];
uint32_t u32[1];
#include "swizzle/hlsl++_vector_uint_x.h"
};
};
Expand Down Expand Up @@ -376,10 +388,22 @@ namespace hlslpp
hlslpp_inline uint2(uint2&& i) hlslpp_noexcept : vec(i.vec) {}
hlslpp_inline uint2& operator = (uint2&& i) hlslpp_noexcept { vec = i.vec; return *this; }

uint32_t& operator[](int N)
{
hlslpp_assert(N >= 0 && N <= 1);
return u32[N];
}

const uint32_t& operator[](int N) const
{
hlslpp_assert(N >= 0 && N <= 1);
return u32[N];
}

union
{
n128u vec;
uint32_t u32[4];
uint32_t u32[2];
#include "swizzle/hlsl++_vector_uint_x.h"
#include "swizzle/hlsl++_vector_uint_y.h"
};
Expand Down Expand Up @@ -416,10 +440,22 @@ namespace hlslpp
hlslpp_inline uint3(uint3&& i) hlslpp_noexcept : vec(i.vec) {}
hlslpp_inline uint3& operator = (uint3&& i) hlslpp_noexcept { vec = i.vec; return *this; }

uint32_t& operator[](int N)
{
hlslpp_assert(N >= 0 && N <= 2);
return u32[N];
}

const uint32_t& operator[](int N) const
{
hlslpp_assert(N >= 0 && N <= 2);
return u32[N];
}

union
{
n128u vec;
uint32_t u32[4];
uint32_t u32[3];
#include "swizzle/hlsl++_vector_uint_x.h"
#include "swizzle/hlsl++_vector_uint_y.h"
#include "swizzle/hlsl++_vector_uint_z.h"
Expand Down Expand Up @@ -466,6 +502,18 @@ namespace hlslpp
hlslpp_inline uint4(uint4&& i) hlslpp_noexcept : vec(i.vec) {}
hlslpp_inline uint4& operator = (uint4&& i) hlslpp_noexcept { vec = i.vec; return *this; }

uint32_t& operator[](int N)
{
hlslpp_assert(N >= 0 && N <= 3);
return u32[N];
}

const uint32_t& operator[](int N) const
{
hlslpp_assert(N >= 0 && N <= 3);
return u32[N];
}

union
{
n128u vec;
Expand Down

0 comments on commit dfabd70

Please sign in to comment.