rsScriptC.cpp revision fd10b71b33b7340c00c11c8684ca940e83b5aaca
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 133extern "C" float 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 141extern "C" int32_t 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 149extern "C" uint32_t 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 168extern "C" void 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 175extern "C" void 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 181extern "C" void 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 315extern "C" void drawQuadF(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 loadF, 477 loadI32, 478 loadU32, 479 loadEnvVec4, 480 loadEnvMatrix, 481 482 storeF, 483 storeI32, 484 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 578 579void ScriptCState::runCompiler(Context *rsc) 580{ 581 mAccScript = accCreateScript(); 582 String8 tmp; 583 584 rsc->appendNameDefines(&tmp); 585 586 const char* scriptSource[] = {tmp.string(), mProgram.mScriptText}; 587 int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ; 588 accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength); 589 accCompileScript(mAccScript); 590 accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript); 591 rsAssert(mProgram.mScript); 592 593 mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); 594 mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); 595 mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore()); 596 597 if (mProgram.mScript) { 598 const static int pragmaMax = 16; 599 ACCsizei pragmaCount; 600 ACCchar * str[pragmaMax]; 601 accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]); 602 603 for (int ct=0; ct < pragmaCount; ct+=2) { 604 if (!strcmp(str[ct], "version")) { 605 continue; 606 } 607 608 if (!strcmp(str[ct], "stateVertex")) { 609 if (!strcmp(str[ct+1], "default")) { 610 continue; 611 } 612 if (!strcmp(str[ct+1], "parent")) { 613 mEnviroment.mVertex.clear(); 614 continue; 615 } 616 ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]); 617 if (pv != NULL) { 618 mEnviroment.mVertex.set(pv); 619 continue; 620 } 621 LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); 622 } 623 624 if (!strcmp(str[ct], "stateRaster")) { 625 LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); 626 } 627 628 if (!strcmp(str[ct], "stateFragment")) { 629 if (!strcmp(str[ct+1], "default")) { 630 continue; 631 } 632 if (!strcmp(str[ct+1], "parent")) { 633 mEnviroment.mFragment.clear(); 634 continue; 635 } 636 ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]); 637 if (pf != NULL) { 638 mEnviroment.mFragment.set(pf); 639 continue; 640 } 641 LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); 642 } 643 644 if (!strcmp(str[ct], "stateFragmentStore")) { 645 if (!strcmp(str[ct+1], "default")) { 646 continue; 647 } 648 if (!strcmp(str[ct+1], "parent")) { 649 mEnviroment.mFragmentStore.clear(); 650 continue; 651 } 652 ProgramFragmentStore * pfs = 653 (ProgramFragmentStore *)rsc->lookupName(str[ct+1]); 654 if (pfs != NULL) { 655 mEnviroment.mFragmentStore.set(pfs); 656 continue; 657 } 658 LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]); 659 } 660 661 } 662 663 664 } else { 665 // Deal with an error. 666 } 667 668} 669 670namespace android { 671namespace renderscript { 672 673void rsi_ScriptCBegin(Context * rsc) 674{ 675 ScriptCState *ss = &rsc->mScriptC; 676 ss->clear(); 677} 678 679void rsi_ScriptCSetClearColor(Context * rsc, float r, float g, float b, float a) 680{ 681 ScriptCState *ss = &rsc->mScriptC; 682 ss->mEnviroment.mClearColor[0] = r; 683 ss->mEnviroment.mClearColor[1] = g; 684 ss->mEnviroment.mClearColor[2] = b; 685 ss->mEnviroment.mClearColor[3] = a; 686} 687 688void rsi_ScriptCSetClearDepth(Context * rsc, float v) 689{ 690 ScriptCState *ss = &rsc->mScriptC; 691 ss->mEnviroment.mClearDepth = v; 692} 693 694void rsi_ScriptCSetClearStencil(Context * rsc, uint32_t v) 695{ 696 ScriptCState *ss = &rsc->mScriptC; 697 ss->mEnviroment.mClearStencil = v; 698} 699 700void rsi_ScriptCAddType(Context * rsc, RsType vt) 701{ 702 ScriptCState *ss = &rsc->mScriptC; 703 ss->mConstantBufferTypes.add(static_cast<const Type *>(vt)); 704} 705 706void rsi_ScriptCSetScript(Context * rsc, void *vp) 707{ 708 ScriptCState *ss = &rsc->mScriptC; 709 ss->mProgram.mScript = reinterpret_cast<rsc_RunScript>(vp); 710} 711 712void rsi_ScriptCSetRoot(Context * rsc, bool isRoot) 713{ 714 ScriptCState *ss = &rsc->mScriptC; 715 ss->mEnviroment.mIsRoot = isRoot; 716} 717 718void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) 719{ 720 ScriptCState *ss = &rsc->mScriptC; 721 ss->mProgram.mScriptText = text; 722 ss->mProgram.mScriptTextLength = len; 723} 724 725 726RsScript rsi_ScriptCCreate(Context * rsc) 727{ 728 ScriptCState *ss = &rsc->mScriptC; 729 730 ss->runCompiler(rsc); 731 732 ScriptC *s = new ScriptC(); 733 s->incRef(); 734 s->mAccScript = ss->mAccScript; 735 ss->mAccScript = NULL; 736 s->mEnviroment = ss->mEnviroment; 737 s->mProgram = ss->mProgram; 738 ss->clear(); 739 740 return s; 741} 742 743} 744} 745 746 747