FileDocCategorySizeDatePackage
FBOSyncRS.javaAPI DocAndroid 5.1 API7120Thu Mar 12 22:22:44 GMT 2015com.android.fbotest

FBOSyncRS

public class FBOSyncRS extends Object

Fields Summary
private android.content.res.Resources
mRes
private RenderScriptGL
mRS
private Sampler
mSampler
private ProgramStore
mPSBackground
private ProgramFragment
mPFBackground
private ProgramVertex
mPVBackground
private ProgramVertexFixedFunction.Constants
mPVA
private Allocation
mGridImage
private Allocation
mOffscreen
private Allocation
mOffscreenDepth
private Allocation
mAllocPV
private Allocation
mReadBackTest
private Font
mItalic
private Allocation
mTextAlloc
private ScriptField_MeshInfo
mMeshes
private ScriptC_fbosync
mScript
Constructors Summary
public FBOSyncRS()

    
Methods Summary
public voidinit(RenderScriptGL rs, android.content.res.Resources res)

        mRS = rs;
        mRes = res;
        initRS();
    
private voidinitMeshes(FileA3D model)

        int numEntries = model.getIndexEntryCount();
        int numMeshes = 0;
        for (int i = 0; i < numEntries; i ++) {
            FileA3D.IndexEntry entry = model.getIndexEntry(i);
            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
                numMeshes ++;
            }
        }

        if (numMeshes > 0) {
            mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);

            for (int i = 0; i < numEntries; i ++) {
                FileA3D.IndexEntry entry = model.getIndexEntry(i);
                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
                    Mesh mesh = entry.getMesh();
                    mMeshes.set_mMesh(i, mesh, false);
                    mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
                }
            }
            mMeshes.copyAll();
        } else {
            throw new RSRuntimeException("No valid meshes in file");
        }

        mScript.bind_gMeshes(mMeshes);
        mScript.invoke_updateMeshInfo();
    
private voidinitPF()

        Sampler.Builder bs = new Sampler.Builder(mRS);
        bs.setMinification(Sampler.Value.LINEAR);
        bs.setMagnification(Sampler.Value.LINEAR);
        bs.setWrapS(Sampler.Value.CLAMP);
        bs.setWrapT(Sampler.Value.CLAMP);
        mSampler = bs.create();

        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
        mPFBackground = b.create();
        mPFBackground.bindSampler(mSampler, 0);

        mScript.set_gPFBackground(mPFBackground);
    
private voidinitPFS()

        ProgramStore.Builder b = new ProgramStore.Builder(mRS);

        b.setDepthFunc(ProgramStore.DepthFunc.LESS);
        b.setDitherEnabled(false);
        b.setDepthMaskEnabled(true);
        mPSBackground = b.create();

        mScript.set_gPFSBackground(mPSBackground);
    
private voidinitPV()

        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
        mPVBackground = pvb.create();

        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
        ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);

        mScript.set_gPVBackground(mPVBackground);
    
private voidinitRS()


        mScript = new ScriptC_fbosync(mRS, mRes, R.raw.fbosync);

        initPFS();
        initPF();
        initPV();

        loadImage();

        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
        b.setX(512).setY(512);
        mOffscreen = Allocation.createTyped(mRS,
                                            b.create(),
                                            Allocation.USAGE_SCRIPT |
                                            Allocation.USAGE_GRAPHICS_TEXTURE |
                                            Allocation.USAGE_GRAPHICS_RENDER_TARGET);
        mScript.set_gOffscreen(mOffscreen);

        mReadBackTest = Allocation.createTyped(mRS,
                                               b.create(),
                                               Allocation.USAGE_SCRIPT |
                                               Allocation.USAGE_GRAPHICS_TEXTURE);
        mScript.set_gReadBackTest(mReadBackTest);

        b = new Type.Builder(mRS,
                             Element.createPixel(mRS, DataType.UNSIGNED_16,
                             DataKind.PIXEL_DEPTH));
        b.setX(512).setY(512);
        mOffscreenDepth = Allocation.createTyped(mRS,
                                                 b.create(),
                                                 Allocation.USAGE_GRAPHICS_RENDER_TARGET);
        mScript.set_gOffscreenDepth(mOffscreenDepth);

        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
        initMeshes(model);

        mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
        mScript.set_gItalic(mItalic);

        initTextAllocation("R.raw.robot");

        mRS.bindRootScript(mScript);
    
private voidinitTextAllocation(java.lang.String fileName)

        String allocString = "Displaying file: " + fileName;
        mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
        mScript.set_gTextAlloc(mTextAlloc);
    
public voidloadA3DFile(java.lang.String path)

        FileA3D model = FileA3D.createFromFile(mRS, path);
        initMeshes(model);
        initTextAllocation(path);
    
private voidloadImage()

        mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
                                                         Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
                                                         Allocation.USAGE_GRAPHICS_TEXTURE);
        mScript.set_gTGrid(mGridImage);
    
public voidonActionDown(float x, float y)

        mScript.invoke_onActionDown(x, y);
    
public voidonActionMove(float x, float y)

        mScript.invoke_onActionMove(x, y);
    
public voidonActionScale(float scale)

        mScript.invoke_onActionScale(scale);
    
public voidsurfaceChanged()

        mRS.getWidth();
        mRS.getHeight();