RenderScript.java revision 36e612a488511940b61f09803b270aa1c61b68e0
1/* 2 * Copyright (C) 2008 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 17package android.renderscript; 18 19import java.io.IOException; 20import java.io.InputStream; 21 22import android.content.res.Resources; 23import android.os.Bundle; 24import android.util.Config; 25import android.util.Log; 26import android.view.Surface; 27 28import android.graphics.Bitmap; 29import android.graphics.BitmapFactory; 30import android.graphics.Color; 31 32 33/** 34 * @hide 35 * 36 **/ 37public class RenderScript { 38 static final String LOG_TAG = "libRS_jni"; 39 private static final boolean DEBUG = false; 40 private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; 41 42 43 44 /* 45 * We use a class initializer to allow the native code to cache some 46 * field offsets. 47 */ 48 private static boolean sInitialized; 49 native private static void _nInit(); 50 51 private static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); 52 53 static { 54 sInitialized = false; 55 try { 56 System.loadLibrary("rs_jni"); 57 _nInit(); 58 sInitialized = true; 59 } catch (UnsatisfiedLinkError e) { 60 Log.d(LOG_TAG, "RenderScript JNI library not found!"); 61 } 62 mBitmapOptions.inScaled = false; 63 } 64 65 native int nDeviceCreate(); 66 native void nDeviceDestroy(int dev); 67 native int nContextCreate(int dev, Surface sur, int ver); 68 native void nContextDestroy(int con); 69 70 //void rsContextBindSampler (uint32_t slot, RsSampler sampler); 71 //void rsContextBindRootScript (RsScript sampler); 72 native void nContextBindRootScript(int script); 73 native void nContextBindSampler(int sampler, int slot); 74 native void nContextBindProgramFragmentStore(int pfs); 75 native void nContextBindProgramFragment(int pf); 76 native void nContextBindProgramVertex(int pf); 77 78 native void nAssignName(int obj, byte[] name); 79 native int nFileOpen(byte[] name); 80 81 native void nElementBegin(); 82 native void nElementAddPredefined(int predef); 83 native void nElementAdd(int kind, int type, int norm, int bits); 84 native int nElementCreate(); 85 native int nElementGetPredefined(int predef); 86 native void nElementDestroy(int obj); 87 88 native void nTypeBegin(int elementID); 89 native void nTypeAdd(int dim, int val); 90 native int nTypeCreate(); 91 native void nTypeDestroy(int id); 92 93 native int nAllocationCreateTyped(int type); 94 native int nAllocationCreatePredefSized(int predef, int count); 95 native int nAllocationCreateSized(int elem, int count); 96 native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp); 97 native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp); 98 99 native void nAllocationUploadToTexture(int alloc, int baseMioLevel); 100 native void nAllocationDestroy(int alloc); 101 native void nAllocationData(int id, int[] d); 102 native void nAllocationData(int id, float[] d); 103 native void nAllocationSubData1D(int id, int off, int count, int[] d); 104 native void nAllocationSubData1D(int id, int off, int count, float[] d); 105 native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d); 106 native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); 107 108 native void nTriangleMeshDestroy(int id); 109 native void nTriangleMeshBegin(int vertex, int index); 110 native void nTriangleMeshAddVertex_XY (float x, float y); 111 native void nTriangleMeshAddVertex_XYZ (float x, float y, float z); 112 native void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t); 113 native void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t); 114 native void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz); 115 native void nTriangleMeshAddTriangle(int i1, int i2, int i3); 116 native int nTriangleMeshCreate(); 117 118 native void nAdapter1DDestroy(int id); 119 native void nAdapter1DBindAllocation(int ad, int alloc); 120 native void nAdapter1DSetConstraint(int ad, int dim, int value); 121 native void nAdapter1DData(int ad, int[] d); 122 native void nAdapter1DSubData(int ad, int off, int count, int[] d); 123 native void nAdapter1DData(int ad, float[] d); 124 native void nAdapter1DSubData(int ad, int off, int count, float[] d); 125 native int nAdapter1DCreate(); 126 127 native void nScriptDestroy(int script); 128 native void nScriptBindAllocation(int vtm, int alloc, int slot); 129 native void nScriptCBegin(); 130 native void nScriptCSetClearColor(float r, float g, float b, float a); 131 native void nScriptCSetClearDepth(float depth); 132 native void nScriptCSetClearStencil(int stencil); 133 native void nScriptCSetTimeZone(byte[] timeZone); 134 native void nScriptCAddType(int type); 135 native void nScriptCSetRoot(boolean isRoot); 136 native void nScriptCSetScript(byte[] script, int offset, int length); 137 native int nScriptCCreate(); 138 139 native void nSamplerDestroy(int sampler); 140 native void nSamplerBegin(); 141 native void nSamplerSet(int param, int value); 142 native int nSamplerCreate(); 143 144 native void nProgramFragmentStoreBegin(int in, int out); 145 native void nProgramFragmentStoreDepthFunc(int func); 146 native void nProgramFragmentStoreDepthMask(boolean enable); 147 native void nProgramFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a); 148 native void nProgramFragmentStoreBlendFunc(int src, int dst); 149 native void nProgramFragmentStoreDither(boolean enable); 150 native int nProgramFragmentStoreCreate(); 151 native void nProgramFragmentStoreDestroy(int pgm); 152 153 native void nProgramFragmentBegin(int in, int out); 154 native void nProgramFragmentBindTexture(int vpf, int slot, int a); 155 native void nProgramFragmentBindSampler(int vpf, int slot, int s); 156 native void nProgramFragmentSetType(int slot, int vt); 157 native void nProgramFragmentSetEnvMode(int slot, int env); 158 native void nProgramFragmentSetTexEnable(int slot, boolean enable); 159 native int nProgramFragmentCreate(); 160 native void nProgramFragmentDestroy(int pgm); 161 162 native void nProgramVertexDestroy(int pv); 163 native void nProgramVertexBindAllocation(int pv, int slot, int mID); 164 native void nProgramVertexBegin(int inID, int outID); 165 native void nProgramVertexSetType(int slot, int mID); 166 native void nProgramVertexSetTextureMatrixEnable(boolean enable); 167 native void nProgramVertexAddLight(int id); 168 native int nProgramVertexCreate(); 169 170 native void nLightBegin(); 171 native void nLightSetIsMono(boolean isMono); 172 native void nLightSetIsLocal(boolean isLocal); 173 native int nLightCreate(); 174 native void nLightDestroy(int l); 175 native void nLightSetColor(int l, float r, float g, float b); 176 native void nLightSetPosition(int l, float x, float y, float z); 177 178 179 private int mDev; 180 private int mContext; 181 private Surface mSurface; 182 183 private static boolean mElementsInitialized = false; 184 185 /////////////////////////////////////////////////////////////////////////////////// 186 // 187 188 RenderScript(Surface sur) { 189 mSurface = sur; 190 mDev = nDeviceCreate(); 191 mContext = nContextCreate(mDev, mSurface, 0); 192 193 // TODO: This should be protected by a lock 194 if(!mElementsInitialized) { 195 Element.init(this); 196 mElementsInitialized = true; 197 } 198 } 199 200 ////////////////////////////////////////////////////////////////////////////////// 201 // Element 202 203 Element.Builder mElementBuilder = new Element.Builder(this); 204 public Element.Builder elementBuilderCreate() throws IllegalStateException { 205 mElementBuilder.begin(); 206 return mElementBuilder; 207 } 208 209 210 211 212 public enum DepthFunc { 213 ALWAYS (0), 214 LESS (1), 215 LEQUAL (2), 216 GREATER (3), 217 GEQUAL (4), 218 EQUAL (5), 219 NOTEQUAL (6); 220 221 int mID; 222 DepthFunc(int id) { 223 mID = id; 224 } 225 } 226 227 public enum BlendSrcFunc { 228 ZERO (0), 229 ONE (1), 230 DST_COLOR (2), 231 ONE_MINUS_DST_COLOR (3), 232 SRC_ALPHA (4), 233 ONE_MINUS_SRC_ALPHA (5), 234 DST_ALPHA (6), 235 ONE_MINUS_DST_ALPA (7), 236 SRC_ALPHA_SATURATE (8); 237 238 int mID; 239 BlendSrcFunc(int id) { 240 mID = id; 241 } 242 } 243 244 public enum BlendDstFunc { 245 ZERO (0), 246 ONE (1), 247 SRC_COLOR (2), 248 ONE_MINUS_SRC_COLOR (3), 249 SRC_ALPHA (4), 250 ONE_MINUS_SRC_ALPHA (5), 251 DST_ALPHA (6), 252 ONE_MINUS_DST_ALPA (7); 253 254 int mID; 255 BlendDstFunc(int id) { 256 mID = id; 257 } 258 } 259 260 public enum EnvMode { 261 REPLACE (0), 262 MODULATE (1), 263 DECAL (2); 264 265 int mID; 266 EnvMode(int id) { 267 mID = id; 268 } 269 } 270 271 public enum SamplerParam { 272 FILTER_MIN (0), 273 FILTER_MAG (1), 274 WRAP_MODE_S (2), 275 WRAP_MODE_T (3), 276 WRAP_MODE_R (4); 277 278 int mID; 279 SamplerParam(int id) { 280 mID = id; 281 } 282 } 283 284 public enum SamplerValue { 285 NEAREST (0), 286 LINEAR (1), 287 LINEAR_MIP_LINEAR (2), 288 WRAP (3), 289 CLAMP (4); 290 291 int mID; 292 SamplerValue(int id) { 293 mID = id; 294 } 295 } 296 297 ////////////////////////////////////////////////////////////////////////////////// 298 // Type 299 300 public enum Dimension { 301 X (0), 302 Y (1), 303 Z (2), 304 LOD (3), 305 FACE (4), 306 ARRAY_0 (100); 307 308 int mID; 309 Dimension(int id) { 310 mID = id; 311 } 312 } 313 314 public class Type extends BaseObj { 315 Type(int id) { 316 super(RenderScript.this); 317 mID = id; 318 } 319 320 public void destroy() { 321 nTypeDestroy(mID); 322 mID = 0; 323 } 324 } 325 326 public void typeBegin(Element e) { 327 nTypeBegin(e.mID); 328 } 329 330 public void typeAdd(Dimension d, int value) { 331 nTypeAdd(d.mID, value); 332 } 333 334 public Type typeCreate() { 335 int id = nTypeCreate(); 336 return new Type(id); 337 } 338 339 340 ////////////////////////////////////////////////////////////////////////////////// 341 // Allocation 342 343 public class Allocation extends BaseObj { 344 Allocation(int id) { 345 super(RenderScript.this); 346 mID = id; 347 } 348 349 public void uploadToTexture(int baseMipLevel) { 350 nAllocationUploadToTexture(mID, baseMipLevel); 351 } 352 353 public void destroy() { 354 nAllocationDestroy(mID); 355 mID = 0; 356 } 357 358 public void data(int[] d) { 359 nAllocationData(mID, d); 360 } 361 362 public void data(float[] d) { 363 nAllocationData(mID, d); 364 } 365 366 public void subData1D(int off, int count, int[] d) { 367 nAllocationSubData1D(mID, off, count, d); 368 } 369 370 public void subData1D(int off, int count, float[] d) { 371 nAllocationSubData1D(mID, off, count, d); 372 } 373 374 public void subData2D(int xoff, int yoff, int w, int h, int[] d) { 375 nAllocationSubData2D(mID, xoff, yoff, w, h, d); 376 } 377 378 public void subData2D(int xoff, int yoff, int w, int h, float[] d) { 379 nAllocationSubData2D(mID, xoff, yoff, w, h, d); 380 } 381 } 382 383 public Allocation allocationCreateTyped(Type type) { 384 int id = nAllocationCreateTyped(type.mID); 385 return new Allocation(id); 386 } 387 388 public Allocation allocationCreateSized(Element e, int count) { 389 int id; 390 if(e.mIsPredefined) { 391 id = nAllocationCreatePredefSized(e.mPredefinedID, count); 392 } else { 393 id = nAllocationCreateSized(e.mID, count); 394 } 395 return new Allocation(id); 396 } 397 398 public Allocation allocationCreateFromBitmap(Bitmap b, Element dstFmt, boolean genMips) 399 throws IllegalArgumentException { 400 if(!dstFmt.mIsPredefined) { 401 throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); 402 } 403 404 int id = nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b); 405 return new Allocation(id); 406 } 407 408 public Allocation allocationCreateFromBitmapBoxed(Bitmap b, Element dstFmt, boolean genMips) 409 throws IllegalArgumentException { 410 if(!dstFmt.mIsPredefined) { 411 throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); 412 } 413 414 int id = nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b); 415 return new Allocation(id); 416 } 417 418 public Allocation allocationCreateFromBitmapResource(Resources res, int id, Element dstFmt, boolean genMips) 419 throws IllegalArgumentException { 420 421 Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); 422 return allocationCreateFromBitmap(b, dstFmt, genMips); 423 } 424 425 public Allocation allocationCreateFromBitmapResourceBoxed(Resources res, int id, Element dstFmt, boolean genMips) 426 throws IllegalArgumentException { 427 428 Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); 429 return allocationCreateFromBitmapBoxed(b, dstFmt, genMips); 430 } 431 432 433 ////////////////////////////////////////////////////////////////////////////////// 434 // Adapter1D 435 436 public class Adapter1D extends BaseObj { 437 Adapter1D(int id) { 438 super(RenderScript.this); 439 mID = id; 440 } 441 442 public void destroy() { 443 nAdapter1DDestroy(mID); 444 mID = 0; 445 } 446 447 public void bindAllocation(Allocation a) { 448 nAdapter1DBindAllocation(mID, a.mID); 449 } 450 451 public void setConstraint(Dimension dim, int value) { 452 nAdapter1DSetConstraint(mID, dim.mID, value); 453 } 454 455 public void data(int[] d) { 456 nAdapter1DData(mID, d); 457 } 458 459 public void subData(int off, int count, int[] d) { 460 nAdapter1DSubData(mID, off, count, d); 461 } 462 463 public void data(float[] d) { 464 nAdapter1DData(mID, d); 465 } 466 467 public void subData(int off, int count, float[] d) { 468 nAdapter1DSubData(mID, off, count, d); 469 } 470 } 471 472 public Adapter1D adapter1DCreate() { 473 int id = nAdapter1DCreate(); 474 return new Adapter1D(id); 475 } 476 477 478 ////////////////////////////////////////////////////////////////////////////////// 479 // Triangle Mesh 480 481 public class TriangleMesh extends BaseObj { 482 TriangleMesh(int id) { 483 super(RenderScript.this); 484 mID = id; 485 } 486 487 public void destroy() { 488 nTriangleMeshDestroy(mID); 489 mID = 0; 490 } 491 } 492 493 public void triangleMeshBegin(Element vertex, Element index) { 494 Log.e("rs", "vtx " + vertex.toString() + " " + vertex.mID + " " + vertex.mPredefinedID); 495 nTriangleMeshBegin(vertex.mID, index.mID); 496 } 497 498 public void triangleMeshAddVertex_XY(float x, float y) { 499 nTriangleMeshAddVertex_XY(x, y); 500 } 501 502 public void triangleMeshAddVertex_XYZ(float x, float y, float z) { 503 nTriangleMeshAddVertex_XYZ(x, y, z); 504 } 505 506 public void triangleMeshAddVertex_XY_ST(float x, float y, float s, float t) { 507 nTriangleMeshAddVertex_XY_ST(x, y, s, t); 508 } 509 510 public void triangleMeshAddVertex_XYZ_ST(float x, float y, float z, float s, float t) { 511 nTriangleMeshAddVertex_XYZ_ST(x, y, z, s, t); 512 } 513 514 public void triangleMeshAddVertex_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) { 515 nTriangleMeshAddVertex_XYZ_ST_NORM(x, y, z, s, t, nx, ny, nz); 516 } 517 518 public void triangleMeshAddTriangle(int i1, int i2, int i3) { 519 nTriangleMeshAddTriangle(i1, i2, i3); 520 } 521 522 public TriangleMesh triangleMeshCreate() { 523 int id = nTriangleMeshCreate(); 524 return new TriangleMesh(id); 525 } 526 527 ////////////////////////////////////////////////////////////////////////////////// 528 // Script 529 530 public class Script extends BaseObj { 531 Script(int id) { 532 super(RenderScript.this); 533 mID = id; 534 } 535 536 public void destroy() { 537 nScriptDestroy(mID); 538 mID = 0; 539 } 540 541 public void bindAllocation(Allocation va, int slot) { 542 nScriptBindAllocation(mID, va.mID, slot); 543 } 544 } 545 546 public void scriptCBegin() { 547 nScriptCBegin(); 548 } 549 550 public void scriptCSetTimeZone(String timeZone) { 551 try { 552 byte[] bytes = timeZone.getBytes("UTF-8"); 553 nScriptCSetTimeZone(bytes); 554 } catch (java.io.UnsupportedEncodingException e) { 555 throw new RuntimeException(e); 556 } 557 } 558 559 public void scriptCSetClearColor(float r, float g, float b, float a) { 560 nScriptCSetClearColor(r, g, b, a); 561 } 562 563 public void scriptCSetClearDepth(float d) { 564 nScriptCSetClearDepth(d); 565 } 566 567 public void scriptCSetClearStencil(int stencil) { 568 nScriptCSetClearStencil(stencil); 569 } 570 571 public void scriptCAddType(Type t) { 572 nScriptCAddType(t.mID); 573 } 574 575 public void scriptCSetRoot(boolean r) { 576 nScriptCSetRoot(r); 577 } 578 579 public void scriptCSetScript(String s) { 580 try { 581 byte[] bytes = s.getBytes("UTF-8"); 582 nScriptCSetScript(bytes, 0, bytes.length); 583 } catch (java.io.UnsupportedEncodingException e) { 584 throw new RuntimeException(e); 585 } 586 } 587 588 public void scriptCSetScript(Resources resources, int id) { 589 InputStream is = resources.openRawResource(id); 590 try { 591 try { 592 scriptCSetScript(is); 593 } finally { 594 is.close(); 595 } 596 } catch(IOException e) { 597 throw new Resources.NotFoundException(); 598 } 599 } 600 601 public void scriptCSetScript(InputStream is) throws IOException { 602 byte[] buf = new byte[1024]; 603 int currentPos = 0; 604 while(true) { 605 int bytesLeft = buf.length - currentPos; 606 if (bytesLeft == 0) { 607 byte[] buf2 = new byte[buf.length * 2]; 608 System.arraycopy(buf, 0, buf2, 0, buf.length); 609 buf = buf2; 610 bytesLeft = buf.length - currentPos; 611 } 612 int bytesRead = is.read(buf, currentPos, bytesLeft); 613 if (bytesRead <= 0) { 614 break; 615 } 616 currentPos += bytesRead; 617 } 618 nScriptCSetScript(buf, 0, currentPos); 619 } 620 621 public Script scriptCCreate() { 622 int id = nScriptCCreate(); 623 return new Script(id); 624 } 625 626 ////////////////////////////////////////////////////////////////////////////////// 627 // ProgramVertex 628 629 public class ProgramVertex extends BaseObj { 630 ProgramVertex(int id) { 631 super(RenderScript.this); 632 mID = id; 633 } 634 635 public void destroy() { 636 nProgramVertexDestroy(mID); 637 mID = 0; 638 } 639 640 public void bindAllocation(int slot, Allocation va) { 641 nProgramVertexBindAllocation(mID, slot, va.mID); 642 } 643 } 644 645 public void programVertexBegin(Element in, Element out) { 646 int inID = 0; 647 int outID = 0; 648 if (in != null) { 649 inID = in.mID; 650 } 651 if (out != null) { 652 outID = out.mID; 653 } 654 nProgramVertexBegin(inID, outID); 655 } 656 657 public void programVertexSetType(int slot, Type t) { 658 nProgramVertexSetType(slot, t.mID); 659 } 660 661 public void programVertexSetTextureMatrixEnable(boolean enable) { 662 nProgramVertexSetTextureMatrixEnable(enable); 663 } 664 665 public void programVertexAddLight(Light l) { 666 nProgramVertexAddLight(l.mID); 667 } 668 669 public ProgramVertex programVertexCreate() { 670 int id = nProgramVertexCreate(); 671 return new ProgramVertex(id); 672 } 673 674 675 ////////////////////////////////////////////////////////////////////////////////// 676 // ProgramFragmentStore 677 678 public class ProgramFragmentStore extends BaseObj { 679 ProgramFragmentStore(int id) { 680 super(RenderScript.this); 681 mID = id; 682 } 683 684 public void destroy() { 685 nProgramFragmentStoreDestroy(mID); 686 mID = 0; 687 } 688 } 689 690 public void programFragmentStoreBegin(Element in, Element out) { 691 int inID = 0; 692 int outID = 0; 693 if (in != null) { 694 inID = in.mID; 695 } 696 if (out != null) { 697 outID = out.mID; 698 } 699 nProgramFragmentStoreBegin(inID, outID); 700 } 701 702 public void programFragmentStoreDepthFunc(DepthFunc func) { 703 nProgramFragmentStoreDepthFunc(func.mID); 704 } 705 706 public void programFragmentStoreDepthMask(boolean enable) { 707 nProgramFragmentStoreDepthMask(enable); 708 } 709 710 public void programFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a) { 711 nProgramFragmentStoreColorMask(r,g,b,a); 712 } 713 714 public void programFragmentStoreBlendFunc(BlendSrcFunc src, BlendDstFunc dst) { 715 nProgramFragmentStoreBlendFunc(src.mID, dst.mID); 716 } 717 718 public void programFragmentStoreDitherEnable(boolean enable) { 719 nProgramFragmentStoreDither(enable); 720 } 721 722 public ProgramFragmentStore programFragmentStoreCreate() { 723 int id = nProgramFragmentStoreCreate(); 724 return new ProgramFragmentStore(id); 725 } 726 727 ////////////////////////////////////////////////////////////////////////////////// 728 // ProgramFragment 729 730 public class ProgramFragment extends BaseObj { 731 ProgramFragment(int id) { 732 super(RenderScript.this); 733 mID = id; 734 } 735 736 public void destroy() { 737 nProgramFragmentDestroy(mID); 738 mID = 0; 739 } 740 741 public void bindTexture(Allocation va, int slot) { 742 nProgramFragmentBindTexture(mID, slot, va.mID); 743 } 744 745 public void bindSampler(Sampler vs, int slot) { 746 nProgramFragmentBindSampler(mID, slot, vs.mID); 747 } 748 } 749 750 public void programFragmentBegin(Element in, Element out) { 751 int inID = 0; 752 int outID = 0; 753 if (in != null) { 754 inID = in.mID; 755 } 756 if (out != null) { 757 outID = out.mID; 758 } 759 nProgramFragmentBegin(inID, outID); 760 } 761 762 public void programFragmentSetType(int slot, Type t) { 763 nProgramFragmentSetType(slot, t.mID); 764 } 765 766 public void programFragmentSetType(int slot, EnvMode t) { 767 nProgramFragmentSetEnvMode(slot, t.mID); 768 } 769 770 public void programFragmentSetTexEnable(int slot, boolean enable) { 771 nProgramFragmentSetTexEnable(slot, enable); 772 } 773 774 public void programFragmentSetTexEnvMode(int slot, EnvMode env) { 775 nProgramFragmentSetEnvMode(slot, env.mID); 776 } 777 778 public ProgramFragment programFragmentCreate() { 779 int id = nProgramFragmentCreate(); 780 return new ProgramFragment(id); 781 } 782 783 ////////////////////////////////////////////////////////////////////////////////// 784 // Sampler 785 786 public class Sampler extends BaseObj { 787 Sampler(int id) { 788 super(RenderScript.this); 789 mID = id; 790 } 791 792 public void destroy() { 793 nSamplerDestroy(mID); 794 mID = 0; 795 } 796 } 797 798 public void samplerBegin() { 799 nSamplerBegin(); 800 } 801 802 public void samplerSet(SamplerParam p, SamplerValue v) { 803 nSamplerSet(p.mID, v.mID); 804 } 805 806 public Sampler samplerCreate() { 807 int id = nSamplerCreate(); 808 return new Sampler(id); 809 } 810 811 ////////////////////////////////////////////////////////////////////////////////// 812 // Light 813 814 public class Light extends BaseObj { 815 Light(int id) { 816 super(RenderScript.this); 817 mID = id; 818 } 819 820 public void destroy() { 821 nLightDestroy(mID); 822 mID = 0; 823 } 824 825 public void setColor(float r, float g, float b) { 826 nLightSetColor(mID, r, g, b); 827 } 828 829 public void setPosition(float x, float y, float z) { 830 nLightSetPosition(mID, x, y, z); 831 } 832 } 833 834 public void lightBegin() { 835 nLightBegin(); 836 } 837 838 public void lightSetIsMono(boolean isMono) { 839 nLightSetIsMono(isMono); 840 } 841 842 public void lightSetIsLocal(boolean isLocal) { 843 nLightSetIsLocal(isLocal); 844 } 845 846 public Light lightCreate() { 847 int id = nLightCreate(); 848 return new Light(id); 849 } 850 851 ////////////////////////////////////////////////////////////////////////////////// 852 // File 853 854 public class File extends BaseObj { 855 File(int id) { 856 super(RenderScript.this); 857 mID = id; 858 } 859 860 public void destroy() { 861 //nLightDestroy(mID); 862 mID = 0; 863 } 864 } 865 866 public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException 867 { 868 if(s.length() < 1) { 869 throw new IllegalArgumentException("fileOpen does not accept a zero length string."); 870 } 871 872 try { 873 byte[] bytes = s.getBytes("UTF-8"); 874 int id = nFileOpen(bytes); 875 return new File(id); 876 } catch (java.io.UnsupportedEncodingException e) { 877 throw new RuntimeException(e); 878 } 879 } 880 881 882 /////////////////////////////////////////////////////////////////////////////////// 883 // Root state 884 885 public void contextBindRootScript(Script s) { 886 nContextBindRootScript(s.mID); 887 } 888 889 //public void contextBindSampler(Sampler s, int slot) { 890 //nContextBindSampler(s.mID); 891 //} 892 893 public void contextBindProgramFragmentStore(ProgramFragmentStore pfs) { 894 nContextBindProgramFragmentStore(pfs.mID); 895 } 896 897 public void contextBindProgramFragment(ProgramFragment pf) { 898 nContextBindProgramFragment(pf.mID); 899 } 900 901 public void contextBindProgramVertex(ProgramVertex pf) { 902 nContextBindProgramVertex(pf.mID); 903 } 904 905/* 906 RsAdapter2D rsAdapter2DCreate (); 907 void rsAdapter2DBindAllocation (RsAdapter2D adapt, RsAllocation alloc); 908 void rsAdapter2DDestroy (RsAdapter2D adapter); 909 void rsAdapter2DSetConstraint (RsAdapter2D adapter, RsDimension dim, uint32_t value); 910 void rsAdapter2DData (RsAdapter2D adapter, const void * data); 911 void rsAdapter2DSubData (RsAdapter2D adapter, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void * data); 912 void rsSamplerBegin (); 913 void rsSamplerSet (RsSamplerParam p, RsSamplerValue value); 914 RsSampler rsSamplerCreate (); 915 void rsSamplerBind (RsSampler sampler, RsAllocation alloc); 916*/ 917 918} 919 920 921