Skip to content

Add packed/aligned quat types #1353

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

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
63 changes: 63 additions & 0 deletions glm/gtc/type_aligned.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "../mat2x4.hpp"
#include "../mat2x3.hpp"
#include "../mat2x2.hpp"
#include "../gtc/quaternion.hpp"
#include "../gtc/vec1.hpp"
#include "../vec2.hpp"
#include "../vec3.hpp"
Expand Down Expand Up @@ -863,6 +864,44 @@ namespace glm
/// 4 by 4 matrix tightly packed in memory of double-precision floating-point numbers using low precision arithmetic in term of ULPs.
typedef mat<4, 4, double, packed_lowp> packed_lowp_dmat4x4;

// -- *quat --

/// quaternion aligned in memory of single-precision floating-point numbers using high precision arithmetic in term of ULPs.
typedef qua<float, aligned_highp> aligned_highp_quat;

/// quaternion aligned in memory of single-precision floating-point numbers using medium precision arithmetic in term of ULPs.
typedef qua<float, aligned_mediump> aligned_mediump_quat;

/// quaternion aligned in memory of single-precision floating-point numbers using low precision arithmetic in term of ULPs.
typedef qua<float, aligned_lowp> aligned_lowp_quat;

/// quaternion aligned in memory of double-precision floating-point numbers using high precision arithmetic in term of ULPs.
typedef qua<double, aligned_highp> aligned_highp_dquat;

/// quaternion aligned in memory of double-precision floating-point numbers using medium precision arithmetic in term of ULPs.
typedef qua<double, aligned_mediump> aligned_mediump_dquat;

/// quaternion aligned in memory of double-precision floating-point numbers using low precision arithmetic in term of ULPs.
typedef qua<double, aligned_lowp> aligned_lowp_dquat;

/// quaternion tightly packed in memory of single-precision floating-point numbers using high precision arithmetic in term of ULPs.
typedef qua<float, packed_highp> packed_highp_quat;

/// quaternion tightly packed in memory of single-precision floating-point numbers using medium precision arithmetic in term of ULPs.
typedef qua<float, packed_mediump> packed_mediump_quat;

/// quaternion tightly packed in memory of single-precision floating-point numbers using low precision arithmetic in term of ULPs.
typedef qua<float, packed_lowp> packed_lowp_quat;

/// quaternion tightly packed in memory of double-precision floating-point numbers using high precision arithmetic in term of ULPs.
typedef qua<double, packed_highp> packed_highp_dquat;

/// quaternion tightly packed in memory of double-precision floating-point numbers using medium precision arithmetic in term of ULPs.
typedef qua<double, packed_mediump> packed_mediump_dquat;

/// quaternion tightly packed in memory of double-precision floating-point numbers using low precision arithmetic in term of ULPs.
typedef qua<double, packed_lowp> packed_lowp_dquat;

// -- default --

#if(defined(GLM_PRECISION_LOWP_FLOAT))
Expand Down Expand Up @@ -900,6 +939,9 @@ namespace glm
typedef packed_lowp_mat4x2 packed_mat4x2;
typedef packed_lowp_mat4x3 packed_mat4x3;
typedef packed_lowp_mat4x4 packed_mat4x4;

typedef aligned_lowp_quat aligned_quat;
typedef packed_lowp_quat packed_quat;
#elif(defined(GLM_PRECISION_MEDIUMP_FLOAT))
typedef aligned_mediump_vec1 aligned_vec1;
typedef aligned_mediump_vec2 aligned_vec2;
Expand Down Expand Up @@ -935,6 +977,9 @@ namespace glm
typedef packed_mediump_mat4x2 packed_mat4x2;
typedef packed_mediump_mat4x3 packed_mat4x3;
typedef packed_mediump_mat4x4 packed_mat4x4;

typedef aligned_mediump_quat aligned_quat;
typedef packed_mediump_quat packed_quat;
#else //defined(GLM_PRECISION_HIGHP_FLOAT)
/// 1 component vector aligned in memory of single-precision floating-point numbers.
typedef aligned_highp_vec1 aligned_vec1;
Expand Down Expand Up @@ -1031,6 +1076,12 @@ namespace glm

