Skip to content

Commit

Permalink
Fix 'dereferencing type-punned pointer will break strict aliasing'
Browse files Browse the repository at this point in the history
  • Loading branch information
klemmster committed Jun 6, 2014
1 parent 7d61eba commit a894a9f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/glm/detail/func_packing.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////

#include <cstring>

#include "func_common.hpp"
#include "type_half.hpp"
#include "../fwd.hpp"
Expand All @@ -35,7 +37,9 @@ namespace glm
GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v)
{
u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
return reinterpret_cast<uint&>(Topack);
uint32 Result(0);
std::memcpy(&Result, &Topack, sizeof Result);
return Result;
}

GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p)
Expand All @@ -47,7 +51,9 @@ namespace glm
GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v)
{
i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
return reinterpret_cast<uint32&>(Topack);
uint32 Result(0);
std::memcpy(&Result, &Topack, sizeof Result);
return Result;
}

GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p)
Expand Down

0 comments on commit a894a9f

Please sign in to comment.