summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsScriptC_Lib.cpp
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-09-04 14:42:41 -0700
committerJason Sams <rjsams@android.com>2009-09-04 14:42:41 -0700
commitea84a7c51790f9ba5f2194a66d6cf4ea8d879776 (patch)
tree089830bec92dcfb6fb7738f920433a8957b49de0 /libs/rs/rsScriptC_Lib.cpp
parent2525a815220652b37e2e390fe8c62394a6d0e574 (diff)
downloadframeworks_base-ea84a7c51790f9ba5f2194a66d6cf4ea8d879776.zip
frameworks_base-ea84a7c51790f9ba5f2194a66d6cf4ea8d879776.tar.gz
frameworks_base-ea84a7c51790f9ba5f2194a66d6cf4ea8d879776.tar.bz2
Remove "predefined" elements from Java layer. Static elements continue to exist but are no longer treated as a special version of element.
Diffstat (limited to 'libs/rs/rsScriptC_Lib.cpp')
-rw-r--r--libs/rs/rsScriptC_Lib.cpp99
1 files changed, 93 insertions, 6 deletions
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 84a39aa..5b19f17 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -36,6 +36,23 @@ using namespace android::renderscript;
Context * rsc = tls->mContext; \
ScriptC * sc = (ScriptC *) tls->mScript
+typedef struct {
+ float x;
+ float y;
+ float z;
+} vec3_t;
+
+typedef struct {
+ float x;
+ float y;
+ float z;
+ float w;
+} vec4_t;
+
+typedef struct {
+ float x;
+ float y;
+} vec2_t;
//////////////////////////////////////////////////////////////////////////////
// IO routines
@@ -161,6 +178,60 @@ static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
memcpy(&f[offset], m, sizeof(rsc_Matrix));
}
+//////////////////////////////////////////////////////////////////////////////
+// Vec3 routines
+//////////////////////////////////////////////////////////////////////////////
+
+static void SC_vec3Norm(vec3_t *v)
+{
+ float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
+ len = 1 / len;
+ v->x *= len;
+ v->y *= len;
+ v->z *= len;
+}
+
+static float SC_vec3Length(const vec3_t *v)
+{
+ return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
+}
+
+static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
+{
+ dest->x = lhs->x + rhs->x;
+ dest->y = lhs->y + rhs->y;
+ dest->z = lhs->z + rhs->z;
+}
+
+static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
+{
+ dest->x = lhs->x - rhs->x;
+ dest->y = lhs->y - rhs->y;
+ dest->z = lhs->z - rhs->z;
+}
+
+static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
+{
+ float x = lhs->y * rhs->z - lhs->z * rhs->y;
+ float y = lhs->z * rhs->x - lhs->x * rhs->z;
+ float z = lhs->x * rhs->y - lhs->y * rhs->x;
+ dest->x = x;
+ dest->y = y;
+ dest->z = z;
+}
+
+static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
+{
+ return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
+}
+
+static void SC_vec3Scale(vec3_t *lhs, float scale)
+{
+ lhs->x *= scale;
+ lhs->y *= scale;
+ lhs->z *= scale;
+}
+
//////////////////////////////////////////////////////////////////////////////
// Math routines
@@ -175,15 +246,15 @@ static float SC_sinf_fast(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;
}
@@ -195,15 +266,15 @@ static float SC_cosf_fast(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;
}
@@ -1038,6 +1109,22 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
{ "vec2Rand", (void *)&SC_vec2Rand,
"void", "(float *vec, float maxLen)" },
+ // vec3
+ { "vec3Norm", (void *)&SC_vec3Norm,
+ "void", "(struct vec3_s *)" },
+ { "vec3Length", (void *)&SC_vec3Length,
+ "float", "(struct vec3_s *)" },
+ { "vec3Add", (void *)&SC_vec3Add,
+ "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
+ { "vec3Sub", (void *)&SC_vec3Sub,
+ "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
+ { "vec3Cross", (void *)&SC_vec3Cross,
+ "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
+ { "vec3Dot", (void *)&SC_vec3Dot,
+ "float", "(struct vec3_s *lhs, struct vec3_s *rhs)" },
+ { "vec3Scale", (void *)&SC_vec3Scale,
+ "void", "(struct vec3_s *lhs, float scale)" },
+
// context
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
"void", "(int)" },