diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index b7fb5648..73abedd5 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -62,7 +62,7 @@ namespace glm /// @see uint32 packUnorm4x8(vec4 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint8 packUnorm1x8(float const & v); + GLM_FUNC_DECL uint8 packUnorm1x8(float v); /// Convert a single 8-bit integer to a normalized floating-point value. /// @@ -74,7 +74,7 @@ namespace glm /// @see vec4 unpackUnorm4x8(uint32 p) /// @see GLSL unpackUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackUnorm1x8(uint8 const & p); + GLM_FUNC_DECL float unpackUnorm1x8(uint8 p); /// First, converts each component of the normalized floating-point value v into 8-bit integer values. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -106,7 +106,7 @@ namespace glm /// @see vec4 unpackUnorm4x8(uint32 p) /// @see GLSL unpackUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 const & p); + GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 p); /// First, converts the normalized floating-point value v into 8-bit integer value. /// Then, the results are packed into the returned 8-bit unsigned integer. @@ -119,7 +119,7 @@ namespace glm /// @see uint32 packSnorm4x8(vec4 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint8 packSnorm1x8(float const & s); + GLM_FUNC_DECL uint8 packSnorm1x8(float s); /// First, unpacks a single 8-bit unsigned integer p into a single 8-bit signed integers. /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. @@ -132,7 +132,7 @@ namespace glm /// @see vec4 unpackSnorm4x8(uint32 p) /// @see GLSL unpackSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackSnorm1x8(uint8 const & p); + GLM_FUNC_DECL float unpackSnorm1x8(uint8 p); /// First, converts each component of the normalized floating-point value v into 8-bit integer values. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -164,7 +164,7 @@ namespace glm /// @see vec4 unpackSnorm4x8(uint32 p) /// @see GLSL unpackSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 const & p); + GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 p); /// First, converts the normalized floating-point value v into a 16-bit integer value. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -177,7 +177,7 @@ namespace glm /// @see uint64 packSnorm4x16(vec4 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint16 packUnorm1x16(float const & v); + GLM_FUNC_DECL uint16 packUnorm1x16(float v); /// First, unpacks a single 16-bit unsigned integer p into a of 16-bit unsigned integers. /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. @@ -190,7 +190,7 @@ namespace glm /// @see vec4 unpackUnorm4x16(uint64 p) /// @see GLSL unpackUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackUnorm1x16(uint16 const & p); + GLM_FUNC_DECL float unpackUnorm1x16(uint16 p); /// First, converts each component of the normalized floating-point value v into 16-bit integer values. /// Then, the results are packed into the returned 64-bit unsigned integer. @@ -222,7 +222,7 @@ namespace glm /// @see vec2 unpackUnorm2x16(uint32 p) /// @see GLSL unpackUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & p); + GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 p); /// First, converts the normalized floating-point value v into 16-bit integer value. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -235,7 +235,7 @@ namespace glm /// @see uint64 packSnorm4x16(vec4 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint16 packSnorm1x16(float const & v); + GLM_FUNC_DECL uint16 packSnorm1x16(float v); /// First, unpacks a single 16-bit unsigned integer p into a single 16-bit signed integers. /// Then, each component is converted to a normalized floating-point value to generate the returned scalar. @@ -248,7 +248,7 @@ namespace glm /// @see vec4 unpackSnorm4x16(uint64 p) /// @see GLSL unpackSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackSnorm1x16(uint16 const & p); + GLM_FUNC_DECL float unpackSnorm1x16(uint16 p); /// First, converts each component of the normalized floating-point value v into 16-bit integer values. /// Then, the results are packed into the returned 64-bit unsigned integer. @@ -291,7 +291,7 @@ namespace glm /// @see uint64 packHalf4x16(vec4 const & v) /// @see GLSL packHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL uint16 packHalf1x16(float const & v); + GLM_FUNC_DECL uint16 packHalf1x16(float v); /// Returns a floating-point scalar with components obtained by unpacking a 16-bit unsigned integer into a 16-bit value, /// interpreted as a 16-bit floating-point number according to the OpenGL Specification, @@ -302,7 +302,7 @@ namespace glm /// @see vec4 unpackHalf4x16(uint64 const & v) /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v); + GLM_FUNC_DECL float unpackHalf1x16(uint16 v); /// Returns an unsigned integer obtained by converting the components of a four-component floating-point vector /// to the 16-bit floating-point representation found in the OpenGL Specification, @@ -328,7 +328,7 @@ namespace glm /// @see vec2 unpackHalf2x16(uint32 const & v) /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 const & p); + GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 p); /// Returns an unsigned integer obtained by converting the components of a four-component signed integer vector /// to the 10-10-10-2-bit signed integer representation found in the OpenGL Specification, @@ -352,7 +352,7 @@ namespace glm /// @see uint32 packU3x10_1x2(uvec4 const & v) /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); /// @see uvec4 unpackI3x10_1x2(uint32 const & p); - GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 const & p); + GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 p); /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector /// to the 10-10-10-2-bit unsigned integer representation found in the OpenGL Specification, @@ -376,7 +376,7 @@ namespace glm /// @see uint32 packU3x10_1x2(uvec4 const & v) /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); /// @see uvec4 unpackI3x10_1x2(uint32 const & p); - GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 const & p); + GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 p); /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values. /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed integer values. @@ -411,7 +411,7 @@ namespace glm /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p)) /// @see uvec4 unpackI3x10_1x2(uint32 const & p) /// @see uvec4 unpackU3x10_1x2(uint32 const & p) - GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 const & p); + GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 p); /// First, converts the first three components of the normalized floating-point value v into 10-bit unsigned integer values. /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed uninteger values. @@ -446,7 +446,7 @@ namespace glm /// @see vec4 unpackInorm3x10_1x2(uint32 const & p)) /// @see uvec4 unpackI3x10_1x2(uint32 const & p) /// @see uvec4 unpackU3x10_1x2(uint32 const & p) - GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 const & p); + GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 p); /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values. /// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value. @@ -467,7 +467,7 @@ namespace glm /// /// @see gtc_packing /// @see uint32 packF2x11_1x10(vec3 const & v) - GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 const & p); + GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 p); /// @} }// namespace glm diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 9e3fa87c..353dc6eb 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -165,8 +165,14 @@ namespace detail else if(x == (0x1f << 6)) return ~0;//Inf - uint result = packed11ToFloat(x); - return reinterpret_cast(result); + uint Result = packed11ToFloat(x); + +# if(GLM_COMPILER & GLM_COMPILER_GCC || GLM_COMPILER & GLM_COMPILER_CLANG) + float Temp = 0; + memcpy(&Temp, &Result, sizeof(Temp)); +# else + return reinterpret_cast(Result); +# endif } GLM_FUNC_QUALIFIER glm::uint floatTo10bit(float x) @@ -226,12 +232,12 @@ namespace detail }//namespace detail - GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float const & v) + GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float v) { return static_cast(round(clamp(v, 0.0f, 1.0f) * 255.0f)); } - GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 const & p) + GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 p) { float Unpack(static_cast(p)); return Unpack * static_cast(0.0039215686274509803921568627451); // 1 / 255 @@ -244,20 +250,20 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 const & p) + GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p) { u8vec2* Unpacked = reinterpret_cast(const_cast(&p)); return vec2(*Unpacked) * float(0.0039215686274509803921568627451); // 1 / 255 } - GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float const & v) + GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v) { int8 Topack(static_cast(round(clamp(v ,-1.0f, 1.0f) * 127.0f))); uint8* Packed = reinterpret_cast(&Topack); return *Packed; } - GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 const & p) + GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p) { float Unpack(static_cast(*const_cast(&p))); return clamp( @@ -272,7 +278,7 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 const & p) + GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p) { i8vec2* Unpack = reinterpret_cast(const_cast(&p)); return clamp( @@ -280,12 +286,12 @@ namespace detail -1.0f, 1.0f); } - GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float const & s) + GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float s) { return static_cast(round(clamp(s, 0.0f, 1.0f) * 65535.0f)); } - GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 const & p) + GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 p) { float Unpack = static_cast(*const_cast(&p)); return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 @@ -298,20 +304,20 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 const & p) + GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p) { u16vec4* Unpack = reinterpret_cast(const_cast(&p)); return vec4(*Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 } - GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float const & v) + GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v) { int16 Topack = static_cast(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); uint16* Packed = reinterpret_cast(&Topack); return *Packed; } - GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 const & p) + GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p) { float Unpack = static_cast(*const_cast(&p)); return clamp( @@ -326,7 +332,7 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 const & p) + GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p) { i16vec4* Unpack(reinterpret_cast(const_cast(&p))); return clamp( @@ -334,14 +340,14 @@ namespace detail -1.0f, 1.0f); } - GLM_FUNC_QUALIFIER uint16 packHalf1x16(float const & v) + GLM_FUNC_QUALIFIER uint16 packHalf1x16(float v) { int16 Topack = detail::toFloat16(v); uint16* Packed = reinterpret_cast(&Topack); return *Packed; } - GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 const & v) + GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 v) { int16* Unpack = reinterpret_cast(const_cast(&v)); return detail::toFloat32(*Unpack); @@ -359,7 +365,7 @@ namespace detail return *Packed; } - GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 const & v) + GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v) { i16vec4* p = reinterpret_cast(const_cast(&v)); i16vec4 Unpack(*p); @@ -381,7 +387,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -402,7 +408,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 v) { detail::u10u10u10u2 Unpack; Unpack.pack = v; @@ -423,7 +429,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER vec4 unpackSnorm3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER vec4 unpackSnorm3x10_1x2(uint32 v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -445,7 +451,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -465,7 +471,7 @@ namespace detail ((detail::floatTo10bit(v.z) & ((1 << 10) - 1)) << 22); } - GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 const & v) + GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 v) { return vec3( detail::packed11bitToFloat(v >> 0),