1/*
2 * Copyright (C) 2011 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
17package com.android.rs.test;
18
19import android.content.Context;
20import android.content.res.Resources;
21import android.renderscript.*;
22import android.renderscript.Mesh.*;
23
24public class UT_mesh extends UnitTest {
25    private Resources mRes;
26
27    Mesh mesh;
28
29    protected UT_mesh(RSTestCore rstc, Resources res, Context ctx) {
30        super(rstc, "Mesh", ctx);
31        mRes = res;
32    }
33
34    private void initializeGlobals(RenderScript RS, ScriptC_mesh s) {
35        Allocation vAlloc0 = Allocation.createSized(RS, Element.F32(RS), 10);
36        Allocation vAlloc1 = Allocation.createSized(RS, Element.F32_2(RS), 10);
37
38        Allocation iAlloc0 = Allocation.createSized(RS, Element.I16(RS), 10);
39        Allocation iAlloc2 = Allocation.createSized(RS, Element.I16(RS), 10);
40
41        Mesh.AllocationBuilder mBuilder = new Mesh.AllocationBuilder(RS);
42        mBuilder.addVertexAllocation(vAlloc0);
43        mBuilder.addVertexAllocation(vAlloc1);
44
45        mBuilder.addIndexSetAllocation(iAlloc0, Primitive.POINT);
46        mBuilder.addIndexSetType(Primitive.LINE);
47        mBuilder.addIndexSetAllocation(iAlloc2, Primitive.TRIANGLE);
48
49        s.set_mesh(mBuilder.create());
50        s.set_vertexAlloc0(vAlloc0);
51        s.set_vertexAlloc1(vAlloc1);
52        s.set_indexAlloc0(iAlloc0);
53        s.set_indexAlloc2(iAlloc2);
54    }
55
56    private void testScriptSide(RenderScript pRS) {
57        ScriptC_mesh s = new ScriptC_mesh(pRS);
58        pRS.setMessageHandler(mRsMessage);
59        initializeGlobals(pRS, s);
60        s.invoke_mesh_test();
61        pRS.finish();
62        waitForMessage();
63    }
64
65    private void testJavaSide(RenderScript RS) {
66    }
67
68    public void run() {
69        RenderScript pRS = RenderScript.create(mCtx);
70        testScriptSide(pRS);
71        testJavaSide(pRS);
72        passTest();
73        pRS.destroy();
74    }
75}
76