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