mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-24 12:55:39 +01:00
Abstract away a bit more logic in order to allow us to easily override the core vector operations if need be.
This commit is contained in:
parent
01a38dc76b
commit
47074c1224
@ -137,6 +137,41 @@ class Pixel : public Vector4<uint16> {
|
|||||||
};
|
};
|
||||||
REGISTER_VECTOR_TYPE(Pixel);
|
REGISTER_VECTOR_TYPE(Pixel);
|
||||||
|
|
||||||
|
// Overload operators so that we can preserve bit depths...
|
||||||
|
template<typename ScalarType>
|
||||||
|
static inline Pixel ScalarMultiply(const Pixel &p, const ScalarType &s) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++)
|
||||||
|
a(i) = p(i) * s;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ScalarType>
|
||||||
|
static inline Pixel ScalarDivide(const Pixel &p, const ScalarType &s) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++)
|
||||||
|
a(i) = p(i) / s;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorType>
|
||||||
|
static inline Pixel VectorAddition(const Pixel &p, const VectorType &v) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++) {
|
||||||
|
a(i) += v(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename VectorType>
|
||||||
|
static inline Pixel VectorSubtraction(const Pixel &p, const VectorType &v) {
|
||||||
|
Pixel a(p);
|
||||||
|
for(int i = 0; i < Pixel::Size; i++) {
|
||||||
|
a(i) -= v(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace FasTC
|
} // namespace FasTC
|
||||||
|
|
||||||
#endif // BASE_INCLUDE_PIXEL_H_
|
#endif // BASE_INCLUDE_PIXEL_H_
|
||||||
|
@ -88,38 +88,47 @@ namespace FasTC {
|
|||||||
|
|
||||||
// Operators
|
// Operators
|
||||||
template<typename VectorTypeOne, typename VectorTypeTwo>
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
static inline VectorTypeOne operator+(const VectorTypeOne &v1,
|
static inline VectorTypeOne VectorAddition(const VectorTypeOne &v1,
|
||||||
const VectorTypeTwo &v2) {
|
const VectorTypeTwo &v2) {
|
||||||
VectorTypeOne a;
|
VectorTypeOne a;
|
||||||
for(int i = 0; i < VectorTypeOne::Size; i++)
|
for(int i = 0; i < VectorTypeOne::Size; i++) {
|
||||||
a(i) = v1(i) + v2(i);
|
a(i) = v1(i) + v2(i);
|
||||||
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne operator+(const VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
return VectorAddition(v1, v2);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename VectorTypeOne, typename VectorTypeTwo>
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
static inline VectorTypeOne &operator+=(VectorTypeOne &v1,
|
static inline VectorTypeOne &operator+=(VectorTypeOne &v1,
|
||||||
const VectorTypeTwo &v2) {
|
const VectorTypeTwo &v2) {
|
||||||
for(int i = 0; i < VectorTypeOne::Size; i++)
|
return v1 = VectorAddition(v1, v2);
|
||||||
v1(i) += v2(i);
|
}
|
||||||
return v1;
|
|
||||||
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
|
static inline VectorTypeOne VectorSubtraction(const VectorTypeOne &v1,
|
||||||
|
const VectorTypeTwo &v2) {
|
||||||
|
VectorTypeOne a;
|
||||||
|
for(int i = 0; i < VectorTypeOne::Size; i++) {
|
||||||
|
a(i) = v1(i) - v2(i);
|
||||||
|
}
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VectorTypeOne, typename VectorTypeTwo>
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
static inline VectorTypeOne operator-(const VectorTypeOne &v1,
|
static inline VectorTypeOne operator-(const VectorTypeOne &v1,
|
||||||
const VectorTypeTwo &v2) {
|
const VectorTypeTwo &v2) {
|
||||||
VectorTypeOne a;
|
return VectorSubtraction(v1, v2);
|
||||||
for(int i = 0; i < VectorTypeOne::Size; i++)
|
|
||||||
a(i) = v1(i) - v2(i);
|
|
||||||
return a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VectorTypeOne, typename VectorTypeTwo>
|
template<typename VectorTypeOne, typename VectorTypeTwo>
|
||||||
static inline VectorTypeOne &operator-=(VectorTypeOne &v1,
|
static inline VectorTypeOne &operator-=(VectorTypeOne &v1,
|
||||||
const VectorTypeTwo &v2) {
|
const VectorTypeTwo &v2) {
|
||||||
for(int i = 0; i < VectorTypeOne::Size; i++) {
|
return v1 = VectorSubtraction(v1, v2);
|
||||||
v1(i) -= v2(i);
|
|
||||||
}
|
|
||||||
return v1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -217,18 +226,12 @@ namespace FasTC {
|
|||||||
|
|
||||||
template<typename VectorType, typename ScalarType>
|
template<typename VectorType, typename ScalarType>
|
||||||
static inline VectorType &operator*=(VectorType &v, const ScalarType &s) {
|
static inline VectorType &operator*=(VectorType &v, const ScalarType &s) {
|
||||||
for(int i = 0; i < VectorType::Size; i++) {
|
return v = ScalarMultiply(v, s);
|
||||||
v(i) *= s;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VectorType, typename ScalarType>
|
template<typename VectorType, typename ScalarType>
|
||||||
static inline VectorType &operator/=(VectorType &v, const ScalarType &s) {
|
static inline VectorType &operator/=(VectorType &v, const ScalarType &s) {
|
||||||
for(int i = 0; i < VectorType::Size; i++) {
|
return v = ScalarDivide(v, s);
|
||||||
v(i) /= s;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user