Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix -Wall Compilation #1276 #1277

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion glm/gtc/bitfield.inl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace detail
{
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'mask' accepts only integer values");

return Bits >= sizeof(genIUType) * 8 ? ~static_cast<genIUType>(0) : (static_cast<genIUType>(1) << Bits) - static_cast<genIUType>(1);
return Bits >= static_cast<genIUType>(sizeof(genIUType) * 8) ? ~static_cast<genIUType>(0) : (static_cast<genIUType>(1) << Bits) - static_cast<genIUType>(1);
}

#if GLM_COMPILER & GLM_COMPILER_CLANG
Expand Down
53 changes: 27 additions & 26 deletions glm/gtc/packing.inl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../detail/type_half.hpp"
#include "type_ptr.hpp"
#include <cstring>
#include <limits>

Expand Down Expand Up @@ -295,14 +296,14 @@ namespace detail
{
int16 const Unpack(detail::toFloat16(v.x));
u16vec1 Packed;
memcpy(&Packed, &Unpack, sizeof(Packed));
memcpy(value_ptr(Packed), &Unpack, sizeof(Packed));
return Packed;
}

GLM_FUNC_QUALIFIER static vec<1, float, Q> unpack(vec<1, uint16, Q> const& v)
{
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));
}
};
Expand All @@ -314,14 +315,14 @@ namespace detail
{
vec<2, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y));
u16vec2 Packed;
memcpy(&Packed, &Unpack, sizeof(Packed));
memcpy(value_ptr(Packed), value_ptr(Unpack), sizeof(Packed));
return Packed;
}

GLM_FUNC_QUALIFIER static vec<2, float, Q> unpack(vec<2, uint16, Q> const& v)
{
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));
}
};
Expand All @@ -333,14 +334,14 @@ namespace detail
{
vec<3, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z));
u16vec3 Packed;
memcpy(&Packed, &Unpack, sizeof(Packed));
memcpy(value_ptr(Packed), value_ptr(Unpack), sizeof(Packed));
return Packed;
}

GLM_FUNC_QUALIFIER static vec<3, float, Q> unpack(vec<3, uint16, Q> const& v)
{
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));
}
};
Expand All @@ -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));
u16vec4 Packed;
memcpy(&Packed, &Unpack, sizeof(Packed));
memcpy(value_ptr(Packed), value_ptr(Unpack), sizeof(Packed));
return Packed;
}

GLM_FUNC_QUALIFIER static vec<4, float, Q> unpack(vec<4, uint16, Q> const& v)
{
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));
}
};
Expand Down Expand Up @@ -388,7 +389,7 @@ namespace detail
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
{
u8vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return vec2(Unpack) * float(0.0039215686274509803921568627451); // 1 / 255
}

Expand All @@ -413,14 +414,14 @@ namespace detail
{
i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f));
uint16 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
memcpy(&Packed, value_ptr(Topack), sizeof(Packed));
return Packed;
}

GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
{
i8vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return clamp(
vec2(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
-1.0f, 1.0f);
Expand Down Expand Up @@ -448,7 +449,7 @@ namespace detail
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p)
{
u16vec4 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return vec4(Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
}

Expand All @@ -473,14 +474,14 @@ namespace detail
{
i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
uint64 Packed = 0;
memcpy(&Packed, &Topack, sizeof(Packed));
memcpy(&Packed, value_ptr(Topack), sizeof(Packed));
return Packed;
}

GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p)
{
i16vec4 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return clamp(
vec4(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
-1.0f, 1.0f);
Expand Down Expand Up @@ -509,14 +510,14 @@ namespace detail
detail::toFloat16(v.z),
detail::toFloat16(v.w));
uint64 Packed = 0;
memcpy(&Packed, &Unpack, sizeof(Packed));
memcpy(&Packed, value_ptr(Unpack), sizeof(Packed));
return Packed;
}

GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v)
{
i16vec4 Unpack;
memcpy(&Unpack, &v, sizeof(Unpack));
memcpy(value_ptr(Unpack), &v, sizeof(Unpack));
return vec4(
detail::toFloat32(Unpack.x),
detail::toFloat32(Unpack.y),
Expand Down Expand Up @@ -818,7 +819,7 @@ namespace detail
GLM_FUNC_QUALIFIER i8vec2 unpackInt2x8(int16 p)
{
i8vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -832,7 +833,7 @@ namespace detail
GLM_FUNC_QUALIFIER u8vec2 unpackUint2x8(uint16 p)
{
u8vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -846,7 +847,7 @@ namespace detail
GLM_FUNC_QUALIFIER i8vec4 unpackInt4x8(int32 p)
{
i8vec4 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -860,7 +861,7 @@ namespace detail
GLM_FUNC_QUALIFIER u8vec4 unpackUint4x8(uint32 p)
{
u8vec4 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -874,7 +875,7 @@ namespace detail
GLM_FUNC_QUALIFIER i16vec2 unpackInt2x16(int p)
{
i16vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -888,7 +889,7 @@ namespace detail
GLM_FUNC_QUALIFIER i16vec4 unpackInt4x16(int64 p)
{
i16vec4 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -902,7 +903,7 @@ namespace detail
GLM_FUNC_QUALIFIER u16vec2 unpackUint2x16(uint p)
{
u16vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -916,7 +917,7 @@ namespace detail
GLM_FUNC_QUALIFIER u16vec4 unpackUint4x16(uint64 p)
{
u16vec4 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -930,7 +931,7 @@ namespace detail
GLM_FUNC_QUALIFIER i32vec2 unpackInt2x32(int64 p)
{
i32vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}

Expand All @@ -944,7 +945,7 @@ namespace detail
GLM_FUNC_QUALIFIER u32vec2 unpackUint2x32(uint64 p)
{
u32vec2 Unpack;
memcpy(&Unpack, &p, sizeof(Unpack));
memcpy(value_ptr(Unpack), &p, sizeof(Unpack));
return Unpack;
}
}//namespace glm
Expand Down
12 changes: 12 additions & 0 deletions glm/gtc/type_ptr.inl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ namespace glm
/// @addtogroup gtc_type_ptr
/// @{

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER T const* value_ptr(vec<1, T, Q> const& v)
{
return &(v.x);
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER T* value_ptr(vec<1, T, Q>& v)
{
return &(v.x);
}

template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER T const* value_ptr(vec<2, T, Q> const& v)
{
Expand Down
24 changes: 12 additions & 12 deletions test/core/core_func_integer_bit_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static int pop9(unsigned x)
return static_cast<int>(y);
}

int errors;
static int errors;
static void error(int x, int y)
{
errors = errors + 1;
Expand Down Expand Up @@ -208,63 +208,63 @@ int main()
TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop0(test[i]) != test[i+1]) error(test[i], pop0(test[i]));}
if (pop0(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop0(test[i]));}
TimestampEnd = std::clock();

std::printf("pop0: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));

TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop1(test[i]) != test[i+1]) error(test[i], pop1(test[i]));}
if (pop1(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop1(test[i]));}
TimestampEnd = std::clock();

std::printf("pop1: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));

TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop2(test[i]) != test[i+1]) error(test[i], pop2(test[i]));}
if (pop2(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop2(test[i]));}
TimestampEnd = std::clock();

std::printf("pop2: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));

TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop3(test[i]) != test[i+1]) error(test[i], pop3(test[i]));}
if (pop3(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop3(test[i]));}
TimestampEnd = std::clock();

std::printf("pop3: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));

TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop4(test[i]) != test[i+1]) error(test[i], pop4(test[i]));}
if (pop4(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop4(test[i]));}
TimestampEnd = std::clock();

std::printf("pop4: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));

TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop5(test[i]) != test[i+1]) error(test[i], pop5(test[i]));}
if (pop5(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop5(test[i]));}
TimestampEnd = std::clock();

std::printf("pop5: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));

TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop5a(test[i]) != test[i+1]) error(test[i], pop5a(test[i]));}
if (pop5a(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop5a(test[i]));}
TimestampEnd = std::clock();

std::printf("pop5a: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));

TimestampBeg = std::clock();
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if (pop6(test[i]) != test[i+1]) error(test[i], pop6(test[i]));}
if (pop6(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop6(test[i]));}
TimestampEnd = std::clock();

std::printf("pop6: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
Expand All @@ -273,7 +273,7 @@ int main()
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if ((test[i] & 0xffffff00) == 0)
if (pop7(test[i]) != test[i+1]) error(test[i], pop7(test[i]));}
if (pop7(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop7(test[i]));}
TimestampEnd = std::clock();

std::printf("pop7: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
Expand All @@ -282,7 +282,7 @@ int main()
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if ((test[i] & 0xffffff80) == 0)
if (pop8(test[i]) != test[i+1]) error(test[i], pop8(test[i]));}
if (pop8(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop8(test[i]));}
TimestampEnd = std::clock();

std::printf("pop8: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
Expand All @@ -291,7 +291,7 @@ int main()
for (std::size_t k = 0; k < Count; ++k)
for (i = 0; i < n; i += 2) {
if ((test[i] & 0xffff8000) == 0)
if (pop9(test[i]) != test[i+1]) error(test[i], pop9(test[i]));}
if (pop9(test[i]) != static_cast<int>(test[i+1])) error(test[i], pop9(test[i]));}
TimestampEnd = std::clock();

std::printf("pop9: %d clocks\n", static_cast<int>(TimestampEnd - TimestampBeg));
Expand Down
Loading