diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
commit | 9066cfe9886ac131c34d59ed0e2d287b0e3c0087 (patch) | |
tree | d88beb88001f2482911e3d28e43833b50e4b4e97 /opengl/libagl/fp.cpp | |
parent | d83a98f4ce9cfa908f5c54bbd70f03eec07e7553 (diff) | |
download | frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.zip frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.gz frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'opengl/libagl/fp.cpp')
-rw-r--r-- | opengl/libagl/fp.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/opengl/libagl/fp.cpp b/opengl/libagl/fp.cpp new file mode 100644 index 0000000..ae5f1fe --- /dev/null +++ b/opengl/libagl/fp.cpp @@ -0,0 +1,87 @@ +/* libs/opengles/fp.cpp +** +** Copyright 2006, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#include "fp.h" + +// ---------------------------------------------------------------------------- + +#if !defined(__arm__) +GGLfixed gglFloatToFixed(float v) { + return GGLfixed(floorf(v * 65536.0f + 0.5f)); +} +#endif + +// ---------------------------------------------------------------------------- + +namespace android { + +namespace gl { + +GLfloat fixedToFloat(GLfixed x) +{ +#if DEBUG_USE_FLOATS + return x / 65536.0f; +#else + if (!x) return 0; + const uint32_t s = x & 0x80000000; + union { + uint32_t i; + float f; + }; + i = s ? -x : x; + const int c = gglClz(i) - 8; + i = (c>=0) ? (i<<c) : (i>>-c); + const uint32_t e = 134 - c; + i &= ~0x800000; + i |= e<<23; + i |= s; + return f; +#endif +} + +float sinef(float x) +{ + const float A = 1.0f / (2.0f*M_PI); + const float B = -16.0f; + const float C = 8.0f; + + // scale angle for easy argument reduction + x *= A; + + if (fabsf(x) >= 0.5f) { + // Argument reduction + x = x - ceilf(x + 0.5f) + 1.0f; + } + + const float y = B*x*fabsf(x) + C*x; + return 0.2215f * (y*fabsf(y) - y) + y; +} + +float cosinef(float x) +{ + return sinef(x + float(M_PI/2)); +} + +void sincosf(GLfloat angle, GLfloat* s, GLfloat* c) { + *s = sinef(angle); + *c = cosinef(angle); +} + +}; // namespace fp_utils + +// ---------------------------------------------------------------------------- +}; // namespace android |