fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Image / Squish / simd_float.h
blob25fc0588f13cf69ab18e13d5c56b332df53d5e5b
1 /* -----------------------------------------------------------------------------
3 Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 -------------------------------------------------------------------------- */
26 #ifndef SQUISH_SIMD_FLOAT_H
27 #define SQUISH_SIMD_FLOAT_H
29 #include <algorithm>
31 namespace osgsquish {
33 #define VEC4_CONST( X ) Vec4( X )
35 class Vec4
37 public:
38 typedef Vec4 const& Arg;
40 Vec4() : m_x(0.f), m_y(0.f), m_z(0.f), m_w(0.f) {}
42 explicit Vec4( float s )
43 : m_x( s ),
44 m_y( s ),
45 m_z( s ),
46 m_w( s )
50 Vec4( float x, float y, float z, float w )
51 : m_x( x ),
52 m_y( y ),
53 m_z( z ),
54 m_w( w )
58 Vec3 GetVec3() const
60 return Vec3( m_x, m_y, m_z );
63 Vec4 SplatX() const { return Vec4( m_x ); }
64 Vec4 SplatY() const { return Vec4( m_y ); }
65 Vec4 SplatZ() const { return Vec4( m_z ); }
66 Vec4 SplatW() const { return Vec4( m_w ); }
68 Vec4& operator+=( Arg v )
70 m_x += v.m_x;
71 m_y += v.m_y;
72 m_z += v.m_z;
73 m_w += v.m_w;
74 return *this;
77 Vec4& operator-=( Arg v )
79 m_x -= v.m_x;
80 m_y -= v.m_y;
81 m_z -= v.m_z;
82 m_w -= v.m_w;
83 return *this;
86 Vec4& operator*=( Arg v )
88 m_x *= v.m_x;
89 m_y *= v.m_y;
90 m_z *= v.m_z;
91 m_w *= v.m_w;
92 return *this;
95 friend Vec4 operator+( Vec4::Arg left, Vec4::Arg right )
97 Vec4 copy( left );
98 return copy += right;
101 friend Vec4 operator-( Vec4::Arg left, Vec4::Arg right )
103 Vec4 copy( left );
104 return copy -= right;
107 friend Vec4 operator*( Vec4::Arg left, Vec4::Arg right )
109 Vec4 copy( left );
110 return copy *= right;
113 //! Returns a*b + c
114 friend Vec4 MultiplyAdd( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c )
116 return a*b + c;
119 //! Returns -( a*b - c )
120 friend Vec4 NegativeMultiplySubtract( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c )
122 return c - a*b;
125 friend Vec4 Reciprocal( Vec4::Arg v )
127 return Vec4(
128 1.0f/v.m_x,
129 1.0f/v.m_y,
130 1.0f/v.m_z,
131 1.0f/v.m_w
135 friend Vec4 Min( Vec4::Arg left, Vec4::Arg right )
137 return Vec4(
138 std::min( left.m_x, right.m_x ),
139 std::min( left.m_y, right.m_y ),
140 std::min( left.m_z, right.m_z ),
141 std::min( left.m_w, right.m_w )
145 friend Vec4 Max( Vec4::Arg left, Vec4::Arg right )
147 return Vec4(
148 std::max( left.m_x, right.m_x ),
149 std::max( left.m_y, right.m_y ),
150 std::max( left.m_z, right.m_z ),
151 std::max( left.m_w, right.m_w )
155 friend Vec4 Truncate( Vec4::Arg v )
157 return Vec4(
158 v.m_x > 0.0f ? std::floor( v.m_x ) : std::ceil( v.m_x ),
159 v.m_y > 0.0f ? std::floor( v.m_y ) : std::ceil( v.m_y ),
160 v.m_z > 0.0f ? std::floor( v.m_z ) : std::ceil( v.m_z ),
161 v.m_w > 0.0f ? std::floor( v.m_w ) : std::ceil( v.m_w )
165 friend bool CompareAnyLessThan( Vec4::Arg left, Vec4::Arg right )
167 return left.m_x < right.m_x
168 || left.m_y < right.m_y
169 || left.m_z < right.m_z
170 || left.m_w < right.m_w;
173 private:
174 float m_x;
175 float m_y;
176 float m_z;
177 float m_w;
180 } // namespace squish
182 #endif // ndef SQUISH_SIMD_FLOAT_H