summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsScriptC_Lib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/rsScriptC_Lib.cpp')
-rw-r--r--libs/rs/rsScriptC_Lib.cpp1957
1 files changed, 780 insertions, 1177 deletions
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 202ca3d..8a85f6e 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -17,18 +17,9 @@
#include "rsContext.h"
#include "rsScriptC.h"
#include "rsMatrix.h"
-#include "rsNoise.h"
-#include "acc/acc.h"
#include "utils/Timers.h"
-#define GL_GLEXT_PROTOTYPES
-
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-
#include <time.h>
using namespace android;
@@ -39,254 +30,12 @@ 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
-//////////////////////////////////////////////////////////////////////////////
-
-static float SC_loadF(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const float *f = static_cast<const float *>(vp);
- //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]);
- return f[offset];
-}
-
-static int32_t SC_loadI32(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const int32_t *i = static_cast<const int32_t *>(vp);
- //LOGE("loadI32 %i %i = %i", bank, offset, t);
- return i[offset];
-}
-
-static float* SC_loadArrayF(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- return f + offset;
-}
-
-static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- int32_t *i = static_cast<int32_t *>(vp);
- return i + offset;
-}
-
-static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx)
-{
- SimpleMesh *tm = static_cast<SimpleMesh *>(mesh);
- void *vp = tm->mVertexBuffers[idx]->getPtr();;
- return static_cast<float *>(vp);
-}
-
-static void SC_updateSimpleMesh(RsSimpleMesh mesh)
-{
- GET_TLS();
- SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
- sm->uploadAll(rsc);
-}
-
-static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const uint32_t *i = static_cast<const uint32_t *>(vp);
- return i[offset];
-}
-
-static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const float *f = static_cast<const float *>(vp);
- memcpy(v, &f[offset], sizeof(rsc_Vector4));
-}
-
-static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const float *f = static_cast<const float *>(vp);
- memcpy(m, &f[offset], sizeof(rsc_Matrix));
-}
-
-
-static void SC_storeF(uint32_t bank, uint32_t offset, float v)
-{
- //LOGE("storeF %i %i %f", bank, offset, v);
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- f[offset] = v;
-}
-
-static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- int32_t *f = static_cast<int32_t *>(vp);
- static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
-}
-
-static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- uint32_t *f = static_cast<uint32_t *>(vp);
- static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
-}
-
-static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- memcpy(&f[offset], v, sizeof(rsc_Vector4));
-}
-
-static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- 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;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// Vec4 routines
-//////////////////////////////////////////////////////////////////////////////
-
-static void SC_vec4Norm(vec4_t *v)
-{
- float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
- len = 1 / len;
- v->x *= len;
- v->y *= len;
- v->z *= len;
- v->w *= len;
-}
-
-static float SC_vec4Length(const vec4_t *v)
-{
- return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
-}
-
-static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
-{
- dest->x = lhs->x + rhs->x;
- dest->y = lhs->y + rhs->y;
- dest->z = lhs->z + rhs->z;
- dest->w = lhs->w + rhs->w;
-}
-
-static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
-{
- dest->x = lhs->x - rhs->x;
- dest->y = lhs->y - rhs->y;
- dest->z = lhs->z - rhs->z;
- dest->w = lhs->w - rhs->w;
-}
-
-static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
-{
- return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
-}
-
-static void SC_vec4Scale(vec4_t *lhs, float scale)
-{
- lhs->x *= scale;
- lhs->y *= scale;
- lhs->z *= scale;
- lhs->w *= scale;
-}
//////////////////////////////////////////////////////////////////////////////
// Math routines
//////////////////////////////////////////////////////////////////////////////
-#define PI 3.1415926f
-#define DEG_TO_RAD PI / 180.0f
-#define RAD_TO_DEG 180.0f / PI
-
-static float SC_sinf_fast(float x)
-{
+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;
@@ -303,8 +52,7 @@ static float SC_sinf_fast(float x)
return 0.2215f * (y * fabsf(y) - y) + y;
}
-static float SC_cosf_fast(float x)
-{
+static float SC_cosf_fast(float x) {
x += float(M_PI / 2);
const float A = 1.0f / (2.0f * M_PI);
@@ -323,756 +71,762 @@ static float SC_cosf_fast(float x)
return 0.2215f * (y * fabsf(y) - y) + y;
}
-static float SC_randf(float max)
-{
+static float SC_randf(float max) {
float r = (float)rand();
- return r / RAND_MAX * max;
+ r *= max;
+ return r / RAND_MAX;
}
-static float SC_randf2(float min, float max)
-{
+static float SC_randf2(float min, float max) {
float r = (float)rand();
- return r / RAND_MAX * (max - min) + min;
+ r = r * (max - min) + min;
+ return r / RAND_MAX;
}
-static int SC_sign(int value)
-{
- return (value > 0) - (value < 0);
+static int SC_randi(int max) {
+ return (int)SC_randf(max);
}
-static float SC_signf(float value)
-{
- return (value > 0) - (value < 0);
+static int SC_randi2(int min, int max) {
+ return (int)SC_randf2(min, max);
}
-static float SC_clampf(float amount, float low, float high)
-{
- return amount < low ? low : (amount > high ? high : amount);
+static float SC_frac(float v) {
+ int i = (int)floor(v);
+ return fmin(v - i, 0x1.fffffep-1f);
}
-static int SC_clamp(int amount, int low, int high)
-{
- return amount < low ? low : (amount > high ? high : amount);
-}
+//////////////////////////////////////////////////////////////////////////////
+// Time routines
+//////////////////////////////////////////////////////////////////////////////
-static float SC_maxf(float a, float b)
-{
- return a > b ? a : b;
+static time_t SC_time(time_t *timer) {
+ GET_TLS();
+ return time(timer);
}
-static float SC_minf(float a, float b)
-{
- return a < b ? a : b;
-}
+static tm* SC_localtime(tm *local, time_t *timer) {
+ GET_TLS();
+ if (!local) {
+ return NULL;
+ }
-static float SC_sqrf(float v)
-{
- return v * v;
+ // The native localtime function is not thread-safe, so we
+ // have to apply locking for proper behavior in RenderScript.
+ pthread_mutex_lock(&rsc->gLibMutex);
+ tm *tmp = localtime(timer);
+ memcpy(local, tmp, sizeof(*tmp));
+ pthread_mutex_unlock(&rsc->gLibMutex);
+ return local;
}
-static int SC_sqr(int v)
-{
- return v * v;
+static int64_t SC_uptimeMillis() {
+ return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
}
-static float SC_fracf(float v)
-{
- return v - floorf(v);
+static int64_t SC_uptimeNanos() {
+ return systemTime(SYSTEM_TIME_MONOTONIC);
}
-static float SC_roundf(float v)
-{
- return floorf(v + 0.4999999999);
+static float SC_getDt() {
+ GET_TLS();
+ int64_t l = sc->mEnviroment.mLastDtTime;
+ sc->mEnviroment.mLastDtTime = systemTime(SYSTEM_TIME_MONOTONIC);
+ return ((float)(sc->mEnviroment.mLastDtTime - l)) / 1.0e9;
}
-static float SC_distf2(float x1, float y1, float x2, float y2)
-{
- float x = x2 - x1;
- float y = y2 - y1;
- return sqrtf(x * x + y * y);
-}
+//////////////////////////////////////////////////////////////////////////////
+//
+//////////////////////////////////////////////////////////////////////////////
-static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2)
-{
- float x = x2 - x1;
- float y = y2 - y1;
- float z = z2 - z1;
- return sqrtf(x * x + y * y + z * z);
+static uint32_t SC_allocGetDimX(RsAllocation va) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ //LOGE("SC_allocGetDimX a=%p type=%p", a, a->getType());
+ return a->getType()->getDimX();
}
-static float SC_magf2(float a, float b)
-{
- return sqrtf(a * a + b * b);
+static uint32_t SC_allocGetDimY(RsAllocation va) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ return a->getType()->getDimY();
}
-static float SC_magf3(float a, float b, float c)
-{
- return sqrtf(a * a + b * b + c * c);
+static uint32_t SC_allocGetDimZ(RsAllocation va) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ return a->getType()->getDimZ();
}
-static float SC_radf(float degrees)
-{
- return degrees * DEG_TO_RAD;
+static uint32_t SC_allocGetDimLOD(RsAllocation va) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ return a->getType()->getDimLOD();
}
-static float SC_degf(float radians)
-{
- return radians * RAD_TO_DEG;
+static uint32_t SC_allocGetDimFaces(RsAllocation va) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ return a->getType()->getDimFaces();
}
-static float SC_lerpf(float start, float stop, float amount)
-{
- return start + (stop - start) * amount;
+static const void * SC_getElementAtX(RsAllocation va, uint32_t x) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ const Type *t = a->getType();
+ CHECK_OBJ(t);
+ const uint8_t *p = (const uint8_t *)a->getPtr();
+ return &p[t->getElementSizeBytes() * x];
}
-static float SC_normf(float start, float stop, float value)
-{
- return (value - start) / (stop - start);
+static const void * SC_getElementAtXY(RsAllocation va, uint32_t x, uint32_t y) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ const Type *t = a->getType();
+ CHECK_OBJ(t);
+ const uint8_t *p = (const uint8_t *)a->getPtr();
+ return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
}
-static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
-{
- return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
+static const void * SC_getElementAtXYZ(RsAllocation va, uint32_t x, uint32_t y, uint32_t z) {
+ const Allocation *a = static_cast<const Allocation *>(va);
+ CHECK_OBJ(a);
+ const Type *t = a->getType();
+ CHECK_OBJ(t);
+ const uint8_t *p = (const uint8_t *)a->getPtr();
+ return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
}
-//////////////////////////////////////////////////////////////////////////////
-// Time routines
-//////////////////////////////////////////////////////////////////////////////
-
-static int32_t SC_second()
-{
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_sec;
+static void SC_setObject(void **vdst, void * vsrc) {
+ //LOGE("SC_setObject %p,%p %p", vdst, *vdst, vsrc);
+ if (vsrc) {
+ CHECK_OBJ(vsrc);
+ static_cast<ObjectBase *>(vsrc)->incSysRef();
+ }
+ if (vdst[0]) {
+ CHECK_OBJ(vdst[0]);
+ static_cast<ObjectBase *>(vdst[0])->decSysRef();
+ }
+ *vdst = vsrc;
+ //LOGE("SC_setObject *");
}
-static int32_t SC_minute()
-{
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_min;
+static void SC_clearObject(void **vdst) {
+ //LOGE("SC_clearObject %p,%p", vdst, *vdst);
+ if (vdst[0]) {
+ CHECK_OBJ(vdst[0]);
+ static_cast<ObjectBase *>(vdst[0])->decSysRef();
+ }
+ *vdst = NULL;
+ //LOGE("SC_clearObject *");
}
-static int32_t SC_hour()
-{
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_hour;
+static bool SC_isObject(RsAllocation vsrc) {
+ return vsrc != NULL;
}
-static int32_t SC_day()
-{
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_mday;
+static void SC_debugF(const char *s, float f) {
+ LOGD("%s %f, 0x%08x", s, f, *((int *) (&f)));
}
-
-static int32_t SC_month()
-{
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_mon;
+static void SC_debugFv2(const char *s, float f1, float f2) {
+ LOGD("%s {%f, %f}", s, f1, f2);
}
-
-static int32_t SC_year()
-{
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_year;
+static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
+ LOGD("%s {%f, %f, %f}", s, f1, f2, f3);
}
-
-static int32_t SC_uptimeMillis()
-{
- return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
+static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
+ LOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
}
-
-static int32_t SC_startTimeMillis()
-{
- GET_TLS();
- return sc->mEnviroment.mStartTimeMillis;
+static void SC_debugD(const char *s, double d) {
+ LOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
}
-
-static int32_t SC_elapsedTimeMillis()
-{
- GET_TLS();
- return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
- - sc->mEnviroment.mStartTimeMillis;
+static void SC_debugFM4v4(const char *s, const float *f) {
+ LOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
+ LOGD("%s %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
+ LOGD("%s %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
+ LOGD("%s %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
}
-
-//////////////////////////////////////////////////////////////////////////////
-// Matrix routines
-//////////////////////////////////////////////////////////////////////////////
-
-
-static void SC_matrixLoadIdentity(rsc_Matrix *mat)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->loadIdentity();
+static void SC_debugFM3v3(const char *s, const float *f) {
+ LOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]);
+ LOGD("%s %f, %f, %f", s, f[1], f[4], f[7]);
+ LOGD("%s %f, %f, %f}",s, f[2], f[5], f[8]);
}
-
-static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->load(f);
+static void SC_debugFM2v2(const char *s, const float *f) {
+ LOGD("%s {%f, %f", s, f[0], f[2]);
+ LOGD("%s %f, %f}",s, f[1], f[3]);
}
-static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->load(reinterpret_cast<const Matrix *>(newmat));
+static void SC_debugI32(const char *s, int32_t i) {
+ LOGD("%s %i 0x%x", s, i, i);
}
-
-static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->loadRotate(rot, x, y, z);
+static void SC_debugU32(const char *s, uint32_t i) {
+ LOGD("%s %u 0x%x", s, i, i);
}
-
-static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->loadScale(x, y, z);
+static void SC_debugLL64(const char *s, long long ll) {
+ LOGD("%s %lld 0x%llx", s, ll, ll);
}
-
-static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->loadTranslate(x, y, z);
+static void SC_debugULL64(const char *s, unsigned long long ll) {
+ LOGD("%s %llu 0x%llx", s, ll, ll);
}
-static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->loadMultiply(reinterpret_cast<const Matrix *>(lhs),
- reinterpret_cast<const Matrix *>(rhs));
+static void SC_debugP(const char *s, const void *p) {
+ LOGD("%s %p", s, p);
}
-static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->multiply(reinterpret_cast<const Matrix *>(rhs));
+static uint32_t SC_toClient2(int cmdID, void *data, int len) {
+ GET_TLS();
+ //LOGE("SC_toClient %i %i %i", cmdID, len);
+ return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, false);
}
-static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->rotate(rot, x, y, z);
+static uint32_t SC_toClient(int cmdID) {
+ GET_TLS();
+ //LOGE("SC_toClient %i", cmdID);
+ return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, false);
}
-static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->scale(x, y, z);
+static uint32_t SC_toClientBlocking2(int cmdID, void *data, int len) {
+ GET_TLS();
+ //LOGE("SC_toClientBlocking %i %i", cmdID, len);
+ return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, true);
}
-static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
-{
- Matrix *m = reinterpret_cast<Matrix *>(mat);
- m->translate(x, y, z);
+static uint32_t SC_toClientBlocking(int cmdID) {
+ GET_TLS();
+ //LOGE("SC_toClientBlocking %i", cmdID);
+ return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, true);
}
-
-static void SC_vec2Rand(float *vec, float maxLen)
-{
- float angle = SC_randf(PI * 2);
- float len = SC_randf(maxLen);
- vec[0] = len * sinf(angle);
- vec[1] = len * cosf(angle);
+int SC_divsi3(int a, int b) {
+ return a / b;
}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// Context
-//////////////////////////////////////////////////////////////////////////////
-
-static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
-{
- GET_TLS();
- rsi_ProgramBindTexture(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Allocation *>(va));
-
+int SC_modsi3(int a, int b) {
+ return a % b;
}
-static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
-{
- GET_TLS();
- rsi_ProgramBindSampler(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Sampler *>(vs));
-
+unsigned int SC_udivsi3(unsigned int a, unsigned int b) {
+ return a / b;
}
-static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
-{
- GET_TLS();
- rsi_ContextBindProgramFragmentStore(rsc, pfs);
-
+unsigned int SC_umodsi3(unsigned int a, unsigned int b) {
+ return a % b;
}
-static void SC_bindProgramFragment(RsProgramFragment pf)
-{
+int SC_getAllocation(const void *ptr) {
GET_TLS();
- rsi_ContextBindProgramFragment(rsc, pf);
-
+ const Allocation *alloc = sc->ptrToAllocation(ptr);
+ return (int)alloc;
}
-static void SC_bindProgramVertex(RsProgramVertex pv)
-{
- GET_TLS();
- rsi_ContextBindProgramVertex(rsc, pv);
-
+void SC_allocationMarkDirty(RsAllocation a) {
+ Allocation *alloc = static_cast<Allocation *>(a);
+ alloc->sendDirty();
}
-//////////////////////////////////////////////////////////////////////////////
-// VP
-//////////////////////////////////////////////////////////////////////////////
-
-static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
-{
+void SC_ForEach(RsScript vs,
+ RsAllocation vin,
+ RsAllocation vout,
+ const void *usr) {
GET_TLS();
- rsc->getVertex()->setModelviewMatrix(m);
+ const Allocation *ain = static_cast<const Allocation *>(vin);
+ Allocation *aout = static_cast<Allocation *>(vout);
+ Script *s = static_cast<Script *>(vs);
+ s->runForEach(rsc, ain, aout, usr);
}
-static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
-{
+void SC_ForEach2(RsScript vs,
+ RsAllocation vin,
+ RsAllocation vout,
+ const void *usr,
+ const RsScriptCall *call) {
GET_TLS();
- rsc->getVertex()->setTextureMatrix(m);
+ const Allocation *ain = static_cast<const Allocation *>(vin);
+ Allocation *aout = static_cast<Allocation *>(vout);
+ Script *s = static_cast<Script *>(vs);
+ s->runForEach(rsc, ain, aout, usr, call);
}
-
//////////////////////////////////////////////////////////////////////////////
-// Drawing
+// Heavy math functions
//////////////////////////////////////////////////////////////////////////////
-static void SC_drawLine(float x1, float y1, float z1,
- float x2, float y2, float z2)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
- }
-
- float vtx[] = { x1, y1, z1, x2, y2, z2 };
- VertexArray va;
- va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
- if (rsc->checkVersion2_0()) {
- va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
- } else {
- va.setupGL(rsc, &rsc->mStateVertexArray);
- }
+typedef struct {
+ float m[16];
+} rs_matrix4x4;
- glDrawArrays(GL_LINES, 0, 2);
-}
+typedef struct {
+ float m[9];
+} rs_matrix3x3;
-static void SC_drawPoint(float x, float y, float z)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
+typedef struct {
+ float m[4];
+} rs_matrix2x2;
+
+static inline void
+rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) {
+ m->m[row * 4 + col] = v;
+}
+
+static inline float
+rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) {
+ return m->m[row * 4 + col];
+}
+
+static inline void
+rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) {
+ m->m[row * 3 + col] = v;
+}
+
+static inline float
+rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) {
+ return m->m[row * 3 + col];
+}
+
+static inline void
+rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) {
+ m->m[row * 2 + col] = v;
+}
+
+static inline float
+rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) {
+ return m->m[row * 2 + col];
+}
+
+
+static void SC_MatrixLoadIdentity_4x4(rs_matrix4x4 *m) {
+ m->m[0] = 1.f;
+ m->m[1] = 0.f;
+ m->m[2] = 0.f;
+ m->m[3] = 0.f;
+ m->m[4] = 0.f;
+ m->m[5] = 1.f;
+ m->m[6] = 0.f;
+ m->m[7] = 0.f;
+ m->m[8] = 0.f;
+ m->m[9] = 0.f;
+ m->m[10] = 1.f;
+ m->m[11] = 0.f;
+ m->m[12] = 0.f;
+ m->m[13] = 0.f;
+ m->m[14] = 0.f;
+ m->m[15] = 1.f;
+}
+
+static void SC_MatrixLoadIdentity_3x3(rs_matrix3x3 *m) {
+ m->m[0] = 1.f;
+ m->m[1] = 0.f;
+ m->m[2] = 0.f;
+ m->m[3] = 0.f;
+ m->m[4] = 1.f;
+ m->m[5] = 0.f;
+ m->m[6] = 0.f;
+ m->m[7] = 0.f;
+ m->m[8] = 1.f;
+}
+
+static void SC_MatrixLoadIdentity_2x2(rs_matrix2x2 *m) {
+ m->m[0] = 1.f;
+ m->m[1] = 0.f;
+ m->m[2] = 0.f;
+ m->m[3] = 1.f;
+}
+
+static void SC_MatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v) {
+ m->m[0] = v[0];
+ m->m[1] = v[1];
+ m->m[2] = v[2];
+ m->m[3] = v[3];
+ m->m[4] = v[4];
+ m->m[5] = v[5];
+ m->m[6] = v[6];
+ m->m[7] = v[7];
+ m->m[8] = v[8];
+ m->m[9] = v[9];
+ m->m[10] = v[10];
+ m->m[11] = v[11];
+ m->m[12] = v[12];
+ m->m[13] = v[13];
+ m->m[14] = v[14];
+ m->m[15] = v[15];
+}
+
+static void SC_MatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v) {
+ m->m[0] = v[0];
+ m->m[1] = v[1];
+ m->m[2] = v[2];
+ m->m[3] = v[3];
+ m->m[4] = v[4];
+ m->m[5] = v[5];
+ m->m[6] = v[6];
+ m->m[7] = v[7];
+ m->m[8] = v[8];
+}
+
+static void SC_MatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v) {
+ m->m[0] = v[0];
+ m->m[1] = v[1];
+ m->m[2] = v[2];
+ m->m[3] = v[3];
+}
+
+static void SC_MatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = v->m[3];
+ m->m[4] = v->m[4];
+ m->m[5] = v->m[5];
+ m->m[6] = v->m[6];
+ m->m[7] = v->m[7];
+ m->m[8] = v->m[8];
+ m->m[9] = v->m[9];
+ m->m[10] = v->m[10];
+ m->m[11] = v->m[11];
+ m->m[12] = v->m[12];
+ m->m[13] = v->m[13];
+ m->m[14] = v->m[14];
+ m->m[15] = v->m[15];
+}
+
+static void SC_MatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = 0.f;
+ m->m[4] = v->m[3];
+ m->m[5] = v->m[4];
+ m->m[6] = v->m[5];
+ m->m[7] = 0.f;
+ m->m[8] = v->m[6];
+ m->m[9] = v->m[7];
+ m->m[10] = v->m[8];
+ m->m[11] = 0.f;
+ m->m[12] = 0.f;
+ m->m[13] = 0.f;
+ m->m[14] = 0.f;
+ m->m[15] = 1.f;
+}
+
+static void SC_MatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = 0.f;
+ m->m[3] = 0.f;
+ m->m[4] = v->m[2];
+ m->m[5] = v->m[3];
+ m->m[6] = 0.f;
+ m->m[7] = 0.f;
+ m->m[8] = 0.f;
+ m->m[9] = 0.f;
+ m->m[10] = 1.f;
+ m->m[11] = 0.f;
+ m->m[12] = 0.f;
+ m->m[13] = 0.f;
+ m->m[14] = 0.f;
+ m->m[15] = 1.f;
+}
+
+static void SC_MatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = v->m[3];
+ m->m[4] = v->m[4];
+ m->m[5] = v->m[5];
+ m->m[6] = v->m[6];
+ m->m[7] = v->m[7];
+ m->m[8] = v->m[8];
+}
+
+static void SC_MatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v) {
+ m->m[0] = v->m[0];
+ m->m[1] = v->m[1];
+ m->m[2] = v->m[2];
+ m->m[3] = v->m[3];
+}
+
+static void SC_MatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
+ float c, s;
+ m->m[3] = 0;
+ m->m[7] = 0;
+ m->m[11]= 0;
+ m->m[12]= 0;
+ m->m[13]= 0;
+ m->m[14]= 0;
+ m->m[15]= 1;
+ rot *= (float)(M_PI / 180.0f);
+ c = cos(rot);
+ s = sin(rot);
+
+ const float len = x*x + y*y + z*z;
+ if (len != 1) {
+ const float recipLen = 1.f / sqrt(len);
+ x *= recipLen;
+ y *= recipLen;
+ z *= recipLen;
}
-
- float vtx[] = { x, y, z };
-
- VertexArray va;
- va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
- if (rsc->checkVersion2_0()) {
- va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
- } else {
- va.setupGL(rsc, &rsc->mStateVertexArray);
+ const float nc = 1.0f - c;
+ const float xy = x * y;
+ const float yz = y * z;
+ const float zx = z * x;
+ const float xs = x * s;
+ const float ys = y * s;
+ const float zs = z * s;
+ m->m[ 0] = x*x*nc + c;
+ m->m[ 4] = xy*nc - zs;
+ m->m[ 8] = zx*nc + ys;
+ m->m[ 1] = xy*nc + zs;
+ m->m[ 5] = y*y*nc + c;
+ m->m[ 9] = yz*nc - xs;
+ m->m[ 2] = zx*nc - ys;
+ m->m[ 6] = yz*nc + xs;
+ m->m[10] = z*z*nc + c;
+}
+
+static void SC_MatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z) {
+ SC_MatrixLoadIdentity_4x4(m);
+ m->m[0] = x;
+ m->m[5] = y;
+ m->m[10] = z;
+}
+
+static void SC_MatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z) {
+ SC_MatrixLoadIdentity_4x4(m);
+ m->m[12] = x;
+ m->m[13] = y;
+ m->m[14] = z;
+}
+
+static void SC_MatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) {
+ for (int i=0 ; i<4 ; i++) {
+ float ri0 = 0;
+ float ri1 = 0;
+ float ri2 = 0;
+ float ri3 = 0;
+ for (int j=0 ; j<4 ; j++) {
+ const float rhs_ij = rsMatrixGet(rhs, i,j);
+ ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
+ ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
+ ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
+ ri3 += rsMatrixGet(lhs, j, 3) * rhs_ij;
+ }
+ rsMatrixSet(m, i, 0, ri0);
+ rsMatrixSet(m, i, 1, ri1);
+ rsMatrixSet(m, i, 2, ri2);
+ rsMatrixSet(m, i, 3, ri3);
}
-
- glDrawArrays(GL_POINTS, 0, 1);
}
-static void SC_drawQuadTexCoords(float x1, float y1, float z1,
- float u1, float v1,
- float x2, float y2, float z2,
- float u2, float v2,
- float x3, float y3, float z3,
- float u3, float v3,
- float x4, float y4, float z4,
- float u4, float v4)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
- }
-
- //LOGE("Quad");
- //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
- //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
- //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
- //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
-
- float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
- const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
-
- VertexArray va;
- va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
- va.addLegacy(GL_FLOAT, 2, 8, RS_KIND_TEXTURE, false, (uint32_t)tex);
- if (rsc->checkVersion2_0()) {
- va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
- } else {
- va.setupGL(rsc, &rsc->mStateVertexArray);
- }
-
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+static void SC_MatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs) {
+ rs_matrix4x4 mt;
+ SC_MatrixLoadMultiply_4x4_4x4_4x4(&mt, m, rhs);
+ SC_MatrixLoad_4x4_4x4(m, &mt);
}
-static void SC_drawQuad(float x1, float y1, float z1,
- float x2, float y2, float z2,
- float x3, float y3, float z3,
- float x4, float y4, float z4)
-{
- SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
- x2, y2, z2, 1, 1,
- x3, y3, z3, 1, 0,
- x4, y4, z4, 0, 0);
+static void SC_MatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) {
+ for (int i=0 ; i<3 ; i++) {
+ float ri0 = 0;
+ float ri1 = 0;
+ float ri2 = 0;
+ for (int j=0 ; j<3 ; j++) {
+ const float rhs_ij = rsMatrixGet(rhs, i,j);
+ ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
+ ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
+ ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
+ }
+ rsMatrixSet(m, i, 0, ri0);
+ rsMatrixSet(m, i, 1, ri1);
+ rsMatrixSet(m, i, 2, ri2);
+ }
}
-static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h)
-{
- GET_TLS();
- ObjectBaseRef<const ProgramVertex> tmp(rsc->getVertex());
- rsc->setVertex(rsc->getDefaultProgramVertex());
- //rsc->setupCheck();
-
- //GLint crop[4] = {0, h, w, -h};
-
- float sh = rsc->getHeight();
-
- SC_drawQuad(x, sh - y, z,
- x+w, sh - y, z,
- x+w, sh - (y+h), z,
- x, sh - (y+h), z);
- rsc->setVertex((ProgramVertex *)tmp.get());
+static void SC_MatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs) {
+ rs_matrix3x3 mt;
+ SC_MatrixLoadMultiply_3x3_3x3_3x3(&mt, m, rhs);
+ SC_MatrixLoad_3x3_3x3(m, &mt);
}
-static void SC_drawSpriteScreenspaceCropped(float x, float y, float z, float w, float h,
- float cx0, float cy0, float cx1, float cy1)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
+static void SC_MatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
+ for (int i=0 ; i<2 ; i++) {
+ float ri0 = 0;
+ float ri1 = 0;
+ for (int j=0 ; j<2 ; j++) {
+ const float rhs_ij = rsMatrixGet(rhs, i,j);
+ ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
+ ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
+ }
+ rsMatrixSet(m, i, 0, ri0);
+ rsMatrixSet(m, i, 1, ri1);
}
-
- GLint crop[4] = {cx0, cy0, cx1, cy1};
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
- glDrawTexfOES(x, y, z, w, h);
}
-static void SC_drawSprite(float x, float y, float z, float w, float h)
-{
- GET_TLS();
- float vin[3] = {x, y, z};
- float vout[4];
-
- //LOGE("ds in %f %f %f", x, y, z);
- rsc->getVertex()->transformToScreen(rsc, vout, vin);
- //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]);
- vout[0] /= vout[3];
- vout[1] /= vout[3];
- vout[2] /= vout[3];
-
- vout[0] *= rsc->getWidth() / 2;
- vout[1] *= rsc->getHeight() / 2;
- vout[0] += rsc->getWidth() / 2;
- vout[1] += rsc->getHeight() / 2;
-
- vout[0] -= w/2;
- vout[1] -= h/2;
-
- //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]);
+static void SC_MatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs) {
+ rs_matrix2x2 mt;
+ SC_MatrixLoadMultiply_2x2_2x2_2x2(&mt, m, rhs);
+ SC_MatrixLoad_2x2_2x2(m, &mt);
+}
- // U, V, W, H
- SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w);
- //rsc->setupCheck();
+static void SC_MatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
+ rs_matrix4x4 m1;
+ SC_MatrixLoadRotate(&m1, rot, x, y, z);
+ SC_MatrixMultiply_4x4_4x4(m, &m1);
}
+static void SC_MatrixScale(rs_matrix4x4 *m, float x, float y, float z) {
+ rs_matrix4x4 m1;
+ SC_MatrixLoadScale(&m1, x, y, z);
+ SC_MatrixMultiply_4x4_4x4(m, &m1);
+}
-static void SC_drawRect(float x1, float y1,
- float x2, float y2, float z)
-{
- SC_drawQuad(x1, y2, z,
- x2, y2, z,
- x2, y1, z,
- x1, y1, z);
+static void SC_MatrixTranslate(rs_matrix4x4 *m, float x, float y, float z) {
+ rs_matrix4x4 m1;
+ SC_MatrixLoadTranslate(&m1, x, y, z);
+ SC_MatrixMultiply_4x4_4x4(m, &m1);
}
-static void SC_drawSimpleMesh(RsSimpleMesh vsm)
-{
- GET_TLS();
- SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
- if (!rsc->setupCheck()) {
- return;
- }
- sm->render(rsc);
+static void SC_MatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
+ SC_MatrixLoadIdentity_4x4(m);
+ m->m[0] = 2.f / (right - left);
+ m->m[5] = 2.f / (top - bottom);
+ m->m[10]= -2.f / (far - near);
+ m->m[12]= -(right + left) / (right - left);
+ m->m[13]= -(top + bottom) / (top - bottom);
+ m->m[14]= -(far + near) / (far - near);
}
-static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
-{
- GET_TLS();
- SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
- if (!rsc->setupCheck()) {
- return;
- }
- sm->renderRange(rsc, start, len);
+static void SC_MatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
+ SC_MatrixLoadIdentity_4x4(m);
+ m->m[0] = 2.f * near / (right - left);
+ m->m[5] = 2.f * near / (top - bottom);
+ m->m[8] = (right + left) / (right - left);
+ m->m[9] = (top + bottom) / (top - bottom);
+ m->m[10]= -(far + near) / (far - near);
+ m->m[11]= -1.f;
+ m->m[14]= -2.f * far * near / (far - near);
+ m->m[15]= 0.f;
}
+static void SC_MatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far) {
+ float top = near * tan((float) (fovy * M_PI / 360.0f));
+ float bottom = -top;
+ float left = bottom * aspect;
+ float right = top * aspect;
+ SC_MatrixLoadFrustum(m, left, right, bottom, top, near, far);
+}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-static void SC_color(float r, float g, float b, float a)
-{
- GET_TLS();
- rsc->mStateVertex.color[0] = r;
- rsc->mStateVertex.color[1] = g;
- rsc->mStateVertex.color[2] = b;
- rsc->mStateVertex.color[3] = a;
- if (!rsc->checkVersion2_0()) {
- glColor4f(r, g, b, a);
- }
-}
+// Returns true if the matrix was successfully inversed
+static bool SC_MatrixInverse_4x4(rs_matrix4x4 *m) {
+ rs_matrix4x4 result;
-static void SC_ambient(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params);
-}
-
-static void SC_diffuse(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params);
-}
-
-static void SC_specular(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params);
-}
-
-static void SC_emission(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params);
-}
-
-static void SC_shininess(float s)
-{
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
-}
-
-static void SC_pointAttenuation(float a, float b, float c)
-{
- GLfloat params[] = { a, b, c };
- glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params);
-}
-
-static void SC_hsbToRgb(float h, float s, float b, float* rgb)
-{
- float red = 0.0f;
- float green = 0.0f;
- float blue = 0.0f;
-
- float x = h;
- float y = s;
- float z = b;
-
- float hf = (x - (int) x) * 6.0f;
- int ihf = (int) hf;
- float f = hf - ihf;
- float pv = z * (1.0f - y);
- float qv = z * (1.0f - y * f);
- float tv = z * (1.0f - y * (1.0f - f));
-
- switch (ihf) {
- case 0: // Red is the dominant color
- red = z;
- green = tv;
- blue = pv;
- break;
- case 1: // Green is the dominant color
- red = qv;
- green = z;
- blue = pv;
- break;
- case 2:
- red = pv;
- green = z;
- blue = tv;
- break;
- case 3: // Blue is the dominant color
- red = pv;
- green = qv;
- blue = z;
- break;
- case 4:
- red = tv;
- green = pv;
- blue = z;
- break;
- case 5: // Red is the dominant color
- red = z;
- green = pv;
- blue = qv;
- break;
- }
+ int i, j;
+ for (i = 0; i < 4; ++i) {
+ for (j = 0; j < 4; ++j) {
+ // computeCofactor for int i, int j
+ int c0 = (i+1) % 4;
+ int c1 = (i+2) % 4;
+ int c2 = (i+3) % 4;
+ int r0 = (j+1) % 4;
+ int r1 = (j+2) % 4;
+ int r2 = (j+3) % 4;
- rgb[0] = red;
- rgb[1] = green;
- rgb[2] = blue;
-}
+ float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
+ - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
+ + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
-static int SC_hsbToAbgr(float h, float s, float b, float a)
-{
- float rgb[3];
- SC_hsbToRgb(h, s, b, rgb);
- return int(a * 255.0f) << 24 |
- int(rgb[2] * 255.0f) << 16 |
- int(rgb[1] * 255.0f) << 8 |
- int(rgb[0] * 255.0f);
-}
+ float cofactor = (i+j) & 1 ? -minor : minor;
-static void SC_hsb(float h, float s, float b, float a)
-{
- GET_TLS();
- float rgb[3];
- SC_hsbToRgb(h, s, b, rgb);
- if (rsc->checkVersion2_0()) {
- glVertexAttrib4f(1, rgb[0], rgb[1], rgb[2], a);
- } else {
- glColor4f(rgb[0], rgb[1], rgb[2], a);
+ result.m[4*i + j] = cofactor;
+ }
}
-}
-static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
-{
- GET_TLS();
- rsi_AllocationUploadToTexture(rsc, va, false, baseMipLevel);
-}
+ // Dot product of 0th column of source and 0th row of result
+ float det = m->m[0]*result.m[0] + m->m[4]*result.m[1] +
+ m->m[8]*result.m[2] + m->m[12]*result.m[3];
-static void SC_uploadToBufferObject(RsAllocation va)
-{
- GET_TLS();
- rsi_AllocationUploadToBufferObject(rsc, va);
-}
+ if (fabs(det) < 1e-6) {
+ return false;
+ }
-static void SC_syncToGL(RsAllocation va)
-{
- GET_TLS();
- Allocation *a = static_cast<Allocation *>(va);
+ det = 1.0f / det;
+ for (i = 0; i < 16; ++i) {
+ m->m[i] = result.m[i] * det;
+ }
+ return true;
}
-static void SC_ClearColor(float r, float g, float b, float a)
-{
- //LOGE("c %f %f %f %f", r, g, b, a);
- GET_TLS();
- sc->mEnviroment.mClearColor[0] = r;
- sc->mEnviroment.mClearColor[1] = g;
- sc->mEnviroment.mClearColor[2] = b;
- sc->mEnviroment.mClearColor[3] = a;
-}
+// Returns true if the matrix was successfully inversed
+static bool SC_MatrixInverseTranspose_4x4(rs_matrix4x4 *m) {
+ rs_matrix4x4 result;
-static void SC_debugF(const char *s, float f)
-{
- LOGE("%s %f", s, f);
-}
+ int i, j;
+ for (i = 0; i < 4; ++i) {
+ for (j = 0; j < 4; ++j) {
+ // computeCofactor for int i, int j
+ int c0 = (i+1) % 4;
+ int c1 = (i+2) % 4;
+ int c2 = (i+3) % 4;
+ int r0 = (j+1) % 4;
+ int r1 = (j+2) % 4;
+ int r2 = (j+3) % 4;
-static void SC_debugHexF(const char *s, float f)
-{
- LOGE("%s 0x%x", s, *((int *) (&f)));
-}
+ float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
+ - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
+ + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
-static void SC_debugI32(const char *s, int32_t i)
-{
- LOGE("%s %i", s, i);
-}
+ float cofactor = (i+j) & 1 ? -minor : minor;
-static void SC_debugHexI32(const char *s, int32_t i)
-{
- LOGE("%s 0x%x", s, i);
-}
+ result.m[4*j + i] = cofactor;
+ }
+ }
-static uint32_t SC_getWidth()
-{
- GET_TLS();
- return rsc->getWidth();
-}
+ // Dot product of 0th column of source and 0th column of result
+ float det = m->m[0]*result.m[0] + m->m[4]*result.m[4] +
+ m->m[8]*result.m[8] + m->m[12]*result.m[12];
-static uint32_t SC_getHeight()
-{
- GET_TLS();
- return rsc->getHeight();
-}
+ if (fabs(det) < 1e-6) {
+ return false;
+ }
+
+ det = 1.0f / det;
+ for (i = 0; i < 16; ++i) {
+ m->m[i] = result.m[i] * det;
+ }
-static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
-{
- uint32_t c = 0;
- c |= (uint32_t)(r * 255.f + 0.5f);
- c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
- c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
- c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
- return c;
+ return true;
}
-static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
-{
- uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
- uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
- uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
- return rs888to565(ir, ig, ib);
+static void SC_MatrixTranspose_4x4(rs_matrix4x4 *m) {
+ int i, j;
+ float temp;
+ for (i = 0; i < 3; ++i) {
+ for (j = i + 1; j < 4; ++j) {
+ temp = m->m[i*4 + j];
+ m->m[i*4 + j] = m->m[j*4 + i];
+ m->m[j*4 + i] = temp;
+ }
+ }
}
-static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
-{
- GET_TLS();
- return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
+static void SC_MatrixTranspose_3x3(rs_matrix3x3 *m) {
+ int i, j;
+ float temp;
+ for (i = 0; i < 2; ++i) {
+ for (j = i + 1; j < 3; ++j) {
+ temp = m->m[i*3 + j];
+ m->m[i*3 + j] = m->m[j*4 + i];
+ m->m[j*3 + i] = temp;
+ }
+ }
}
-static void SC_scriptCall(int scriptID)
-{
- GET_TLS();
- rsc->runScript((Script *)scriptID, 0);
+static void SC_MatrixTranspose_2x2(rs_matrix2x2 *m) {
+ float temp = m->m[1];
+ m->m[1] = m->m[2];
+ m->m[2] = temp;
}
@@ -1080,315 +834,179 @@ static void SC_scriptCall(int scriptID)
// Class implementation
//////////////////////////////////////////////////////////////////////////////
-ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
- // IO
- { "loadI32", (void *)&SC_loadI32,
- "int", "(int, int)" },
- //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
- { "loadF", (void *)&SC_loadF,
- "float", "(int, int)" },
- { "loadArrayF", (void *)&SC_loadArrayF,
- "float*", "(int, int)" },
- { "loadArrayI32", (void *)&SC_loadArrayI32,
- "int*", "(int, int)" },
- { "loadVec4", (void *)&SC_loadVec4,
- "void", "(int, int, float *)" },
- { "loadMatrix", (void *)&SC_loadMatrix,
- "void", "(int, int, float *)" },
- { "storeI32", (void *)&SC_storeI32,
- "void", "(int, int, int)" },
- //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
- { "storeF", (void *)&SC_storeF,
- "void", "(int, int, float)" },
- { "storeVec4", (void *)&SC_storeVec4,
- "void", "(int, int, float *)" },
- { "storeMatrix", (void *)&SC_storeMatrix,
- "void", "(int, int, float *)" },
- { "loadSimpleMeshVerticesF", (void *)&SC_loadSimpleMeshVerticesF,
- "float*", "(int, int)" },
- { "updateSimpleMesh", (void *)&SC_updateSimpleMesh,
- "void", "(int)" },
-
- // math
- { "modf", (void *)&fmod,
- "float", "(float, float)" },
- { "abs", (void *)&abs,
- "int", "(int)" },
- { "absf", (void *)&fabsf,
- "float", "(float)" },
- { "sinf_fast", (void *)&SC_sinf_fast,
- "float", "(float)" },
- { "cosf_fast", (void *)&SC_cosf_fast,
- "float", "(float)" },
- { "sinf", (void *)&sinf,
- "float", "(float)" },
- { "cosf", (void *)&cosf,
- "float", "(float)" },
- { "asinf", (void *)&asinf,
- "float", "(float)" },
- { "acosf", (void *)&acosf,
- "float", "(float)" },
- { "atanf", (void *)&atanf,
- "float", "(float)" },
- { "atan2f", (void *)&atan2f,
- "float", "(float, float)" },
- { "fabsf", (void *)&fabsf,
- "float", "(float)" },
- { "randf", (void *)&SC_randf,
- "float", "(float)" },
- { "randf2", (void *)&SC_randf2,
- "float", "(float, float)" },
- { "floorf", (void *)&floorf,
- "float", "(float)" },
- { "fracf", (void *)&SC_fracf,
- "float", "(float)" },
- { "ceilf", (void *)&ceilf,
- "float", "(float)" },
- { "roundf", (void *)&SC_roundf,
- "float", "(float)" },
- { "expf", (void *)&expf,
- "float", "(float)" },
- { "logf", (void *)&logf,
- "float", "(float)" },
- { "powf", (void *)&powf,
- "float", "(float, float)" },
- { "maxf", (void *)&SC_maxf,
- "float", "(float, float)" },
- { "minf", (void *)&SC_minf,
- "float", "(float, float)" },
- { "sqrt", (void *)&sqrt,
- "int", "(int)" },
- { "sqrtf", (void *)&sqrtf,
- "float", "(float)" },
- { "sqr", (void *)&SC_sqr,
- "int", "(int)" },
- { "sqrf", (void *)&SC_sqrf,
- "float", "(float)" },
- { "sign", (void *)&SC_sign,
- "int", "(int)" },
- { "signf", (void *)&SC_signf,
- "float", "(float)" },
- { "clamp", (void *)&SC_clamp,
- "int", "(int, int, int)" },
- { "clampf", (void *)&SC_clampf,
- "float", "(float, float, float)" },
- { "distf2", (void *)&SC_distf2,
- "float", "(float, float, float, float)" },
- { "distf3", (void *)&SC_distf3,
- "float", "(float, float, float, float, float, float)" },
- { "magf2", (void *)&SC_magf2,
- "float", "(float, float)" },
- { "magf3", (void *)&SC_magf3,
- "float", "(float, float, float)" },
- { "radf", (void *)&SC_radf,
- "float", "(float)" },
- { "degf", (void *)&SC_degf,
- "float", "(float)" },
- { "lerpf", (void *)&SC_lerpf,
- "float", "(float, float, float)" },
- { "normf", (void *)&SC_normf,
- "float", "(float, float, float)" },
- { "mapf", (void *)&SC_mapf,
- "float", "(float, float, float, float, float)" },
- { "noisef", (void *)&SC_noisef,
- "float", "(float)" },
- { "noisef2", (void *)&SC_noisef2,
- "float", "(float, float)" },
- { "noisef3", (void *)&SC_noisef3,
- "float", "(float, float, float)" },
- { "turbulencef2", (void *)&SC_turbulencef2,
- "float", "(float, float, float)" },
- { "turbulencef3", (void *)&SC_turbulencef3,
- "float", "(float, float, float, float)" },
+// llvm name mangling ref
+// <builtin-type> ::= v # void
+// ::= b # bool
+// ::= c # char
+// ::= a # signed char
+// ::= h # unsigned char
+// ::= s # short
+// ::= t # unsigned short
+// ::= i # int
+// ::= j # unsigned int
+// ::= l # long
+// ::= m # unsigned long
+// ::= x # long long, __int64
+// ::= y # unsigned long long, __int64
+// ::= f # float
+// ::= d # double
+
+static ScriptCState::SymbolTable_t gSyms[] = {
+ { "__divsi3", (void *)&SC_divsi3, true },
+ { "__modsi3", (void *)&SC_modsi3, true },
+ { "__udivsi3", (void *)&SC_udivsi3, true },
+ { "__umodsi3", (void *)&SC_umodsi3, true },
+
+ // allocation
+ { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true },
+ { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true },
+ { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true },
+ { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true },
+ { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true },
+ { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true },
+
+ { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true },
+ { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true },
+ { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true },
+
+ { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP10rs_element", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject10rs_element", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP7rs_type", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject7rs_type", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject13rs_allocation", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject10rs_sampler", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP9rs_script", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject9rs_script", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject7rs_mesh", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject17rs_program_raster", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject16rs_program_store", (void *)&SC_isObject, true },
+
+ { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_setObject, true },
+ { "_Z13rsClearObjectP7rs_font", (void *)&SC_clearObject, true },
+ { "_Z10rsIsObject7rs_font", (void *)&SC_isObject, true },
+
+
+ { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_allocationMarkDirty, true },
+
+
+ // Debug
+ { "_Z7rsDebugPKcf", (void *)&SC_debugF, true },
+ { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true },
+ { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true },
+ { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true },
+ { "_Z7rsDebugPKcd", (void *)&SC_debugD, true },
+ { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true },
+ { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true },
+ { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true },
+ { "_Z7rsDebugPKci", (void *)&SC_debugI32, true },
+ { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true },
+ // Both "long" and "unsigned long" need to be redirected to their
+ // 64-bit counterparts, since we have hacked Slang to use 64-bit
+ // for "long" on Arm (to be similar to Java).
+ { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true },
+ { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true },
+ { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true },
+ { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true },
+ { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true },
+
+ // RS Math
+ { "_Z6rsRandi", (void *)&SC_randi, true },
+ { "_Z6rsRandii", (void *)&SC_randi2, true },
+ { "_Z6rsRandf", (void *)&SC_randf, true },
+ { "_Z6rsRandff", (void *)&SC_randf2, true },
+ { "_Z6rsFracf", (void *)&SC_frac, true },
// time
- { "second", (void *)&SC_second,
- "int", "()" },
- { "minute", (void *)&SC_minute,
- "int", "()" },
- { "hour", (void *)&SC_hour,
- "int", "()" },
- { "day", (void *)&SC_day,
- "int", "()" },
- { "month", (void *)&SC_month,
- "int", "()" },
- { "year", (void *)&SC_year,
- "int", "()" },
- { "uptimeMillis", (void*)&SC_uptimeMillis,
- "int", "()" }, // TODO: use long instead
- { "startTimeMillis", (void*)&SC_startTimeMillis,
- "int", "()" }, // TODO: use long instead
- { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
- "int", "()" }, // TODO: use long instead
+ { "_Z6rsTimePi", (void *)&SC_time, true },
+ { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_localtime, true },
+ { "_Z14rsUptimeMillisv", (void*)&SC_uptimeMillis, true },
+ { "_Z13rsUptimeNanosv", (void*)&SC_uptimeNanos, true },
+ { "_Z7rsGetDtv", (void*)&SC_getDt, false },
+
+ { "_Z14rsSendToClienti", (void *)&SC_toClient, false },
+ { "_Z14rsSendToClientiPKvj", (void *)&SC_toClient2, false },
+ { "_Z22rsSendToClientBlockingi", (void *)&SC_toClientBlocking, false },
+ { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_toClientBlocking2, false },
// matrix
- { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
- "void", "(float *mat)" },
- { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
- "void", "(float *mat, float *f)" },
- { "matrixLoadMat", (void *)&SC_matrixLoadMat,
- "void", "(float *mat, float *newmat)" },
- { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
- "void", "(float *mat, float rot, float x, float y, float z)" },
- { "matrixLoadScale", (void *)&SC_matrixLoadScale,
- "void", "(float *mat, float x, float y, float z)" },
- { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
- "void", "(float *mat, float x, float y, float z)" },
- { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
- "void", "(float *mat, float *lhs, float *rhs)" },
- { "matrixMultiply", (void *)&SC_matrixMultiply,
- "void", "(float *mat, float *rhs)" },
- { "matrixRotate", (void *)&SC_matrixRotate,
- "void", "(float *mat, float rot, float x, float y, float z)" },
- { "matrixScale", (void *)&SC_matrixScale,
- "void", "(float *mat, float x, float y, float z)" },
- { "matrixTranslate", (void *)&SC_matrixTranslate,
- "void", "(float *mat, float x, float y, float z)" },
-
- // vector
- { "vec2Rand", (void *)&SC_vec2Rand,
- "void", "(float *vec, float maxLen)" },
-
- // vec3
- { "vec3Norm", (void *)&SC_vec3Norm,
- "void", "(struct vecF32_3_s *)" },
- { "vec3Length", (void *)&SC_vec3Length,
- "float", "(struct vecF32_3_s *)" },
- { "vec3Add", (void *)&SC_vec3Add,
- "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Sub", (void *)&SC_vec3Sub,
- "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Cross", (void *)&SC_vec3Cross,
- "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Dot", (void *)&SC_vec3Dot,
- "float", "(struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Scale", (void *)&SC_vec3Scale,
- "void", "(struct vecF32_3_s *lhs, float scale)" },
-
- // vec4
- { "vec4Norm", (void *)&SC_vec4Norm,
- "void", "(struct vecF32_4_s *)" },
- { "vec4Length", (void *)&SC_vec4Length,
- "float", "(struct vecF32_4_s *)" },
- { "vec4Add", (void *)&SC_vec4Add,
- "void", "(struct vecF32_4_s *dest, struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
- { "vec4Sub", (void *)&SC_vec4Sub,
- "void", "(struct vecF32_4_s *dest, struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
- { "vec4Dot", (void *)&SC_vec4Dot,
- "float", "(struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
- { "vec4Scale", (void *)&SC_vec4Scale,
- "void", "(struct vecF32_4_s *lhs, float scale)" },
-
- // context
- { "bindProgramFragment", (void *)&SC_bindProgramFragment,
- "void", "(int)" },
- { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
- "void", "(int)" },
- { "bindProgramStore", (void *)&SC_bindProgramFragmentStore,
- "void", "(int)" },
- { "bindProgramVertex", (void *)&SC_bindProgramVertex,
- "void", "(int)" },
- { "bindSampler", (void *)&SC_bindSampler,
- "void", "(int, int, int)" },
- { "bindTexture", (void *)&SC_bindTexture,
- "void", "(int, int, int)" },
-
- // vp
- { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
- "void", "(void *)" },
- { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
- "void", "(void *)" },
-
-
-
- // drawing
- { "drawRect", (void *)&SC_drawRect,
- "void", "(float x1, float y1, float x2, float y2, float z)" },
- { "drawQuad", (void *)&SC_drawQuad,
- "void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
- { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
- "void", "(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4)" },
- { "drawSprite", (void *)&SC_drawSprite,
- "void", "(float x, float y, float z, float w, float h)" },
- { "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace,
- "void", "(float x, float y, float z, float w, float h)" },
- { "drawSpriteScreenspaceCropped", (void *)&SC_drawSpriteScreenspaceCropped,
- "void", "(float x, float y, float z, float w, float h, float cx0, float cy0, float cx1, float cy1)" },
- { "drawLine", (void *)&SC_drawLine,
- "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
- { "drawPoint", (void *)&SC_drawPoint,
- "void", "(float x1, float y1, float z1)" },
- { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
- "void", "(int ism)" },
- { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
- "void", "(int ism, int start, int len)" },
-
-
- // misc
- { "pfClearColor", (void *)&SC_ClearColor,
- "void", "(float, float, float, float)" },
- { "color", (void *)&SC_color,
- "void", "(float, float, float, float)" },
- { "hsb", (void *)&SC_hsb,
- "void", "(float, float, float, float)" },
- { "hsbToRgb", (void *)&SC_hsbToRgb,
- "void", "(float, float, float, float*)" },
- { "hsbToAbgr", (void *)&SC_hsbToAbgr,
- "int", "(float, float, float, float)" },
- { "ambient", (void *)&SC_ambient,
- "void", "(float, float, float, float)" },
- { "diffuse", (void *)&SC_diffuse,
- "void", "(float, float, float, float)" },
- { "specular", (void *)&SC_specular,
- "void", "(float, float, float, float)" },
- { "emission", (void *)&SC_emission,
- "void", "(float, float, float, float)" },
- { "shininess", (void *)&SC_shininess,
- "void", "(float)" },
- { "pointAttenuation", (void *)&SC_pointAttenuation,
- "void", "(float, float, float)" },
-
- { "uploadToTexture", (void *)&SC_uploadToTexture,
- "void", "(int, int)" },
- { "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
- "void", "(int)" },
-
- { "syncToGL", (void *)&SC_syncToGL,
- "void", "(int)" },
-
- { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
- "int", "(float, float, float, float)" },
- { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
- "int", "(float, float, float)" },
-
-
- { "getWidth", (void *)&SC_getWidth,
- "int", "()" },
- { "getHeight", (void *)&SC_getHeight,
- "int", "()" },
-
- { "sendToClient", (void *)&SC_toClient,
- "int", "(void *data, int cmdID, int len, int waitForSpace)" },
-
-
- { "debugF", (void *)&SC_debugF,
- "void", "(void *, float)" },
- { "debugI32", (void *)&SC_debugI32,
- "void", "(void *, int)" },
- { "debugHexF", (void *)&SC_debugHexF,
- "void", "(void *, float)" },
- { "debugHexI32", (void *)&SC_debugHexI32,
- "void", "(void *, int)" },
-
- { "scriptCall", (void *)&SC_scriptCall,
- "void", "(int)" },
-
-
- { NULL, NULL, NULL, NULL }
+ { "_Z20rsMatrixLoadIdentityP12rs_matrix4x4", (void *)&SC_MatrixLoadIdentity_4x4, false },
+ { "_Z20rsMatrixLoadIdentityP12rs_matrix3x3", (void *)&SC_MatrixLoadIdentity_3x3, false },
+ { "_Z20rsMatrixLoadIdentityP12rs_matrix2x2", (void *)&SC_MatrixLoadIdentity_2x2, false },
+
+ { "_Z12rsMatrixLoadP12rs_matrix4x4PKf", (void *)&SC_MatrixLoad_4x4_f, false },
+ { "_Z12rsMatrixLoadP12rs_matrix3x3PKf", (void *)&SC_MatrixLoad_3x3_f, false },
+ { "_Z12rsMatrixLoadP12rs_matrix2x2PKf", (void *)&SC_MatrixLoad_2x2_f, false },
+
+ { "_Z12rsMatrixLoadP12rs_matrix4x4PKS_", (void *)&SC_MatrixLoad_4x4_4x4, false },
+ { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix3x3", (void *)&SC_MatrixLoad_4x4_3x3, false },
+ { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix2x2", (void *)&SC_MatrixLoad_4x4_2x2, false },
+ { "_Z12rsMatrixLoadP12rs_matrix3x3PKS_", (void *)&SC_MatrixLoad_3x3_3x3, false },
+ { "_Z12rsMatrixLoadP12rs_matrix2x2PKS_", (void *)&SC_MatrixLoad_2x2_2x2, false },
+
+ { "_Z18rsMatrixLoadRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadRotate, false },
+ { "_Z17rsMatrixLoadScaleP12rs_matrix4x4fff", (void *)&SC_MatrixLoadScale, false },
+ { "_Z21rsMatrixLoadTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixLoadTranslate, false },
+ { "_Z14rsMatrixRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixRotate, false },
+ { "_Z13rsMatrixScaleP12rs_matrix4x4fff", (void *)&SC_MatrixScale, false },
+ { "_Z17rsMatrixTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixTranslate, false },
+
+ { "_Z20rsMatrixLoadMultiplyP12rs_matrix4x4PKS_S2_", (void *)&SC_MatrixLoadMultiply_4x4_4x4_4x4, false },
+ { "_Z16rsMatrixMultiplyP12rs_matrix4x4PKS_", (void *)&SC_MatrixMultiply_4x4_4x4, false },
+ { "_Z20rsMatrixLoadMultiplyP12rs_matrix3x3PKS_S2_", (void *)&SC_MatrixLoadMultiply_3x3_3x3_3x3, false },
+ { "_Z16rsMatrixMultiplyP12rs_matrix3x3PKS_", (void *)&SC_MatrixMultiply_3x3_3x3, false },
+ { "_Z20rsMatrixLoadMultiplyP12rs_matrix2x2PKS_S2_", (void *)&SC_MatrixLoadMultiply_2x2_2x2_2x2, false },
+ { "_Z16rsMatrixMultiplyP12rs_matrix2x2PKS_", (void *)&SC_MatrixMultiply_2x2_2x2, false },
+
+ { "_Z17rsMatrixLoadOrthoP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadOrtho, false },
+ { "_Z19rsMatrixLoadFrustumP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadFrustum, false },
+ { "_Z23rsMatrixLoadPerspectiveP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadPerspective, false },
+
+ { "_Z15rsMatrixInverseP12rs_matrix4x4", (void *)&SC_MatrixInverse_4x4, false },
+ { "_Z24rsMatrixInverseTransposeP12rs_matrix4x4", (void *)&SC_MatrixInverseTranspose_4x4, false },
+ { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_4x4, false },
+ { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_3x3, false },
+ { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_2x2, false },
+
+ { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false },
+ //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2, true },
+
+////////////////////////////////////////////////////////////////////
+
+ //{ "sinf_fast", (void *)&SC_sinf_fast, true },
+ //{ "cosf_fast", (void *)&SC_cosf_fast, true },
+
+ { NULL, NULL, false }
};
-const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
-{
+const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) {
ScriptCState::SymbolTable_t *syms = gSyms;
while (syms->mPtr) {
@@ -1399,18 +1017,3 @@ const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
}
return NULL;
}
-
-void ScriptCState::appendDecls(String8 *str)
-{
- ScriptCState::SymbolTable_t *syms = gSyms;
- while (syms->mPtr) {
- str->append(syms->mRet);
- str->append(" ");
- str->append(syms->mName);
- str->append(syms->mParam);
- str->append(";\n");
- syms++;
- }
-}
-
-