Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "rsContext.h" |
| 18 | #include "rsScriptC.h" |
| 19 | #include "rsMatrix.h" |
| 20 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 21 | #include "utils/Timers.h" |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 22 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 23 | #include <time.h> |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 24 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 25 | using namespace android; |
| 26 | using namespace android::renderscript; |
| 27 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 28 | #define GET_TLS() ScriptTLSStruct * tls = \ |
| 29 | (ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 30 | Context * rsc = tls->mContext; \ |
| 31 | ScriptC * sc = (ScriptC *) tls->mScript |
| 32 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 33 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 34 | ////////////////////////////////////////////////////////////////////////////// |
| 35 | // Math routines |
| 36 | ////////////////////////////////////////////////////////////////////////////// |
| 37 | |
Stephen Hines | 1bf1f8d | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 38 | #if 0 |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 39 | static float SC_sinf_fast(float x) { |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 40 | const float A = 1.0f / (2.0f * M_PI); |
| 41 | const float B = -16.0f; |
| 42 | const float C = 8.0f; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 43 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 44 | // scale angle for easy argument reduction |
| 45 | x *= A; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 46 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 47 | if (fabsf(x) >= 0.5f) { |
| 48 | // argument reduction |
| 49 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 50 | } |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 51 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 52 | const float y = B * x * fabsf(x) + C * x; |
| 53 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 54 | } |
| 55 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 56 | static float SC_cosf_fast(float x) { |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 57 | x += float(M_PI / 2); |
| 58 | |
| 59 | const float A = 1.0f / (2.0f * M_PI); |
| 60 | const float B = -16.0f; |
| 61 | const float C = 8.0f; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 62 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 63 | // scale angle for easy argument reduction |
| 64 | x *= A; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 65 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 66 | if (fabsf(x) >= 0.5f) { |
| 67 | // argument reduction |
| 68 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 69 | } |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 70 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 71 | const float y = B * x * fabsf(x) + C * x; |
| 72 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 73 | } |
Stephen Hines | 1bf1f8d | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 74 | #endif |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 75 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 76 | static float SC_randf(float max) { |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 77 | float r = (float)rand(); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 78 | r *= max; |
| 79 | return r / RAND_MAX; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 82 | static float SC_randf2(float min, float max) { |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 83 | float r = (float)rand(); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 84 | r = r * (max - min) + min; |
| 85 | return r / RAND_MAX; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 88 | static int SC_randi(int max) { |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 89 | return (int)SC_randf(max); |
| 90 | } |
| 91 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 92 | static int SC_randi2(int min, int max) { |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 93 | return (int)SC_randf2(min, max); |
| 94 | } |
| 95 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 96 | static float SC_frac(float v) { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 97 | int i = (int)floor(v); |
| 98 | return fmin(v - i, 0x1.fffffep-1f); |
| 99 | } |
| 100 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 101 | ////////////////////////////////////////////////////////////////////////////// |
| 102 | // Time routines |
| 103 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 104 | |
Stephen Hines | 1ac9da6 | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 105 | static time_t SC_time(time_t *timer) { |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 106 | GET_TLS(); |
Stephen Hines | 1ac9da6 | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 107 | return time(timer); |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Stephen Hines | 1ac9da6 | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 110 | static tm* SC_localtime(tm *local, time_t *timer) { |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 111 | GET_TLS(); |
Stephen Hines | 1ac9da6 | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 112 | if (!local) { |
| 113 | return NULL; |
| 114 | } |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 115 | |
Stephen Hines | 1ac9da6 | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 116 | // The native localtime function is not thread-safe, so we |
| 117 | // have to apply locking for proper behavior in RenderScript. |
| 118 | pthread_mutex_lock(&rsc->gLibMutex); |
| 119 | tm *tmp = localtime(timer); |
| 120 | memcpy(local, tmp, sizeof(*tmp)); |
| 121 | pthread_mutex_unlock(&rsc->gLibMutex); |
| 122 | return local; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 125 | static int64_t SC_uptimeMillis() { |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 126 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 127 | } |
| 128 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 129 | static int64_t SC_uptimeNanos() { |
Jason Sams | f0690c4 | 2010-07-29 17:31:14 -0700 | [diff] [blame] | 130 | return systemTime(SYSTEM_TIME_MONOTONIC); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 133 | static float SC_getDt() { |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 134 | GET_TLS(); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 135 | int64_t l = sc->mEnviroment.mLastDtTime; |
| 136 | sc->mEnviroment.mLastDtTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 137 | return ((float)(sc->mEnviroment.mLastDtTime - l)) / 1.0e9; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 140 | ////////////////////////////////////////////////////////////////////////////// |
| 141 | // |
| 142 | ////////////////////////////////////////////////////////////////////////////// |
| 143 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 144 | static uint32_t SC_allocGetDimX(Allocation *a) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 145 | CHECK_OBJ(a); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 146 | return a->mHal.state.dimensionX; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 149 | static uint32_t SC_allocGetDimY(Allocation *a) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 150 | CHECK_OBJ(a); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 151 | return a->mHal.state.dimensionY; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 154 | static uint32_t SC_allocGetDimZ(Allocation *a) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 155 | CHECK_OBJ(a); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 156 | return a->mHal.state.dimensionZ; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 159 | static uint32_t SC_allocGetDimLOD(Allocation *a) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 160 | CHECK_OBJ(a); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 161 | return a->mHal.state.hasMipmaps; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 164 | static uint32_t SC_allocGetDimFaces(Allocation *a) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 165 | CHECK_OBJ(a); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 166 | return a->mHal.state.hasFaces; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 169 | static const void * SC_getElementAtX(Allocation *a, uint32_t x) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 170 | CHECK_OBJ(a); |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 171 | const uint8_t *p = (const uint8_t *)a->getPtr(); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 172 | return &p[a->mHal.state.elementSizeBytes * x]; |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 175 | static const void * SC_getElementAtXY(Allocation *a, uint32_t x, uint32_t y) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 176 | CHECK_OBJ(a); |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 177 | const uint8_t *p = (const uint8_t *)a->getPtr(); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 178 | return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX)]; |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 181 | static const void * SC_getElementAtXYZ(Allocation *a, uint32_t x, uint32_t y, uint32_t z) { |
Jason Sams | f166d9b | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 182 | CHECK_OBJ(a); |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 183 | const uint8_t *p = (const uint8_t *)a->getPtr(); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 184 | return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX + |
| 185 | z * a->mHal.state.dimensionX * a->mHal.state.dimensionY)]; |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 186 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 187 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 188 | void android::renderscript::rsiSetObject(ObjectBase **dst, ObjectBase * src) { |
| 189 | //LOGE("rsiSetObject %p,%p %p", vdst, *vdst, vsrc); |
| 190 | if (src) { |
| 191 | CHECK_OBJ(src); |
| 192 | src->incSysRef(); |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 193 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 194 | if (dst[0]) { |
| 195 | CHECK_OBJ(dst[0]); |
| 196 | dst[0]->decSysRef(); |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 197 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 198 | *dst = src; |
Jason Sams | 02f62aa | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 199 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 200 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 201 | void android::renderscript::rsiClearObject(ObjectBase **dst) { |
| 202 | //LOGE("rsiClearObject %p,%p", vdst, *vdst); |
| 203 | if (dst[0]) { |
| 204 | CHECK_OBJ(dst[0]); |
| 205 | dst[0]->decSysRef(); |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 206 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 207 | *dst = NULL; |
Jason Sams | 02f62aa | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 208 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 209 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 210 | bool android::renderscript::rsiIsObject(const ObjectBase *src) { |
| 211 | return src != NULL; |
Jason Sams | 02f62aa | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 214 | static void SC_debugF(const char *s, float f) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 215 | LOGD("%s %f, 0x%08x", s, f, *((int *) (&f))); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 216 | } |
Jason Sams | d64188a | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 217 | static void SC_debugFv2(const char *s, float f1, float f2) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 218 | LOGD("%s {%f, %f}", s, f1, f2); |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 219 | } |
Jason Sams | d64188a | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 220 | static void SC_debugFv3(const char *s, float f1, float f2, float f3) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 221 | LOGD("%s {%f, %f, %f}", s, f1, f2, f3); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 222 | } |
Jason Sams | d64188a | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 223 | static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 224 | LOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 225 | } |
Stephen Hines | 6568896 | 2010-10-15 12:47:49 -0700 | [diff] [blame] | 226 | static void SC_debugD(const char *s, double d) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 227 | LOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d))); |
Stephen Hines | 6568896 | 2010-10-15 12:47:49 -0700 | [diff] [blame] | 228 | } |
Jason Sams | d64188a | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 229 | static void SC_debugFM4v4(const char *s, const float *f) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 230 | LOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]); |
| 231 | LOGD("%s %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]); |
| 232 | LOGD("%s %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]); |
| 233 | LOGD("%s %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]); |
Jason Sams | d64188a | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 234 | } |
| 235 | static void SC_debugFM3v3(const char *s, const float *f) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 236 | LOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]); |
| 237 | LOGD("%s %f, %f, %f", s, f[1], f[4], f[7]); |
| 238 | LOGD("%s %f, %f, %f}",s, f[2], f[5], f[8]); |
Jason Sams | d64188a | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 239 | } |
| 240 | static void SC_debugFM2v2(const char *s, const float *f) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 241 | LOGD("%s {%f, %f", s, f[0], f[2]); |
| 242 | LOGD("%s %f, %f}",s, f[1], f[3]); |
Jason Sams | d64188a | 2010-08-06 16:22:50 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 245 | static void SC_debugI32(const char *s, int32_t i) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 246 | LOGD("%s %i 0x%x", s, i, i); |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 247 | } |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 248 | static void SC_debugU32(const char *s, uint32_t i) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 249 | LOGD("%s %u 0x%x", s, i, i); |
Stephen Hines | 6568896 | 2010-10-15 12:47:49 -0700 | [diff] [blame] | 250 | } |
| 251 | static void SC_debugLL64(const char *s, long long ll) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 252 | LOGD("%s %lld 0x%llx", s, ll, ll); |
Stephen Hines | 6568896 | 2010-10-15 12:47:49 -0700 | [diff] [blame] | 253 | } |
| 254 | static void SC_debugULL64(const char *s, unsigned long long ll) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 255 | LOGD("%s %llu 0x%llx", s, ll, ll); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 256 | } |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 257 | |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 258 | static void SC_debugP(const char *s, const void *p) { |
Jason Sams | bf2afed | 2011-01-18 18:22:19 -0800 | [diff] [blame] | 259 | LOGD("%s %p", s, p); |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 262 | static uint32_t SC_toClient2(int cmdID, void *data, int len) { |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 263 | GET_TLS(); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 264 | //LOGE("SC_toClient %i %i %i", cmdID, len); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 265 | return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, false); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 268 | static uint32_t SC_toClient(int cmdID) { |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 269 | GET_TLS(); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 270 | //LOGE("SC_toClient %i", cmdID); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 271 | return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, false); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 274 | static uint32_t SC_toClientBlocking2(int cmdID, void *data, int len) { |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 275 | GET_TLS(); |
| 276 | //LOGE("SC_toClientBlocking %i %i", cmdID, len); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 277 | return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, true); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 280 | static uint32_t SC_toClientBlocking(int cmdID) { |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 281 | GET_TLS(); |
| 282 | //LOGE("SC_toClientBlocking %i", cmdID); |
Jason Sams | 1c41517 | 2010-11-08 17:06:46 -0800 | [diff] [blame] | 283 | return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, true); |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 286 | int SC_divsi3(int a, int b) { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 287 | return a / b; |
| 288 | } |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 289 | |
Bryan Mawhinney | c0aaccc | 2010-11-11 14:33:12 +0000 | [diff] [blame] | 290 | int SC_modsi3(int a, int b) { |
| 291 | return a % b; |
| 292 | } |
| 293 | |
Stephen Hines | 7e893e1 | 2011-01-24 12:03:51 -0800 | [diff] [blame] | 294 | unsigned int SC_udivsi3(unsigned int a, unsigned int b) { |
| 295 | return a / b; |
| 296 | } |
| 297 | |
| 298 | unsigned int SC_umodsi3(unsigned int a, unsigned int b) { |
| 299 | return a % b; |
| 300 | } |
| 301 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 302 | int SC_getAllocation(const void *ptr) { |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 303 | GET_TLS(); |
| 304 | const Allocation *alloc = sc->ptrToAllocation(ptr); |
| 305 | return (int)alloc; |
| 306 | } |
| 307 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 308 | void SC_allocationMarkDirty(RsAllocation a) { |
Alex Sakhartchouk | 8e95466 | 2010-09-01 16:34:48 -0700 | [diff] [blame] | 309 | Allocation *alloc = static_cast<Allocation *>(a); |
| 310 | alloc->sendDirty(); |
| 311 | } |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 312 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 313 | void SC_ForEach(RsScript vs, |
| 314 | RsAllocation vin, |
| 315 | RsAllocation vout, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 316 | const void *usr) { |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 317 | GET_TLS(); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 318 | const Allocation *ain = static_cast<const Allocation *>(vin); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 319 | Allocation *aout = static_cast<Allocation *>(vout); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 320 | Script *s = static_cast<Script *>(vs); |
| 321 | s->runForEach(rsc, ain, aout, usr); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 324 | void SC_ForEach2(RsScript vs, |
| 325 | RsAllocation vin, |
| 326 | RsAllocation vout, |
| 327 | const void *usr, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 328 | const RsScriptCall *call) { |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 329 | GET_TLS(); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 330 | const Allocation *ain = static_cast<const Allocation *>(vin); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 331 | Allocation *aout = static_cast<Allocation *>(vout); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 332 | Script *s = static_cast<Script *>(vs); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 333 | s->runForEach(rsc, ain, aout, usr, call); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 336 | |
| 337 | ////////////////////////////////////////////////////////////////////////////// |
| 338 | // Heavy math functions |
| 339 | ////////////////////////////////////////////////////////////////////////////// |
| 340 | |
| 341 | typedef struct { |
| 342 | float m[16]; |
| 343 | } rs_matrix4x4; |
| 344 | |
| 345 | typedef struct { |
| 346 | float m[9]; |
| 347 | } rs_matrix3x3; |
| 348 | |
| 349 | typedef struct { |
| 350 | float m[4]; |
| 351 | } rs_matrix2x2; |
| 352 | |
| 353 | static inline void |
| 354 | rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) { |
| 355 | m->m[row * 4 + col] = v; |
| 356 | } |
| 357 | |
| 358 | static inline float |
| 359 | rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) { |
| 360 | return m->m[row * 4 + col]; |
| 361 | } |
| 362 | |
| 363 | static inline void |
| 364 | rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) { |
| 365 | m->m[row * 3 + col] = v; |
| 366 | } |
| 367 | |
| 368 | static inline float |
| 369 | rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) { |
| 370 | return m->m[row * 3 + col]; |
| 371 | } |
| 372 | |
| 373 | static inline void |
| 374 | rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) { |
| 375 | m->m[row * 2 + col] = v; |
| 376 | } |
| 377 | |
| 378 | static inline float |
| 379 | rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) { |
| 380 | return m->m[row * 2 + col]; |
| 381 | } |
| 382 | |
| 383 | |
| 384 | static void SC_MatrixLoadIdentity_4x4(rs_matrix4x4 *m) { |
| 385 | m->m[0] = 1.f; |
| 386 | m->m[1] = 0.f; |
| 387 | m->m[2] = 0.f; |
| 388 | m->m[3] = 0.f; |
| 389 | m->m[4] = 0.f; |
| 390 | m->m[5] = 1.f; |
| 391 | m->m[6] = 0.f; |
| 392 | m->m[7] = 0.f; |
| 393 | m->m[8] = 0.f; |
| 394 | m->m[9] = 0.f; |
| 395 | m->m[10] = 1.f; |
| 396 | m->m[11] = 0.f; |
| 397 | m->m[12] = 0.f; |
| 398 | m->m[13] = 0.f; |
| 399 | m->m[14] = 0.f; |
| 400 | m->m[15] = 1.f; |
| 401 | } |
| 402 | |
| 403 | static void SC_MatrixLoadIdentity_3x3(rs_matrix3x3 *m) { |
| 404 | m->m[0] = 1.f; |
| 405 | m->m[1] = 0.f; |
| 406 | m->m[2] = 0.f; |
| 407 | m->m[3] = 0.f; |
| 408 | m->m[4] = 1.f; |
| 409 | m->m[5] = 0.f; |
| 410 | m->m[6] = 0.f; |
| 411 | m->m[7] = 0.f; |
| 412 | m->m[8] = 1.f; |
| 413 | } |
| 414 | |
| 415 | static void SC_MatrixLoadIdentity_2x2(rs_matrix2x2 *m) { |
| 416 | m->m[0] = 1.f; |
| 417 | m->m[1] = 0.f; |
| 418 | m->m[2] = 0.f; |
| 419 | m->m[3] = 1.f; |
| 420 | } |
| 421 | |
| 422 | static void SC_MatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v) { |
| 423 | m->m[0] = v[0]; |
| 424 | m->m[1] = v[1]; |
| 425 | m->m[2] = v[2]; |
| 426 | m->m[3] = v[3]; |
| 427 | m->m[4] = v[4]; |
| 428 | m->m[5] = v[5]; |
| 429 | m->m[6] = v[6]; |
| 430 | m->m[7] = v[7]; |
| 431 | m->m[8] = v[8]; |
| 432 | m->m[9] = v[9]; |
| 433 | m->m[10] = v[10]; |
| 434 | m->m[11] = v[11]; |
| 435 | m->m[12] = v[12]; |
| 436 | m->m[13] = v[13]; |
| 437 | m->m[14] = v[14]; |
| 438 | m->m[15] = v[15]; |
| 439 | } |
| 440 | |
| 441 | static void SC_MatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v) { |
| 442 | m->m[0] = v[0]; |
| 443 | m->m[1] = v[1]; |
| 444 | m->m[2] = v[2]; |
| 445 | m->m[3] = v[3]; |
| 446 | m->m[4] = v[4]; |
| 447 | m->m[5] = v[5]; |
| 448 | m->m[6] = v[6]; |
| 449 | m->m[7] = v[7]; |
| 450 | m->m[8] = v[8]; |
| 451 | } |
| 452 | |
| 453 | static void SC_MatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v) { |
| 454 | m->m[0] = v[0]; |
| 455 | m->m[1] = v[1]; |
| 456 | m->m[2] = v[2]; |
| 457 | m->m[3] = v[3]; |
| 458 | } |
| 459 | |
| 460 | static void SC_MatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v) { |
| 461 | m->m[0] = v->m[0]; |
| 462 | m->m[1] = v->m[1]; |
| 463 | m->m[2] = v->m[2]; |
| 464 | m->m[3] = v->m[3]; |
| 465 | m->m[4] = v->m[4]; |
| 466 | m->m[5] = v->m[5]; |
| 467 | m->m[6] = v->m[6]; |
| 468 | m->m[7] = v->m[7]; |
| 469 | m->m[8] = v->m[8]; |
| 470 | m->m[9] = v->m[9]; |
| 471 | m->m[10] = v->m[10]; |
| 472 | m->m[11] = v->m[11]; |
| 473 | m->m[12] = v->m[12]; |
| 474 | m->m[13] = v->m[13]; |
| 475 | m->m[14] = v->m[14]; |
| 476 | m->m[15] = v->m[15]; |
| 477 | } |
| 478 | |
| 479 | static void SC_MatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v) { |
| 480 | m->m[0] = v->m[0]; |
| 481 | m->m[1] = v->m[1]; |
| 482 | m->m[2] = v->m[2]; |
| 483 | m->m[3] = 0.f; |
| 484 | m->m[4] = v->m[3]; |
| 485 | m->m[5] = v->m[4]; |
| 486 | m->m[6] = v->m[5]; |
| 487 | m->m[7] = 0.f; |
| 488 | m->m[8] = v->m[6]; |
| 489 | m->m[9] = v->m[7]; |
| 490 | m->m[10] = v->m[8]; |
| 491 | m->m[11] = 0.f; |
| 492 | m->m[12] = 0.f; |
| 493 | m->m[13] = 0.f; |
| 494 | m->m[14] = 0.f; |
| 495 | m->m[15] = 1.f; |
| 496 | } |
| 497 | |
| 498 | static void SC_MatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v) { |
| 499 | m->m[0] = v->m[0]; |
| 500 | m->m[1] = v->m[1]; |
| 501 | m->m[2] = 0.f; |
| 502 | m->m[3] = 0.f; |
| 503 | m->m[4] = v->m[2]; |
| 504 | m->m[5] = v->m[3]; |
| 505 | m->m[6] = 0.f; |
| 506 | m->m[7] = 0.f; |
| 507 | m->m[8] = 0.f; |
| 508 | m->m[9] = 0.f; |
| 509 | m->m[10] = 1.f; |
| 510 | m->m[11] = 0.f; |
| 511 | m->m[12] = 0.f; |
| 512 | m->m[13] = 0.f; |
| 513 | m->m[14] = 0.f; |
| 514 | m->m[15] = 1.f; |
| 515 | } |
| 516 | |
| 517 | static void SC_MatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v) { |
| 518 | m->m[0] = v->m[0]; |
| 519 | m->m[1] = v->m[1]; |
| 520 | m->m[2] = v->m[2]; |
| 521 | m->m[3] = v->m[3]; |
| 522 | m->m[4] = v->m[4]; |
| 523 | m->m[5] = v->m[5]; |
| 524 | m->m[6] = v->m[6]; |
| 525 | m->m[7] = v->m[7]; |
| 526 | m->m[8] = v->m[8]; |
| 527 | } |
| 528 | |
| 529 | static void SC_MatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v) { |
| 530 | m->m[0] = v->m[0]; |
| 531 | m->m[1] = v->m[1]; |
| 532 | m->m[2] = v->m[2]; |
| 533 | m->m[3] = v->m[3]; |
| 534 | } |
| 535 | |
| 536 | static void SC_MatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) { |
| 537 | float c, s; |
| 538 | m->m[3] = 0; |
| 539 | m->m[7] = 0; |
| 540 | m->m[11]= 0; |
| 541 | m->m[12]= 0; |
| 542 | m->m[13]= 0; |
| 543 | m->m[14]= 0; |
| 544 | m->m[15]= 1; |
| 545 | rot *= (float)(M_PI / 180.0f); |
| 546 | c = cos(rot); |
| 547 | s = sin(rot); |
| 548 | |
| 549 | const float len = x*x + y*y + z*z; |
| 550 | if (len != 1) { |
| 551 | const float recipLen = 1.f / sqrt(len); |
| 552 | x *= recipLen; |
| 553 | y *= recipLen; |
| 554 | z *= recipLen; |
| 555 | } |
| 556 | const float nc = 1.0f - c; |
| 557 | const float xy = x * y; |
| 558 | const float yz = y * z; |
| 559 | const float zx = z * x; |
| 560 | const float xs = x * s; |
| 561 | const float ys = y * s; |
| 562 | const float zs = z * s; |
| 563 | m->m[ 0] = x*x*nc + c; |
| 564 | m->m[ 4] = xy*nc - zs; |
| 565 | m->m[ 8] = zx*nc + ys; |
| 566 | m->m[ 1] = xy*nc + zs; |
| 567 | m->m[ 5] = y*y*nc + c; |
| 568 | m->m[ 9] = yz*nc - xs; |
| 569 | m->m[ 2] = zx*nc - ys; |
| 570 | m->m[ 6] = yz*nc + xs; |
| 571 | m->m[10] = z*z*nc + c; |
| 572 | } |
| 573 | |
| 574 | static void SC_MatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z) { |
| 575 | SC_MatrixLoadIdentity_4x4(m); |
| 576 | m->m[0] = x; |
| 577 | m->m[5] = y; |
| 578 | m->m[10] = z; |
| 579 | } |
| 580 | |
| 581 | static void SC_MatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z) { |
| 582 | SC_MatrixLoadIdentity_4x4(m); |
| 583 | m->m[12] = x; |
| 584 | m->m[13] = y; |
| 585 | m->m[14] = z; |
| 586 | } |
| 587 | |
| 588 | static void SC_MatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) { |
| 589 | for (int i=0 ; i<4 ; i++) { |
| 590 | float ri0 = 0; |
| 591 | float ri1 = 0; |
| 592 | float ri2 = 0; |
| 593 | float ri3 = 0; |
| 594 | for (int j=0 ; j<4 ; j++) { |
| 595 | const float rhs_ij = rsMatrixGet(rhs, i,j); |
| 596 | ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij; |
| 597 | ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij; |
| 598 | ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij; |
| 599 | ri3 += rsMatrixGet(lhs, j, 3) * rhs_ij; |
| 600 | } |
| 601 | rsMatrixSet(m, i, 0, ri0); |
| 602 | rsMatrixSet(m, i, 1, ri1); |
| 603 | rsMatrixSet(m, i, 2, ri2); |
| 604 | rsMatrixSet(m, i, 3, ri3); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | static void SC_MatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs) { |
| 609 | rs_matrix4x4 mt; |
| 610 | SC_MatrixLoadMultiply_4x4_4x4_4x4(&mt, m, rhs); |
| 611 | SC_MatrixLoad_4x4_4x4(m, &mt); |
| 612 | } |
| 613 | |
| 614 | static void SC_MatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) { |
| 615 | for (int i=0 ; i<3 ; i++) { |
| 616 | float ri0 = 0; |
| 617 | float ri1 = 0; |
| 618 | float ri2 = 0; |
| 619 | for (int j=0 ; j<3 ; j++) { |
| 620 | const float rhs_ij = rsMatrixGet(rhs, i,j); |
| 621 | ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij; |
| 622 | ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij; |
| 623 | ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij; |
| 624 | } |
| 625 | rsMatrixSet(m, i, 0, ri0); |
| 626 | rsMatrixSet(m, i, 1, ri1); |
| 627 | rsMatrixSet(m, i, 2, ri2); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | static void SC_MatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs) { |
| 632 | rs_matrix3x3 mt; |
| 633 | SC_MatrixLoadMultiply_3x3_3x3_3x3(&mt, m, rhs); |
| 634 | SC_MatrixLoad_3x3_3x3(m, &mt); |
| 635 | } |
| 636 | |
| 637 | static void SC_MatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) { |
| 638 | for (int i=0 ; i<2 ; i++) { |
| 639 | float ri0 = 0; |
| 640 | float ri1 = 0; |
| 641 | for (int j=0 ; j<2 ; j++) { |
| 642 | const float rhs_ij = rsMatrixGet(rhs, i,j); |
| 643 | ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij; |
| 644 | ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij; |
| 645 | } |
| 646 | rsMatrixSet(m, i, 0, ri0); |
| 647 | rsMatrixSet(m, i, 1, ri1); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | static void SC_MatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs) { |
| 652 | rs_matrix2x2 mt; |
| 653 | SC_MatrixLoadMultiply_2x2_2x2_2x2(&mt, m, rhs); |
| 654 | SC_MatrixLoad_2x2_2x2(m, &mt); |
| 655 | } |
| 656 | |
| 657 | static void SC_MatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) { |
| 658 | rs_matrix4x4 m1; |
| 659 | SC_MatrixLoadRotate(&m1, rot, x, y, z); |
| 660 | SC_MatrixMultiply_4x4_4x4(m, &m1); |
| 661 | } |
| 662 | |
| 663 | static void SC_MatrixScale(rs_matrix4x4 *m, float x, float y, float z) { |
| 664 | rs_matrix4x4 m1; |
| 665 | SC_MatrixLoadScale(&m1, x, y, z); |
| 666 | SC_MatrixMultiply_4x4_4x4(m, &m1); |
| 667 | } |
| 668 | |
| 669 | static void SC_MatrixTranslate(rs_matrix4x4 *m, float x, float y, float z) { |
| 670 | rs_matrix4x4 m1; |
| 671 | SC_MatrixLoadTranslate(&m1, x, y, z); |
| 672 | SC_MatrixMultiply_4x4_4x4(m, &m1); |
| 673 | } |
| 674 | |
| 675 | static void SC_MatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) { |
| 676 | SC_MatrixLoadIdentity_4x4(m); |
| 677 | m->m[0] = 2.f / (right - left); |
| 678 | m->m[5] = 2.f / (top - bottom); |
| 679 | m->m[10]= -2.f / (far - near); |
| 680 | m->m[12]= -(right + left) / (right - left); |
| 681 | m->m[13]= -(top + bottom) / (top - bottom); |
| 682 | m->m[14]= -(far + near) / (far - near); |
| 683 | } |
| 684 | |
| 685 | static void SC_MatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) { |
| 686 | SC_MatrixLoadIdentity_4x4(m); |
| 687 | m->m[0] = 2.f * near / (right - left); |
| 688 | m->m[5] = 2.f * near / (top - bottom); |
| 689 | m->m[8] = (right + left) / (right - left); |
| 690 | m->m[9] = (top + bottom) / (top - bottom); |
| 691 | m->m[10]= -(far + near) / (far - near); |
| 692 | m->m[11]= -1.f; |
| 693 | m->m[14]= -2.f * far * near / (far - near); |
| 694 | m->m[15]= 0.f; |
| 695 | } |
| 696 | |
| 697 | static void SC_MatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far) { |
| 698 | float top = near * tan((float) (fovy * M_PI / 360.0f)); |
| 699 | float bottom = -top; |
| 700 | float left = bottom * aspect; |
| 701 | float right = top * aspect; |
| 702 | SC_MatrixLoadFrustum(m, left, right, bottom, top, near, far); |
| 703 | } |
| 704 | |
| 705 | |
| 706 | // Returns true if the matrix was successfully inversed |
| 707 | static bool SC_MatrixInverse_4x4(rs_matrix4x4 *m) { |
| 708 | rs_matrix4x4 result; |
| 709 | |
| 710 | int i, j; |
| 711 | for (i = 0; i < 4; ++i) { |
| 712 | for (j = 0; j < 4; ++j) { |
| 713 | // computeCofactor for int i, int j |
| 714 | int c0 = (i+1) % 4; |
| 715 | int c1 = (i+2) % 4; |
| 716 | int c2 = (i+3) % 4; |
| 717 | int r0 = (j+1) % 4; |
| 718 | int r1 = (j+2) % 4; |
| 719 | int r2 = (j+3) % 4; |
| 720 | |
| 721 | 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])) |
| 722 | - (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])) |
| 723 | + (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])); |
| 724 | |
| 725 | float cofactor = (i+j) & 1 ? -minor : minor; |
| 726 | |
| 727 | result.m[4*i + j] = cofactor; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | // Dot product of 0th column of source and 0th row of result |
| 732 | float det = m->m[0]*result.m[0] + m->m[4]*result.m[1] + |
| 733 | m->m[8]*result.m[2] + m->m[12]*result.m[3]; |
| 734 | |
| 735 | if (fabs(det) < 1e-6) { |
| 736 | return false; |
| 737 | } |
| 738 | |
| 739 | det = 1.0f / det; |
| 740 | for (i = 0; i < 16; ++i) { |
| 741 | m->m[i] = result.m[i] * det; |
| 742 | } |
| 743 | |
| 744 | return true; |
| 745 | } |
| 746 | |
| 747 | // Returns true if the matrix was successfully inversed |
| 748 | static bool SC_MatrixInverseTranspose_4x4(rs_matrix4x4 *m) { |
| 749 | rs_matrix4x4 result; |
| 750 | |
| 751 | int i, j; |
| 752 | for (i = 0; i < 4; ++i) { |
| 753 | for (j = 0; j < 4; ++j) { |
| 754 | // computeCofactor for int i, int j |
| 755 | int c0 = (i+1) % 4; |
| 756 | int c1 = (i+2) % 4; |
| 757 | int c2 = (i+3) % 4; |
| 758 | int r0 = (j+1) % 4; |
| 759 | int r1 = (j+2) % 4; |
| 760 | int r2 = (j+3) % 4; |
| 761 | |
| 762 | 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])) |
| 763 | - (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])) |
| 764 | + (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])); |
| 765 | |
| 766 | float cofactor = (i+j) & 1 ? -minor : minor; |
| 767 | |
| 768 | result.m[4*j + i] = cofactor; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | // Dot product of 0th column of source and 0th column of result |
| 773 | float det = m->m[0]*result.m[0] + m->m[4]*result.m[4] + |
| 774 | m->m[8]*result.m[8] + m->m[12]*result.m[12]; |
| 775 | |
| 776 | if (fabs(det) < 1e-6) { |
| 777 | return false; |
| 778 | } |
| 779 | |
| 780 | det = 1.0f / det; |
| 781 | for (i = 0; i < 16; ++i) { |
| 782 | m->m[i] = result.m[i] * det; |
| 783 | } |
| 784 | |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | static void SC_MatrixTranspose_4x4(rs_matrix4x4 *m) { |
| 789 | int i, j; |
| 790 | float temp; |
| 791 | for (i = 0; i < 3; ++i) { |
| 792 | for (j = i + 1; j < 4; ++j) { |
| 793 | temp = m->m[i*4 + j]; |
| 794 | m->m[i*4 + j] = m->m[j*4 + i]; |
| 795 | m->m[j*4 + i] = temp; |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | static void SC_MatrixTranspose_3x3(rs_matrix3x3 *m) { |
| 801 | int i, j; |
| 802 | float temp; |
| 803 | for (i = 0; i < 2; ++i) { |
| 804 | for (j = i + 1; j < 3; ++j) { |
| 805 | temp = m->m[i*3 + j]; |
| 806 | m->m[i*3 + j] = m->m[j*4 + i]; |
| 807 | m->m[j*3 + i] = temp; |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | static void SC_MatrixTranspose_2x2(rs_matrix2x2 *m) { |
| 813 | float temp = m->m[1]; |
| 814 | m->m[1] = m->m[2]; |
| 815 | m->m[2] = temp; |
| 816 | } |
| 817 | |
| 818 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 819 | ////////////////////////////////////////////////////////////////////////////// |
| 820 | // Class implementation |
| 821 | ////////////////////////////////////////////////////////////////////////////// |
| 822 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 823 | // llvm name mangling ref |
| 824 | // <builtin-type> ::= v # void |
| 825 | // ::= b # bool |
| 826 | // ::= c # char |
| 827 | // ::= a # signed char |
| 828 | // ::= h # unsigned char |
| 829 | // ::= s # short |
| 830 | // ::= t # unsigned short |
| 831 | // ::= i # int |
| 832 | // ::= j # unsigned int |
| 833 | // ::= l # long |
| 834 | // ::= m # unsigned long |
| 835 | // ::= x # long long, __int64 |
| 836 | // ::= y # unsigned long long, __int64 |
| 837 | // ::= f # float |
| 838 | // ::= d # double |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 839 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 840 | static ScriptCState::SymbolTable_t gSyms[] = { |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 841 | { "__divsi3", (void *)&SC_divsi3, true }, |
Bryan Mawhinney | c0aaccc | 2010-11-11 14:33:12 +0000 | [diff] [blame] | 842 | { "__modsi3", (void *)&SC_modsi3, true }, |
Stephen Hines | 7e893e1 | 2011-01-24 12:03:51 -0800 | [diff] [blame] | 843 | { "__udivsi3", (void *)&SC_udivsi3, true }, |
| 844 | { "__umodsi3", (void *)&SC_umodsi3, true }, |
Stephen Hines | 3f73da5 | 2011-02-04 14:39:57 -0800 | [diff] [blame] | 845 | { "memset", (void *)&memset, true }, |
| 846 | { "memcpy", (void *)&memcpy, true }, |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 847 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 848 | // allocation |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 849 | { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true }, |
| 850 | { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true }, |
| 851 | { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true }, |
| 852 | { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true }, |
| 853 | { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true }, |
| 854 | { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 855 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 856 | { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true }, |
| 857 | { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true }, |
| 858 | { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true }, |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 859 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 860 | { "_Z11rsSetObjectP10rs_elementS_", (void *)&rsiSetObject, true }, |
| 861 | { "_Z13rsClearObjectP10rs_element", (void *)&rsiClearObject, true }, |
| 862 | { "_Z10rsIsObject10rs_element", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 863 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 864 | { "_Z11rsSetObjectP7rs_typeS_", (void *)&rsiSetObject, true }, |
| 865 | { "_Z13rsClearObjectP7rs_type", (void *)&rsiClearObject, true }, |
| 866 | { "_Z10rsIsObject7rs_type", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 867 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 868 | { "_Z11rsSetObjectP13rs_allocationS_", (void *)&rsiSetObject, true }, |
| 869 | { "_Z13rsClearObjectP13rs_allocation", (void *)&rsiClearObject, true }, |
| 870 | { "_Z10rsIsObject13rs_allocation", (void *)&rsiIsObject, true }, |
Jason Sams | 02f62aa | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 871 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 872 | { "_Z11rsSetObjectP10rs_samplerS_", (void *)&rsiSetObject, true }, |
| 873 | { "_Z13rsClearObjectP10rs_sampler", (void *)&rsiClearObject, true }, |
| 874 | { "_Z10rsIsObject10rs_sampler", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 875 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 876 | { "_Z11rsSetObjectP9rs_scriptS_", (void *)&rsiSetObject, true }, |
| 877 | { "_Z13rsClearObjectP9rs_script", (void *)&rsiClearObject, true }, |
| 878 | { "_Z10rsIsObject9rs_script", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 879 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 880 | { "_Z11rsSetObjectP7rs_meshS_", (void *)&rsiSetObject, true }, |
| 881 | { "_Z13rsClearObjectP7rs_mesh", (void *)&rsiClearObject, true }, |
| 882 | { "_Z10rsIsObject7rs_mesh", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 883 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 884 | { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&rsiSetObject, true }, |
| 885 | { "_Z13rsClearObjectP19rs_program_fragment", (void *)&rsiClearObject, true }, |
| 886 | { "_Z10rsIsObject19rs_program_fragment", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 887 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 888 | { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&rsiSetObject, true }, |
| 889 | { "_Z13rsClearObjectP17rs_program_vertex", (void *)&rsiClearObject, true }, |
| 890 | { "_Z10rsIsObject17rs_program_vertex", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 891 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 892 | { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&rsiSetObject, true }, |
| 893 | { "_Z13rsClearObjectP17rs_program_raster", (void *)&rsiClearObject, true }, |
| 894 | { "_Z10rsIsObject17rs_program_raster", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 895 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 896 | { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&rsiSetObject, true }, |
| 897 | { "_Z13rsClearObjectP16rs_program_store", (void *)&rsiClearObject, true }, |
| 898 | { "_Z10rsIsObject16rs_program_store", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 899 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 900 | { "_Z11rsSetObjectP7rs_fontS_", (void *)&rsiSetObject, true }, |
| 901 | { "_Z13rsClearObjectP7rs_font", (void *)&rsiClearObject, true }, |
| 902 | { "_Z10rsIsObject7rs_font", (void *)&rsiIsObject, true }, |
Jason Sams | 4fd8bb4 | 2010-09-17 13:17:17 -0700 | [diff] [blame] | 903 | |
| 904 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 905 | { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_allocationMarkDirty, true }, |
Alex Sakhartchouk | 8e95466 | 2010-09-01 16:34:48 -0700 | [diff] [blame] | 906 | |
Jason Sams | 02f62aa | 2010-08-16 12:41:48 -0700 | [diff] [blame] | 907 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 908 | // Debug |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 909 | { "_Z7rsDebugPKcf", (void *)&SC_debugF, true }, |
| 910 | { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true }, |
| 911 | { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true }, |
| 912 | { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true }, |
| 913 | { "_Z7rsDebugPKcd", (void *)&SC_debugD, true }, |
| 914 | { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true }, |
| 915 | { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true }, |
| 916 | { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true }, |
| 917 | { "_Z7rsDebugPKci", (void *)&SC_debugI32, true }, |
| 918 | { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true }, |
Stephen Hines | 6568896 | 2010-10-15 12:47:49 -0700 | [diff] [blame] | 919 | // Both "long" and "unsigned long" need to be redirected to their |
| 920 | // 64-bit counterparts, since we have hacked Slang to use 64-bit |
| 921 | // for "long" on Arm (to be similar to Java). |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 922 | { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true }, |
| 923 | { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true }, |
| 924 | { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true }, |
| 925 | { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true }, |
| 926 | { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 927 | |
| 928 | // RS Math |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 929 | { "_Z6rsRandi", (void *)&SC_randi, true }, |
| 930 | { "_Z6rsRandii", (void *)&SC_randi2, true }, |
| 931 | { "_Z6rsRandf", (void *)&SC_randf, true }, |
| 932 | { "_Z6rsRandff", (void *)&SC_randf2, true }, |
| 933 | { "_Z6rsFracf", (void *)&SC_frac, true }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 934 | |
| 935 | // time |
Stephen Hines | 1ac9da6 | 2011-01-07 15:11:30 -0800 | [diff] [blame] | 936 | { "_Z6rsTimePi", (void *)&SC_time, true }, |
| 937 | { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_localtime, true }, |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 938 | { "_Z14rsUptimeMillisv", (void*)&SC_uptimeMillis, true }, |
| 939 | { "_Z13rsUptimeNanosv", (void*)&SC_uptimeNanos, true }, |
| 940 | { "_Z7rsGetDtv", (void*)&SC_getDt, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 941 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 942 | { "_Z14rsSendToClienti", (void *)&SC_toClient, false }, |
| 943 | { "_Z14rsSendToClientiPKvj", (void *)&SC_toClient2, false }, |
| 944 | { "_Z22rsSendToClientBlockingi", (void *)&SC_toClientBlocking, false }, |
| 945 | { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_toClientBlocking2, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 946 | |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 947 | // matrix |
Stephen Hines | 413bce4 | 2011-03-14 19:15:47 -0700 | [diff] [blame] | 948 | { "_Z20rsMatrixLoadIdentityP12rs_matrix4x4", (void *)&SC_MatrixLoadIdentity_4x4, true }, |
| 949 | { "_Z20rsMatrixLoadIdentityP12rs_matrix3x3", (void *)&SC_MatrixLoadIdentity_3x3, true }, |
| 950 | { "_Z20rsMatrixLoadIdentityP12rs_matrix2x2", (void *)&SC_MatrixLoadIdentity_2x2, true }, |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 951 | |
Stephen Hines | 413bce4 | 2011-03-14 19:15:47 -0700 | [diff] [blame] | 952 | { "_Z12rsMatrixLoadP12rs_matrix4x4PKf", (void *)&SC_MatrixLoad_4x4_f, true }, |
| 953 | { "_Z12rsMatrixLoadP12rs_matrix3x3PKf", (void *)&SC_MatrixLoad_3x3_f, true }, |
| 954 | { "_Z12rsMatrixLoadP12rs_matrix2x2PKf", (void *)&SC_MatrixLoad_2x2_f, true }, |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 955 | |
Stephen Hines | 413bce4 | 2011-03-14 19:15:47 -0700 | [diff] [blame] | 956 | { "_Z12rsMatrixLoadP12rs_matrix4x4PKS_", (void *)&SC_MatrixLoad_4x4_4x4, true }, |
| 957 | { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix3x3", (void *)&SC_MatrixLoad_4x4_3x3, true }, |
| 958 | { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix2x2", (void *)&SC_MatrixLoad_4x4_2x2, true }, |
| 959 | { "_Z12rsMatrixLoadP12rs_matrix3x3PKS_", (void *)&SC_MatrixLoad_3x3_3x3, true }, |
| 960 | { "_Z12rsMatrixLoadP12rs_matrix2x2PKS_", (void *)&SC_MatrixLoad_2x2_2x2, true }, |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 961 | |
Stephen Hines | 413bce4 | 2011-03-14 19:15:47 -0700 | [diff] [blame] | 962 | { "_Z18rsMatrixLoadRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadRotate, true }, |
| 963 | { "_Z17rsMatrixLoadScaleP12rs_matrix4x4fff", (void *)&SC_MatrixLoadScale, true }, |
| 964 | { "_Z21rsMatrixLoadTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixLoadTranslate, true }, |
| 965 | { "_Z14rsMatrixRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixRotate, true }, |
| 966 | { "_Z13rsMatrixScaleP12rs_matrix4x4fff", (void *)&SC_MatrixScale, true }, |
| 967 | { "_Z17rsMatrixTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixTranslate, true }, |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 968 | |
Stephen Hines | 413bce4 | 2011-03-14 19:15:47 -0700 | [diff] [blame] | 969 | { "_Z20rsMatrixLoadMultiplyP12rs_matrix4x4PKS_S2_", (void *)&SC_MatrixLoadMultiply_4x4_4x4_4x4, true }, |
| 970 | { "_Z16rsMatrixMultiplyP12rs_matrix4x4PKS_", (void *)&SC_MatrixMultiply_4x4_4x4, true }, |
| 971 | { "_Z20rsMatrixLoadMultiplyP12rs_matrix3x3PKS_S2_", (void *)&SC_MatrixLoadMultiply_3x3_3x3_3x3, true }, |
| 972 | { "_Z16rsMatrixMultiplyP12rs_matrix3x3PKS_", (void *)&SC_MatrixMultiply_3x3_3x3, true }, |
| 973 | { "_Z20rsMatrixLoadMultiplyP12rs_matrix2x2PKS_S2_", (void *)&SC_MatrixLoadMultiply_2x2_2x2_2x2, true }, |
| 974 | { "_Z16rsMatrixMultiplyP12rs_matrix2x2PKS_", (void *)&SC_MatrixMultiply_2x2_2x2, true }, |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 975 | |
Stephen Hines | 413bce4 | 2011-03-14 19:15:47 -0700 | [diff] [blame] | 976 | { "_Z17rsMatrixLoadOrthoP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadOrtho, true }, |
| 977 | { "_Z19rsMatrixLoadFrustumP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadFrustum, true }, |
| 978 | { "_Z23rsMatrixLoadPerspectiveP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadPerspective, true }, |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 979 | |
Stephen Hines | 413bce4 | 2011-03-14 19:15:47 -0700 | [diff] [blame] | 980 | { "_Z15rsMatrixInverseP12rs_matrix4x4", (void *)&SC_MatrixInverse_4x4, true }, |
| 981 | { "_Z24rsMatrixInverseTransposeP12rs_matrix4x4", (void *)&SC_MatrixInverseTranspose_4x4, true }, |
| 982 | { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_4x4, true }, |
| 983 | { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_3x3, true }, |
| 984 | { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_2x2, true }, |
Jason Sams | 1afbf54 | 2011-01-25 21:33:44 -0800 | [diff] [blame] | 985 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 986 | { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false }, |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 987 | //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2, false }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 988 | |
| 989 | //////////////////////////////////////////////////////////////////// |
| 990 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 991 | //{ "sinf_fast", (void *)&SC_sinf_fast, true }, |
| 992 | //{ "cosf_fast", (void *)&SC_cosf_fast, true }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 993 | |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 994 | { NULL, NULL, false } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 995 | }; |
| 996 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 997 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) { |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 998 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 999 | |
| 1000 | while (syms->mPtr) { |
| 1001 | if (!strcmp(syms->mName, sym)) { |
| 1002 | return syms; |
| 1003 | } |
| 1004 | syms++; |
| 1005 | } |
| 1006 | return NULL; |
| 1007 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1008 | |