Added GTX_common with isdenomal #223

This commit is contained in:
Christophe Riccio 2014-09-07 20:53:35 +02:00
parent cccf2af0a2
commit ec513f4466
6 changed files with 208 additions and 5 deletions

70
glm/gtx/common.hpp Normal file
View File

@ -0,0 +1,70 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_common
/// @file glm/gtx/common.hpp
/// @date 2014-09-08 / 2014-09-08
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtc_half_float (dependence)
///
/// @defgroup gtx_common GLM_GTX_common
/// @ingroup gtx
///
/// @brief Provide functions to increase the compatibility with Cg and HLSL languages
///
/// <glm/gtx/common.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependencies:
#include "../vec2.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../gtx/vec1.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_common extension included")
#endif
namespace glm
{
/// @addtogroup gtx_common
/// @{
/// Returns true if x is a denormalized number
/// Numbers whose absolute value is too small to be represented in the normal format are represented in an alternate, denormalized format.
/// This format is less precise but can represent values closer to zero.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isnan.xml">GLSL isnan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL typename genType::bool_type isdenormal(genType const & x);
/// @}
}//namespace glm
#include "common.inl"

98
glm/gtx/common.inl Normal file
View File

@ -0,0 +1,98 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_common
/// @file glm/gtx/common.inl
/// @date 2014-09-08 / 2014-09-08
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <cmath>
namespace glm
{
template <typename T>
GLM_FUNC_QUALIFIER bool isdenormal(T const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
# if(GLM_LANG & GLM_LANG_CXX11_FLAG)
return std::fpclassify(x) == FP_SUBNORMAL;
# else
return x != static_cast<T>(0) && std::fabs(x) < std::numeric_limits<T>::min();
# endif
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename detail::tvec1<T, P>::bool_type isdenormal
(
detail::tvec1<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename detail::tvec1<T, P>::bool_type(
isdenormal(x.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename detail::tvec2<T, P>::bool_type isdenormal
(
detail::tvec2<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename detail::tvec2<T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename detail::tvec3<T, P>::bool_type isdenormal
(
detail::tvec3<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename detail::tvec3<T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename detail::tvec4<T, P>::bool_type isdenormal
(
detail::tvec4<T, P> const & x
)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isdenormal' only accept floating-point inputs");
return typename detail::tvec4<T, P>::bool_type(
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z),
isdenormal(x.w));
}
}//namespace glm

View File

@ -42,13 +42,14 @@ GLM 0.9.6.0: 2014-XX-XX
- Added transparent use of SIMD instructions for vec4 and mat4 types - Added transparent use of SIMD instructions for vec4 and mat4 types
- Removed degrees for function parameters - Removed degrees for function parameters
- Removed GLM_FORCE_RADIANS, active by default - Removed GLM_FORCE_RADIANS, active by default
- Added move contructors and assignment operators (#141) - Added move contructors and assignment operators #141
- Use pragma once - Use pragma once
- Fixed Visual Studio 14 compiler warnings - Fixed Visual Studio 14 compiler warnings
- Added *vec1 support to *vec2 types - Added *vec1 support to *vec2 types
- Limited extended integer type redifinition (#233) - Limited extended integer type redifinition #233
- Improved linearRand: support precision and integers (#230) - Improved linearRand: support precision and integers #230
- Added vec3 slerp (#237) - Added vec3 slerp #237
- Added GTX_common with isdenomal #223
================================================================================ ================================================================================
GLM 0.9.5.5: 2014-XX-XX GLM 0.9.5.5: 2014-XX-XX

View File

@ -3,6 +3,7 @@ glmCreateTestGTC(gtx_bit)
glmCreateTestGTC(gtx_closest_point) glmCreateTestGTC(gtx_closest_point)
glmCreateTestGTC(gtx_color_space_YCoCg) glmCreateTestGTC(gtx_color_space_YCoCg)
glmCreateTestGTC(gtx_color_space) glmCreateTestGTC(gtx_color_space)
glmCreateTestGTC(gtx_common)
glmCreateTestGTC(gtx_compatibility) glmCreateTestGTC(gtx_compatibility)
glmCreateTestGTC(gtx_component_wise) glmCreateTestGTC(gtx_component_wise)
glmCreateTestGTC(gtx_euler_angle) glmCreateTestGTC(gtx_euler_angle)

33
test/gtx/gtx_common.cpp Normal file
View File

@ -0,0 +1,33 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2014-09-08
// Updated : 2014-09-08
// Licence : This source is under MIT licence
// File : test/gtx/common.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/gtx/common.hpp>
#include <glm/gtx/vec1.hpp>
int test_isdenormal()
{
int Error(0);
bool A = glm::isdenormal(1.0f);
glm::bvec1 B = glm::isdenormal(glm::vec1(1.0f));
glm::bvec2 C = glm::isdenormal(glm::vec2(1.0f));
glm::bvec3 D = glm::isdenormal(glm::vec3(1.0f));
glm::bvec4 E = glm::isdenormal(glm::vec4(1.0f));
return Error;
}
int main()
{
int Error(0);
Error += test_isdenormal();
return Error;
}