76 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType,
bool isInteger,
bool signedType>
77 struct compute_compNormalize
80 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType>
81 struct compute_compNormalize<T, floatType, P, vecType, true, true>
83 GLM_FUNC_QUALIFIER
static vecType<floatType, P> call(vecType<T, P>
const & v)
85 floatType
const Min =
static_cast<floatType
>(std::numeric_limits<T>::min());
86 floatType
const Max =
static_cast<floatType
>(std::numeric_limits<T>::max());
87 return (vecType<floatType, P>(v) - Min) / (Max - Min) *
static_cast<floatType
>(2) - static_cast<floatType>(1);
91 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType>
92 struct compute_compNormalize<T, floatType, P, vecType, true, false>
94 GLM_FUNC_QUALIFIER
static vecType<floatType, P> call(vecType<T, P>
const & v)
96 return vecType<floatType, P>(v) / static_cast<floatType>(std::numeric_limits<T>::max());
100 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType>
101 struct compute_compNormalize<T, floatType, P, vecType, false, true>
103 GLM_FUNC_QUALIFIER
static vecType<floatType, P> call(vecType<T, P>
const & v)
109 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType,
bool isInteger,
bool signedType>
110 struct compute_compScale
113 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType>
114 struct compute_compScale<T, floatType, P, vecType, true, true>
116 GLM_FUNC_QUALIFIER
static vecType<T, P> call(vecType<floatType, P>
const & v)
118 floatType
const Max =
static_cast<floatType
>(std::numeric_limits<T>::max()) + static_cast<floatType>(0.5);
119 vecType<floatType, P>
const Scaled(v * Max);
120 vecType<T, P>
const Result(Scaled - static_cast<floatType>(0.5));
125 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType>
126 struct compute_compScale<T, floatType, P, vecType, true, false>
128 GLM_FUNC_QUALIFIER
static vecType<T, P> call(vecType<floatType, P>
const & v)
130 return vecType<T, P>(vecType<floatType, P>(v) * static_cast<floatType>(std::numeric_limits<T>::max()));
134 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType>
135 struct compute_compScale<T, floatType, P, vecType, false, true>
137 GLM_FUNC_QUALIFIER
static vecType<T, P> call(vecType<floatType, P>
const & v)
143 template <precision P,
template <
typename, precision>
class vecType>
147 template <precision P>
148 struct compute_half<P, tvec1>
150 GLM_FUNC_QUALIFIER
static tvec1<uint16, P> pack(tvec1<float, P>
const & v)
152 int16
const Unpacked(glm::detail::toFloat16(v.x));
153 return tvec1<uint16, P>(
reinterpret_cast<uint16
const &
>(Unpacked));
156 GLM_FUNC_QUALIFIER
static tvec1<float, P> unpack(tvec1<uint16, P>
const & v)
158 return tvec1<float, P>(glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.x)));
162 template <precision P>
163 struct compute_half<P, tvec2>
165 GLM_FUNC_QUALIFIER
static tvec2<uint16, P> pack(tvec2<float, P>
const & v)
167 tvec2<int16, P>
const Unpacked(glm::detail::toFloat16(v.x), glm::detail::toFloat16(v.y));
168 return tvec2<uint16, P>(
169 reinterpret_cast<uint16
const &
>(Unpacked.x),
170 reinterpret_cast<uint16 const &>(Unpacked.y));
173 GLM_FUNC_QUALIFIER
static tvec2<float, P> unpack(tvec2<uint16, P>
const & v)
175 return tvec2<float, P>(
176 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.x)),
177 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.y)));
181 template <precision P>
182 struct compute_half<P, tvec3>
184 GLM_FUNC_QUALIFIER
static tvec3<uint16, P> pack(tvec3<float, P>
const & v)
186 tvec3<int16, P>
const Unpacked(glm::detail::toFloat16(v.x), glm::detail::toFloat16(v.y), glm::detail::toFloat16(v.z));
187 return tvec3<uint16, P>(
188 reinterpret_cast<uint16
const &
>(Unpacked.x),
189 reinterpret_cast<uint16 const &>(Unpacked.y),
190 reinterpret_cast<uint16
const &
>(Unpacked.z));
193 GLM_FUNC_QUALIFIER
static tvec3<float, P> unpack(tvec3<uint16, P>
const & v)
195 return tvec3<float, P>(
196 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.x)),
197 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.y)),
198 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.z)));
202 template <precision P>
203 struct compute_half<P, tvec4>
205 GLM_FUNC_QUALIFIER
static tvec4<uint16, P> pack(tvec4<float, P>
const & v)
207 tvec4<int16, P>
const Unpacked(glm::detail::toFloat16(v.x), glm::detail::toFloat16(v.y), glm::detail::toFloat16(v.z), glm::detail::toFloat16(v.w));
208 return tvec4<uint16, P>(
209 reinterpret_cast<uint16
const &
>(Unpacked.x),
210 reinterpret_cast<uint16 const &>(Unpacked.y),
211 reinterpret_cast<uint16
const &
>(Unpacked.z),
212 reinterpret_cast<uint16 const &>(Unpacked.w));
215 GLM_FUNC_QUALIFIER
static tvec4<float, P> unpack(tvec4<uint16, P>
const & v)
217 return tvec4<float, P>(
218 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.x)),
219 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.y)),
220 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.z)),
221 glm::detail::toFloat32(reinterpret_cast<int16 const &>(v.w)));
226 template <
typename floatType,
typename T, precision P,
template <
typename, precision>
class vecType>
227 GLM_FUNC_QUALIFIER vecType<floatType, P> compNormalize(vecType<T, P>
const & v)
229 GLM_STATIC_ASSERT(std::numeric_limits<floatType>::is_iec559,
"'compNormalize' accepts only floating-point types for 'floatType' template parameter");
234 template <
typename T,
typename floatType, precision P,
template <
typename, precision>
class vecType>
235 GLM_FUNC_QUALIFIER vecType<T, P> compScale(vecType<floatType, P>
const & v)
237 GLM_STATIC_ASSERT(std::numeric_limits<floatType>::is_iec559,
"'compScale' accepts only floating-point types for 'floatType' template parameter");
242 template <
typename u
intType,
typename floatType, precision P,
template <
typename, precision>
class vecType>
243 GLM_FUNC_QUALIFIER vecType<uintType, P> packUnorm(vecType<floatType, P>
const & v)
246 GLM_STATIC_ASSERT(std::numeric_limits<floatType>::is_iec559,
"floatType must be a floating point type");
248 return vecType<uintType, P>(round(clamp(v, static_cast<floatType>(0), static_cast<floatType>(1)) * static_cast<floatType>(std::numeric_limits<uintType>::max())));
251 template <
typename u
intType,
typename floatType, precision P,
template <
typename, precision>
class vecType>
252 GLM_FUNC_QUALIFIER vecType<floatType, P> unpackUnorm(vecType<uintType, P>
const & v)
255 GLM_STATIC_ASSERT(std::numeric_limits<floatType>::is_iec559,
"floatType must be a floating point type");
257 return vecType<float, P>(v) * (static_cast<floatType>(1) /
static_cast<floatType
>(std::numeric_limits<uintType>::max()));
260 GLM_FUNC_QUALIFIER uint8 packUnorm2x3_1x2(vec3
const & v)
262 u32vec3
const Unpack(round(clamp(v, 0.0f, 1.0f) * vec3(7.f, 7.f, 3.f)));
263 detail::u3u3u2 Result;
264 Result.data.x = Unpack.x;
265 Result.data.y = Unpack.y;
266 Result.data.z = Unpack.z;
270 GLM_FUNC_QUALIFIER vec3 unpackUnorm2x3_1x2(uint8 v)
272 vec3
const ScaleFactor(1.f / 7.f, 1.f / 7.f, 1.f / 3.f);
273 detail::u3u3u2 Unpack;
275 return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * ScaleFactor;
278 GLM_FUNC_QUALIFIER uint8 packUnorm2x4(vec2
const & v)
280 u32vec2
const Unpack(round(clamp(v, 0.0f, 1.0f) * 15.0f));
282 Result.data.x = Unpack.x;
283 Result.data.y = Unpack.y;
287 GLM_FUNC_QUALIFIER vec2 unpackUnorm2x4(uint8 v)
289 float const ScaleFactor(1.f / 15.f);
292 return vec2(Unpack.data.x, Unpack.data.y) * ScaleFactor;
295 GLM_FUNC_QUALIFIER uint16 packUnorm4x4(vec4
const & v)
297 u32vec4
const Unpack(round(clamp(v, 0.0f, 1.0f) * 15.0f));
298 detail::u4u4u4u4 Result;
299 Result.data.x = Unpack.x;
300 Result.data.y = Unpack.y;
301 Result.data.z = Unpack.z;
302 Result.data.w = Unpack.w;
306 GLM_FUNC_QUALIFIER vec4 unpackUnorm4x4(uint16 v)
308 float const ScaleFactor(1.f / 15.f);
309 detail::u4u4u4u4 Unpack;
311 return vec4(Unpack.data.x, Unpack.data.y, Unpack.data.z, Unpack.data.w) * ScaleFactor;
314 GLM_FUNC_QUALIFIER uint16 packUnorm3x5_1x1(vec4
const & v)
316 u32vec4
const Unpack(round(clamp(v, 0.0f, 1.0f) * vec4(15.f, 15.f, 15.f, 1.f)));
317 detail::u5u5u5u1 Result;
318 Result.data.x = Unpack.x;
319 Result.data.y = Unpack.y;
320 Result.data.z = Unpack.z;
321 Result.data.w = Unpack.w;
325 GLM_FUNC_QUALIFIER vec4 unpackUnorm3x5_1x1(uint16 v)
327 vec4
const ScaleFactor(1.f / 15.f, 1.f / 15.f, 1.f / 15.f, 1.f);
328 detail::u5u5u5u1 Unpack;
330 return vec4(Unpack.data.x, Unpack.data.y, Unpack.data.z, Unpack.data.w) * ScaleFactor;
333 GLM_FUNC_QUALIFIER uint16 packUnorm1x5_1x6_1x5(vec3
const & v)
335 u32vec3
const Unpack(round(clamp(v, 0.0f, 1.0f) * vec3(15.f, 31.f, 15.f)));
336 detail::u5u6u5 Result;
337 Result.data.x = Unpack.x;
338 Result.data.y = Unpack.y;
339 Result.data.z = Unpack.z;
343 GLM_FUNC_QUALIFIER vec3 unpackUnorm1x5_1x6_1x5(uint16 v)
345 vec3
const ScaleFactor(1.f / 15.f, 1.f / 31.f, 1.f / 15.f);
346 detail::u5u6u5 Unpack;
348 return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * ScaleFactor;
351 GLM_FUNC_QUALIFIER uint32 packF3x9_E1x5(vec3
const & v)
353 float const SharedExpMax = (pow(2.0f, 9.0f - 1.0f) / pow(2.0f, 9.0f)) * pow(2.0f, 31.f - 15.f);
354 vec3
const Color = clamp(v, 0.0f, SharedExpMax);
355 float const MaxColor = max(Color.x, max(Color.y, Color.z));
357 float const ExpSharedP = max(-15.f - 1.f, floor(log2(MaxColor))) + 1.0f + 15.f;
358 float const MaxShared = floor(MaxColor / pow(2.0f, (ExpSharedP - 16.f - 9.f)) + 0.5f);
359 float const ExpShared = MaxShared == pow(2.0f, 9.0f) ? ExpSharedP + 1.0f : ExpSharedP;
361 uvec3
const ColorComp(floor(Color / pow(2.f, (ExpShared - 15.f - 9.f)) + 0.5f));
363 detail::u9u9u9e5 Unpack;
364 Unpack.data.x = ColorComp.x;
365 Unpack.data.y = ColorComp.y;
366 Unpack.data.z = ColorComp.z;
367 Unpack.data.w = uint(ExpShared);
371 GLM_FUNC_QUALIFIER vec3 unpackF3x9_E1x5(uint32 v)
373 detail::u9u9u9e5 Unpack;
376 return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * pow(2.0f, Unpack.data.w - 15.f - 9.f);
379 template <precision P,
template <
typename, precision>
class vecType>
380 GLM_FUNC_QUALIFIER vecType<uint16, P> packHalf(vecType<float, P>
const & v)
382 return detail::compute_half<P, vecType>::pack(v);
385 template <precision P,
template <
typename, precision>
class vecType>
386 GLM_FUNC_QUALIFIER vecType<float, P> unpackHalf(vecType<uint16, P>
const & v)
388 return detail::compute_half<P, vecType>::unpack(v);
bool is_integer(format Format)
Evaluate whether the format is an integer format.
bool is_signed(format Format)
Evaluate whether a format is signed.
Namespace where all the classes and functions provided by GLI are exposed.