glm/test/gtc/gtc_swizzle.cpp

204 lines
4.3 KiB
C++
Raw Permalink Normal View History

///////////////////////////////////////////////////////////////////////////////////////////////////
2012-01-09 11:20:01 +00:00
// OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-16
// Updated : 2010-09-16
// Licence : This source is under MIT licence
2011-03-11 02:09:33 +00:00
// File : test/gtc/swizzle.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/swizzle.hpp>
2011-01-15 02:37:34 +00:00
int test_swizzle_vec4_ref_dynamic()
{
2011-05-02 21:27:55 +00:00
int Error = 0;
2011-01-15 02:37:34 +00:00
{
glm::ivec4 A(0, 1, 2, 3);
glm::ivec4 B(2, 1, 0, 3);
glm::swizzle(A, glm::Z, glm::Y, glm::X, glm::W) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B.x && A.y == B.y && A.x == B.z && A.w == B.w) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
{
glm::ivec4 A(0, 1, 2, 3);
glm::ivec3 B(2, 1, 0);
glm::swizzle(A, glm::Z, glm::Y, glm::X) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B.x && A.y == B.y && A.x == B.z) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
{
glm::ivec4 A(0, 1, 2, 3);
glm::ivec2 B(2, 1);
glm::swizzle(A, glm::Z, glm::Y) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B.x && A.y == B.y) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
{
glm::ivec4 A(0, 1, 2, 3);
int B(2);
glm::swizzle(A, glm::Z) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
2011-05-02 21:27:55 +00:00
return Error;
2011-01-15 02:37:34 +00:00
}
int test_swizzle_vec4_ref_static()
{
2011-05-02 21:27:55 +00:00
int Error = 0;
2011-01-15 02:37:34 +00:00
{
glm::ivec4 A(0, 1, 2, 3);
glm::ivec4 B(2, 1, 0, 3);
glm::swizzle<glm::Z, glm::Y, glm::X, glm::W>(A) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B.x && A.y == B.y && A.x == B.z && A.w == B.w) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
{
glm::ivec4 A(0, 1, 2, 3);
glm::ivec3 B(2, 1, 0);
glm::swizzle<glm::Z, glm::Y, glm::X>(A) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B.x && A.y == B.y && A.x == B.z) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
{
glm::ivec4 A(0, 1, 2, 3);
glm::ivec2 B(2, 1);
glm::swizzle<glm::Z, glm::Y>(A) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B.x && A.y == B.y) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
{
glm::ivec4 A(0, 1, 2, 3);
int B(2);
glm::swizzle<glm::Z>(A) = B;
2011-05-02 21:27:55 +00:00
Error += (A.z == B) ? 0 : 1;
2011-01-15 02:37:34 +00:00
}
2011-05-02 21:27:55 +00:00
return Error;
2011-01-15 02:37:34 +00:00
}
int test_swizzle_vec4_const_dynamic()
{
2011-05-02 21:27:55 +00:00
int Error = 0;
glm::ivec4 A(0, 1, 2, 3);
glm::ivec4 B = glm::swizzle(A, glm::B, glm::G, glm::R, glm::A);
2011-05-02 21:27:55 +00:00
Error += (glm::all(glm::equal(glm::ivec4(2, 1, 0, 3), B))) ? 0 : 1;
2011-01-15 02:37:34 +00:00
glm::ivec3 C = glm::swizzle(A, glm::W, glm::Y, glm::Z);
2011-05-02 21:27:55 +00:00
Error += (glm::all(glm::equal(glm::ivec3(3, 1, 2), C))) ? 0 : 1;
2011-01-15 02:37:34 +00:00
glm::ivec2 D = glm::swizzle(A, glm::W, glm::X);
2011-05-02 21:27:55 +00:00
Error += (glm::all(glm::equal(glm::ivec2(3, 0), D))) ? 0 : 1;
2011-01-15 02:37:34 +00:00
int E = glm::swizzle(A, glm::Q);
2011-05-02 21:27:55 +00:00
Error += (E == 3) ? 0 : 1;
2011-05-02 21:27:55 +00:00
return Error;
}
2011-01-15 02:37:34 +00:00
int test_swizzle_vec4_const_static()
{
2011-05-02 21:27:55 +00:00
int Error = 0;
glm::ivec4 A(0, 1, 2, 3);
2011-01-15 02:37:34 +00:00
glm::ivec4 B = glm::swizzle<glm::B, glm::G, glm::R, glm::A>(A);
2011-05-02 21:27:55 +00:00
Error += (glm::all(glm::equal(glm::ivec4(2, 1, 0, 3), B))) ? 0 : 1;
2011-01-15 02:37:34 +00:00
glm::ivec3 C = glm::swizzle<glm::W, glm::Y, glm::Z>(A);
2011-05-02 21:27:55 +00:00
Error += (glm::all(glm::equal(glm::ivec3(3, 1, 2), C))) ? 0 : 1;
2011-01-15 02:37:34 +00:00
glm::ivec2 D = glm::swizzle<glm::W, glm::X>(A);
2011-05-02 21:27:55 +00:00
Error += (glm::all(glm::equal(glm::ivec2(3, 0), D))) ? 0 : 1;
2011-01-15 02:37:34 +00:00
int E = glm::swizzle<glm::Q>(A);
2011-05-02 21:27:55 +00:00
Error += (E == 3) ? 0 : 1;
2011-05-02 21:27:55 +00:00
return Error;
}
int test_swizzle_vec3_partial()
{
int Error = 0;
glm::ivec3 A(0, 1, 2);
{
glm::ivec3 B(A.swizzle(glm::R, glm::G, glm::B));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec3 B(A.swizzle(glm::R, glm::G), 2);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec3 B(0, A.swizzle(glm::G, glm::B));
Error += (A == B) ? 0 : 1;
}
return Error;
}
int test_swizzle_vec4_partial()
{
int Error = 0;
glm::ivec4 A(0, 1, 2, 3);
{
glm::ivec4 B(A.swizzle(glm::R, glm::G, glm::B), 3);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(A.swizzle(glm::R, glm::G), 2, 3);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(0, A.swizzle(glm::G, glm::B), 3);
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(0, 1, A.swizzle(glm::B, glm::A));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(A.swizzle(glm::X, glm::Y), A.swizzle(glm::Z, glm::W));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(A.swizzle(glm::X, glm::Y), glm::vec2(2, 3));
Error += (A == B) ? 0 : 1;
}
{
glm::ivec4 B(glm::vec2(0, 1), A.swizzle(glm::Z, glm::W));
Error += (A == B) ? 0 : 1;
}
return Error;
}
2011-01-24 15:44:14 +00:00
int main()
{
2011-05-02 21:27:55 +00:00
int Error = 0;
Error += test_swizzle_vec3_partial();
2011-05-02 21:27:55 +00:00
Error += test_swizzle_vec4_ref_dynamic();
Error += test_swizzle_vec4_ref_static();
Error += test_swizzle_vec4_const_dynamic();
Error += test_swizzle_vec4_const_static();
Error += test_swizzle_vec4_partial();
2011-05-02 21:27:55 +00:00
return Error;
}