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