mirror of
https://github.com/g-truc/glm.git
synced 2024-11-15 06:24:34 +00:00
Use value_ptr in packing.inl
This commit is contained in:
parent
b793c6f8cf
commit
357804af06
@ -7,6 +7,7 @@
|
|||||||
#include "../vec3.hpp"
|
#include "../vec3.hpp"
|
||||||
#include "../vec4.hpp"
|
#include "../vec4.hpp"
|
||||||
#include "../detail/type_half.hpp"
|
#include "../detail/type_half.hpp"
|
||||||
|
#include "type_ptr.hpp"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
@ -295,14 +296,14 @@ namespace detail
|
|||||||
{
|
{
|
||||||
int16 const Unpack(detail::toFloat16(v.x));
|
int16 const Unpack(detail::toFloat16(v.x));
|
||||||
u16vec1 Packed;
|
u16vec1 Packed;
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
memcpy(value_ptr(Packed), &Unpack, sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<1, float, Q> unpack(vec<1, uint16, Q> const& v)
|
GLM_FUNC_QUALIFIER static vec<1, float, Q> unpack(vec<1, uint16, Q> const& v)
|
||||||
{
|
{
|
||||||
i16vec1 Unpack;
|
i16vec1 Unpack;
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), value_ptr(v), sizeof(Unpack));
|
||||||
return vec<1, float, Q>(detail::toFloat32(v.x));
|
return vec<1, float, Q>(detail::toFloat32(v.x));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -314,14 +315,14 @@ namespace detail
|
|||||||
{
|
{
|
||||||
vec<2, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y));
|
vec<2, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y));
|
||||||
u16vec2 Packed;
|
u16vec2 Packed;
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
memcpy(value_ptr(Packed), value_ptr(Unpack), sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<2, float, Q> unpack(vec<2, uint16, Q> const& v)
|
GLM_FUNC_QUALIFIER static vec<2, float, Q> unpack(vec<2, uint16, Q> const& v)
|
||||||
{
|
{
|
||||||
i16vec2 Unpack;
|
i16vec2 Unpack;
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), value_ptr(v), sizeof(Unpack));
|
||||||
return vec<2, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y));
|
return vec<2, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -333,14 +334,14 @@ namespace detail
|
|||||||
{
|
{
|
||||||
vec<3, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z));
|
vec<3, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z));
|
||||||
u16vec3 Packed;
|
u16vec3 Packed;
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
memcpy(value_ptr(Packed), value_ptr(Unpack), sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<3, float, Q> unpack(vec<3, uint16, Q> const& v)
|
GLM_FUNC_QUALIFIER static vec<3, float, Q> unpack(vec<3, uint16, Q> const& v)
|
||||||
{
|
{
|
||||||
i16vec3 Unpack;
|
i16vec3 Unpack;
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &v, sizeof(Unpack));
|
||||||
return vec<3, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z));
|
return vec<3, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -352,14 +353,14 @@ namespace detail
|
|||||||
{
|
{
|
||||||
vec<4, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z), detail::toFloat16(v.w));
|
vec<4, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z), detail::toFloat16(v.w));
|
||||||
u16vec4 Packed;
|
u16vec4 Packed;
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
memcpy(value_ptr(Packed), value_ptr(Unpack), sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<4, float, Q> unpack(vec<4, uint16, Q> const& v)
|
GLM_FUNC_QUALIFIER static vec<4, float, Q> unpack(vec<4, uint16, Q> const& v)
|
||||||
{
|
{
|
||||||
i16vec4 Unpack;
|
i16vec4 Unpack;
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &v, sizeof(Unpack));
|
||||||
return vec<4, float, Q>(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y), detail::toFloat32(Unpack.z), detail::toFloat32(Unpack.w));
|
return vec<4, float, Q>(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y), detail::toFloat32(Unpack.z), detail::toFloat32(Unpack.w));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -388,7 +389,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
|
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
|
||||||
{
|
{
|
||||||
u8vec2 Unpack;
|
u8vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return vec2(Unpack) * float(0.0039215686274509803921568627451); // 1 / 255
|
return vec2(Unpack) * float(0.0039215686274509803921568627451); // 1 / 255
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,14 +414,14 @@ namespace detail
|
|||||||
{
|
{
|
||||||
i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f));
|
i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f));
|
||||||
uint16 Packed = 0;
|
uint16 Packed = 0;
|
||||||
memcpy(&Packed, &Topack, sizeof(Packed));
|
memcpy(&Packed, value_ptr(Topack), sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
|
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
|
||||||
{
|
{
|
||||||
i8vec2 Unpack;
|
i8vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return clamp(
|
return clamp(
|
||||||
vec2(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
vec2(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
@ -448,7 +449,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p)
|
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p)
|
||||||
{
|
{
|
||||||
u16vec4 Unpack;
|
u16vec4 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return vec4(Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
return vec4(Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,14 +474,14 @@ namespace detail
|
|||||||
{
|
{
|
||||||
i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||||
uint64 Packed = 0;
|
uint64 Packed = 0;
|
||||||
memcpy(&Packed, &Topack, sizeof(Packed));
|
memcpy(&Packed, value_ptr(Topack), sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p)
|
GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p)
|
||||||
{
|
{
|
||||||
i16vec4 Unpack;
|
i16vec4 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return clamp(
|
return clamp(
|
||||||
vec4(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
vec4(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
@ -509,14 +510,14 @@ namespace detail
|
|||||||
detail::toFloat16(v.z),
|
detail::toFloat16(v.z),
|
||||||
detail::toFloat16(v.w));
|
detail::toFloat16(v.w));
|
||||||
uint64 Packed = 0;
|
uint64 Packed = 0;
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
memcpy(&Packed, value_ptr(Unpack), sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v)
|
GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v)
|
||||||
{
|
{
|
||||||
i16vec4 Unpack;
|
i16vec4 Unpack;
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &v, sizeof(Unpack));
|
||||||
return vec4(
|
return vec4(
|
||||||
detail::toFloat32(Unpack.x),
|
detail::toFloat32(Unpack.x),
|
||||||
detail::toFloat32(Unpack.y),
|
detail::toFloat32(Unpack.y),
|
||||||
@ -818,7 +819,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER i8vec2 unpackInt2x8(int16 p)
|
GLM_FUNC_QUALIFIER i8vec2 unpackInt2x8(int16 p)
|
||||||
{
|
{
|
||||||
i8vec2 Unpack;
|
i8vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,7 +833,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER u8vec2 unpackUint2x8(uint16 p)
|
GLM_FUNC_QUALIFIER u8vec2 unpackUint2x8(uint16 p)
|
||||||
{
|
{
|
||||||
u8vec2 Unpack;
|
u8vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -846,7 +847,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER i8vec4 unpackInt4x8(int32 p)
|
GLM_FUNC_QUALIFIER i8vec4 unpackInt4x8(int32 p)
|
||||||
{
|
{
|
||||||
i8vec4 Unpack;
|
i8vec4 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -860,7 +861,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER u8vec4 unpackUint4x8(uint32 p)
|
GLM_FUNC_QUALIFIER u8vec4 unpackUint4x8(uint32 p)
|
||||||
{
|
{
|
||||||
u8vec4 Unpack;
|
u8vec4 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -874,7 +875,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER i16vec2 unpackInt2x16(int p)
|
GLM_FUNC_QUALIFIER i16vec2 unpackInt2x16(int p)
|
||||||
{
|
{
|
||||||
i16vec2 Unpack;
|
i16vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -888,7 +889,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER i16vec4 unpackInt4x16(int64 p)
|
GLM_FUNC_QUALIFIER i16vec4 unpackInt4x16(int64 p)
|
||||||
{
|
{
|
||||||
i16vec4 Unpack;
|
i16vec4 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,7 +903,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER u16vec2 unpackUint2x16(uint p)
|
GLM_FUNC_QUALIFIER u16vec2 unpackUint2x16(uint p)
|
||||||
{
|
{
|
||||||
u16vec2 Unpack;
|
u16vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -916,7 +917,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER u16vec4 unpackUint4x16(uint64 p)
|
GLM_FUNC_QUALIFIER u16vec4 unpackUint4x16(uint64 p)
|
||||||
{
|
{
|
||||||
u16vec4 Unpack;
|
u16vec4 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,7 +931,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER i32vec2 unpackInt2x32(int64 p)
|
GLM_FUNC_QUALIFIER i32vec2 unpackInt2x32(int64 p)
|
||||||
{
|
{
|
||||||
i32vec2 Unpack;
|
i32vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -944,7 +945,7 @@ namespace detail
|
|||||||
GLM_FUNC_QUALIFIER u32vec2 unpackUint2x32(uint64 p)
|
GLM_FUNC_QUALIFIER u32vec2 unpackUint2x32(uint64 p)
|
||||||
{
|
{
|
||||||
u32vec2 Unpack;
|
u32vec2 Unpack;
|
||||||
memcpy(&Unpack, &p, sizeof(Unpack));
|
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
|
||||||
return Unpack;
|
return Unpack;
|
||||||
}
|
}
|
||||||
}//namespace glm
|
}//namespace glm
|
||||||
|
Loading…
Reference in New Issue
Block a user