diff --git a/inc/hgl/math/HalfFloat.h b/inc/hgl/math/HalfFloat.h index f6c3aa7..8670a2a 100644 --- a/inc/hgl/math/HalfFloat.h +++ b/inc/hgl/math/HalfFloat.h @@ -52,56 +52,7 @@ namespace hgl /** * 标准版float32转float16处理 */ - void Float32toFloat16(half_float *output,const float *input,const uint count) - { - const uint32 *src=(const uint32 *)input; - uint16 *dst=output; - - for(uint i=0;i>23; - uint32 mantissa=value&0x007FFFFF; - - if(exponent==0xFF) - { - if(mantissa==0) - dst[i]=sign_bit>>16; - else - dst[i]=0x7FFF; - } - else - { - if(exponent==0) - { - if(mantissa==0) - dst[i]=sign_bit>>16; - else - { - uint32 mantissa_bit=0x00800000; - - while((mantissa&mantissa_bit)==0) - { - mantissa_bit>>=1; - --exponent; - } - - exponent+=1; - mantissa&=~mantissa_bit; - } - } - else - { - exponent+=15-127; - mantissa>>=13; - } - - dst[i]=sign_bit>>16|exponent<<10|mantissa; - } - } - } + void Float32toFloat16(half_float *output,const float *input,const uint count); /** * 快速版float32转float16处理 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 060f910..0486703 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,11 +35,13 @@ SET(MATH_HEADER_FILES ${MATH_INCLUDE_PATH}/bvec.h ${MATH_INCLUDE_PATH}/Vector.h ${MATH_INCLUDE_PATH}/PrimaryMathematics.h ${MATH_INCLUDE_PATH}/PhysicsConst.h + ${MATH_INCLUDE_PATH}/HalfFloat.h ) SET(MATH_SOURCE_FILES Math/LAtan.cpp Math/LSinCos.cpp - Math/Matrix4f.cpp) + Math/Matrix4f.cpp + Math/HalfFloat.cpp) SOURCE_GROUP("Math\\Header Files" FILES ${MATH_HEADER_FILES}) SOURCE_GROUP("Math\\Source Files" FILES ${MATH_SOURCE_FILES}) diff --git a/src/Math/HalfFloat.cpp b/src/Math/HalfFloat.cpp new file mode 100644 index 0000000..0e6563e --- /dev/null +++ b/src/Math/HalfFloat.cpp @@ -0,0 +1,55 @@ +#include + +namespace hgl +{ + void Float32toFloat16(half_float *output,const float *input,const uint count) + { + const uint32 *src=(const uint32 *)input; + uint16 *dst=output; + + for(uint i=0;i>23; + uint32 mantissa=value&0x007FFFFF; + + if(exponent==0xFF) + { + if(mantissa==0) + dst[i]=sign_bit>>16; + else + dst[i]=0x7FFF; + } + else + { + if(exponent==0) + { + if(mantissa==0) + dst[i]=sign_bit>>16; + else + { + uint32 mantissa_bit=0x00800000; + + while((mantissa&mantissa_bit)==0) + { + mantissa_bit>>=1; + --exponent; + } + + exponent+=1; + mantissa&=~mantissa_bit; + } + } + else + { + exponent+=15-127; + mantissa>>=13; + } + + dst[i]=sign_bit>>16|exponent<<10|mantissa; + } + } + } +}//namespace hgl \ No newline at end of file