rsScriptC.cpp revision 29df66f82aeef7fa7e2cf00edbf00d43c822b05a
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 27using namespace android; 28using namespace android::renderscript; 29 30#define GET_TLS() Context::ScriptTLSStruct * tls = \ 31 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ 32 Context * rsc = tls->mContext; \ 33 ScriptC * sc = (ScriptC *) tls->mScript 34 35 36ScriptC::ScriptC() 37{ 38 mAccScript = NULL; 39 memset(&mProgram, 0, sizeof(mProgram)); 40} 41 42ScriptC::~ScriptC() 43{ 44 if (mAccScript) { 45 accDeleteScript(mAccScript); 46 } 47} 48 49extern "C" float fixedToFloat(int32_t f) 50{ 51 return ((float)f) / 0x10000; 52} 53 54extern "C" float intToFloat(int32_t f) 55{ 56 return (float)f; 57} 58 59extern "C" void matrixLoadIdentity(rsc_Matrix *mat) 60{ 61 Matrix *m = reinterpret_cast<Matrix *>(mat); 62 m->loadIdentity(); 63} 64 65extern "C" void matrixLoadFloat(rsc_Matrix *mat, const float *f) 66{ 67 Matrix *m = reinterpret_cast<Matrix *>(mat); 68 m->load(f); 69} 70 71extern "C" void matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat) 72{ 73 Matrix *m = reinterpret_cast<Matrix *>(mat); 74 m->load(reinterpret_cast<const Matrix *>(newmat)); 75} 76 77extern "C" void matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z) 78{ 79 Matrix *m = reinterpret_cast<Matrix *>(mat); 80 m->loadRotate(rot, x, y, z); 81} 82 83extern "C" void matrixLoadScale(rsc_Matrix *mat, float x, float y, float z) 84{ 85 Matrix *m = reinterpret_cast<Matrix *>(mat); 86 m->loadScale(x, y, z); 87} 88 89extern "C" void matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z) 90{ 91 Matrix *m = reinterpret_cast<Matrix *>(mat); 92 m->loadTranslate(x, y, z); 93} 94 95extern "C" void matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs) 96{ 97 Matrix *m = reinterpret_cast<Matrix *>(mat); 98 m->loadMultiply(reinterpret_cast<const Matrix *>(lhs), 99 reinterpret_cast<const Matrix *>(rhs)); 100} 101 102extern "C" void matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs) 103{ 104 Matrix *m = reinterpret_cast<Matrix *>(mat); 105 m->multiply(reinterpret_cast<const Matrix *>(rhs)); 106} 107 108extern "C" void matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z) 109{ 110 Matrix *m = reinterpret_cast<Matrix *>(mat); 111 m->rotate(rot, x, y, z); 112} 113 114extern "C" void matrixScale(rsc_Matrix *mat, float x, float y, float z) 115{ 116 Matrix *m = reinterpret_cast<Matrix *>(mat); 117 m->scale(x, y, z); 118} 119 120extern "C" void matrixTranslate(rsc_Matrix *mat, float x, float y, float z) 121{ 122 Matrix *m = reinterpret_cast<Matrix *>(mat); 123 m->translate(x, y, z); 124} 125 126 127extern "C" const void * loadVp(uint32_t bank, uint32_t offset) 128{ 129 GET_TLS(); 130 return &static_cast<const uint8_t *>(sc->mSlots[bank]->getPtr())[offset]; 131} 132 133static float SC_loadF(uint32_t bank, uint32_t offset) 134{ 135 GET_TLS(); 136 float f = static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset]; 137 //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]); 138 return f; 139} 140 141static int32_t SC_loadI32(uint32_t bank, uint32_t offset) 142{ 143 GET_TLS(); 144 int32_t t = static_cast<const int32_t *>(sc->mSlots[bank]->getPtr())[offset]; 145 //LOGE("loadI32 %i %i = %i", bank, offset, t); 146 return t; 147} 148 149static uint32_t SC_loadU32(uint32_t bank, uint32_t offset) 150{ 151 GET_TLS(); 152 return static_cast<const uint32_t *>(sc->mSlots[bank]->getPtr())[offset]; 153} 154 155extern "C" void loadEnvVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v) 156{ 157 GET_TLS(); 158 memcpy(v, &static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset], sizeof(rsc_Vector4)); 159} 160 161extern "C" void loadEnvMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m) 162{ 163 GET_TLS(); 164 memcpy(m, &static_cast<const float *>(sc->mSlots[bank]->getPtr())[offset], sizeof(rsc_Matrix)); 165} 166 167 168static void SC_storeF(uint32_t bank, uint32_t offset, float v) 169{ 170 //LOGE("storeF %i %i %f", bank, offset, v); 171 GET_TLS(); 172 static_cast<float *>(sc->mSlots[bank]->getPtr())[offset] = v; 173} 174 175static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v) 176{ 177 GET_TLS(); 178 static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; 179} 180 181static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v) 182{ 183 GET_TLS(); 184 static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v; 185} 186 187extern "C" void storeEnvVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v) 188{ 189 GET_TLS(); 190 memcpy(&static_cast<float *>(sc->mSlots[bank]->getPtr())[offset], v, sizeof(rsc_Vector4)); 191} 192 193extern "C" void storeEnvMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m) 194{ 195 GET_TLS(); 196 memcpy(&static_cast<float *>(sc->mSlots[bank]->getPtr())[offset], m, sizeof(rsc_Matrix)); 197} 198 199 200extern "C" void color(float r, float g, float b, float a) 201{ 202 glColor4f(r, g, b, a); 203} 204 205extern "C" void renderTriangleMesh(RsTriangleMesh mesh) 206{ 207 GET_TLS(); 208 rsi_TriangleMeshRender(rsc, mesh); 209} 210 211extern "C" void renderTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count) 212{ 213 GET_TLS(); 214 rsi_TriangleMeshRenderRange(rsc, mesh, start, count); 215} 216 217extern "C" void materialDiffuse(float r, float g, float b, float a) 218{ 219 float v[] = {r, g, b, a}; 220 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, v); 221} 222 223extern "C" void materialSpecular(float r, float g, float b, float a) 224{ 225 float v[] = {r, g, b, a}; 226 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, v); 227} 228 229extern "C" void lightPosition(float x, float y, float z, float w) 230{ 231 float v[] = {x, y, z, w}; 232 glLightfv(GL_LIGHT0, GL_POSITION, v); 233} 234 235extern "C" void materialShininess(float s) 236{ 237 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &s); 238} 239 240extern "C" void uploadToTexture(RsAllocation va, uint32_t baseMipLevel) 241{ 242 GET_TLS(); 243 rsi_AllocationUploadToTexture(rsc, va, baseMipLevel); 244} 245 246extern "C" void enable(uint32_t p) 247{ 248 glEnable(p); 249} 250 251extern "C" void disable(uint32_t p) 252{ 253 glDisable(p); 254} 255 256extern "C" uint32_t scriptRand(uint32_t max) 257{ 258 return (uint32_t)(((float)rand()) * max / RAND_MAX); 259} 260 261// Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a 262extern "C" void drawTriangleArray(RsAllocation alloc, uint32_t count) 263{ 264 GET_TLS(); 265 266 const Allocation *a = (const Allocation *)alloc; 267 const uint32_t *ptr = (const uint32_t *)a->getPtr(); 268 269 rsc->setupCheck(); 270 271 glBindBuffer(GL_ARRAY_BUFFER, 0); 272 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); 273 274 glEnableClientState(GL_VERTEX_ARRAY); 275 glDisableClientState(GL_NORMAL_ARRAY); 276 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 277 glEnableClientState(GL_COLOR_ARRAY); 278 279 glVertexPointer(2, GL_FIXED, 12, ptr + 1); 280 //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1); 281 glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); 282 283 glDrawArrays(GL_TRIANGLES, 0, count * 3); 284} 285 286extern "C" void drawRect(int32_t x1, int32_t x2, int32_t y1, int32_t y2) 287{ 288 GET_TLS(); 289 x1 = (x1 << 16); 290 x2 = (x2 << 16); 291 y1 = (y1 << 16); 292 y2 = (y2 << 16); 293 294 int32_t vtx[] = {x1,y1, x1,y2, x2,y1, x2,y2}; 295 static const int32_t tex[] = {0,0, 0,0x10000, 0x10000,0, 0x10000,0x10000}; 296 297 298 rsc->setupCheck(); 299 300 glBindBuffer(GL_ARRAY_BUFFER, 0); 301 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); 302 303 glEnableClientState(GL_VERTEX_ARRAY); 304 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 305 glDisableClientState(GL_NORMAL_ARRAY); 306 glDisableClientState(GL_COLOR_ARRAY); 307 308 glVertexPointer(2, GL_FIXED, 8, vtx); 309 glTexCoordPointer(2, GL_FIXED, 8, tex); 310 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); 311 312 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 313} 314 315static void SC_drawQuad(float x1, float y1, float z1, 316 float x2, float y2, float z2, 317 float x3, float y3, float z3, 318 float x4, float y4, float z4) 319{ 320 GET_TLS(); 321 322 //LOGE("Quad"); 323 //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1); 324 //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2); 325 //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3); 326 //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4); 327 328 float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; 329 static const float tex[] = {0,0, 0,1, 1,1, 1,0}; 330 331 332 rsc->setupCheck(); 333 334 glBindBuffer(GL_ARRAY_BUFFER, 0); 335 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); 336 337 glEnableClientState(GL_VERTEX_ARRAY); 338 glVertexPointer(3, GL_FLOAT, 0, vtx); 339 340 glClientActiveTexture(GL_TEXTURE0); 341 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 342 glTexCoordPointer(2, GL_FLOAT, 0, tex); 343 glClientActiveTexture(GL_TEXTURE1); 344 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 345 glTexCoordPointer(2, GL_FLOAT, 0, tex); 346 glClientActiveTexture(GL_TEXTURE0); 347 348 glDisableClientState(GL_NORMAL_ARRAY); 349 glDisableClientState(GL_COLOR_ARRAY); 350 351 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); 352 353 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 354} 355 356extern "C" void drawQuad(int32_t x1, int32_t y1, int32_t z1, 357 int32_t x2, int32_t y2, int32_t z2, 358 int32_t x3, int32_t y3, int32_t z3, 359 int32_t x4, int32_t y4, int32_t z4) 360{ 361 GET_TLS(); 362 //x1 = (x1 << 16); 363 //x2 = (x2 << 16); 364 //y1 = (y1 << 16); 365 //y2 = (y2 << 16); 366 367 //LOGE("Quad"); 368 //LOGE("0x%08x, 0x%08x, 0x%08x", x1, y1, z1); 369 //LOGE("0x%08x, 0x%08x, 0x%08x", x2, y2, z2); 370 //LOGE("0x%08x, 0x%08x, 0x%08x", x3, y3, z3); 371 //LOGE("0x%08x, 0x%08x, 0x%08x", x4, y4, z4); 372 373 int32_t vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4}; 374 static const int32_t tex[] = {0,0, 0,0x10000, 0x10000,0x10000, 0x10000,0}; 375 376 377 rsc->setupCheck(); 378 379 glBindBuffer(GL_ARRAY_BUFFER, 0); 380 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]); 381 382 glEnableClientState(GL_VERTEX_ARRAY); 383 glVertexPointer(3, GL_FIXED, 0, vtx); 384 385 glClientActiveTexture(GL_TEXTURE0); 386 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 387 glTexCoordPointer(2, GL_FIXED, 0, tex); 388 glClientActiveTexture(GL_TEXTURE1); 389 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 390 glTexCoordPointer(2, GL_FIXED, 0, tex); 391 glClientActiveTexture(GL_TEXTURE0); 392 393 glDisableClientState(GL_NORMAL_ARRAY); 394 glDisableClientState(GL_COLOR_ARRAY); 395 396 //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr); 397 398 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 399} 400 401extern "C" int32_t sinx(int32_t angle) 402{ 403 float a = ((float)angle) / 0x10000; 404 a *= 3.14f / 180.f; 405 float s = (float)sin(a); 406 return int32_t(s * 0x10000); 407} 408 409extern "C" int32_t cosx(int32_t angle) 410{ 411 float a = ((float)angle) / 0x10000; 412 a *= 3.14f / 180.f; 413 float s = (float)cos(a); 414 return int32_t(s * 0x10000); 415} 416 417extern "C" float sinf(float angle) 418{ 419 float s = (float)sin(angle); 420 return s; 421} 422 423extern "C" float cosf(float angle) 424{ 425 float s = (float)cos(angle); 426 return s; 427} 428 429extern "C" void pfClearColor(float r, float g, float b, float a) 430{ 431 //LOGE("c %f %f %f %f", r, g, b, a); 432 GET_TLS(); 433 sc->mEnviroment.mClearColor[0] = r; 434 sc->mEnviroment.mClearColor[1] = g; 435 sc->mEnviroment.mClearColor[2] = b; 436 sc->mEnviroment.mClearColor[3] = a; 437} 438 439extern "C" void pfBindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va) 440{ 441 GET_TLS(); 442 rsi_ProgramFragmentBindTexture(rsc, 443 static_cast<ProgramFragment *>(vpf), 444 slot, 445 static_cast<Allocation *>(va)); 446 447} 448 449extern "C" void pfBindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs) 450{ 451 GET_TLS(); 452 rsi_ProgramFragmentBindSampler(rsc, 453 static_cast<ProgramFragment *>(vpf), 454 slot, 455 static_cast<Sampler *>(vs)); 456 457} 458 459extern "C" void contextBindProgramFragmentStore(RsProgramFragmentStore pfs) 460{ 461 GET_TLS(); 462 rsi_ContextBindProgramFragmentStore(rsc, pfs); 463 464} 465 466extern "C" void contextBindProgramFragment(RsProgramFragment pf) 467{ 468 GET_TLS(); 469 rsi_ContextBindProgramFragment(rsc, pf); 470 471} 472 473 474static rsc_FunctionTable scriptCPtrTable = { 475 loadVp, 476 SC_loadF, 477 SC_loadI32, 478 SC_loadU32, 479 loadEnvVec4, 480 loadEnvMatrix, 481 482 SC_storeF, 483 SC_storeI32, 484 SC_storeU32, 485 storeEnvVec4, 486 storeEnvMatrix, 487 488 matrixLoadIdentity, 489 matrixLoadFloat, 490 matrixLoadMat, 491 matrixLoadRotate, 492 matrixLoadScale, 493 matrixLoadTranslate, 494 matrixLoadMultiply, 495 matrixMultiply, 496 matrixRotate, 497 matrixScale, 498 matrixTranslate, 499 500 color, 501 502 pfBindTexture, 503 pfBindSampler, 504 505 materialDiffuse, 506 materialSpecular, 507 lightPosition, 508 materialShininess, 509 uploadToTexture, 510 enable, 511 disable, 512 513 scriptRand, 514 contextBindProgramFragment, 515 contextBindProgramFragmentStore, 516 517 518 renderTriangleMesh, 519 renderTriangleMeshRange, 520 521 drawTriangleArray, 522 drawRect 523 524}; 525 526 527bool ScriptC::run(Context *rsc, uint32_t launchIndex) 528{ 529 Context::ScriptTLSStruct * tls = 530 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); 531 532 if (mEnviroment.mFragmentStore.get()) { 533 rsc->setFragmentStore(mEnviroment.mFragmentStore.get()); 534 } 535 if (mEnviroment.mFragment.get()) { 536 rsc->setFragment(mEnviroment.mFragment.get()); 537 } 538 if (mEnviroment.mVertex.get()) { 539 rsc->setVertex(mEnviroment.mVertex.get()); 540 } 541 542 tls->mScript = this; 543 return mProgram.mScript(launchIndex, &scriptCPtrTable) != 0; 544 tls->mScript = NULL; 545} 546 547ScriptCState::ScriptCState() 548{ 549 clear(); 550} 551 552ScriptCState::~ScriptCState() 553{ 554 if (mAccScript) { 555 accDeleteScript(mAccScript); 556 } 557} 558 559void ScriptCState::clear() 560{ 561 memset(&mProgram, 0, sizeof(mProgram)); 562 563 mConstantBufferTypes.clear(); 564 565 memset(&mEnviroment, 0, sizeof(mEnviroment)); 566 mEnviroment.mClearColor[0] = 0; 567 mEnviroment.mClearColor[1] = 0; 568 mEnviroment.mClearColor[2] = 0; 569 mEnviroment.mClearColor[3] = 1; 570 mEnviroment.mClearDepth = 1; 571 mEnviroment.mClearStencil = 0; 572 mEnviroment.mIsRoot = false; 573 574 mAccScript = NULL; 575 576} 577 578ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { 579 { "loadI32", (void *)&SC_loadI32, "int loadI32(int, int)" }, 580 { "loadF", (void *)&SC_loadF, "float loadF(int, int)" }, 581 { "storeI32", (void *)&SC_storeI32, "void storeI32(int, int, int)" }, 582 { "storeF", (void *)&SC_storeF, "void storeF(int, int, float)" }, 583 { "drawQuad", (void *)&SC_drawQuad, "drawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" }, 584 { "sinf", (void *)&sinf, "float sinf(float)" }, 585 { "cosf", (void *)&cosf, "float cosf(float)" }, 586 { "contextBindProgramFragmentStore", (void *)&contextBindProgramFragmentStore, "" }, 587 { "pfClearColor", (void *)&pfClearColor, "" }, 588 { "pfBindTexture", (void *)&pfBindTexture, "" }, 589 590 591 { NULL, NULL, NULL } 592}; 593 594const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) 595{ 596 ScriptCState::SymbolTable_t *syms = gSyms; 597 598 while (syms->mPtr) { 599 if (!strcmp(syms->mName, sym)) { 600 return syms; 601 } 602 syms++; 603 } 604 return NULL; 605} 606 607static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) 608{ 609 const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name); 610 611 if (sym) { 612 return sym->mPtr; 613 } 614 615 LOGE("ScriptC sym lookup failed for %s", name); 616 617 // Default to calling dlsym to allow any global symbol: 618 return NULL; 619} 620 621void ScriptCState::runCompiler(Context *rsc) 622{ 623 mAccScript = accCreateScript(); 624 String8 tmp; 625 626 rsc->appendNameDefines(&tmp); 627 628 const char* scriptSource[] = {tmp.string(), mProgram.mScriptText}; 629 int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ; 630 accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength); 631 accRegisterSymbolCallback(mAccScript, symbolLookup, NULL); 632 accCompileScript(mAccScript); 633 accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript); 634 rsAssert(mProgram.mScript); 635 636 mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); 637 mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); 638 mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore()); 639 640 if (mProgram.mScript) { 641 const static int pragmaMax = 16; 642 ACCsizei pragmaCount; 643 ACCchar * str[pragmaMax]; 644 accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]); 645 646 for (int ct=0; ct < pragmaCount; ct+=2) { 647 if (!strcmp(str[ct], "version")) { 648 continue; 649 } 650 651 if (!strcmp(str[ct], "stateVertex")) { 652 if (!strcmp(str[ct+1], "default")) { 653 continue; 654 } 655 if (!strcmp(str[ct+1], "parent")) { 656 mEnviroment.mVertex.clear(); 657 continue; 658 } 659 ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]); 660 if (pv != NULL) { 661 mEnviroment.mVertex.set(pv); 662 continue; 663 } 664 LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); 665 } 666 667 if (!strcmp(str[ct], "stateRaster")) { 668 LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); 669 } 670 671 if (!strcmp(str[ct], "stateFragment")) { 672 if (!strcmp(str[ct+1], "default")) { 673 continue; 674 } 675 if (!strcmp(str[ct+1], "parent")) { 676 mEnviroment.mFragment.clear(); 677 continue; 678 } 679 ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]); 680 if (pf != NULL) { 681 mEnviroment.mFragment.set(pf); 682 continue; 683 } 684 LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); 685 } 686 687 if (!strcmp(str[ct], "stateFragmentStore")) { 688 if (!strcmp(str[ct+1], "default")) { 689 continue; 690 } 691 if (!strcmp(str[ct+1], "parent")) { 692 mEnviroment.mFragmentStore.clear(); 693 continue; 694 } 695 ProgramFragmentStore * pfs = 696 (ProgramFragmentStore *)rsc->lookupName(str[ct+1]); 697 if (pfs != NULL) { 698 mEnviroment.mFragmentStore.set(pfs); 699 continue; 700 } 701 LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]); 702 } 703 704 } 705 706 707 } else { 708 // Deal with an error. 709 } 710 711} 712 713namespace android { 714namespace renderscript { 715 716void rsi_ScriptCBegin(Context * rsc) 717{ 718 ScriptCState *ss = &rsc->mScriptC; 719 ss->clear(); 720} 721 722void rsi_ScriptCSetClearColor(Context * rsc, float r, float g, float b, float a) 723{ 724 ScriptCState *ss = &rsc->mScriptC; 725 ss->mEnviroment.mClearColor[0] = r; 726 ss->mEnviroment.mClearColor[1] = g; 727 ss->mEnviroment.mClearColor[2] = b; 728 ss->mEnviroment.mClearColor[3] = a; 729} 730 731void rsi_ScriptCSetClearDepth(Context * rsc, float v) 732{ 733 ScriptCState *ss = &rsc->mScriptC; 734 ss->mEnviroment.mClearDepth = v; 735} 736 737void rsi_ScriptCSetClearStencil(Context * rsc, uint32_t v) 738{ 739 ScriptCState *ss = &rsc->mScriptC; 740 ss->mEnviroment.mClearStencil = v; 741} 742 743void rsi_ScriptCAddType(Context * rsc, RsType vt) 744{ 745 ScriptCState *ss = &rsc->mScriptC; 746 ss->mConstantBufferTypes.add(static_cast<const Type *>(vt)); 747} 748 749void rsi_ScriptCSetScript(Context * rsc, void *vp) 750{ 751 ScriptCState *ss = &rsc->mScriptC; 752 ss->mProgram.mScript = reinterpret_cast<rsc_RunScript>(vp); 753} 754 755void rsi_ScriptCSetRoot(Context * rsc, bool isRoot) 756{ 757 ScriptCState *ss = &rsc->mScriptC; 758 ss->mEnviroment.mIsRoot = isRoot; 759} 760 761void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) 762{ 763 ScriptCState *ss = &rsc->mScriptC; 764 ss->mProgram.mScriptText = text; 765 ss->mProgram.mScriptTextLength = len; 766} 767 768 769RsScript rsi_ScriptCCreate(Context * rsc) 770{ 771 ScriptCState *ss = &rsc->mScriptC; 772 773 ss->runCompiler(rsc); 774 775 ScriptC *s = new ScriptC(); 776 s->incRef(); 777 s->mAccScript = ss->mAccScript; 778 ss->mAccScript = NULL; 779 s->mEnviroment = ss->mEnviroment; 780 s->mProgram = ss->mProgram; 781 ss->clear(); 782 783 return s; 784} 785 786} 787} 788 789 790