FileDocCategorySizeDatePackage
TorusTest.javaAPI DocAndroid 5.1 API11830Thu Mar 12 22:22:44 GMT 2015com.android.perftest

TorusTest

public class TorusTest extends Object implements RsBenchBaseTest

Fields Summary
private static final String
TAG
private RenderScriptGL
mRS
private android.content.res.Resources
mRes
private ProgramStore
mProgStoreBlendNoneDepth
private ProgramStore
mProgStoreBlendNone
private ProgramStore
mProgStoreBlendAlpha
private ProgramFragment
mProgFragmentTexture
private ProgramFragment
mProgFragmentColor
private ProgramVertex
mProgVertex
private ProgramVertexFixedFunction.Constants
mPVA
private ProgramVertexFixedFunction.Constants
mPvProjectionAlloc
private ProgramVertex
mProgVertexCustom
private ProgramFragment
mProgFragmentCustom
private ProgramFragment
mProgFragmentMultitex
private ProgramVertex
mProgVertexPixelLight
private ProgramVertex
mProgVertexPixelLightMove
private ProgramFragment
mProgFragmentPixelLight
private ScriptField_VertexShaderConstants_s
mVSConst
private ScriptField_FragentShaderConstants_s
mFSConst
private ScriptField_VertexShaderConstants3_s
mVSConstPixel
private ScriptField_FragentShaderConstants3_s
mFSConstPixel
private Allocation
mTexTorus
private Mesh
mTorus
private ScriptC_torus_test
mTorusScript
private final BitmapFactory.Options
mOptionsARGB
ScriptField_TestScripts_s.Item[]
mTests
private final String[]
mNames
Constructors Summary
public TorusTest()


      
    
Methods Summary
voidaddTest(int index, int testId, int user1, int user2)

        mTests[index] = new ScriptField_TestScripts_s.Item();
        mTests[index].testScript = mTorusScript;
        mTests[index].testName = Allocation.createFromString(mRS,
                                                             mNames[index],
                                                             Allocation.USAGE_SCRIPT);
        mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
                                                                      mNames[index],
                                                                      Allocation.USAGE_SCRIPT);

        ScriptField_TorusTestData_s.Item dataItem = new ScriptField_TorusTestData_s.Item();
        dataItem.testId = testId;
        dataItem.user1 = user1;
        dataItem.user2 = user2;
        ScriptField_TorusTestData_s testData = new ScriptField_TorusTestData_s(mRS, 1);
        testData.set(dataItem, 0, true);
        mTests[index].testData = testData.getAllocation();
    
public java.lang.String[]getTestNames()

        return mNames;
    
public ScriptField_TestScripts_s.Item[]getTests()

        return mTests;
    
public booleaninit(RenderScriptGL rs, android.content.res.Resources res)

        mRS = rs;
        mRes = res;
        initCustomShaders();
        loadImages();
        initMesh();
        initTorusScript();
        mTests = new ScriptField_TestScripts_s.Item[mNames.length];

        int index = 0;
        addTest(index++, 0, 0 /*useTexture*/, 1 /*numMeshes*/);
        addTest(index++, 0, 0 /*useTexture*/, 2 /*numMeshes*/);
        addTest(index++, 0, 0 /*useTexture*/, 8 /*numMeshes*/);
        addTest(index++, 0, 1 /*useTexture*/, 1 /*numMeshes*/);
        addTest(index++, 0, 1 /*useTexture*/, 2 /*numMeshes*/);
        addTest(index++, 0, 1 /*useTexture*/, 8 /*numMeshes*/);

        // Secont test
        addTest(index++, 1, 1 /*numMeshes*/, 0 /*unused*/);
        addTest(index++, 1, 2 /*numMeshes*/, 0 /*unused*/);
        addTest(index++, 1, 8 /*numMeshes*/, 0 /*unused*/);

        // Third test
        addTest(index++, 2, 1 /*numMeshes*/, 0 /*heavyVertex*/);
        addTest(index++, 2, 2 /*numMeshes*/, 0 /*heavyVertex*/);
        addTest(index++, 2, 8 /*numMeshes*/, 0 /*heavyVertex*/);
        addTest(index++, 2, 1 /*numMeshes*/, 1 /*heavyVertex*/);
        addTest(index++, 2, 2 /*numMeshes*/, 1 /*heavyVertex*/);
        addTest(index++, 2, 8 /*numMeshes*/, 1 /*heavyVertex*/);

        return true;
    
private voidinitCustomShaders()

        mVSConst = new ScriptField_VertexShaderConstants_s(mRS, 1);
        mFSConst = new ScriptField_FragentShaderConstants_s(mRS, 1);

        mVSConstPixel = new ScriptField_VertexShaderConstants3_s(mRS, 1);
        mFSConstPixel = new ScriptField_FragentShaderConstants3_s(mRS, 1);

        // Initialize the shader builder
        ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS);
        // Specify the resource that contains the shader string
        pvbCustom.setShader(mRes, R.raw.shaderv);
        // Use a script field to specify the input layout
        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
        // Define the constant input layout
        pvbCustom.addConstant(mVSConst.getAllocation().getType());
        mProgVertexCustom = pvbCustom.create();
        // Bind the source of constant data
        mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0);

        ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS);
        // Specify the resource that contains the shader string
        pfbCustom.setShader(mRes, R.raw.shaderf);
        // Tell the builder how many textures we have
        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
        // Define the constant input layout
        pfbCustom.addConstant(mFSConst.getAllocation().getType());
        mProgFragmentCustom = pfbCustom.create();
        // Bind the source of constant data
        mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0);

        pvbCustom = new ProgramVertex.Builder(mRS);
        pvbCustom.setShader(mRes, R.raw.shader2v);
        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
        pvbCustom.addConstant(mVSConstPixel.getAllocation().getType());
        mProgVertexPixelLight = pvbCustom.create();
        mProgVertexPixelLight.bindConstants(mVSConstPixel.getAllocation(), 0);

        pvbCustom = new ProgramVertex.Builder(mRS);
        pvbCustom.setShader(mRes, R.raw.shader2movev);
        pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
        pvbCustom.addConstant(mVSConstPixel.getAllocation().getType());
        mProgVertexPixelLightMove = pvbCustom.create();
        mProgVertexPixelLightMove.bindConstants(mVSConstPixel.getAllocation(), 0);

        pfbCustom = new ProgramFragment.Builder(mRS);
        pfbCustom.setShader(mRes, R.raw.shader2f);
        pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
        pfbCustom.addConstant(mFSConstPixel.getAllocation().getType());
        mProgFragmentPixelLight = pfbCustom.create();
        mProgFragmentPixelLight.bindConstants(mFSConstPixel.getAllocation(), 0);

        pfbCustom = new ProgramFragment.Builder(mRS);
        pfbCustom.setShader(mRes, R.raw.multitexf);
        for (int texCount = 0; texCount < 3; texCount ++) {
            pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
        }
        mProgFragmentMultitex = pfbCustom.create();

        ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
        colBuilder.setVaryingColor(false);
        mProgFragmentColor = colBuilder.create();

        ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
        texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
                              ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
        mProgFragmentTexture = texBuilder.create();

        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
        mProgVertex = pvb.create();
        ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
        ((ProgramVertexFixedFunction)mProgVertex).bindConstants(PVA);
        Matrix4f proj = new Matrix4f();
        proj.loadOrthoWindow(1280, 720);
        PVA.setProjection(proj);
    
private voidinitMesh()

        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
        FileA3D.IndexEntry entry = model.getIndexEntry(0);
        if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) {
            Log.e("rs", "could not load model");
        } else {
            mTorus = (Mesh)entry.getObject();
        }
    
voidinitTorusScript()

        mTorusScript = new ScriptC_torus_test(mRS, mRes, R.raw.torus_test);
        mTorusScript.set_gCullFront(ProgramRaster.CULL_FRONT(mRS));
        mTorusScript.set_gCullBack(ProgramRaster.CULL_BACK(mRS));
        mTorusScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
        mTorusScript.set_gTorusMesh(mTorus);
        mTorusScript.set_gTexTorus(mTexTorus);
        mTorusScript.set_gProgVertexCustom(mProgVertexCustom);
        mTorusScript.set_gProgFragmentCustom(mProgFragmentCustom);
        mTorusScript.set_gProgVertexPixelLight(mProgVertexPixelLight);
        mTorusScript.set_gProgVertexPixelLightMove(mProgVertexPixelLightMove);
        mTorusScript.set_gProgFragmentPixelLight(mProgFragmentPixelLight);
        mTorusScript.bind_gVSConstPixel(mVSConstPixel);
        mTorusScript.bind_gFSConstPixel(mFSConstPixel);
        mTorusScript.bind_gVSConstants(mVSConst);
        mTorusScript.bind_gFSConstants(mFSConst);
        mTorusScript.set_gProgVertex(mProgVertex);
        mTorusScript.set_gProgFragmentTexture(mProgFragmentTexture);
        mTorusScript.set_gProgFragmentColor(mProgFragmentColor);
        mTorusScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth);
    
private voidloadImages()

        mTexTorus = loadTextureRGB(R.drawable.torusmap);
    
private AllocationloadTextureRGB(int id)

        return Allocation.createFromBitmapResource(mRS, mRes, id,
                Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
                Allocation.USAGE_GRAPHICS_TEXTURE);