blob: cf16cec7c5a5c52faa4b46843374fd836da56ba5 [file] [log] [blame]
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001/*
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
Jack Palevichdf988512009-05-27 17:00:45 -070017package com.android.fountain;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070018
Jack Palevich43702d82009-05-28 13:38:16 -070019import java.io.InputStream;
20import java.io.IOException;
21
Jack Palevich60aa3ea2009-05-26 13:45:08 -070022import android.os.Bundle;
Jack Palevich43702d82009-05-28 13:38:16 -070023import android.content.res.Resources;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070024import android.util.Log;
25import android.util.Config;
26import android.view.Menu;
27import android.view.MenuItem;
28import android.view.Window;
29import android.view.View;
30import android.view.Surface;
Jason Samsfe08d992009-05-27 14:45:32 -070031import android.graphics.Bitmap;
32import android.graphics.Color;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070033
34public class RenderScript {
35 private static final String LOG_TAG = "libRS_jni";
36 private static final boolean DEBUG = false;
37 private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
38
39
40
Jason Sams02fb2cb2009-05-28 15:37:57 -070041 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070042 * We use a class initializer to allow the native code to cache some
43 * field offsets.
44 */
45 private static boolean sInitialized;
46 native private static void _nInit();
47
48 static {
49 sInitialized = false;
50 try {
51 System.loadLibrary("RS_jni");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070052 _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070053 sInitialized = true;
54 } catch (UnsatisfiedLinkError e) {
55 Log.d(LOG_TAG, "RenderScript JNI library not found!");
56 }
57 }
58
59 native private int nDeviceCreate();
60 native private void nDeviceDestroy(int dev);
61 native private int nContextCreate(int dev, Surface sur, int ver);
62 native private void nContextDestroy(int con);
63
64 //void rsContextBindSampler (uint32_t slot, RsSampler sampler);
65 //void rsContextBindRootScript (RsScript sampler);
66 native private void nContextBindRootScript(int script);
67 native private void nContextBindSampler(int sampler, int slot);
68 native private void nContextBindProgramFragmentStore(int pfs);
69 native private void nContextBindProgramFragment(int pf);
70
71 native private void nElementBegin();
72 native private void nElementAddPredefined(int predef);
73 native private void nElementAdd(int kind, int type, int norm, int bits);
74 native private int nElementCreate();
75 native private int nElementGetPredefined(int predef);
76 native private void nElementDestroy(int obj);
77
78 native private void nTypeBegin(int elementID);
79 native private void nTypeAdd(int dim, int val);
80 native private int nTypeCreate();
81 native private void nTypeDestroy(int id);
82
83 native private int nAllocationCreateTyped(int type);
84 native private int nAllocationCreatePredefSized(int predef, int count);
85 native private int nAllocationCreateSized(int elem, int count);
Jason Samsfe08d992009-05-27 14:45:32 -070086 native private int nAllocationCreateFromBitmap(int w, int h, int dstFmt, int srcFmt, boolean genMips, int[] data);
87
Jack Palevich60aa3ea2009-05-26 13:45:08 -070088 //native private int nAllocationCreateFromBitmap(type.mID);
89 native private void nAllocationUploadToTexture(int alloc, int baseMioLevel);
90 native private void nAllocationDestroy(int alloc);
91 native private void nAllocationData(int id, int[] d);
92 native private void nAllocationData(int id, float[] d);
93 native private void nAllocationSubData1D(int id, int off, int count, int[] d);
94 native private void nAllocationSubData1D(int id, int off, int count, float[] d);
95 native private void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d);
96 native private void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d);
97
98 native private void nTriangleMeshDestroy(int id);
99 native private void nTriangleMeshBegin(int vertex, int index);
100 native private void nTriangleMeshAddVertex_XY (float x, float y);
101 native private void nTriangleMeshAddVertex_XYZ (float x, float y, float z);
102 native private void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t);
103 native private void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t);
104 native private void nTriangleMeshAddTriangle(int i1, int i2, int i3);
105 native private int nTriangleMeshCreate();
106
107 native private void nAdapter1DDestroy(int id);
108 native private void nAdapter1DBindAllocation(int ad, int alloc);
109 native private void nAdapter1DSetConstraint(int ad, int dim, int value);
110 native private void nAdapter1DData(int ad, int[] d);
111 native private void nAdapter1DSubData(int ad, int off, int count, int[] d);
112 native private void nAdapter1DData(int ad, float[] d);
113 native private void nAdapter1DSubData(int ad, int off, int count, float[] d);
114 native private int nAdapter1DCreate();
115
116 native private void nScriptDestroy(int script);
117 native private void nScriptBindAllocation(int vtm, int alloc, int slot);
118 native private void nScriptCBegin();
119 native private void nScriptCSetClearColor(float r, float g, float b, float a);
120 native private void nScriptCSetClearDepth(float depth);
121 native private void nScriptCSetClearStencil(int stencil);
122 native private void nScriptCAddType(int type);
123 native private void nScriptCSetRoot(boolean isRoot);
Jack Palevich43702d82009-05-28 13:38:16 -0700124 native private void nScriptCSetScript(byte[] script, int offset, int length);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700125 native private int nScriptCCreate();
126
Jason Sams02fb2cb2009-05-28 15:37:57 -0700127 native private void nSamplerDestroy(int sampler);
128 native private void nSamplerBegin();
129 native private void nSamplerSet(int param, int value);
130 native private int nSamplerCreate();
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700131
132 native private void nProgramFragmentStoreBegin(int in, int out);
133 native private void nProgramFragmentStoreDepthFunc(int func);
134 native private void nProgramFragmentStoreDepthMask(boolean enable);
135 native private void nProgramFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a);
136 native private void nProgramFragmentStoreBlendFunc(int src, int dst);
137 native private void nProgramFragmentStoreDither(boolean enable);
138 native private int nProgramFragmentStoreCreate();
139
140 native private void nProgramFragmentBegin(int in, int out);
141 native private void nProgramFragmentBindTexture(int vpf, int slot, int a);
142 native private void nProgramFragmentBindSampler(int vpf, int slot, int s);
143 native private void nProgramFragmentSetType(int slot, int vt);
144 native private void nProgramFragmentSetEnvMode(int slot, int env);
145 native private void nProgramFragmentSetTexEnable(int slot, boolean enable);
146 native private int nProgramFragmentCreate();
147
148
149 private int mDev;
150 private int mContext;
151 private Surface mSurface;
152
153
154
155 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -0700156 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700157
158 RenderScript(Surface sur) {
159 mSurface = sur;
160 mDev = nDeviceCreate();
161 mContext = nContextCreate(mDev, mSurface, 0);
162 }
163
164 private class BaseObj {
165 BaseObj() {
166 mID = 0;
167 }
168
169 int mID;
170 protected void finalize() throws Throwable
171 {
172 if (mID != 0) {
Jack Palevich43702d82009-05-28 13:38:16 -0700173 Log.v(LOG_TAG,
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700174 "Element finalized without having released the RS reference.");
175 }
176 super.finalize();
177 }
178 }
179
Jack Palevich43702d82009-05-28 13:38:16 -0700180
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700181 //////////////////////////////////////////////////////////////////////////////////
182 // Element
183
184 public enum ElementPredefined {
185 USER_U8 (0),
186 USER_I8 (1),
187 USER_U16 (2),
188 USER_I16 (3),
189 USER_U32 (4),
190 USER_I32 (5),
191 USER_FLOAT (6),
192
Jason Samsfe08d992009-05-27 14:45:32 -0700193 A_8 (7),
194 RGB_565 (8),
195 RGBA_5551 (9),
196 RGBA_4444 (10),
197 RGB_888 (11),
198 RGBA_8888 (12),
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700199
Jason Samsfe08d992009-05-27 14:45:32 -0700200 INDEX_16 (13),
201 INDEX_32 (14),
202 XY_F32 (15),
203 XYZ_F32 (16),
204 ST_XY_F32 (17),
205 ST_XYZ_F32 (18),
206 NORM_XYZ_F32 (19),
207 NORM_ST_XYZ_F32 (20);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700208
209 int mID;
210 ElementPredefined(int id) {
211 mID = id;
212 }
213 }
214
215 public enum DataType {
216 FLOAT (0),
217 UNSIGNED (1),
218 SIGNED (2);
219
220 int mID;
221 DataType(int id) {
222 mID = id;
223 }
224 }
225
226 public enum DataKind {
227 USER (0),
228 RED (1),
229 GREEN (2),
230 BLUE (3),
231 ALPHA (4),
232 LUMINANCE (5),
233 INTENSITY (6),
234 X (7),
235 Y (8),
236 Z (9),
237 W (10),
238 S (11),
239 T (12),
240 Q (13),
241 R (14),
242 NX (15),
243 NY (16),
244 NZ (17),
245 INDEX (18);
246
247 int mID;
248 DataKind(int id) {
249 mID = id;
250 }
251 }
252
253 public enum DepthFunc {
254 ALWAYS (0),
255 LESS (1),
256 LEQUAL (2),
257 GREATER (3),
258 GEQUAL (4),
259 EQUAL (5),
260 NOTEQUAL (6);
261
262 int mID;
263 DepthFunc(int id) {
264 mID = id;
265 }
266 }
267
268 public enum BlendSrcFunc {
269 ZERO (0),
270 ONE (1),
271 DST_COLOR (2),
272 ONE_MINUS_DST_COLOR (3),
273 SRC_ALPHA (4),
274 ONE_MINUS_SRC_ALPHA (5),
275 DST_ALPHA (6),
276 ONE_MINUS_DST_ALPA (7),
277 SRC_ALPHA_SATURATE (8);
278
279 int mID;
280 BlendSrcFunc(int id) {
281 mID = id;
282 }
283 }
284
285 public enum BlendDstFunc {
286 ZERO (0),
287 ONE (1),
288 SRC_COLOR (2),
289 ONE_MINUS_SRC_COLOR (3),
290 SRC_ALPHA (4),
291 ONE_MINUS_SRC_ALPHA (5),
292 DST_ALPHA (6),
293 ONE_MINUS_DST_ALPA (7);
294
295 int mID;
296 BlendDstFunc(int id) {
297 mID = id;
298 }
299 }
300
301 public enum EnvMode {
302 REPLACE (0),
303 MODULATE (1),
304 DECAL (2);
305
306 int mID;
307 EnvMode(int id) {
308 mID = id;
309 }
310 }
311
Jason Sams02fb2cb2009-05-28 15:37:57 -0700312 public enum SamplerParam {
313 FILTER_MIN (0),
314 FILTER_MAG (1),
315 WRAP_MODE_S (2),
316 WRAP_MODE_T (3),
317 WRAP_MODE_R (4);
318
319 int mID;
320 SamplerParam(int id) {
321 mID = id;
322 }
323 }
324
325 public enum SamplerValue {
326 NEAREST (0),
327 LINEAR (1),
328 LINEAR_MIP_LINEAR (2),
329 WRAP (3),
330 CLAMP (4);
331
332 int mID;
333 SamplerValue(int id) {
334 mID = id;
335 }
336 }
337
338
339
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700340 public class Element extends BaseObj {
341 Element(int id) {
342 mID = id;
343 }
344
345 public void estroy() {
346 nElementDestroy(mID);
347 mID = 0;
348 }
349 }
350
351 public void elementBegin() {
352 nElementBegin();
353 }
354
355 public void elementAddPredefined(ElementPredefined e) {
356 nElementAddPredefined(e.mID);
357 }
358
359 public void elementAdd(DataType dt, DataKind dk, boolean isNormalized, int bits) {
360 int norm = 0;
361 if (isNormalized) {
362 norm = 1;
363 }
364 nElementAdd(dt.mID, dk.mID, norm, bits);
365 }
366
367 public Element elementCreate() {
368 int id = nElementCreate();
369 return new Element(id);
370 }
371
372 public Element elementGetPredefined(ElementPredefined predef) {
373 int id = nElementGetPredefined(predef.mID);
374 return new Element(id);
375 }
376
377
378 //////////////////////////////////////////////////////////////////////////////////
379 // Type
380
381 public enum Dimension {
382 X (0),
383 Y (1),
384 Z (2),
385 LOD (3),
386 FACE (4),
387 ARRAY_0 (100);
388
389 int mID;
390 Dimension(int id) {
391 mID = id;
392 }
393 }
394
395 public class Type extends BaseObj {
396 Type(int id) {
397 mID = id;
398 }
399
400 public void destroy() {
401 nTypeDestroy(mID);
402 mID = 0;
403 }
404 }
405
406 public void typeBegin(Element e) {
407 nTypeBegin(e.mID);
408 }
409
410 public void typeAdd(Dimension d, int value) {
411 nTypeAdd(d.mID, value);
412 }
413
414 public Type typeCreate() {
415 int id = nTypeCreate();
416 return new Type(id);
417 }
418
419
420 //////////////////////////////////////////////////////////////////////////////////
421 // Allocation
422
423 public class Allocation extends BaseObj {
424 Allocation(int id) {
425 mID = id;
426 }
427
428 public void uploadToTexture(int baseMipLevel) {
429 nAllocationUploadToTexture(mID, baseMipLevel);
430 }
431
432 public void destroy() {
433 nAllocationDestroy(mID);
434 mID = 0;
435 }
436
437 public void data(int[] d) {
438 nAllocationData(mID, d);
439 }
440
441 public void data(float[] d) {
442 nAllocationData(mID, d);
443 }
444
445 public void subData1D(int off, int count, int[] d) {
446 nAllocationSubData1D(mID, off, count, d);
447 }
448
449 public void subData1D(int off, int count, float[] d) {
450 nAllocationSubData1D(mID, off, count, d);
451 }
452
453 public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
454 nAllocationSubData2D(mID, xoff, yoff, w, h, d);
455 }
456
457 public void subData2D(int xoff, int yoff, int w, int h, float[] d) {
458 nAllocationSubData2D(mID, xoff, yoff, w, h, d);
459 }
460 }
461
462 public Allocation allocationCreateTyped(Type type) {
463 int id = nAllocationCreateTyped(type.mID);
464 return new Allocation(id);
465 }
466
467 public Allocation allocationCreatePredefSized(ElementPredefined e, int count) {
468 int id = nAllocationCreatePredefSized(e.mID, count);
469 return new Allocation(id);
470 }
471
472 public Allocation allocationCreateSized(Element e, int count) {
473 int id = nAllocationCreateSized(e.mID, count);
474 return new Allocation(id);
475 }
476
Jason Samsfe08d992009-05-27 14:45:32 -0700477 public Allocation allocationCreateFromBitmap(Bitmap b, ElementPredefined dstFmt, boolean genMips) {
478 int w = b.getWidth();
479 int h = b.getHeight();
480 int[] data = new int[w * h];
481
482 int outPtr = 0;
483 for(int y=0; y < h; y++) {
484 for(int x=0; x < w; x++) {
485 data[outPtr] = b.getPixel(x, y);
486 outPtr++;
487 }
488 }
489
490 int srcFmt = 0;
491 /*
492 switch(b.getConfig()) {
493 case ALPHA_8:
494 srcFmt = ElementPredefined.A_8.mID;
495 break;
496 case ARGB_4444:
497 srcFmt = ElementPredefined.RGBA_4444.mID;
498 break;
499 case ARGB_8888:
500 srcFmt = ElementPredefined.RGBA_8888.mID;
501 break;
502 case RGB_565:
503 srcFmt = ElementPredefined.RGB_565.mID;
504 break;
505 default:
506 Log.e(LOG_TAG, "allocationCreateFromBitmap, unknown bitmap format");
Jack Palevich43702d82009-05-28 13:38:16 -0700507 }
508 */
Jason Samsfe08d992009-05-27 14:45:32 -0700509
510 srcFmt = ElementPredefined.RGBA_8888.mID;
511
512 int id = nAllocationCreateFromBitmap(w, h, dstFmt.mID, srcFmt, genMips, data);
513 return new Allocation(id);
514 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700515
516 //////////////////////////////////////////////////////////////////////////////////
517 // Adapter1D
518
519 public class Adapter1D extends BaseObj {
520 Adapter1D(int id) {
521 mID = id;
522 }
523
524 public void destroy() {
525 nAdapter1DDestroy(mID);
526 mID = 0;
527 }
528
529 public void bindAllocation(Allocation a) {
530 nAdapter1DBindAllocation(mID, a.mID);
531 }
532
533 public void setConstraint(Dimension dim, int value) {
534 nAdapter1DSetConstraint(mID, dim.mID, value);
535 }
536
537 public void data(int[] d) {
538 nAdapter1DData(mID, d);
539 }
540
541 public void subData(int off, int count, int[] d) {
542 nAdapter1DSubData(mID, off, count, d);
543 }
544
545 public void data(float[] d) {
546 nAdapter1DData(mID, d);
547 }
548
549 public void subData(int off, int count, float[] d) {
550 nAdapter1DSubData(mID, off, count, d);
551 }
552 }
553
554 public Adapter1D adapter1DCreate() {
555 int id = nAdapter1DCreate();
556 return new Adapter1D(id);
557 }
558
559
560 //////////////////////////////////////////////////////////////////////////////////
561 // Triangle Mesh
562
563 public class TriangleMesh extends BaseObj {
564 TriangleMesh(int id) {
565 mID = id;
566 }
567
568 public void destroy() {
569 nTriangleMeshDestroy(mID);
570 mID = 0;
571 }
572 }
573
574 public void triangleMeshBegin(Element vertex, Element index) {
575 nTriangleMeshBegin(vertex.mID, index.mID);
576 }
577
578 public void triangleMeshAddVertex_XY(float x, float y) {
579 nTriangleMeshAddVertex_XY(x, y);
580 }
581
582 public void triangleMeshAddVertex_XYZ(float x, float y, float z) {
583 nTriangleMeshAddVertex_XYZ(x, y, z);
584 }
585
586 public void triangleMeshAddVertex_XY_ST(float x, float y, float s, float t) {
587 nTriangleMeshAddVertex_XY_ST(x, y, s, t);
588 }
589
590 public void triangleMeshAddVertex_XYZ_ST(float x, float y, float z, float s, float t) {
591 nTriangleMeshAddVertex_XYZ_ST(x, y, z, s, t);
592 }
593
594 public void triangleMeshAddTriangle(int i1, int i2, int i3) {
595 nTriangleMeshAddTriangle(i1, i2, i3);
596 }
597
598 public TriangleMesh triangleMeshCreate() {
599 int id = nTriangleMeshCreate();
600 return new TriangleMesh(id);
601 }
602
603 //////////////////////////////////////////////////////////////////////////////////
604 // Script
605
606 public class Script extends BaseObj {
607 Script(int id) {
608 mID = id;
609 }
610
611 public void destroy() {
612 nScriptDestroy(mID);
613 mID = 0;
614 }
615
616 public void bindAllocation(Allocation va, int slot) {
617 nScriptBindAllocation(mID, va.mID, slot);
618 }
619 }
620
621 public void scriptCBegin() {
622 nScriptCBegin();
623 }
624
625 public void scriptCSetClearColor(float r, float g, float b, float a) {
626 nScriptCSetClearColor(r, g, b, a);
627 }
628
629 public void scriptCSetClearDepth(float d) {
630 nScriptCSetClearDepth(d);
631 }
632
633 public void scriptCSetClearStencil(int stencil) {
634 nScriptCSetClearStencil(stencil);
635 }
636
637 public void scriptCAddType(Type t) {
638 nScriptCAddType(t.mID);
639 }
640
641 public void scriptCSetRoot(boolean r) {
642 nScriptCSetRoot(r);
643 }
644
645 public void scriptCSetScript(String s) {
Jack Palevich43702d82009-05-28 13:38:16 -0700646 try {
Jack Palevich63975dd2009-05-28 15:34:15 -0700647 byte[] bytes = s.getBytes("UTF-8");
648 nScriptCSetScript(bytes, 0, bytes.length);
Jack Palevich43702d82009-05-28 13:38:16 -0700649 } catch (java.io.UnsupportedEncodingException e) {
650 throw new RuntimeException(e);
651 }
652 }
653
Jack Palevich43702d82009-05-28 13:38:16 -0700654 public void scriptCSetScript(Resources resources, int id) {
655 InputStream is = resources.openRawResource(id);
656 try {
657 try {
658 scriptCSetScript(is);
659 } finally {
660 is.close();
661 }
662 } catch(IOException e) {
663 throw new Resources.NotFoundException();
664 }
665 }
666
667 public void scriptCSetScript(InputStream is) throws IOException {
668 byte[] buf = new byte[1024];
669 int currentPos = 0;
670 while(true) {
671 int bytesLeft = buf.length - currentPos;
672 if (bytesLeft == 0) {
673 byte[] buf2 = new byte[buf.length * 2];
674 System.arraycopy(buf, 0, buf2, 0, buf.length);
675 buf = buf2;
676 bytesLeft = buf.length - currentPos;
677 }
678 int bytesRead = is.read(buf, currentPos, bytesLeft);
679 if (bytesRead <= 0) {
680 break;
681 }
682 currentPos += bytesRead;
683 }
684 nScriptCSetScript(buf, 0, currentPos);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700685 }
686
687 public Script scriptCCreate() {
688 int id = nScriptCCreate();
689 return new Script(id);
690 }
691
692 //////////////////////////////////////////////////////////////////////////////////
693 // ProgramFragmentStore
694
695 public class ProgramFragmentStore extends BaseObj {
696 ProgramFragmentStore(int id) {
697 mID = id;
698 }
699
700 public void destroy() {
701 nScriptDestroy(mID);
702 mID = 0;
703 }
704 }
705
706 public void programFragmentStoreBegin(Element in, Element out) {
707 int inID = 0;
708 int outID = 0;
709 if (in != null) {
710 inID = in.mID;
711 }
712 if (out != null) {
713 outID = out.mID;
714 }
715 nProgramFragmentStoreBegin(inID, outID);
716 }
717
718 public void programFragmentStoreDepthFunc(DepthFunc func) {
719 nProgramFragmentStoreDepthFunc(func.mID);
720 }
721
722 public void programFragmentStoreDepthMask(boolean enable) {
723 nProgramFragmentStoreDepthMask(enable);
724 }
725
726 public void programFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
727 nProgramFragmentStoreColorMask(r,g,b,a);
728 }
729
730 public void programFragmentStoreBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
731 nProgramFragmentStoreBlendFunc(src.mID, dst.mID);
732 }
733
734 public void programFragmentStoreDitherEnable(boolean enable) {
735 nProgramFragmentStoreDither(enable);
736 }
737
738 public ProgramFragmentStore programFragmentStoreCreate() {
739 int id = nProgramFragmentStoreCreate();
740 return new ProgramFragmentStore(id);
741 }
742
743 //////////////////////////////////////////////////////////////////////////////////
744 // ProgramFragment
745
746 public class ProgramFragment extends BaseObj {
747 ProgramFragment(int id) {
748 mID = id;
749 }
750
751 public void destroy() {
752 nScriptDestroy(mID);
753 mID = 0;
754 }
755
756 public void bindTexture(Allocation va, int slot) {
757 nProgramFragmentBindTexture(mID, slot, va.mID);
758 }
759
Jason Sams02fb2cb2009-05-28 15:37:57 -0700760 public void bindSampler(Sampler vs, int slot) {
761 nProgramFragmentBindSampler(mID, slot, vs.mID);
762 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700763 }
764
765 public void programFragmentBegin(Element in, Element out) {
766 int inID = 0;
767 int outID = 0;
768 if (in != null) {
769 inID = in.mID;
770 }
771 if (out != null) {
772 outID = out.mID;
773 }
774 nProgramFragmentBegin(inID, outID);
775 }
776
777 public void programFragmentSetType(int slot, Type t) {
778 nProgramFragmentSetType(slot, t.mID);
779 }
780
781 public void programFragmentSetType(int slot, EnvMode t) {
782 nProgramFragmentSetEnvMode(slot, t.mID);
783 }
784
785 public void programFragmentSetTexEnable(int slot, boolean enable) {
786 nProgramFragmentSetTexEnable(slot, enable);
787 }
788
789 public ProgramFragment programFragmentCreate() {
790 int id = nProgramFragmentCreate();
791 return new ProgramFragment(id);
792 }
793
Jason Sams02fb2cb2009-05-28 15:37:57 -0700794 //////////////////////////////////////////////////////////////////////////////////
795 // Sampler
796
797 public class Sampler extends BaseObj {
798 Sampler(int id) {
799 mID = id;
800 }
801
802 public void destroy() {
803 nSamplerDestroy(mID);
804 mID = 0;
805 }
806 }
807
808 public void samplerBegin() {
809 nSamplerBegin();
810 }
811
812 public void samplerSet(SamplerParam p, SamplerValue v) {
813 nSamplerSet(p.mID, v.mID);
814 }
815
816 public Sampler samplerCreate() {
817 int id = nSamplerCreate();
818 return new Sampler(id);
819 }
820
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700821
822 ///////////////////////////////////////////////////////////////////////////////////
823 // Root state
824
825 public void contextBindRootScript(Script s) {
826 nContextBindRootScript(s.mID);
827 }
828
829 //public void contextBindSampler(Sampler s, int slot) {
830 //nContextBindSampler(s.mID);
831 //}
832
833 public void contextBindProgramFragmentStore(ProgramFragmentStore pfs) {
834 nContextBindProgramFragmentStore(pfs.mID);
835 }
836
837 public void contextBindProgramFragment(ProgramFragment pf) {
838 nContextBindProgramFragment(pf.mID);
839 }
840
841/*
842 RsAdapter2D rsAdapter2DCreate ();
843 void rsAdapter2DBindAllocation (RsAdapter2D adapt, RsAllocation alloc);
844 void rsAdapter2DDestroy (RsAdapter2D adapter);
845 void rsAdapter2DSetConstraint (RsAdapter2D adapter, RsDimension dim, uint32_t value);
846 void rsAdapter2DData (RsAdapter2D adapter, const void * data);
847 void rsAdapter2DSubData (RsAdapter2D adapter, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void * data);
848 void rsSamplerBegin ();
849 void rsSamplerSet (RsSamplerParam p, RsSamplerValue value);
850 RsSampler rsSamplerCreate ();
851 void rsSamplerBind (RsSampler sampler, RsAllocation alloc);
852*/
853
854}
855