FileDocCategorySizeDatePackage
MeshTest.javaAPI DocAndroid 5.1 API6480Thu Mar 12 22:22:44 GMT 2015com.android.perftest

MeshTest

public class MeshTest extends Object implements RsBenchBaseTest

Fields Summary
private static final String
TAG
private RenderScriptGL
mRS
private android.content.res.Resources
mRes
int
mBenchmarkDimX
int
mBenchmarkDimY
private Mesh
m10by10Mesh
private Mesh
m100by100Mesh
private Mesh
mWbyHMesh
private ScriptC_mesh_test
mGeoScript
private final BitmapFactory.Options
mOptionsARGB
ScriptField_TestScripts_s.Item[]
mTests
private final String[]
mNames
Constructors Summary
public MeshTest()


      
        mBenchmarkDimX = 1280;
        mBenchmarkDimY = 720;
    
Methods Summary
voidaddTest(int index, int meshNum)

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

        ScriptField_MeshTestData_s.Item dataItem = new ScriptField_MeshTestData_s.Item();
        dataItem.meshNum = meshNum;
        ScriptField_MeshTestData_s testData = new ScriptField_MeshTestData_s(mRS, 1);
        testData.set(dataItem, 0, true);
        mTests[index].testData = testData.getAllocation();
    
private MeshgetMbyNMesh(float width, float height, int wResolution, int hResolution)


        Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
                                           2, Mesh.TriangleMeshBuilder.TEXTURE_0);

        for (int y = 0; y <= hResolution; y++) {
            final float normalizedY = (float)y / hResolution;
            final float yOffset = (normalizedY - 0.5f) * height;
            for (int x = 0; x <= wResolution; x++) {
                float normalizedX = (float)x / wResolution;
                float xOffset = (normalizedX - 0.5f) * width;
                tmb.setTexture((float)x % 2, (float)y % 2);
                tmb.addVertex(xOffset, yOffset);
             }
        }

        for (int y = 0; y < hResolution; y++) {
            final int curY = y * (wResolution + 1);
            final int belowY = (y + 1) * (wResolution + 1);
            for (int x = 0; x < wResolution; x++) {
                int curV = curY + x;
                int belowV = belowY + x;
                tmb.addTriangle(curV, belowV, curV + 1);
                tmb.addTriangle(belowV, belowV + 1, curV + 1);
            }
        }

        return tmb.create(true);
    
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;
        initGeoScript();
        mTests = new ScriptField_TestScripts_s.Item[mNames.length];

        int index = 0;
        addTest(index++, 0 /*meshNum*/);
        addTest(index++, 1 /*meshNum*/);
        addTest(index++, 2 /*meshNum*/);

        return true;
    
voidinitGeoScript()

        mGeoScript = new ScriptC_mesh_test(mRS, mRes, R.raw.mesh_test);

        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
        ProgramVertexFixedFunction progVertex = pvb.create();
        ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
        ((ProgramVertexFixedFunction)progVertex).bindConstants(PVA);
        Matrix4f proj = new Matrix4f();
        proj.loadOrthoWindow(mBenchmarkDimX, mBenchmarkDimY);
        PVA.setProjection(proj);

        mGeoScript.set_gProgVertex(progVertex);
        ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
        texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
                              ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
        mGeoScript.set_gProgFragmentTexture(texBuilder.create());
        mGeoScript.set_gProgStoreBlendNone(ProgramStore.BLEND_NONE_DEPTH_NONE(mRS));

        mGeoScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
        mGeoScript.set_gTexOpaque(loadTextureRGB(R.drawable.data));

        m10by10Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 10, 10);
        m100by100Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 100, 100);
        mWbyHMesh= getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, mBenchmarkDimX/4, mBenchmarkDimY/4);

        mGeoScript.set_g10by10Mesh(m10by10Mesh);
        mGeoScript.set_g100by100Mesh(m100by100Mesh);
        mGeoScript.set_gWbyHMesh(mWbyHMesh);
    
private AllocationloadTextureRGB(int id)

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