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" |
| 23 | #include "utils/String8.h" |
| 24 | |
| 25 | #include <GLES/gl.h> |
| 26 | #include <GLES/glext.h> |
| 27 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 28 | #include <time.h> |
| 29 | #include <cutils/tztime.h> |
| 30 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 31 | using namespace android; |
| 32 | using namespace android::renderscript; |
| 33 | |
| 34 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 35 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 36 | Context * rsc = tls->mContext; \ |
| 37 | ScriptC * sc = (ScriptC *) tls->mScript |
| 38 | |
| 39 | |
| 40 | ////////////////////////////////////////////////////////////////////////////// |
| 41 | // IO routines |
| 42 | ////////////////////////////////////////////////////////////////////////////// |
| 43 | |
| 44 | static float SC_loadF(uint32_t bank, uint32_t offset) |
| 45 | { |
| 46 | GET_TLS(); |
| 47 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 48 | const float *f = static_cast<const float *>(vp); |
| 49 | //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]); |
| 50 | return f[offset]; |
| 51 | } |
| 52 | |
| 53 | static int32_t SC_loadI32(uint32_t bank, uint32_t offset) |
| 54 | { |
| 55 | GET_TLS(); |
| 56 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 57 | const int32_t *i = static_cast<const int32_t *>(vp); |
| 58 | //LOGE("loadI32 %i %i = %i", bank, offset, t); |
| 59 | return i[offset]; |
| 60 | } |
| 61 | |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 62 | static float* SC_loadArrayF(uint32_t bank, uint32_t offset) |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 63 | { |
| 64 | GET_TLS(); |
| 65 | void *vp = sc->mSlots[bank]->getPtr(); |
| 66 | float *f = static_cast<float *>(vp); |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 67 | return f + offset; |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 70 | static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset) |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 71 | { |
| 72 | GET_TLS(); |
| 73 | void *vp = sc->mSlots[bank]->getPtr(); |
| 74 | int32_t *i = static_cast<int32_t *>(vp); |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 75 | return i + offset; |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame^] | 78 | static float* SC_loadTriangleMeshVerticesF(RsTriangleMesh mesh) |
| 79 | { |
| 80 | TriangleMesh *tm = static_cast<TriangleMesh *>(mesh); |
| 81 | void *vp = tm->mVertexData; |
| 82 | float *f = static_cast<float *>(vp); |
| 83 | return f; |
| 84 | } |
| 85 | |
| 86 | static void SC_updateTriangleMesh(RsTriangleMesh mesh) |
| 87 | { |
| 88 | TriangleMesh *tm = static_cast<TriangleMesh *>(mesh); |
| 89 | glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]); |
| 90 | glBufferData(GL_ARRAY_BUFFER, tm->mVertexDataSize, tm->mVertexData, GL_STATIC_DRAW); |
| 91 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 92 | |
| 93 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 94 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, tm->mIndexDataSize, tm->mIndexData, GL_STATIC_DRAW); |
| 95 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 96 | } |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 97 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 98 | static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) |
| 99 | { |
| 100 | GET_TLS(); |
| 101 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 102 | const uint32_t *i = static_cast<const uint32_t *>(vp); |
| 103 | return i[offset]; |
| 104 | } |
| 105 | |
| 106 | static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v) |
| 107 | { |
| 108 | GET_TLS(); |
| 109 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 110 | const float *f = static_cast<const float *>(vp); |
| 111 | memcpy(v, &f[offset], sizeof(rsc_Vector4)); |
| 112 | } |
| 113 | |
| 114 | static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m) |
| 115 | { |
| 116 | GET_TLS(); |
| 117 | const void *vp = sc->mSlots[bank]->getPtr(); |
| 118 | const float *f = static_cast<const float *>(vp); |
| 119 | memcpy(m, &f[offset], sizeof(rsc_Matrix)); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | static void SC_storeF(uint32_t bank, uint32_t offset, float v) |
| 124 | { |
| 125 | //LOGE("storeF %i %i %f", bank, offset, v); |
| 126 | GET_TLS(); |
| 127 | void *vp = sc->mSlots[bank]->getPtr(); |
| 128 | float *f = static_cast<float *>(vp); |
| 129 | f[offset] = v; |
| 130 | } |
| 131 | |
| 132 | static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v) |
| 133 | { |
| 134 | GET_TLS(); |
| 135 | void *vp = sc->mSlots[bank]->getPtr(); |
| 136 | int32_t *f = static_cast<int32_t *>(vp); |
| 137 | static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
| 138 | } |
| 139 | |
| 140 | static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v) |
| 141 | { |
| 142 | GET_TLS(); |
| 143 | void *vp = sc->mSlots[bank]->getPtr(); |
| 144 | uint32_t *f = static_cast<uint32_t *>(vp); |
| 145 | static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; |
| 146 | } |
| 147 | |
| 148 | static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v) |
| 149 | { |
| 150 | GET_TLS(); |
| 151 | void *vp = sc->mSlots[bank]->getPtr(); |
| 152 | float *f = static_cast<float *>(vp); |
| 153 | memcpy(&f[offset], v, sizeof(rsc_Vector4)); |
| 154 | } |
| 155 | |
| 156 | static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m) |
| 157 | { |
| 158 | GET_TLS(); |
| 159 | void *vp = sc->mSlots[bank]->getPtr(); |
| 160 | float *f = static_cast<float *>(vp); |
| 161 | memcpy(&f[offset], m, sizeof(rsc_Matrix)); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | ////////////////////////////////////////////////////////////////////////////// |
| 166 | // Math routines |
| 167 | ////////////////////////////////////////////////////////////////////////////// |
| 168 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 169 | #define PI 3.1415926f |
| 170 | #define DEG_TO_RAD PI / 180.0f |
| 171 | #define RAD_TO_DEG 180.0f / PI |
| 172 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 173 | static float SC_randf(float max) |
| 174 | { |
| 175 | float r = (float)rand(); |
| 176 | return r / RAND_MAX * max; |
| 177 | } |
| 178 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 179 | static float SC_randf2(float min, float max) |
| 180 | { |
| 181 | float r = (float)rand(); |
| 182 | return r / RAND_MAX * (max - min) + min; |
| 183 | } |
| 184 | |
| 185 | static float SC_clampf(float amount, float low, float high) |
| 186 | { |
| 187 | return amount < low ? low : (amount > high ? high : amount); |
| 188 | } |
| 189 | |
| 190 | static float SC_maxf(float a, float b) |
| 191 | { |
| 192 | return a > b ? a : b; |
| 193 | } |
| 194 | |
| 195 | static float SC_minf(float a, float b) |
| 196 | { |
| 197 | return a < b ? a : b; |
| 198 | } |
| 199 | |
| 200 | static float SC_sqrf(float v) |
| 201 | { |
| 202 | return v * v; |
| 203 | } |
| 204 | |
| 205 | static float SC_distf2(float x1, float y1, float x2, float y2) |
| 206 | { |
| 207 | float x = x2 - x1; |
| 208 | float y = y2 - y1; |
| 209 | return sqrtf(x * x + y * y); |
| 210 | } |
| 211 | |
| 212 | static float SC_distf3(float x1, float y1, float z1, float x2, float y2, float z2) |
| 213 | { |
| 214 | float x = x2 - x1; |
| 215 | float y = y2 - y1; |
| 216 | float z = z2 - z1; |
| 217 | return sqrtf(x * x + y * y + z * z); |
| 218 | } |
| 219 | |
| 220 | static float SC_magf2(float a, float b) |
| 221 | { |
| 222 | return sqrtf(a * a + b * b); |
| 223 | } |
| 224 | |
| 225 | static float SC_magf3(float a, float b, float c) |
| 226 | { |
| 227 | return sqrtf(a * a + b * b + c * c); |
| 228 | } |
| 229 | |
| 230 | static float SC_radf(float degrees) |
| 231 | { |
| 232 | return degrees * DEG_TO_RAD; |
| 233 | } |
| 234 | |
| 235 | static float SC_degf(float radians) |
| 236 | { |
| 237 | return radians * RAD_TO_DEG; |
| 238 | } |
| 239 | |
| 240 | static float SC_lerpf(float start, float stop, float amount) |
| 241 | { |
| 242 | return start + (stop - start) * amount; |
| 243 | } |
| 244 | |
| 245 | static float SC_normf(float start, float stop, float value) |
| 246 | { |
| 247 | return (value - start) / (stop - start); |
| 248 | } |
| 249 | |
| 250 | static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value) |
| 251 | { |
| 252 | return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart)); |
| 253 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 254 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 255 | ////////////////////////////////////////////////////////////////////////////// |
| 256 | // Time routines |
| 257 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 258 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 259 | static uint32_t SC_second() |
| 260 | { |
| 261 | GET_TLS(); |
| 262 | |
| 263 | time_t rawtime; |
| 264 | time(&rawtime); |
| 265 | |
| 266 | if (sc->mEnviroment.mTimeZone) { |
| 267 | struct tm timeinfo; |
| 268 | localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); |
| 269 | return timeinfo.tm_sec; |
| 270 | } else { |
| 271 | struct tm *timeinfo; |
| 272 | timeinfo = localtime(&rawtime); |
| 273 | return timeinfo->tm_sec; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | static uint32_t SC_minute() |
| 278 | { |
| 279 | GET_TLS(); |
| 280 | |
| 281 | time_t rawtime; |
| 282 | time(&rawtime); |
| 283 | |
| 284 | if (sc->mEnviroment.mTimeZone) { |
| 285 | struct tm timeinfo; |
| 286 | localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); |
| 287 | return timeinfo.tm_min; |
| 288 | } else { |
| 289 | struct tm *timeinfo; |
| 290 | timeinfo = localtime(&rawtime); |
| 291 | return timeinfo->tm_min; |
| 292 | } |
| 293 | } |
| 294 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 295 | static uint32_t SC_hour() |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 296 | { |
| 297 | GET_TLS(); |
| 298 | |
| 299 | time_t rawtime; |
| 300 | time(&rawtime); |
| 301 | |
| 302 | if (sc->mEnviroment.mTimeZone) { |
| 303 | struct tm timeinfo; |
| 304 | localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); |
| 305 | return timeinfo.tm_hour; |
| 306 | } else { |
| 307 | struct tm *timeinfo; |
| 308 | timeinfo = localtime(&rawtime); |
| 309 | return timeinfo->tm_hour; |
| 310 | } |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static uint32_t SC_day() |
| 314 | { |
| 315 | GET_TLS(); |
| 316 | |
| 317 | time_t rawtime; |
| 318 | time(&rawtime); |
| 319 | |
| 320 | if (sc->mEnviroment.mTimeZone) { |
| 321 | struct tm timeinfo; |
| 322 | localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); |
| 323 | return timeinfo.tm_mday; |
| 324 | } else { |
| 325 | struct tm *timeinfo; |
| 326 | timeinfo = localtime(&rawtime); |
| 327 | return timeinfo->tm_mday; |
| 328 | } |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 329 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 330 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 331 | static uint32_t SC_month() |
| 332 | { |
| 333 | GET_TLS(); |
| 334 | |
| 335 | time_t rawtime; |
| 336 | time(&rawtime); |
| 337 | |
| 338 | if (sc->mEnviroment.mTimeZone) { |
| 339 | struct tm timeinfo; |
| 340 | localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); |
| 341 | return timeinfo.tm_mon; |
| 342 | } else { |
| 343 | struct tm *timeinfo; |
| 344 | timeinfo = localtime(&rawtime); |
| 345 | return timeinfo->tm_mon; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | static uint32_t SC_year() |
| 350 | { |
| 351 | GET_TLS(); |
| 352 | |
| 353 | time_t rawtime; |
| 354 | time(&rawtime); |
| 355 | |
| 356 | if (sc->mEnviroment.mTimeZone) { |
| 357 | struct tm timeinfo; |
| 358 | localtime_tz(&rawtime, &timeinfo, sc->mEnviroment.mTimeZone); |
| 359 | return timeinfo.tm_year; |
| 360 | } else { |
| 361 | struct tm *timeinfo; |
| 362 | timeinfo = localtime(&rawtime); |
| 363 | return timeinfo->tm_year; |
| 364 | } |
| 365 | } |
| 366 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 367 | ////////////////////////////////////////////////////////////////////////////// |
| 368 | // Matrix routines |
| 369 | ////////////////////////////////////////////////////////////////////////////// |
| 370 | |
| 371 | |
| 372 | static void SC_matrixLoadIdentity(rsc_Matrix *mat) |
| 373 | { |
| 374 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 375 | m->loadIdentity(); |
| 376 | } |
| 377 | |
| 378 | static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f) |
| 379 | { |
| 380 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 381 | m->load(f); |
| 382 | } |
| 383 | |
| 384 | static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat) |
| 385 | { |
| 386 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 387 | m->load(reinterpret_cast<const Matrix *>(newmat)); |
| 388 | } |
| 389 | |
| 390 | static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
| 391 | { |
| 392 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 393 | m->loadRotate(rot, x, y, z); |
| 394 | } |
| 395 | |
| 396 | static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z) |
| 397 | { |
| 398 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 399 | m->loadScale(x, y, z); |
| 400 | } |
| 401 | |
| 402 | static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z) |
| 403 | { |
| 404 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 405 | m->loadTranslate(x, y, z); |
| 406 | } |
| 407 | |
| 408 | static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs) |
| 409 | { |
| 410 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 411 | m->loadMultiply(reinterpret_cast<const Matrix *>(lhs), |
| 412 | reinterpret_cast<const Matrix *>(rhs)); |
| 413 | } |
| 414 | |
| 415 | static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs) |
| 416 | { |
| 417 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 418 | m->multiply(reinterpret_cast<const Matrix *>(rhs)); |
| 419 | } |
| 420 | |
| 421 | static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
| 422 | { |
| 423 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 424 | m->rotate(rot, x, y, z); |
| 425 | } |
| 426 | |
| 427 | static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z) |
| 428 | { |
| 429 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 430 | m->scale(x, y, z); |
| 431 | } |
| 432 | |
| 433 | static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z) |
| 434 | { |
| 435 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 436 | m->translate(x, y, z); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | ////////////////////////////////////////////////////////////////////////////// |
| 443 | // Context |
| 444 | ////////////////////////////////////////////////////////////////////////////// |
| 445 | |
| 446 | static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) |
| 447 | { |
| 448 | GET_TLS(); |
| 449 | rsi_ProgramFragmentBindTexture(rsc, |
| 450 | static_cast<ProgramFragment *>(vpf), |
| 451 | slot, |
| 452 | static_cast<Allocation *>(va)); |
| 453 | |
| 454 | } |
| 455 | |
| 456 | static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) |
| 457 | { |
| 458 | GET_TLS(); |
| 459 | rsi_ProgramFragmentBindSampler(rsc, |
| 460 | static_cast<ProgramFragment *>(vpf), |
| 461 | slot, |
| 462 | static_cast<Sampler *>(vs)); |
| 463 | |
| 464 | } |
| 465 | |
| 466 | static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs) |
| 467 | { |
| 468 | GET_TLS(); |
| 469 | rsi_ContextBindProgramFragmentStore(rsc, pfs); |
| 470 | |
| 471 | } |
| 472 | |
| 473 | static void SC_bindProgramFragment(RsProgramFragment pf) |
| 474 | { |
| 475 | GET_TLS(); |
| 476 | rsi_ContextBindProgramFragment(rsc, pf); |
| 477 | |
| 478 | } |
| 479 | |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 480 | static void SC_bindProgramVertex(RsProgramVertex pv) |
| 481 | { |
| 482 | GET_TLS(); |
| 483 | rsi_ContextBindProgramVertex(rsc, pv); |
| 484 | |
| 485 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 486 | |
| 487 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 488 | // VP |
| 489 | ////////////////////////////////////////////////////////////////////////////// |
| 490 | |
| 491 | static void SC_vpLoadModelMatrix(const rsc_Matrix *m) |
| 492 | { |
| 493 | GET_TLS(); |
| 494 | rsc->getVertex()->setModelviewMatrix(m); |
| 495 | } |
| 496 | |
| 497 | static void SC_vpLoadTextureMatrix(const rsc_Matrix *m) |
| 498 | { |
| 499 | GET_TLS(); |
| 500 | rsc->getVertex()->setTextureMatrix(m); |
| 501 | } |
| 502 | |
| 503 | |
| 504 | |
| 505 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 506 | // Drawing |
| 507 | ////////////////////////////////////////////////////////////////////////////// |
| 508 | |
| 509 | static void SC_drawTriangleMesh(RsTriangleMesh mesh) |
| 510 | { |
| 511 | GET_TLS(); |
| 512 | rsi_TriangleMeshRender(rsc, mesh); |
| 513 | } |
| 514 | |
| 515 | static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count) |
| 516 | { |
| 517 | GET_TLS(); |
| 518 | rsi_TriangleMeshRenderRange(rsc, mesh, start, count); |
| 519 | } |
| 520 | |
| 521 | // Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a |
| 522 | static void SC_drawTriangleArray(int ialloc, uint32_t count) |
| 523 | { |
| 524 | GET_TLS(); |
| 525 | RsAllocation alloc = (RsAllocation)ialloc; |
| 526 | |
| 527 | const Allocation *a = (const Allocation *)alloc; |
| 528 | const uint32_t *ptr = (const uint32_t *)a->getPtr(); |
| 529 | |
| 530 | rsc->setupCheck(); |
| 531 | |
| 532 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 533 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 534 | |
| 535 | glEnableClientState(GL_VERTEX_ARRAY); |
| 536 | glDisableClientState(GL_NORMAL_ARRAY); |
| 537 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 538 | glEnableClientState(GL_COLOR_ARRAY); |
| 539 | |
| 540 | glVertexPointer(2, GL_FIXED, 12, ptr + 1); |
| 541 | //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1); |
| 542 | glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 543 | |
| 544 | glDrawArrays(GL_TRIANGLES, 0, count * 3); |
| 545 | } |
| 546 | |
| 547 | static void SC_drawQuad(float x1, float y1, float z1, |
| 548 | float x2, float y2, float z2, |
| 549 | float x3, float y3, float z3, |
| 550 | float x4, float y4, float z4) |
| 551 | { |
| 552 | GET_TLS(); |
| 553 | |
| 554 | //LOGE("Quad"); |
| 555 | //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); |
| 556 | //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); |
| 557 | //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); |
| 558 | //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); |
| 559 | |
| 560 | float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; |
| 561 | static const float tex[] = {0,1, 1,1, 1,0, 0,0}; |
| 562 | |
| 563 | |
| 564 | rsc->setupCheck(); |
| 565 | |
| 566 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 567 | //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); |
| 568 | |
| 569 | glEnableClientState(GL_VERTEX_ARRAY); |
| 570 | glVertexPointer(3, GL_FLOAT, 0, vtx); |
| 571 | |
| 572 | glClientActiveTexture(GL_TEXTURE0); |
| 573 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 574 | glTexCoordPointer(2, GL_FLOAT, 0, tex); |
| 575 | glClientActiveTexture(GL_TEXTURE1); |
| 576 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 577 | glTexCoordPointer(2, GL_FLOAT, 0, tex); |
| 578 | glClientActiveTexture(GL_TEXTURE0); |
| 579 | |
| 580 | glDisableClientState(GL_NORMAL_ARRAY); |
| 581 | glDisableClientState(GL_COLOR_ARRAY); |
| 582 | |
| 583 | //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); |
| 584 | |
| 585 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 586 | } |
| 587 | |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 588 | static void SC_drawRect(float x1, float y1, |
| 589 | float x2, float y2, float z) |
| 590 | { |
| 591 | SC_drawQuad(x1, y2, z, |
| 592 | x2, y2, z, |
| 593 | x2, y1, z, |
| 594 | x1, y1, z); |
| 595 | } |
| 596 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 597 | ////////////////////////////////////////////////////////////////////////////// |
| 598 | // |
| 599 | ////////////////////////////////////////////////////////////////////////////// |
| 600 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 601 | static void SC_color(float r, float g, float b, float a) |
| 602 | { |
| 603 | glColor4f(r, g, b, a); |
| 604 | } |
| 605 | |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame^] | 606 | static void SC_ambient(float r, float g, float b, float a) |
| 607 | { |
| 608 | GLfloat params[] = { r, g, b, a }; |
| 609 | glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params); |
| 610 | } |
| 611 | |
| 612 | static void SC_diffuse(float r, float g, float b, float a) |
| 613 | { |
| 614 | GLfloat params[] = { r, g, b, a }; |
| 615 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params); |
| 616 | } |
| 617 | |
| 618 | static void SC_specular(float r, float g, float b, float a) |
| 619 | { |
| 620 | GLfloat params[] = { r, g, b, a }; |
| 621 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params); |
| 622 | } |
| 623 | |
| 624 | static void SC_emission(float r, float g, float b, float a) |
| 625 | { |
| 626 | GLfloat params[] = { r, g, b, a }; |
| 627 | glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params); |
| 628 | } |
| 629 | |
| 630 | static void SC_shininess(float r, float g, float b, float a) |
| 631 | { |
| 632 | GLfloat params[] = { r, g, b, a }; |
| 633 | glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, params); |
| 634 | } |
| 635 | |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 636 | static void SC_hsb(float h, float s, float b, float a) |
| 637 | { |
| 638 | float red = 0.0f; |
| 639 | float green = 0.0f; |
| 640 | float blue = 0.0f; |
| 641 | |
| 642 | float x = h; |
| 643 | float y = s; |
| 644 | float z = b; |
| 645 | |
| 646 | float hf = (x - (int) x) * 6.0f; |
| 647 | int ihf = (int) hf; |
| 648 | float f = hf - ihf; |
| 649 | float pv = z * (1.0f - y); |
| 650 | float qv = z * (1.0f - y * f); |
| 651 | float tv = z * (1.0f - y * (1.0f - f)); |
| 652 | |
| 653 | switch (ihf) { |
| 654 | case 0: // Red is the dominant color |
| 655 | red = z; |
| 656 | green = tv; |
| 657 | blue = pv; |
| 658 | break; |
| 659 | case 1: // Green is the dominant color |
| 660 | red = qv; |
| 661 | green = z; |
| 662 | blue = pv; |
| 663 | break; |
| 664 | case 2: |
| 665 | red = pv; |
| 666 | green = z; |
| 667 | blue = tv; |
| 668 | break; |
| 669 | case 3: // Blue is the dominant color |
| 670 | red = pv; |
| 671 | green = qv; |
| 672 | blue = z; |
| 673 | break; |
| 674 | case 4: |
| 675 | red = tv; |
| 676 | green = pv; |
| 677 | blue = z; |
| 678 | break; |
| 679 | case 5: // Red is the dominant color |
| 680 | red = z; |
| 681 | green = pv; |
| 682 | blue = qv; |
| 683 | break; |
| 684 | } |
| 685 | |
| 686 | glColor4f(red, green, blue, a); |
| 687 | } |
| 688 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 689 | /* |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 690 | extern "C" void materialDiffuse(float r, float g, float b, float a) |
| 691 | { |
| 692 | float v[] = {r, g, b, a}; |
| 693 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v); |
| 694 | } |
| 695 | |
| 696 | extern "C" void materialSpecular(float r, float g, float b, float a) |
| 697 | { |
| 698 | float v[] = {r, g, b, a}; |
| 699 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); |
| 700 | } |
| 701 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 702 | extern "C" void materialShininess(float s) |
| 703 | { |
| 704 | glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); |
| 705 | } |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 706 | */ |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 707 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 708 | static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel) |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 709 | { |
| 710 | GET_TLS(); |
| 711 | rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); |
| 712 | } |
| 713 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 714 | static void SC_ClearColor(float r, float g, float b, float a) |
| 715 | { |
| 716 | //LOGE("c %f %f %f %f", r, g, b, a); |
| 717 | GET_TLS(); |
| 718 | sc->mEnviroment.mClearColor[0] = r; |
| 719 | sc->mEnviroment.mClearColor[1] = g; |
| 720 | sc->mEnviroment.mClearColor[2] = b; |
| 721 | sc->mEnviroment.mClearColor[3] = a; |
| 722 | } |
| 723 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 724 | static void SC_debugF(const char *s, float f) |
| 725 | { |
| 726 | LOGE("%s %f", s, f); |
| 727 | } |
| 728 | |
| 729 | static void SC_debugI32(const char *s, int32_t i) |
| 730 | { |
| 731 | LOGE("%s %i", s, i); |
| 732 | } |
| 733 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 734 | |
| 735 | |
| 736 | ////////////////////////////////////////////////////////////////////////////// |
| 737 | // Class implementation |
| 738 | ////////////////////////////////////////////////////////////////////////////// |
| 739 | |
| 740 | ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { |
| 741 | // IO |
| 742 | { "loadI32", (void *)&SC_loadI32, |
| 743 | "int", "(int, int)" }, |
| 744 | //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" }, |
| 745 | { "loadF", (void *)&SC_loadF, |
| 746 | "float", "(int, int)" }, |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 747 | { "loadArrayF", (void *)&SC_loadArrayF, |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 748 | "float*", "(int, int)" }, |
Romain Guy | a2136d6 | 2009-08-04 17:19:48 -0700 | [diff] [blame] | 749 | { "loadArrayI32", (void *)&SC_loadArrayI32, |
Romain Guy | f8e136d | 2009-08-06 12:40:41 -0700 | [diff] [blame] | 750 | "int*", "(int, int)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 751 | { "loadVec4", (void *)&SC_loadVec4, |
| 752 | "void", "(int, int, float *)" }, |
| 753 | { "loadMatrix", (void *)&SC_loadMatrix, |
| 754 | "void", "(int, int, float *)" }, |
| 755 | { "storeI32", (void *)&SC_storeI32, |
| 756 | "void", "(int, int, int)" }, |
| 757 | //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" }, |
| 758 | { "storeF", (void *)&SC_storeF, |
| 759 | "void", "(int, int, float)" }, |
| 760 | { "storeVec4", (void *)&SC_storeVec4, |
| 761 | "void", "(int, int, float *)" }, |
| 762 | { "storeMatrix", (void *)&SC_storeMatrix, |
| 763 | "void", "(int, int, float *)" }, |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame^] | 764 | { "loadTriangleMeshVerticesF", (void *)&SC_loadTriangleMeshVerticesF, |
| 765 | "float*", "(int)" }, |
| 766 | { "updateTriangleMesh", (void *)&SC_updateTriangleMesh, |
| 767 | "void", "(int)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 768 | |
| 769 | // math |
| 770 | { "sinf", (void *)&sinf, |
| 771 | "float", "(float)" }, |
| 772 | { "cosf", (void *)&cosf, |
| 773 | "float", "(float)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 774 | { "asinf", (void *)&asinf, |
| 775 | "float", "(float)" }, |
| 776 | { "acosf", (void *)&acosf, |
| 777 | "float", "(float)" }, |
| 778 | { "atanf", (void *)&atanf, |
| 779 | "float", "(float)" }, |
| 780 | { "atan2f", (void *)&atan2f, |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 781 | "float", "(float, float)" }, |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 782 | { "fabsf", (void *)&fabsf, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 783 | "float", "(float)" }, |
| 784 | { "randf", (void *)&SC_randf, |
| 785 | "float", "(float)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 786 | { "randf2", (void *)&SC_randf2, |
| 787 | "float", "(float, float)" }, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 788 | { "floorf", (void *)&floorf, |
| 789 | "float", "(float)" }, |
| 790 | { "ceilf", (void *)&ceilf, |
| 791 | "float", "(float)" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 792 | { "expf", (void *)&expf, |
| 793 | "float", "(float)" }, |
| 794 | { "logf", (void *)&logf, |
| 795 | "float", "(float)" }, |
| 796 | { "powf", (void *)&powf, |
| 797 | "float", "(float, float)" }, |
| 798 | { "maxf", (void *)&SC_maxf, |
| 799 | "float", "(float, float)" }, |
| 800 | { "minf", (void *)&SC_minf, |
| 801 | "float", "(float, float)" }, |
| 802 | { "sqrtf", (void *)&sqrtf, |
| 803 | "float", "(float)" }, |
| 804 | { "sqrf", (void *)&SC_sqrf, |
| 805 | "float", "(float)" }, |
| 806 | { "clampf", (void *)&SC_clampf, |
| 807 | "float", "(float, float, float)" }, |
| 808 | { "distf2", (void *)&SC_distf2, |
| 809 | "float", "(float, float, float, float)" }, |
| 810 | { "distf3", (void *)&SC_distf3, |
| 811 | "float", "(float, float, float, float, float, float)" }, |
| 812 | { "magf2", (void *)&SC_magf2, |
| 813 | "float", "(float, float)" }, |
| 814 | { "magf3", (void *)&SC_magf3, |
| 815 | "float", "(float, float, float)" }, |
| 816 | { "radf", (void *)&SC_radf, |
| 817 | "float", "(float)" }, |
| 818 | { "degf", (void *)&SC_degf, |
| 819 | "float", "(float)" }, |
| 820 | { "lerpf", (void *)&SC_lerpf, |
| 821 | "float", "(float, float, float)" }, |
| 822 | { "normf", (void *)&SC_normf, |
| 823 | "float", "(float, float, float)" }, |
| 824 | { "mapf", (void *)&SC_mapf, |
| 825 | "float", "(float, float, float, float, float)" }, |
Romain Guy | ecc7ca0 | 2009-08-03 21:12:51 -0700 | [diff] [blame] | 826 | { "noisef", (void *)&SC_noisef, |
| 827 | "float", "(float)" }, |
| 828 | { "noisef2", (void *)&SC_noisef2, |
| 829 | "float", "(float, float)" }, |
| 830 | { "noisef3", (void *)&SC_noisef3, |
| 831 | "float", "(float, float, float)" }, |
| 832 | { "turbulencef2", (void *)&SC_turbulencef2, |
| 833 | "float", "(float, float, float)" }, |
| 834 | { "turbulencef3", (void *)&SC_turbulencef3, |
| 835 | "float", "(float, float, float, float)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 836 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 837 | // time |
| 838 | { "second", (void *)&SC_second, |
| 839 | "int", "()" }, |
| 840 | { "minute", (void *)&SC_minute, |
| 841 | "int", "()" }, |
| 842 | { "hour", (void *)&SC_hour, |
| 843 | "int", "()" }, |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 844 | { "day", (void *)&SC_day, |
| 845 | "int", "()" }, |
| 846 | { "month", (void *)&SC_month, |
| 847 | "int", "()" }, |
| 848 | { "year", (void *)&SC_year, |
| 849 | "int", "()" }, |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 850 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 851 | // matrix |
| 852 | { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity, |
| 853 | "void", "(float *mat)" }, |
| 854 | { "matrixLoadFloat", (void *)&SC_matrixLoadFloat, |
| 855 | "void", "(float *mat, float *f)" }, |
| 856 | { "matrixLoadMat", (void *)&SC_matrixLoadMat, |
| 857 | "void", "(float *mat, float *newmat)" }, |
| 858 | { "matrixLoadRotate", (void *)&SC_matrixLoadRotate, |
| 859 | "void", "(float *mat, float rot, float x, float y, float z)" }, |
| 860 | { "matrixLoadScale", (void *)&SC_matrixLoadScale, |
| 861 | "void", "(float *mat, float x, float y, float z)" }, |
| 862 | { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate, |
| 863 | "void", "(float *mat, float x, float y, float z)" }, |
| 864 | { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply, |
| 865 | "void", "(float *mat, float *lhs, float *rhs)" }, |
| 866 | { "matrixMultiply", (void *)&SC_matrixMultiply, |
| 867 | "void", "(float *mat, float *rhs)" }, |
| 868 | { "matrixRotate", (void *)&SC_matrixRotate, |
| 869 | "void", "(float *mat, float rot, float x, float y, float z)" }, |
| 870 | { "matrixScale", (void *)&SC_matrixScale, |
| 871 | "void", "(float *mat, float x, float y, float z)" }, |
| 872 | { "matrixTranslate", (void *)&SC_matrixTranslate, |
| 873 | "void", "(float *mat, float x, float y, float z)" }, |
| 874 | |
| 875 | // context |
| 876 | { "bindProgramFragment", (void *)&SC_bindProgramFragment, |
| 877 | "void", "(int)" }, |
| 878 | { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore, |
| 879 | "void", "(int)" }, |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 880 | { "bindProgramVertex", (void *)&SC_bindProgramVertex, |
| 881 | "void", "(int)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 882 | { "bindSampler", (void *)&SC_bindSampler, |
| 883 | "void", "(int, int, int)" }, |
| 884 | { "bindTexture", (void *)&SC_bindTexture, |
| 885 | "void", "(int, int, int)" }, |
| 886 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 887 | // vp |
Jason Sams | faf1520 | 2009-07-29 20:55:44 -0700 | [diff] [blame] | 888 | { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 889 | "void", "(void *)" }, |
Jason Sams | faf1520 | 2009-07-29 20:55:44 -0700 | [diff] [blame] | 890 | { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix, |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 891 | "void", "(void *)" }, |
| 892 | |
| 893 | |
| 894 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 895 | // drawing |
Jason Sams | 6f5c61c | 2009-07-28 17:20:11 -0700 | [diff] [blame] | 896 | { "drawRect", (void *)&SC_drawRect, |
| 897 | "void", "(float x1, float y1, float x2, float y2, float z)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 898 | { "drawQuad", (void *)&SC_drawQuad, |
| 899 | "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)" }, |
| 900 | { "drawTriangleArray", (void *)&SC_drawTriangleArray, |
| 901 | "void", "(int ialloc, int count)" }, |
| 902 | { "drawTriangleMesh", (void *)&SC_drawTriangleMesh, |
| 903 | "void", "(int mesh)" }, |
| 904 | { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange, |
| 905 | "void", "(int mesh, int start, int count)" }, |
| 906 | |
| 907 | |
| 908 | // misc |
| 909 | { "pfClearColor", (void *)&SC_ClearColor, |
| 910 | "void", "(float, float, float, float)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 911 | { "color", (void *)&SC_color, |
| 912 | "void", "(float, float, float, float)" }, |
Romain Guy | a32d100 | 2009-07-31 15:33:59 -0700 | [diff] [blame] | 913 | { "hsb", (void *)&SC_hsb, |
| 914 | "void", "(float, float, float, float)" }, |
Romain Guy | b62627e | 2009-08-06 22:52:13 -0700 | [diff] [blame^] | 915 | { "ambient", (void *)&SC_ambient, |
| 916 | "void", "(float, float, float, float)" }, |
| 917 | { "diffuse", (void *)&SC_diffuse, |
| 918 | "void", "(float, float, float, float)" }, |
| 919 | { "specular", (void *)&SC_specular, |
| 920 | "void", "(float, float, float, float)" }, |
| 921 | { "emission", (void *)&SC_emission, |
| 922 | "void", "(float, float, float, float)" }, |
| 923 | { "shininess", (void *)&SC_shininess, |
| 924 | "void", "(float, float, float, float)" }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 925 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 926 | { "uploadToTexture", (void *)&SC_uploadToTexture, |
| 927 | "void", "(int, int)" }, |
| 928 | |
| 929 | |
| 930 | { "debugF", (void *)&SC_debugF, |
| 931 | "void", "(void *, float)" }, |
| 932 | { "debugI32", (void *)&SC_debugI32, |
| 933 | "void", "(void *, int)" }, |
| 934 | |
| 935 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 936 | { NULL, NULL, NULL, NULL } |
| 937 | }; |
| 938 | |
| 939 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) |
| 940 | { |
| 941 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 942 | |
| 943 | while (syms->mPtr) { |
| 944 | if (!strcmp(syms->mName, sym)) { |
| 945 | return syms; |
| 946 | } |
| 947 | syms++; |
| 948 | } |
| 949 | return NULL; |
| 950 | } |
| 951 | |
| 952 | void ScriptCState::appendDecls(String8 *str) |
| 953 | { |
| 954 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 955 | while (syms->mPtr) { |
| 956 | str->append(syms->mRet); |
| 957 | str->append(" "); |
| 958 | str->append(syms->mName); |
| 959 | str->append(syms->mParam); |
| 960 | str->append(";\n"); |
| 961 | syms++; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | |