diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-10-19 11:14:41 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-10-19 11:14:41 -0300 |
commit | 4428115916144b45c4697cd65d9c8c093631bec6 (patch) | |
tree | afff5350ae57ba65b190f16b27db892173d9f43f /core | |
parent | 1527cf8c0d17891dd0ebf99d484f83daa46eba3c (diff) |
Everything returning to normal in 3D, still a long way to go
-implemented the scene part of visual server and rasterizer, objects without lighting and material are rendererd only
Diffstat (limited to 'core')
-rw-r--r-- | core/math/math_funcs.h | 102 | ||||
-rw-r--r-- | core/rid.h | 8 |
2 files changed, 110 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index fc76d96b2e..c8ced0b306 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -175,6 +175,108 @@ public: static double log(double x); static double exp(double x); + + static _FORCE_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h) + { + uint16_t h_exp, h_sig; + uint32_t f_sgn, f_exp, f_sig; + + h_exp = (h&0x7c00u); + f_sgn = ((uint32_t)h&0x8000u) << 16; + switch (h_exp) { + case 0x0000u: /* 0 or subnormal */ + h_sig = (h&0x03ffu); + /* Signed zero */ + if (h_sig == 0) { + return f_sgn; + } + /* Subnormal */ + h_sig <<= 1; + while ((h_sig&0x0400u) == 0) { + h_sig <<= 1; + h_exp++; + } + f_exp = ((uint32_t)(127 - 15 - h_exp)) << 23; + f_sig = ((uint32_t)(h_sig&0x03ffu)) << 13; + return f_sgn + f_exp + f_sig; + case 0x7c00u: /* inf or NaN */ + /* All-ones exponent and a copy of the significand */ + return f_sgn + 0x7f800000u + (((uint32_t)(h&0x03ffu)) << 13); + default: /* normalized */ + /* Just need to adjust the exponent and shift */ + return f_sgn + (((uint32_t)(h&0x7fffu) + 0x1c000u) << 13); + } + } + + static _FORCE_INLINE_ float halfptr_to_float(uint16_t *h) { + + union { + uint32_t u32; + float f32; + } u; + + u.u32=halfbits_to_floatbits(*h); + return u.f32; + } + + static _FORCE_INLINE_ uint16_t make_half_float(float f) { + + union { + float fv; + uint32_t ui; + } ci; + ci.fv=f; + + uint32_t x = ci.ui; + uint32_t sign = (unsigned short)(x >> 31); + uint32_t mantissa; + uint32_t exp; + uint16_t hf; + + // get mantissa + mantissa = x & ((1 << 23) - 1); + // get exponent bits + exp = x & (0xFF << 23); + if (exp >= 0x47800000) + { + // check if the original single precision float number is a NaN + if (mantissa && (exp == (0xFF << 23))) + { + // we have a single precision NaN + mantissa = (1 << 23) - 1; + } + else + { + // 16-bit half-float representation stores number as Inf + mantissa = 0; + } + hf = (((uint16_t)sign) << 15) | (uint16_t)((0x1F << 10)) | + (uint16_t)(mantissa >> 13); + } + // check if exponent is <= -15 + else if (exp <= 0x38000000) + { + + /*// store a denorm half-float value or zero + exp = (0x38000000 - exp) >> 23; + mantissa >>= (14 + exp); + + hf = (((uint16_t)sign) << 15) | (uint16_t)(mantissa); + */ + hf=0; //denormals do not work for 3D, convert to zero + } + else + { + hf = (((uint16_t)sign) << 15) | + (uint16_t)((exp - 0x38000000) >> 13) | + (uint16_t)(mantissa >> 13); + } + + return hf; + } + + + }; diff --git a/core/rid.h b/core/rid.h index 85a69ac0ef..92b7e6ee69 100644 --- a/core/rid.h +++ b/core/rid.h @@ -181,6 +181,14 @@ public: } + + _FORCE_INLINE_ T * getptr(const RID& p_rid) { + + return static_cast<T*>(p_rid.get_data()); + + } + + _FORCE_INLINE_ bool owns(const RID& p_rid) const { if (p_rid.get_data()==NULL) |