Added explicit swizzle functions

This commit is contained in:
Christophe Riccio 2011-10-18 16:27:20 +01:00
parent b4206636b7
commit 9e735277ad
10 changed files with 87 additions and 7 deletions

View File

@ -7,7 +7,7 @@ enable_testing()
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
#add_definitions(/Za) add_definitions(/Za)
#add_definitions(-pedantic) #add_definitions(-pedantic)
#add_definitions(-S) #add_definitions(-S)
#add_definitions(-s) #add_definitions(-s)

View File

@ -29,6 +29,8 @@
#ifndef glm_core_swizzle #ifndef glm_core_swizzle
#define glm_core_swizzle #define glm_core_swizzle
#include "_swizzle_func.hpp"
namespace glm namespace glm
{ {
enum comp enum comp

View File

@ -30,20 +30,38 @@
#define glm_core_swizzle_func #define glm_core_swizzle_func
#define GLM_SWIZZLE_GEN_VEC2_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B) \ #define GLM_SWIZZLE_GEN_VEC2_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B) \
SWIZZLED_TYPE<TMPL_TYPE> A ## B() CONST \
{ \
return SWIZZLED_TYPE<TMPL_TYPE>(this->A, this->B); \
}
#define GLM_SWIZZLE_GEN_VEC3_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B, C) \
SWIZZLED_TYPE<TMPL_TYPE> A ## B ## C() CONST \
{ \
return SWIZZLED_TYPE<TMPL_TYPE>(this->A, this->B, this->B); \
}
#define GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B, C, D) \
SWIZZLED_TYPE<TMPL_TYPE> A ## B ## C ## D() CONST \
{ \
return SWIZZLED_TYPE<TMPL_TYPE>(this->A, this->B, this->C, this->D); \
}
#define GLM_SWIZZLE_GEN_VEC2_ENTRY_DEF(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B) \
template <typename TMPL_TYPE> \ template <typename TMPL_TYPE> \
SWIZZLED_TYPE<TMPL_TYPE> CLASS_TYPE<TMPL_TYPE>::A ## B() CONST \ SWIZZLED_TYPE<TMPL_TYPE> CLASS_TYPE<TMPL_TYPE>::A ## B() CONST \
{ \ { \
return SWIZZLED_TYPE<TMPL_TYPE>(this->A, this->B); \ return SWIZZLED_TYPE<TMPL_TYPE>(this->A, this->B); \
} }
#define GLM_SWIZZLE_GEN_VEC3_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B, C) \ #define GLM_SWIZZLE_GEN_VEC3_ENTRY_DEF(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B, C) \
template <typename TMPL_TYPE> \ template <typename TMPL_TYPE> \
SWIZZLED_TYPE<TMPL_TYPE> CLASS_TYPE<TMPL_TYPE>::A ## B ## C() CONST \ SWIZZLED_TYPE<TMPL_TYPE> CLASS_TYPE<TMPL_TYPE>::A ## B ## C() CONST \
{ \ { \
return SWIZZLED_TYPE<TMPL_TYPE>(this->A, this->B, this->B); \ return SWIZZLED_TYPE<TMPL_TYPE>(this->A, this->B, this->B); \
} }
#define GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B, C, D) \ #define GLM_SWIZZLE_GEN_VEC4_ENTRY_DEF(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, CONST, A, B, C, D) \
template <typename TMPL_TYPE> \ template <typename TMPL_TYPE> \
SWIZZLED_TYPE<TMPL_TYPE> CLASS_TYPE<TMPL_TYPE>::A ## B ## C ## D() CONST \ SWIZZLED_TYPE<TMPL_TYPE> CLASS_TYPE<TMPL_TYPE>::A ## B ## C ## D() CONST \
{ \ { \
@ -252,7 +270,7 @@
GLM_SWIZZLE_GEN_VEC3_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, C, C, B) \ GLM_SWIZZLE_GEN_VEC3_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, C, C, B) \
GLM_SWIZZLE_GEN_VEC3_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, C, C, C) GLM_SWIZZLE_GEN_VEC3_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, C, C, C)
#define GLM_SWIZZLE_GEN_VEC3_FROM_VEC4_SWIZZLE(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, A, B, C) \ #define GLM_SWIZZLE_GEN_VEC4_FROM_VEC3_SWIZZLE(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, A, B, C) \
GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, A, A, A, A) \ GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, A, A, A, A) \
GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, A, A, A, B) \ GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, A, A, A, B) \
GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, A, A, A, C) \ GLM_SWIZZLE_GEN_VEC4_ENTRY(TMPL_TYPE, CLASS_TYPE, SWIZZLED_TYPE, const, A, A, A, C) \

View File

