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" |
Romain Guy | ecc7ca0 | 2009-08-03 21:12:51 -0700 | [diff] [blame] | 20 | #include "rsNoise.h" |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 21 | |
| 22 | #include "acc/acc.h" |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 23 | #include "utils/Timers.h" |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 24 | |
Jason Sams | e9ad9a7 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 25 | #define GL_GLEXT_PROTOTYPES |
| 26 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 27 | #include <GLES/gl.h> |
| 28 | #include <GLES/glext.h> |
| 29 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 30 | #include <time.h> |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 31 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 32 | using namespace android; |
| 33 | using namespace android::renderscript; |
| 34 | |
| 35 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 36 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 37 | Context * rsc = tls->mContext; \ |
| 38 | ScriptC * sc = (ScriptC *) tls->mScript |
| 39 | |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 40 | typedef struct { |
| 41 | float x; |
| 42 | float y; |
| 43 | float z; |
| 44 | } vec3_t; |
| 45 | |
| 46 | typedef struct { |
| 47 | float x; |
| 48 | float y; |
| 49 | float z; |
| 50 | float w; |
| 51 | } vec4_t; |
| 52 | |
| 53 | typedef struct { |
| 54 | float x; |
| 55 | float y; |
| 56 | } vec2_t; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 57 | |
| 58 | ////////////////////////////////////////////////////////////////////////////// |
| 59 | // IO routines |
| 60 | ////////////////////////////////////////////////////////////////////////////// |
| 61 | |
| 62 | static float SC_loadF(uint32_t bank, uint32_t offset) |
| 63 | { |
| 64 | GET_TLS(); |
| 65 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 66 | const float *f = static_cast<const float *>(vp); |
| 67 | //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]); |
| 68 | return f[offset]; |
| 69 | } |
| 70 | |
| 71 | static int32_t SC_loadI32(uint32_t bank, uint32_t offset) |
| 72 | { |
| 73 | GET_TLS(); |
| 74 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 75 | const int32_t *i = static_cast<const int32_t *>(vp); |
| 76 | //LOGE("loadI32 %i %i = %i", bank, offset, t); |
| 77 | return i[offset]; |
| 78 | } |
| 79 | |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 80 | static float* SC_loadArrayF(uint32_t bank, uint32_t offset) |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 81 | { |
| 82 | GET_TLS(); |
| 83 | void *vp = sc->mSlots[bank]->getPtr(); |
| 84 | float *f = static_cast<float *>(vp); |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 85 | return f + offset; |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 88 | static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset) |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 89 | { |
| 90 | GET_TLS(); |
| 91 | void *vp = sc->mSlots[bank]->getPtr(); |
| 92 | int32_t *i = static_cast<int32_t *>(vp); |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 93 | return i + offset; |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 96 | static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx) |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 97 | { |
Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 98 | SimpleMesh *tm = static_cast<SimpleMesh *>(mesh); |
| 99 | void *vp = tm->mVertexBuffers[idx]->getPtr();; |
| 100 | return static_cast<float *>(vp); |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 103 | static void SC_updateSimpleMesh(RsSimpleMesh mesh) |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 104 | { |
Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 105 | SimpleMesh *sm = static_cast<SimpleMesh *>(mesh); |
| 106 | sm->uploadAll(); |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 107 | } |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 108 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 109 | static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) |
| 110 | { |
| 111 | GET_TLS(); |
| 112 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 113 | const uint32_t *i = static_cast<const uint32_t *>(vp); |
| 114 | return i[offset]; |
| 115 | } |
| 116 | |
| 117 | static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v) |
| 118 | { |
| 119 | GET_TLS(); |
| 120 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 121 | const float *f = static_cast<const float *>(vp); |
| 122 | memcpy(v, &f[offset], sizeof(rsc_Vector4)); |
| 123 | } |
| 124 | |
| 125 | static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m) |
| 126 | { |
| 127 | GET_TLS(); |
| 128 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 129 | const float *f = static_cast<const float *>(vp); |
| 130 | memcpy(m, &f[offset], sizeof(rsc_Matrix)); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | static void SC_storeF(uint32_t bank, uint32_t offset, float v) |
| 135 | { |
| 136 | //LOGE("storeF %i %i %f", bank, offset, v); |
| 137 | GET_TLS(); |
| 138 | void *vp = sc->mSlots[bank]->getPtr(); |
| 139 | float *f = static_cast<float *>(vp); |
| 140 | f[offset] = v; |
| 141 | } |
| 142 | |
| 143 | static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v) |
| 144 | { |
| 145 | GET_TLS(); |
| 146 | void *vp = sc->mSlots[bank]->getPtr(); |
| 147 | int32_t *f = static_cast<int32_t *>(vp); |
| 148 | static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
| 149 | } |
| 150 | |
| 151 | static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v) |
| 152 | { |
| 153 | GET_TLS(); |
| 154 | void *vp = sc->mSlots[bank]->getPtr(); |
| 155 | uint32_t *f = static_cast<uint32_t *>(vp); |
| 156 | static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
| 157 | } |
| 158 | |
| 159 | static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v) |
| 160 | { |
| 161 | GET_TLS(); |
| 162 | void *vp = sc->mSlots[bank]->getPtr(); |
| 163 | float *f = static_cast<float *>(vp); |
| 164 | memcpy(&f[offset], v, sizeof(rsc_Vector4)); |
| 165 | } |
| 166 | |
| 167 | static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m) |
| 168 | { |
| 169 | GET_TLS(); |
| 170 | void *vp = sc->mSlots[bank]->getPtr(); |
| 171 | float *f = static_cast<float *>(vp); |
| 172 | memcpy(&f[offset], m, sizeof(rsc_Matrix)); |
| 173 | } |
| 174 | |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 175 | ////////////////////////////////////////////////////////////////////////////// |
| 176 | // Vec3 routines |
| 177 | ////////////////////////////////////////////////////////////////////////////// |
| 178 | |
| 179 | static void SC_vec3Norm(vec3_t *v) |
| 180 | { |
| 181 | float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z); |
| 182 | len = 1 / len; |
| 183 | v->x *= len; |
| 184 | v->y *= len; |
| 185 | v->z *= len; |
| 186 | } |
| 187 | |
| 188 | static float SC_vec3Length(const vec3_t *v) |
| 189 | { |
| 190 | return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z); |
| 191 | } |
| 192 | |
| 193 | static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs) |
| 194 | { |
| 195 | dest->x = lhs->x + rhs->x; |
| 196 | dest->y = lhs->y + rhs->y; |
| 197 | dest->z = lhs->z + rhs->z; |
| 198 | } |
| 199 | |
| 200 | static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs) |
| 201 | { |
| 202 | dest->x = lhs->x - rhs->x; |
| 203 | dest->y = lhs->y - rhs->y; |
| 204 | dest->z = lhs->z - rhs->z; |
| 205 | } |
| 206 | |
| 207 | static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs) |
| 208 | { |
| 209 | float x = lhs->y * rhs->z - lhs->z * rhs->y; |
| 210 | float y = lhs->z * rhs->x - lhs->x * rhs->z; |
| 211 | float z = lhs->x * rhs->y - lhs->y * rhs->x; |
| 212 | dest->x = x; |
| 213 | dest->y = y; |
| 214 | dest->z = z; |
| 215 | } |
| 216 | |
| 217 | static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs) |
| 218 | { |
| 219 | return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z; |
| 220 | } |
| 221 | |
| 222 | static void SC_vec3Scale(vec3_t *lhs, float scale) |
| 223 | { |
| 224 | lhs->x *= scale; |
| 225 | lhs->y *= scale; |
| 226 | lhs->z *= scale; |
| 227 | } |
| 228 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 229 | ////////////////////////////////////////////////////////////////////////////// |
| 230 | // Vec4 routines |
| 231 | ////////////////////////////////////////////////////////////////////////////// |
| 232 | |
| 233 | static void SC_vec4Norm(vec4_t *v) |
| 234 | { |
| 235 | float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w); |
| 236 | len = 1 / len; |
| 237 | v->x *= len; |
| 238 | v->y *= len; |
| 239 | v->z *= len; |
| 240 | v->w *= len; |
| 241 | } |
| 242 | |
| 243 | static float SC_vec4Length(const vec4_t *v) |
| 244 | { |
| 245 | return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w); |
| 246 | } |
| 247 | |
| 248 | static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs) |
| 249 | { |
| 250 | dest->x = lhs->x + rhs->x; |
| 251 | dest->y = lhs->y + rhs->y; |
| 252 | dest->z = lhs->z + rhs->z; |
| 253 | dest->w = lhs->w + rhs->w; |
| 254 | } |
| 255 | |
| 256 | static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs) |
| 257 | { |
| 258 | dest->x = lhs->x - rhs->x; |
| 259 | dest->y = lhs->y - rhs->y; |
| 260 | dest->z = lhs->z - rhs->z; |
| 261 | dest->w = lhs->w - rhs->w; |
| 262 | } |
| 263 | |
| 264 | static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs) |
| 265 | { |
| 266 | return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w; |
| 267 | } |
| 268 | |
| 269 | static void SC_vec4Scale(vec4_t *lhs, float scale) |
| 270 | { |
| 271 | lhs->x *= scale; |
| 272 | lhs->y *= scale; |
| 273 | lhs->z *= scale; |
| 274 | lhs->w *= scale; |
| 275 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 276 | |
| 277 | ////////////////////////////////////////////////////////////////////////////// |
| 278 | // Math routines |
| 279 | ////////////////////////////////////////////////////////////////////////////// |
| 280 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 281 | #define PI 3.1415926f |
| 282 | #define DEG_TO_RAD PI / 180.0f |
| 283 | #define RAD_TO_DEG 180.0f / PI |
| 284 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 285 | static float SC_sinf_fast(float x) |
| 286 | { |
| 287 | const float A = 1.0f / (2.0f * M_PI); |
| 288 | const float B = -16.0f; |
| 289 | const float C = 8.0f; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 290 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 291 | // scale angle for easy argument reduction |
| 292 | x *= A; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 293 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 294 | if (fabsf(x) >= 0.5f) { |
| 295 | // argument reduction |
| 296 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 297 | } |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 298 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 299 | const float y = B * x * fabsf(x) + C * x; |
| 300 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 301 | } |
| 302 | |
| 303 | static float SC_cosf_fast(float x) |
| 304 | { |
| 305 | x += float(M_PI / 2); |
| 306 | |
| 307 | const float A = 1.0f / (2.0f * M_PI); |
| 308 | const float B = -16.0f; |
| 309 | const float C = 8.0f; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 310 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 311 | // scale angle for easy argument reduction |
| 312 | x *= A; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 313 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 314 | if (fabsf(x) >= 0.5f) { |
| 315 | // argument reduction |
| 316 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 317 | } |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 318 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 319 | const float y = B * x * fabsf(x) + C * x; |
| 320 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 321 | } |
| 322 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 323 | static float SC_randf(float max) |
| 324 | { |
| 325 | float r = (float)rand(); |
| 326 | return r / RAND_MAX * max; |
| 327 | } |
| 328 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 329 | static float SC_randf2(float min, float max) |
| 330 | { |
| 331 | float r = (float)rand(); |
| 332 | return r / RAND_MAX * (max - min) + min; |
| 333 | } |
| 334 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 335 | static int SC_sign(int value) |
| 336 | { |
| 337 | return (value > 0) - (value < 0); |
| 338 | } |
| 339 | |
| 340 | static float SC_signf(float value) |
| 341 | { |
| 342 | return (value > 0) - (value < 0); |
| 343 | } |
| 344 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 345 | static float SC_clampf(float amount, float low, float high) |
| 346 | { |
| 347 | return amount < low ? low : (amount > high ? high : amount); |
| 348 | } |
| 349 | |
Romain Guy | a9d2d5e | 2009-08-09 17:04:54 -0700 | [diff] [blame] | 350 | static int SC_clamp(int amount, int low, int high) |
| 351 | { |
| 352 | return amount < low ? low : (amount > high ? high : amount); |
| 353 | } |
| 354 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 355 | static float SC_maxf(float a, float b) |
| 356 | { |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 357 | return a > b ? a : b; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static float SC_minf(float a, float b) |
| 361 | { |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 362 | return a < b ? a : b; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static float SC_sqrf(float v) |
| 366 | { |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 367 | return v * v; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 370 | static int SC_sqr(int v) |
| 371 | { |
| 372 | return v * v; |
| 373 | } |
| 374 | |
Jason Sams | d342fd7 | 2009-09-18 14:24:24 -0700 | [diff] [blame] | 375 | static float SC_fracf(float v) |
| 376 | { |
| 377 | return v - floorf(v); |
| 378 | } |
| 379 | |
| 380 | static float SC_roundf(float v) |
| 381 | { |
| 382 | return floorf(v + 0.4999999999); |
| 383 | } |
| 384 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 385 | static float SC_distf2(float x1, float y1, float x2, float y2) |
| 386 | { |
| 387 | float x = x2 - x1; |
| 388 | float y = y2 - y1; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 389 | return sqrtf(x * x + y * y); |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2) |
| 393 | { |
| 394 | float x = x2 - x1; |
| 395 | float y = y2 - y1; |
| 396 | float z = z2 - z1; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 397 | return sqrtf(x * x + y * y + z * z); |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static float SC_magf2(float a, float b) |
| 401 | { |
| 402 | return sqrtf(a * a + b * b); |
| 403 | } |
| 404 | |
| 405 | static float SC_magf3(float a, float b, float c) |
| 406 | { |
| 407 | return sqrtf(a * a + b * b + c * c); |
| 408 | } |
| 409 | |
| 410 | static float SC_radf(float degrees) |
| 411 | { |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 412 | return degrees * DEG_TO_RAD; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static float SC_degf(float radians) |
| 416 | { |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 417 | return radians * RAD_TO_DEG; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | static float SC_lerpf(float start, float stop, float amount) |
| 421 | { |
| 422 | return start + (stop - start) * amount; |
| 423 | } |
| 424 | |
| 425 | static float SC_normf(float start, float stop, float value) |
| 426 | { |
| 427 | return (value - start) / (stop - start); |
| 428 | } |
| 429 | |
| 430 | static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value) |
| 431 | { |
| 432 | return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart)); |
| 433 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 434 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 435 | ////////////////////////////////////////////////////////////////////////////// |
| 436 | // Time routines |
| 437 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 438 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 439 | static int32_t SC_second() |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 440 | { |
| 441 | GET_TLS(); |
| 442 | |
| 443 | time_t rawtime; |
| 444 | time(&rawtime); |
| 445 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 446 | struct tm *timeinfo; |
| 447 | timeinfo = localtime(&rawtime); |
| 448 | return timeinfo->tm_sec; |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 451 | static int32_t SC_minute() |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 452 | { |
| 453 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 454 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 455 | time_t rawtime; |
| 456 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 457 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 458 | struct tm *timeinfo; |
| 459 | timeinfo = localtime(&rawtime); |
| 460 | return timeinfo->tm_min; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 461 | } |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 462 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 463 | static int32_t SC_hour() |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 464 | { |
| 465 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 466 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 467 | time_t rawtime; |
| 468 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 469 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 470 | struct tm *timeinfo; |
| 471 | timeinfo = localtime(&rawtime); |
| 472 | return timeinfo->tm_hour; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 475 | static int32_t SC_day() |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 476 | { |
| 477 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 478 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 479 | time_t rawtime; |
| 480 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 481 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 482 | struct tm *timeinfo; |
| 483 | timeinfo = localtime(&rawtime); |
| 484 | return timeinfo->tm_mday; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 485 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 486 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 487 | static int32_t SC_month() |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 488 | { |
| 489 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 490 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 491 | time_t rawtime; |
| 492 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 493 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 494 | struct tm *timeinfo; |
| 495 | timeinfo = localtime(&rawtime); |
| 496 | return timeinfo->tm_mon; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 497 | } |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 498 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 499 | static int32_t SC_year() |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 500 | { |
| 501 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 502 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 503 | time_t rawtime; |
| 504 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 505 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 506 | struct tm *timeinfo; |
| 507 | timeinfo = localtime(&rawtime); |
| 508 | return timeinfo->tm_year; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 511 | static int32_t SC_uptimeMillis() |
| 512 | { |
| 513 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 514 | } |
| 515 | |
| 516 | static int32_t SC_startTimeMillis() |
| 517 | { |
| 518 | GET_TLS(); |
| 519 | return sc->mEnviroment.mStartTimeMillis; |
| 520 | } |
| 521 | |
| 522 | static int32_t SC_elapsedTimeMillis() |
| 523 | { |
| 524 | GET_TLS(); |
| 525 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)) |
| 526 | - sc->mEnviroment.mStartTimeMillis; |
| 527 | } |
| 528 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 529 | ////////////////////////////////////////////////////////////////////////////// |
| 530 | // Matrix routines |
| 531 | ////////////////////////////////////////////////////////////////////////////// |
| 532 | |
| 533 | |
| 534 | static void SC_matrixLoadIdentity(rsc_Matrix *mat) |
| 535 | { |
| 536 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 537 | m->loadIdentity(); |
| 538 | } |
| 539 | |
| 540 | static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f) |
| 541 | { |
| 542 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 543 | m->load(f); |
| 544 | } |
| 545 | |
| 546 | static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat) |
| 547 | { |
| 548 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 549 | m->load(reinterpret_cast<const Matrix *>(newmat)); |
| 550 | } |
| 551 | |
| 552 | static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
| 553 | { |
| 554 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 555 | m->loadRotate(rot, x, y, z); |
| 556 | } |
| 557 | |
| 558 | static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z) |
| 559 | { |
| 560 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 561 | m->loadScale(x, y, z); |
| 562 | } |
| 563 | |
| 564 | static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z) |
| 565 | { |
| 566 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 567 | m->loadTranslate(x, y, z); |
| 568 | } |
| 569 | |
| 570 | static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs) |
| 571 | { |
| 572 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 573 | m->loadMultiply(reinterpret_cast<const Matrix *>(lhs), |
| 574 | reinterpret_cast<const Matrix *>(rhs)); |
| 575 | } |
| 576 | |
| 577 | static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs) |
| 578 | { |
| 579 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 580 | m->multiply(reinterpret_cast<const Matrix *>(rhs)); |
| 581 | } |
| 582 | |
| 583 | static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
| 584 | { |
| 585 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 586 | m->rotate(rot, x, y, z); |
| 587 | } |
| 588 | |
| 589 | static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z) |
| 590 | { |
| 591 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 592 | m->scale(x, y, z); |
| 593 | } |
| 594 | |
| 595 | static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z) |
| 596 | { |
| 597 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 598 | m->translate(x, y, z); |
| 599 | } |
| 600 | |
| 601 | |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 602 | static void SC_vec2Rand(float *vec, float maxLen) |
| 603 | { |
| 604 | float angle = SC_randf(PI * 2); |
| 605 | float len = SC_randf(maxLen); |
| 606 | vec[0] = len * sinf(angle); |
| 607 | vec[1] = len * cosf(angle); |
| 608 | } |
| 609 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 610 | |
| 611 | |
| 612 | ////////////////////////////////////////////////////////////////////////////// |
| 613 | // Context |
| 614 | ////////////////////////////////////////////////////////////////////////////// |
| 615 | |
| 616 | static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) |
| 617 | { |
| 618 | GET_TLS(); |
| 619 | rsi_ProgramFragmentBindTexture(rsc, |
| 620 | static_cast<ProgramFragment *>(vpf), |
| 621 | slot, |
| 622 | static_cast<Allocation *>(va)); |
| 623 | |
| 624 | } |
| 625 | |
| 626 | static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) |
| 627 | { |
| 628 | GET_TLS(); |
| 629 | rsi_ProgramFragmentBindSampler(rsc, |
| 630 | static_cast<ProgramFragment *>(vpf), |
| 631 | slot, |
| 632 | static_cast<Sampler *>(vs)); |
| 633 | |
| 634 | } |
| 635 | |
| 636 | static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs) |
| 637 | { |
| 638 | GET_TLS(); |
| 639 | rsi_ContextBindProgramFragmentStore(rsc, pfs); |
| 640 | |
| 641 | } |
| 642 | |
| 643 | static void SC_bindProgramFragment(RsProgramFragment pf) |
| 644 | { |
| 645 | GET_TLS(); |
| 646 | rsi_ContextBindProgramFragment(rsc, pf); |
| 647 | |
| 648 | } |
| 649 | |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 650 | static void SC_bindProgramVertex(RsProgramVertex pv) |
| 651 | { |
| 652 | GET_TLS(); |
| 653 | rsi_ContextBindProgramVertex(rsc, pv); |
| 654 | |
| 655 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 656 | |
| 657 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 658 | // VP |
| 659 | ////////////////////////////////////////////////////////////////////////////// |
| 660 | |
| 661 | static void SC_vpLoadModelMatrix(const rsc_Matrix *m) |
| 662 | { |
| 663 | GET_TLS(); |
| 664 | rsc->getVertex()->setModelviewMatrix(m); |
| 665 | } |
| 666 | |
| 667 | static void SC_vpLoadTextureMatrix(const rsc_Matrix *m) |
| 668 | { |
| 669 | GET_TLS(); |
| 670 | rsc->getVertex()->setTextureMatrix(m); |
| 671 | } |
| 672 | |
| 673 | |
| 674 | |
| 675 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 676 | // Drawing |
| 677 | ////////////////////////////////////////////////////////////////////////////// |
| 678 | |
Romain Guy | 6c0cc6d | 2009-08-07 15:40:32 -0700 | [diff] [blame] | 679 | static void SC_drawLine(float x1, float y1, float z1, |
| 680 | float x2, float y2, float z2) |
| 681 | { |
| 682 | GET_TLS(); |
| 683 | rsc->setupCheck(); |
| 684 | |
| 685 | float vtx[] = { x1, y1, z1, x2, y2, z2 }; |
| 686 | |
| 687 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 688 | glEnableClientState(GL_VERTEX_ARRAY); |
| 689 | glVertexPointer(3, GL_FLOAT, 0, vtx); |
| 690 | |
| 691 | glDisableClientState(GL_NORMAL_ARRAY); |
| 692 | glDisableClientState(GL_COLOR_ARRAY); |
| 693 | |
| 694 | glDrawArrays(GL_LINES, 0, 2); |
| 695 | } |
| 696 | |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 697 | static void SC_drawPoint(float x, float y, float z) |
| 698 | { |
| 699 | GET_TLS(); |
| 700 | rsc->setupCheck(); |
| 701 | |
| 702 | float vtx[] = { x, y, z }; |
| 703 | |
| 704 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 705 | glEnableClientState(GL_VERTEX_ARRAY); |
| 706 | glVertexPointer(3, GL_FLOAT, 0, vtx); |
| 707 | |
| 708 | glDisableClientState(GL_NORMAL_ARRAY); |
| 709 | glDisableClientState(GL_COLOR_ARRAY); |
| 710 | |
| 711 | glDrawArrays(GL_POINTS, 0, 1); |
| 712 | } |
| 713 | |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 714 | static void SC_drawQuadTexCoords(float x1, float y1, float z1, |
| 715 | float u1, float v1, |
| 716 | float x2, float y2, float z2, |
| 717 | float u2, float v2, |
| 718 | float x3, float y3, float z3, |
| 719 | float u3, float v3, |
| 720 | float x4, float y4, float z4, |
| 721 | float u4, float v4) |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 722 | { |
| 723 | GET_TLS(); |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 724 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 725 | //LOGE("Quad"); |
| 726 | //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); |
| 727 | //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); |
| 728 | //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); |
| 729 | //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 730 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 731 | float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 732 | const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4}; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 733 | |
| 734 | rsc->setupCheck(); |
| 735 | |
| 736 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 737 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 738 | |
| 739 | glEnableClientState(GL_VERTEX_ARRAY); |
| 740 | glVertexPointer(3, GL_FLOAT, 0, vtx); |
| 741 | |
| 742 | glClientActiveTexture(GL_TEXTURE0); |
| 743 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 744 | glTexCoordPointer(2, GL_FLOAT, 0, tex); |
| 745 | glClientActiveTexture(GL_TEXTURE1); |
| 746 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 747 | glTexCoordPointer(2, GL_FLOAT, 0, tex); |
| 748 | glClientActiveTexture(GL_TEXTURE0); |
| 749 | |
| 750 | glDisableClientState(GL_NORMAL_ARRAY); |
| 751 | glDisableClientState(GL_COLOR_ARRAY); |
| 752 | |
| 753 | //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 754 | |
| 755 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 756 | } |
| 757 | |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 758 | static void SC_drawQuad(float x1, float y1, float z1, |
| 759 | float x2, float y2, float z2, |
| 760 | float x3, float y3, float z3, |
| 761 | float x4, float y4, float z4) |
| 762 | { |
| 763 | SC_drawQuadTexCoords(x1, y1, z1, 0, 1, |
| 764 | x2, y2, z2, 1, 1, |
| 765 | x3, y3, z3, 1, 0, |
| 766 | x4, y4, z4, 0, 0); |
| 767 | } |
| 768 | |
Jason Sams | e9ad9a7 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 769 | static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h) |
| 770 | { |
| 771 | GET_TLS(); |
| 772 | rsc->setupCheck(); |
| 773 | |
| 774 | GLint crop[4] = {0, h, w, -h}; |
| 775 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 776 | glDrawTexfOES(x, y, z, w, h); |
| 777 | } |
| 778 | |
Joe Onorato | 6656c1b | 2010-01-14 15:59:35 -0500 | [diff] [blame] | 779 | static void SC_drawSpriteScreenspaceCropped(float x, float y, float z, float w, float h, |
| 780 | float cx0, float cy0, float cx1, float cy1) |
| 781 | { |
| 782 | GET_TLS(); |
| 783 | rsc->setupCheck(); |
| 784 | |
| 785 | GLint crop[4] = {cx0, cy0, cx1, cy1}; |
| 786 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 787 | glDrawTexfOES(x, y, z, w, h); |
| 788 | } |
| 789 | |
Jason Sams | e9ad9a7 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 790 | static void SC_drawSprite(float x, float y, float z, float w, float h) |
| 791 | { |
| 792 | GET_TLS(); |
| 793 | rsc->setupCheck(); |
| 794 | |
| 795 | float vin[3] = {x, y, z}; |
| 796 | float vout[4]; |
| 797 | |
| 798 | //LOGE("ds in %f %f %f", x, y, z); |
| 799 | rsc->getVertex()->transformToScreen(rsc, vout, vin); |
| 800 | //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]); |
| 801 | vout[0] /= vout[3]; |
| 802 | vout[1] /= vout[3]; |
| 803 | vout[2] /= vout[3]; |
| 804 | |
| 805 | vout[0] *= rsc->getWidth() / 2; |
| 806 | vout[1] *= rsc->getHeight() / 2; |
| 807 | vout[0] += rsc->getWidth() / 2; |
| 808 | vout[1] += rsc->getHeight() / 2; |
| 809 | |
| 810 | vout[0] -= w/2; |
| 811 | vout[1] -= h/2; |
| 812 | |
| 813 | //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]); |
| 814 | |
| 815 | // U, V, W, H |
| 816 | GLint crop[4] = {0, h, w, -h}; |
| 817 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 818 | glDrawTexiOES(vout[0], vout[1], 0/*vout[2]*/, w, h); |
| 819 | } |
| 820 | |
| 821 | |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 822 | static void SC_drawRect(float x1, float y1, |
| 823 | float x2, float y2, float z) |
| 824 | { |
| 825 | SC_drawQuad(x1, y2, z, |
| 826 | x2, y2, z, |
| 827 | x2, y1, z, |
| 828 | x1, y1, z); |
| 829 | } |
| 830 | |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 831 | static void SC_drawSimpleMesh(RsSimpleMesh vsm) |
| 832 | { |
| 833 | GET_TLS(); |
| 834 | SimpleMesh *sm = static_cast<SimpleMesh *>(vsm); |
| 835 | rsc->setupCheck(); |
| 836 | sm->render(); |
| 837 | } |
| 838 | |
| 839 | static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len) |
| 840 | { |
| 841 | GET_TLS(); |
| 842 | SimpleMesh *sm = static_cast<SimpleMesh *>(vsm); |
| 843 | rsc->setupCheck(); |
| 844 | sm->renderRange(start, len); |
| 845 | } |
| 846 | |
| 847 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 848 | ////////////////////////////////////////////////////////////////////////////// |
| 849 | // |
| 850 | ////////////////////////////////////////////////////////////////////////////// |
| 851 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 852 | static void SC_color(float r, float g, float b, float a) |
| 853 | { |
| 854 | glColor4f(r, g, b, a); |
| 855 | } |
| 856 | |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 857 | static void SC_ambient(float r, float g, float b, float a) |
| 858 | { |
| 859 | GLfloat params[] = { r, g, b, a }; |
| 860 | glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params); |
| 861 | } |
| 862 | |
| 863 | static void SC_diffuse(float r, float g, float b, float a) |
| 864 | { |
| 865 | GLfloat params[] = { r, g, b, a }; |
| 866 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params); |
| 867 | } |
| 868 | |
| 869 | static void SC_specular(float r, float g, float b, float a) |
| 870 | { |
| 871 | GLfloat params[] = { r, g, b, a }; |
| 872 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params); |
| 873 | } |
| 874 | |
| 875 | static void SC_emission(float r, float g, float b, float a) |
| 876 | { |
| 877 | GLfloat params[] = { r, g, b, a }; |
| 878 | glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params); |
| 879 | } |
| 880 | |
Romain Guy | 6c0cc6d | 2009-08-07 15:40:32 -0700 | [diff] [blame] | 881 | static void SC_shininess(float s) |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 882 | { |
Romain Guy | 6c0cc6d | 2009-08-07 15:40:32 -0700 | [diff] [blame] | 883 | glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s); |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Romain Guy | 2d496bf | 2009-09-04 17:55:41 -0700 | [diff] [blame] | 886 | static void SC_pointAttenuation(float a, float b, float c) |
| 887 | { |
| 888 | GLfloat params[] = { a, b, c }; |
| 889 | glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params); |
| 890 | } |
| 891 | |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 892 | static void SC_hsbToRgb(float h, float s, float b, float* rgb) |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 893 | { |
| 894 | float red = 0.0f; |
| 895 | float green = 0.0f; |
| 896 | float blue = 0.0f; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 897 | |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 898 | float x = h; |
| 899 | float y = s; |
| 900 | float z = b; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 901 | |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 902 | float hf = (x - (int) x) * 6.0f; |
| 903 | int ihf = (int) hf; |
| 904 | float f = hf - ihf; |
| 905 | float pv = z * (1.0f - y); |
| 906 | float qv = z * (1.0f - y * f); |
| 907 | float tv = z * (1.0f - y * (1.0f - f)); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 908 | |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 909 | switch (ihf) { |
| 910 | case 0: // Red is the dominant color |
| 911 | red = z; |
| 912 | green = tv; |
| 913 | blue = pv; |
| 914 | break; |
| 915 | case 1: // Green is the dominant color |
| 916 | red = qv; |
| 917 | green = z; |
| 918 | blue = pv; |
| 919 | break; |
| 920 | case 2: |
| 921 | red = pv; |
| 922 | green = z; |
| 923 | blue = tv; |
| 924 | break; |
| 925 | case 3: // Blue is the dominant color |
| 926 | red = pv; |
| 927 | green = qv; |
| 928 | blue = z; |
| 929 | break; |
| 930 | case 4: |
| 931 | red = tv; |
| 932 | green = pv; |
| 933 | blue = z; |
| 934 | break; |
| 935 | case 5: // Red is the dominant color |
| 936 | red = z; |
| 937 | green = pv; |
| 938 | blue = qv; |
| 939 | break; |
| 940 | } |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 941 | |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 942 | rgb[0] = red; |
| 943 | rgb[1] = green; |
| 944 | rgb[2] = blue; |
| 945 | } |
| 946 | |
| 947 | static int SC_hsbToAbgr(float h, float s, float b, float a) |
| 948 | { |
| 949 | float rgb[3]; |
| 950 | SC_hsbToRgb(h, s, b, rgb); |
| 951 | return int(a * 255.0f) << 24 | |
| 952 | int(rgb[2] * 255.0f) << 16 | |
| 953 | int(rgb[1] * 255.0f) << 8 | |
| 954 | int(rgb[0] * 255.0f); |
| 955 | } |
| 956 | |
| 957 | static void SC_hsb(float h, float s, float b, float a) |
| 958 | { |
| 959 | float rgb[3]; |
| 960 | SC_hsbToRgb(h, s, b, rgb); |
| 961 | glColor4f(rgb[0], rgb[1], rgb[2], a); |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 964 | static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel) |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 965 | { |
| 966 | GET_TLS(); |
| 967 | rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); |
| 968 | } |
| 969 | |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 970 | static void SC_uploadToBufferObject(RsAllocation va) |
| 971 | { |
| 972 | GET_TLS(); |
| 973 | rsi_AllocationUploadToBufferObject(rsc, va); |
| 974 | } |
| 975 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 976 | static void SC_ClearColor(float r, float g, float b, float a) |
| 977 | { |
| 978 | //LOGE("c %f %f %f %f", r, g, b, a); |
| 979 | GET_TLS(); |
| 980 | sc->mEnviroment.mClearColor[0] = r; |
| 981 | sc->mEnviroment.mClearColor[1] = g; |
| 982 | sc->mEnviroment.mClearColor[2] = b; |
| 983 | sc->mEnviroment.mClearColor[3] = a; |
| 984 | } |
| 985 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 986 | static void SC_debugF(const char *s, float f) |
| 987 | { |
| 988 | LOGE("%s %f", s, f); |
| 989 | } |
| 990 | |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 991 | static void SC_debugHexF(const char *s, float f) |
| 992 | { |
| 993 | LOGE("%s 0x%x", s, *((int *) (&f))); |
| 994 | } |
| 995 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 996 | static void SC_debugI32(const char *s, int32_t i) |
| 997 | { |
| 998 | LOGE("%s %i", s, i); |
| 999 | } |
| 1000 | |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 1001 | static void SC_debugHexI32(const char *s, int32_t i) |
| 1002 | { |
| 1003 | LOGE("%s 0x%x", s, i); |
| 1004 | } |
| 1005 | |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1006 | static uint32_t SC_getWidth() |
| 1007 | { |
| 1008 | GET_TLS(); |
| 1009 | return rsc->getWidth(); |
| 1010 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1011 | |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1012 | static uint32_t SC_getHeight() |
| 1013 | { |
| 1014 | GET_TLS(); |
| 1015 | return rsc->getHeight(); |
| 1016 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1017 | |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 1018 | static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a) |
| 1019 | { |
| 1020 | uint32_t c = 0; |
| 1021 | c |= (uint32_t)(r * 255.f + 0.5f); |
| 1022 | c |= ((uint32_t)(g * 255.f + 0.5f)) << 8; |
| 1023 | c |= ((uint32_t)(b * 255.f + 0.5f)) << 16; |
| 1024 | c |= ((uint32_t)(a * 255.f + 0.5f)) << 24; |
| 1025 | return c; |
| 1026 | } |
| 1027 | |
| 1028 | static uint32_t SC_colorFloatRGBAto565(float r, float g, float b) |
| 1029 | { |
| 1030 | uint32_t ir = (uint32_t)(r * 255.f + 0.5f); |
| 1031 | uint32_t ig = (uint32_t)(g * 255.f + 0.5f); |
| 1032 | uint32_t ib = (uint32_t)(b * 255.f + 0.5f); |
| 1033 | return rs888to565(ir, ig, ib); |
| 1034 | } |
| 1035 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1036 | static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace) |
| 1037 | { |
| 1038 | GET_TLS(); |
| 1039 | return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0); |
| 1040 | } |
| 1041 | |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 1042 | static void SC_scriptCall(int scriptID) |
| 1043 | { |
| 1044 | GET_TLS(); |
| 1045 | rsc->runScript((Script *)scriptID, 0); |
| 1046 | } |
| 1047 | |
| 1048 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1049 | ////////////////////////////////////////////////////////////////////////////// |
| 1050 | // Class implementation |
| 1051 | ////////////////////////////////////////////////////////////////////////////// |
| 1052 | |
| 1053 | ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { |
| 1054 | // IO |
| 1055 | { "loadI32", (void *)&SC_loadI32, |
| 1056 | "int", "(int, int)" }, |
| 1057 | //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" }, |
| 1058 | { "loadF", (void *)&SC_loadF, |
| 1059 | "float", "(int, int)" }, |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 1060 | { "loadArrayF", (void *)&SC_loadArrayF, |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 1061 | "float*", "(int, int)" }, |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 1062 | { "loadArrayI32", (void *)&SC_loadArrayI32, |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 1063 | "int*", "(int, int)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1064 | { "loadVec4", (void *)&SC_loadVec4, |
| 1065 | "void", "(int, int, float *)" }, |
| 1066 | { "loadMatrix", (void *)&SC_loadMatrix, |
| 1067 | "void", "(int, int, float *)" }, |
| 1068 | { "storeI32", (void *)&SC_storeI32, |
| 1069 | "void", "(int, int, int)" }, |
| 1070 | //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" }, |
| 1071 | { "storeF", (void *)&SC_storeF, |
| 1072 | "void", "(int, int, float)" }, |
| 1073 | { "storeVec4", (void *)&SC_storeVec4, |
| 1074 | "void", "(int, int, float *)" }, |
| 1075 | { "storeMatrix", (void *)&SC_storeMatrix, |
| 1076 | "void", "(int, int, float *)" }, |
Jason Sams | 6b9dec0 | 2009-09-23 16:38:37 -0700 | [diff] [blame] | 1077 | { "loadSimpleMeshVerticesF", (void *)&SC_loadSimpleMeshVerticesF, |
| 1078 | "float*", "(int, int)" }, |
| 1079 | { "updateSimpleMesh", (void *)&SC_updateSimpleMesh, |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 1080 | "void", "(int)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1081 | |
| 1082 | // math |
Romain Guy | a9d2d5e | 2009-08-09 17:04:54 -0700 | [diff] [blame] | 1083 | { "modf", (void *)&fmod, |
| 1084 | "float", "(float, float)" }, |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 1085 | { "abs", (void *)&abs, |
| 1086 | "int", "(int)" }, |
Romain Guy | bd5b572 | 2009-09-29 13:17:27 -0700 | [diff] [blame] | 1087 | { "absf", (void *)&fabsf, |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 1088 | "float", "(float)" }, |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 1089 | { "sinf_fast", (void *)&SC_sinf_fast, |
| 1090 | "float", "(float)" }, |
| 1091 | { "cosf_fast", (void *)&SC_cosf_fast, |
| 1092 | "float", "(float)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1093 | { "sinf", (void *)&sinf, |
| 1094 | "float", "(float)" }, |
| 1095 | { "cosf", (void *)&cosf, |
| 1096 | "float", "(float)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 1097 | { "asinf", (void *)&asinf, |
| 1098 | "float", "(float)" }, |
| 1099 | { "acosf", (void *)&acosf, |
| 1100 | "float", "(float)" }, |
| 1101 | { "atanf", (void *)&atanf, |
| 1102 | "float", "(float)" }, |
| 1103 | { "atan2f", (void *)&atan2f, |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 1104 | "float", "(float, float)" }, |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 1105 | { "fabsf", (void *)&fabsf, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1106 | "float", "(float)" }, |
| 1107 | { "randf", (void *)&SC_randf, |
| 1108 | "float", "(float)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 1109 | { "randf2", (void *)&SC_randf2, |
| 1110 | "float", "(float, float)" }, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1111 | { "floorf", (void *)&floorf, |
| 1112 | "float", "(float)" }, |
Jason Sams | d342fd7 | 2009-09-18 14:24:24 -0700 | [diff] [blame] | 1113 | { "fracf", (void *)&SC_fracf, |
| 1114 | "float", "(float)" }, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1115 | { "ceilf", (void *)&ceilf, |
| 1116 | "float", "(float)" }, |
Jason Sams | d342fd7 | 2009-09-18 14:24:24 -0700 | [diff] [blame] | 1117 | { "roundf", (void *)&SC_roundf, |
| 1118 | "float", "(float)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 1119 | { "expf", (void *)&expf, |
| 1120 | "float", "(float)" }, |
| 1121 | { "logf", (void *)&logf, |
| 1122 | "float", "(float)" }, |
| 1123 | { "powf", (void *)&powf, |
| 1124 | "float", "(float, float)" }, |
| 1125 | { "maxf", (void *)&SC_maxf, |
| 1126 | "float", "(float, float)" }, |
| 1127 | { "minf", (void *)&SC_minf, |
| 1128 | "float", "(float, float)" }, |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 1129 | { "sqrt", (void *)&sqrt, |
| 1130 | "int", "(int)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 1131 | { "sqrtf", (void *)&sqrtf, |
| 1132 | "float", "(float)" }, |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 1133 | { "sqr", (void *)&SC_sqr, |
| 1134 | "int", "(int)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 1135 | { "sqrf", (void *)&SC_sqrf, |
| 1136 | "float", "(float)" }, |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 1137 | { "sign", (void *)&SC_sign, |
| 1138 | "int", "(int)" }, |
| 1139 | { "signf", (void *)&SC_signf, |
| 1140 | "float", "(float)" }, |
Romain Guy | a9d2d5e | 2009-08-09 17:04:54 -0700 | [diff] [blame] | 1141 | { "clamp", (void *)&SC_clamp, |
| 1142 | "int", "(int, int, int)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 1143 | { "clampf", (void *)&SC_clampf, |
| 1144 | "float", "(float, float, float)" }, |
| 1145 | { "distf2", (void *)&SC_distf2, |
| 1146 | "float", "(float, float, float, float)" }, |
| 1147 | { "distf3", (void *)&SC_distf3, |
| 1148 | "float", "(float, float, float, float, float, float)" }, |
| 1149 | { "magf2", (void *)&SC_magf2, |
| 1150 | "float", "(float, float)" }, |
| 1151 | { "magf3", (void *)&SC_magf3, |
| 1152 | "float", "(float, float, float)" }, |
| 1153 | { "radf", (void *)&SC_radf, |
| 1154 | "float", "(float)" }, |
| 1155 | { "degf", (void *)&SC_degf, |
| 1156 | "float", "(float)" }, |
| 1157 | { "lerpf", (void *)&SC_lerpf, |
| 1158 | "float", "(float, float, float)" }, |
| 1159 | { "normf", (void *)&SC_normf, |
| 1160 | "float", "(float, float, float)" }, |
| 1161 | { "mapf", (void *)&SC_mapf, |
| 1162 | "float", "(float, float, float, float, float)" }, |
Romain Guy | ecc7ca0 | 2009-08-03 21:12:51 -0700 | [diff] [blame] | 1163 | { "noisef", (void *)&SC_noisef, |
| 1164 | "float", "(float)" }, |
| 1165 | { "noisef2", (void *)&SC_noisef2, |
| 1166 | "float", "(float, float)" }, |
| 1167 | { "noisef3", (void *)&SC_noisef3, |
| 1168 | "float", "(float, float, float)" }, |
| 1169 | { "turbulencef2", (void *)&SC_turbulencef2, |
| 1170 | "float", "(float, float, float)" }, |
| 1171 | { "turbulencef3", (void *)&SC_turbulencef3, |
| 1172 | "float", "(float, float, float, float)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1173 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1174 | // time |
| 1175 | { "second", (void *)&SC_second, |
| 1176 | "int", "()" }, |
| 1177 | { "minute", (void *)&SC_minute, |
| 1178 | "int", "()" }, |
| 1179 | { "hour", (void *)&SC_hour, |
| 1180 | "int", "()" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 1181 | { "day", (void *)&SC_day, |
| 1182 | "int", "()" }, |
| 1183 | { "month", (void *)&SC_month, |
| 1184 | "int", "()" }, |
| 1185 | { "year", (void *)&SC_year, |
| 1186 | "int", "()" }, |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 1187 | { "uptimeMillis", (void*)&SC_uptimeMillis, |
| 1188 | "int", "()" }, // TODO: use long instead |
| 1189 | { "startTimeMillis", (void*)&SC_startTimeMillis, |
| 1190 | "int", "()" }, // TODO: use long instead |
| 1191 | { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis, |
| 1192 | "int", "()" }, // TODO: use long instead |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 1193 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1194 | // matrix |
| 1195 | { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity, |
| 1196 | "void", "(float *mat)" }, |
| 1197 | { "matrixLoadFloat", (void *)&SC_matrixLoadFloat, |
| 1198 | "void", "(float *mat, float *f)" }, |
| 1199 | { "matrixLoadMat", (void *)&SC_matrixLoadMat, |
| 1200 | "void", "(float *mat, float *newmat)" }, |
| 1201 | { "matrixLoadRotate", (void *)&SC_matrixLoadRotate, |
| 1202 | "void", "(float *mat, float rot, float x, float y, float z)" }, |
| 1203 | { "matrixLoadScale", (void *)&SC_matrixLoadScale, |
| 1204 | "void", "(float *mat, float x, float y, float z)" }, |
| 1205 | { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate, |
| 1206 | "void", "(float *mat, float x, float y, float z)" }, |
| 1207 | { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply, |
| 1208 | "void", "(float *mat, float *lhs, float *rhs)" }, |
| 1209 | { "matrixMultiply", (void *)&SC_matrixMultiply, |
| 1210 | "void", "(float *mat, float *rhs)" }, |
| 1211 | { "matrixRotate", (void *)&SC_matrixRotate, |
| 1212 | "void", "(float *mat, float rot, float x, float y, float z)" }, |
| 1213 | { "matrixScale", (void *)&SC_matrixScale, |
| 1214 | "void", "(float *mat, float x, float y, float z)" }, |
| 1215 | { "matrixTranslate", (void *)&SC_matrixTranslate, |
| 1216 | "void", "(float *mat, float x, float y, float z)" }, |
| 1217 | |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 1218 | // vector |
| 1219 | { "vec2Rand", (void *)&SC_vec2Rand, |
| 1220 | "void", "(float *vec, float maxLen)" }, |
| 1221 | |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 1222 | // vec3 |
| 1223 | { "vec3Norm", (void *)&SC_vec3Norm, |
| 1224 | "void", "(struct vec3_s *)" }, |
| 1225 | { "vec3Length", (void *)&SC_vec3Length, |
| 1226 | "float", "(struct vec3_s *)" }, |
| 1227 | { "vec3Add", (void *)&SC_vec3Add, |
| 1228 | "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" }, |
| 1229 | { "vec3Sub", (void *)&SC_vec3Sub, |
| 1230 | "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" }, |
| 1231 | { "vec3Cross", (void *)&SC_vec3Cross, |
| 1232 | "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" }, |
| 1233 | { "vec3Dot", (void *)&SC_vec3Dot, |
| 1234 | "float", "(struct vec3_s *lhs, struct vec3_s *rhs)" }, |
| 1235 | { "vec3Scale", (void *)&SC_vec3Scale, |
| 1236 | "void", "(struct vec3_s *lhs, float scale)" }, |
| 1237 | |
Romain Guy | d7fa122 | 2009-10-09 16:05:25 -0700 | [diff] [blame] | 1238 | // vec4 |
| 1239 | { "vec4Norm", (void *)&SC_vec4Norm, |
| 1240 | "void", "(struct vec4_s *)" }, |
| 1241 | { "vec4Length", (void *)&SC_vec4Length, |
| 1242 | "float", "(struct vec4_s *)" }, |
| 1243 | { "vec4Add", (void *)&SC_vec4Add, |
| 1244 | "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" }, |
| 1245 | { "vec4Sub", (void *)&SC_vec4Sub, |
| 1246 | "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" }, |
| 1247 | { "vec4Dot", (void *)&SC_vec4Dot, |
| 1248 | "float", "(struct vec4_s *lhs, struct vec4_s *rhs)" }, |
| 1249 | { "vec4Scale", (void *)&SC_vec4Scale, |
| 1250 | "void", "(struct vec4_s *lhs, float scale)" }, |
| 1251 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1252 | // context |
| 1253 | { "bindProgramFragment", (void *)&SC_bindProgramFragment, |
| 1254 | "void", "(int)" }, |
| 1255 | { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore, |
| 1256 | "void", "(int)" }, |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 1257 | { "bindProgramStore", (void *)&SC_bindProgramFragmentStore, |
| 1258 | "void", "(int)" }, |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 1259 | { "bindProgramVertex", (void *)&SC_bindProgramVertex, |
| 1260 | "void", "(int)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1261 | { "bindSampler", (void *)&SC_bindSampler, |
| 1262 | "void", "(int, int, int)" }, |
| 1263 | { "bindTexture", (void *)&SC_bindTexture, |
| 1264 | "void", "(int, int, int)" }, |
| 1265 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1266 | // vp |
Jason Sams | faf1520 | 2009-07-29 20:55:44 -0700 | [diff] [blame] | 1267 | { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1268 | "void", "(void *)" }, |
Jason Sams | faf1520 | 2009-07-29 20:55:44 -0700 | [diff] [blame] | 1269 | { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1270 | "void", "(void *)" }, |
| 1271 | |
| 1272 | |
| 1273 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1274 | // drawing |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 1275 | { "drawRect", (void *)&SC_drawRect, |
| 1276 | "void", "(float x1, float y1, float x2, float y2, float z)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1277 | { "drawQuad", (void *)&SC_drawQuad, |
| 1278 | "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)" }, |
Romain Guy | 8f5c94b | 2009-08-08 18:30:19 -0700 | [diff] [blame] | 1279 | { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords, |
| 1280 | "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)" }, |
Jason Sams | e9ad9a7 | 2009-09-30 17:36:20 -0700 | [diff] [blame] | 1281 | { "drawSprite", (void *)&SC_drawSprite, |
| 1282 | "void", "(float x, float y, float z, float w, float h)" }, |
| 1283 | { "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace, |
| 1284 | "void", "(float x, float y, float z, float w, float h)" }, |
Joe Onorato | 6656c1b | 2010-01-14 15:59:35 -0500 | [diff] [blame] | 1285 | { "drawSpriteScreenspaceCropped", (void *)&SC_drawSpriteScreenspaceCropped, |
| 1286 | "void", "(float x, float y, float z, float w, float h, float cx0, float cy0, float cx1, float cy1)" }, |
Romain Guy | 6c0cc6d | 2009-08-07 15:40:32 -0700 | [diff] [blame] | 1287 | { "drawLine", (void *)&SC_drawLine, |
| 1288 | "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" }, |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 1289 | { "drawPoint", (void *)&SC_drawPoint, |
| 1290 | "void", "(float x1, float y1, float z1)" }, |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1291 | { "drawSimpleMesh", (void *)&SC_drawSimpleMesh, |
| 1292 | "void", "(int ism)" }, |
| 1293 | { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange, |
| 1294 | "void", "(int ism, int start, int len)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1295 | |
| 1296 | |
| 1297 | // misc |
| 1298 | { "pfClearColor", (void *)&SC_ClearColor, |
| 1299 | "void", "(float, float, float, float)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1300 | { "color", (void *)&SC_color, |
| 1301 | "void", "(float, float, float, float)" }, |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 1302 | { "hsb", (void *)&SC_hsb, |
| 1303 | "void", "(float, float, float, float)" }, |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 1304 | { "hsbToRgb", (void *)&SC_hsbToRgb, |
| 1305 | "void", "(float, float, float, float*)" }, |
| 1306 | { "hsbToAbgr", (void *)&SC_hsbToAbgr, |
| 1307 | "int", "(float, float, float, float)" }, |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame] | 1308 | { "ambient", (void *)&SC_ambient, |
| 1309 | "void", "(float, float, float, float)" }, |
| 1310 | { "diffuse", (void *)&SC_diffuse, |
| 1311 | "void", "(float, float, float, float)" }, |
| 1312 | { "specular", (void *)&SC_specular, |
| 1313 | "void", "(float, float, float, float)" }, |
| 1314 | { "emission", (void *)&SC_emission, |
| 1315 | "void", "(float, float, float, float)" }, |
| 1316 | { "shininess", (void *)&SC_shininess, |
Romain Guy | 6c0cc6d | 2009-08-07 15:40:32 -0700 | [diff] [blame] | 1317 | "void", "(float)" }, |
Romain Guy | 2d496bf | 2009-09-04 17:55:41 -0700 | [diff] [blame] | 1318 | { "pointAttenuation", (void *)&SC_pointAttenuation, |
| 1319 | "void", "(float, float, float)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1320 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1321 | { "uploadToTexture", (void *)&SC_uploadToTexture, |
| 1322 | "void", "(int, int)" }, |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1323 | { "uploadToBufferObject", (void *)&SC_uploadToBufferObject, |
| 1324 | "void", "(int)" }, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1325 | |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 1326 | { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8, |
| 1327 | "int", "(float, float, float, float)" }, |
| 1328 | { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565, |
| 1329 | "int", "(float, float, float)" }, |
| 1330 | |
| 1331 | |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1332 | { "getWidth", (void *)&SC_getWidth, |
| 1333 | "int", "()" }, |
| 1334 | { "getHeight", (void *)&SC_getHeight, |
| 1335 | "int", "()" }, |
| 1336 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 1337 | { "sendToClient", (void *)&SC_toClient, |
| 1338 | "int", "(void *data, int cmdID, int len, int waitForSpace)" }, |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1339 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1340 | |
| 1341 | { "debugF", (void *)&SC_debugF, |
| 1342 | "void", "(void *, float)" }, |
| 1343 | { "debugI32", (void *)&SC_debugI32, |
| 1344 | "void", "(void *, int)" }, |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 1345 | { "debugHexF", (void *)&SC_debugHexF, |
| 1346 | "void", "(void *, float)" }, |
| 1347 | { "debugHexI32", (void *)&SC_debugHexI32, |
| 1348 | "void", "(void *, int)" }, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1349 | |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 1350 | { "scriptCall", (void *)&SC_scriptCall, |
| 1351 | "void", "(int)" }, |
| 1352 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 1353 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1354 | { NULL, NULL, NULL, NULL } |
| 1355 | }; |
| 1356 | |
| 1357 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) |
| 1358 | { |
| 1359 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 1360 | |
| 1361 | while (syms->mPtr) { |
| 1362 | if (!strcmp(syms->mName, sym)) { |
| 1363 | return syms; |
| 1364 | } |
| 1365 | syms++; |
| 1366 | } |
| 1367 | return NULL; |
| 1368 | } |
| 1369 | |
| 1370 | void ScriptCState::appendDecls(String8 *str) |
| 1371 | { |
| 1372 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 1373 | while (syms->mPtr) { |
| 1374 | str->append(syms->mRet); |
| 1375 | str->append(" "); |
| 1376 | str->append(syms->mName); |
| 1377 | str->append(syms->mParam); |
| 1378 | str->append(";\n"); |
| 1379 | syms++; |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | |