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 test suite on big endian platforms #1001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
55 changes: 55 additions & 0 deletions glm/gtc/packing.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "../detail/type_half.hpp"
#include <cstring>
#include <limits>
extern "C" {
#include <endian.h>
}

namespace glm{
namespace detail
Expand Down Expand Up @@ -183,9 +186,15 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint x : 3;
uint y : 3;
uint z : 2;
#else
uint z : 2;
uint y : 3;
uint x : 3;
#endif
} data;
uint8 pack;
};
Expand All @@ -194,8 +203,13 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint x : 4;
uint y : 4;
#else
uint y : 4;
uint x : 4;
#endif
} data;
uint8 pack;
};
Expand All @@ -204,10 +218,17 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint x : 4;
uint y : 4;
uint z : 4;
uint w : 4;
#else
uint w : 4;
uint z : 4;
uint y : 4;
uint x : 4;
#endif
} data;
uint16 pack;
};
Expand All @@ -216,9 +237,15 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint x : 5;
uint y : 6;
uint z : 5;
#else
uint z : 5;
uint y : 6;
uint x : 5;
#endif
} data;
uint16 pack;
};
Expand All @@ -227,10 +254,17 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint x : 5;
uint y : 5;
uint z : 5;
uint w : 1;
#else
uint w : 1;
uint z : 5;
uint y : 5;
uint x : 5;
#endif
} data;
uint16 pack;
};
Expand All @@ -239,10 +273,17 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint x : 10;
uint y : 10;
uint z : 10;
uint w : 2;
#else
uint w : 2;
uint z : 10;
uint y : 10;
uint x : 10;
#endif
} data;
uint32 pack;
};
Expand All @@ -251,10 +292,17 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
int x : 10;
int y : 10;
int z : 10;
int w : 2;
#else
int w : 2;
int z : 10;
int y : 10;
int x : 10;
#endif
} data;
uint32 pack;
};
Expand All @@ -263,10 +311,17 @@ namespace detail
{
struct
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint x : 9;
uint y : 9;
uint z : 9;
uint w : 5;
#else
uint w : 5;
uint z : 9;
uint y : 9;
uint x : 9;
#endif
} data;
uint32 pack;
};
Expand Down
3 changes: 2 additions & 1 deletion test/gtc/gtc_packing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <glm/ext/vector_relational.hpp>
#include <cstdio>
#include <vector>
#include <arpa/inet.h>

void print_bits(float const& s)
{
Expand Down Expand Up @@ -156,7 +157,7 @@ int test_U3x10_1x2()

glm::u8vec4 const v0(0xff, 0x77, 0x0, 0x33);
glm::uint32 const p0 = *reinterpret_cast<glm::uint32 const*>(&v0[0]);
glm::uint32 const r0 = 0x330077ff;
glm::uint32 const r0 = htonl(0xff770033);

Error += p0 == r0 ? 0 : 1;

Expand Down