/// 4 by 4 matrix tightly packed in memory of single-precision floating-point numbers.
typedef packed_highp_mat4x4 packed_mat4x4;

/// quaternion tightly aligned in memory of single-precision floating-point numbers.
typedef aligned_highp_quat aligned_quat;

/// quaternion tightly packed in memory of single-precision floating-point numbers.
typedef packed_highp_quat packed_quat;
#endif//GLM_PRECISION

#if(defined(GLM_PRECISION_LOWP_DOUBLE))
Expand Down Expand Up @@ -1068,6 +1119,9 @@ namespace glm
typedef packed_lowp_dmat4x2 packed_dmat4x2;
typedef packed_lowp_dmat4x3 packed_dmat4x3;
typedef packed_lowp_dmat4x4 packed_dmat4x4;

typedef aligned_lowp_dquat aligned_dquat;
typedef packed_lowp_dquat packed_dquat;
#elif(defined(GLM_PRECISION_MEDIUMP_DOUBLE))
typedef aligned_mediump_dvec1 aligned_dvec1;
typedef aligned_mediump_dvec2 aligned_dvec2;
Expand Down Expand Up @@ -1103,6 +1157,9 @@ namespace glm
typedef packed_mediump_dmat4x2 packed_dmat4x2;
typedef packed_mediump_dmat4x3 packed_dmat4x3;
typedef packed_mediump_dmat4x4 packed_dmat4x4;

typedef aligned_mediump_dquat aligned_dquat;
typedef packed_mediump_dquat packed_dquat;
#else //defined(GLM_PRECISION_HIGHP_DOUBLE)
/// 1 component vector aligned in memory of double-precision floating-point numbers.
typedef aligned_highp_dvec1 aligned_dvec1;
Expand Down Expand Up @@ -1199,6 +1256,12 @@ namespace glm

/// 4 by 4 matrix tightly packed in memory of double-precision floating-point numbers.
typedef packed_highp_dmat4x4 packed_dmat4x4;

/// quaternion tightly aligned in memory of double-precision floating-point numbers.
typedef aligned_highp_dquat aligned_dquat;

/// quaternion tightly packed in memory of double-precision floating-point numbers.
typedef packed_highp_dquat packed_dquat;
#endif//GLM_PRECISION

#if(defined(GLM_PRECISION_LOWP_INT))
Expand Down
41 changes: 41 additions & 0 deletions test/gtc/gtc_type_aligned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,46 @@ static int test_copy_vec3()
return Error;
}

static int test_copy_quat()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be made into a templated function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure! I was trying to follow what seemed to be the prevailing style in the tests, but happy to remove some duplication if that's desired.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previaling style in most of glm is not that great tbh.

In my pr I removed 7600~ lines of code and replaced them with just 2600

{
int Error = 0;
{
glm::aligned_quat const u(1.f, 2.f, 3.f, 4.f);
glm::packed_quat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::packed_quat const u(1.f, 2.f, 3.f, 4.f);
glm::aligned_quat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<float>()) ? 0 : 1;
}

{
glm::aligned_dquat const u(1., 2., 3., 4.);
glm::packed_dquat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<double>()) ? 0 : 1;
}
{
glm::packed_dquat const u(1., 2., 3., 4.);
glm::aligned_dquat const v(u);
Error += glm::equal(v.x, u.x, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.y, u.y, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.z, u.z, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(v.w, u.w, glm::epsilon<double>()) ? 0 : 1;
}

return Error;
}

static int test_splat_vec3()
{
int Error = 0;
Expand Down Expand Up @@ -499,6 +539,7 @@ int Error = 0;
Error += test_copy();
Error += test_copy_vec4();
Error += test_copy_vec3();
Error += test_copy_quat();
Error += test_aligned_ivec4();
Error += test_aligned_mat4();

Expand Down