@ -308,12 +308,18 @@
#define GLM_LANG_CXX 0 #define GLM_LANG_CXX 0
#define GLM_LANG_CXX98 1 #define GLM_LANG_CXX98 1
#define GLM_LANG_CXX0X 2 #define GLM_LANG_CXX03 2
#define GLM_LANG_CXXMS 3 #define GLM_LANG_CXX0X 3
#define GLM_LANG_CXXGNU 4 #define GLM_LANG_CXX11 4
#define GLM_LANG_CXXMS 5
#define GLM_LANG_CXXGNU 6
#if(defined(GLM_FORCE_CXX98)) #if(defined(GLM_FORCE_CXX98))
# define GLM_LANG GLM_LANG_CXX98 # define GLM_LANG GLM_LANG_CXX98
#elif(defined(GLM_FORCE_CXX03))
# define GLM_LANG GLM_LANG_CXX03
#elif(defined(GLM_FORCE_CXX11))
# define GLM_LANG GLM_LANG_CXX11
#elif(((GLM_COMPILER & GLM_COMPILER_GCC) == GLM_COMPILER_GCC) && defined(__GXX_EXPERIMENTAL_CXX0X__)) // -std=c++0x or -std=gnu++0x #elif(((GLM_COMPILER & GLM_COMPILER_GCC) == GLM_COMPILER_GCC) && defined(__GXX_EXPERIMENTAL_CXX0X__)) // -std=c++0x or -std=gnu++0x
# define GLM_LANG GLM_LANG_CXX0X # define GLM_LANG GLM_LANG_CXX0X
#elif(GLM_COMPILER == GLM_COMPILER_VC2010) //_MSC_EXTENSIONS for MS language extensions #elif(GLM_COMPILER == GLM_COMPILER_VC2010) //_MSC_EXTENSIONS for MS language extensions
@ -330,8 +336,12 @@
# define GLM_MESSAGE_LANG_DISPLAYED # define GLM_MESSAGE_LANG_DISPLAYED
# if(GLM_LANG == GLM_LANG_CXX98) # if(GLM_LANG == GLM_LANG_CXX98)
# pragma message("GLM: C++98") # pragma message("GLM: C++98")
# elif(GLM_LANG == GLM_LANG_CXX03)
# pragma message("GLM: C++03")
# elif(GLM_LANG == GLM_LANG_CXX0X) # elif(GLM_LANG == GLM_LANG_CXX0X)
# pragma message("GLM: C++0x") # pragma message("GLM: C++0x")
# elif(GLM_LANG == GLM_LANG_CXX11)
# pragma message("GLM: C++11")
# endif//GLM_MODEL # endif//GLM_MODEL
#endif//GLM_MESSAGE #endif//GLM_MESSAGE

View File

@ -84,6 +84,10 @@ namespace detail
# else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES) # else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES)
union {value_type x, r, s;}; union {value_type x, r, s;};
union {value_type y, g, t;}; union {value_type y, g, t;};
// Defines all he swizzle operator as functions
GLM_SWIZZLE_GEN_REF_FROM_VEC2(T, detail::ref2, detail::vec2)
GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, detail::vec4, detail::vec2, detail::vec3, detail::vec4)
# endif//GLM_COMPONENT # endif//GLM_COMPONENT
////////////////////////////////////// //////////////////////////////////////

View File

@ -85,6 +85,10 @@ namespace detail
union {value_type x, r, s;}; union {value_type x, r, s;};
union {value_type y, g, t;}; union {value_type y, g, t;};
union {value_type z, b, p;}; union {value_type z, b, p;};
// Defines all he swizzle operator as functions
GLM_SWIZZLE_GEN_REF_FROM_VEC3(T, detail::ref3, detail::vec2, detail::vec3)
GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, detail::vec4, detail::vec2, detail::vec3, detail::vec4)
# endif//GLM_COMPONENT # endif//GLM_COMPONENT
////////////////////////////////////// //////////////////////////////////////

View File

@ -86,6 +86,10 @@ namespace detail
union {value_type y, g, t;}; union {value_type y, g, t;};
union {value_type z, b, p;}; union {value_type z, b, p;};
union {value_type w, a, q;}; union {value_type w, a, q;};
// Defines all he swizzle operator as functions
GLM_SWIZZLE_GEN_REF_FROM_VEC4(T, detail::ref4, detail::vec2, detail::vec3, detail::vec4)
GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, detail::vec4, detail::vec2, detail::vec3, detail::vec4)
# endif//GLM_COMPONENT # endif//GLM_COMPONENT
////////////////////////////////////// //////////////////////////////////////

View File

@ -80,6 +80,8 @@
#ifndef glm_glm #ifndef glm_glm
#define glm_glm #define glm_glm
#define GLM_FORCE_CXX98
#include <cmath> #include <cmath>
#include <climits> #include <climits>
#include <cfloat> #include <cfloat>

View File

@ -24,6 +24,7 @@ glmCreateTestGTC(core_func_noise)
glmCreateTestGTC(core_func_packing) glmCreateTestGTC(core_func_packing)
glmCreateTestGTC(core_func_trigonometric) glmCreateTestGTC(core_func_trigonometric)
glmCreateTestGTC(core_func_vector_relational) glmCreateTestGTC(core_func_vector_relational)
glmCreateTestGTC(core_func_swizzle)
glmCreateTestGTC(core_setup_message) glmCreateTestGTC(core_setup_message)
glmCreateTestGTC(core_setup_precision) glmCreateTestGTC(core_setup_precision)

View File

@ -0,0 +1,35 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-10-16
// Updated : 2011-10-16
// Licence : This source is under MIT License
// File : test/core/core_func_swizzle.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_FORCE_CXX98
#include <glm/glm.hpp>
int test_vec4_swizzle()
{
int Error = 0;
glm::ivec4 A(1, 2, 3, 4);
glm::ivec4 B = A.xyzw();
Error += A == B ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_vec4_swizzle();
return Error;
}