• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 package com.example.android.rs.vr.engine;
17 
18 import android.renderscript.Allocation;
19 import android.renderscript.RenderScript;
20 import android.renderscript.Type;
21 import android.util.Log;
22 
23 /**
24  * create bricked binary representation of the non transparent voxels
25  */
26 public class RsBrickedBitMask {
27     private static final String LOGTAG = "BrickedBitMask";
28     ScriptC_bricked scriptC_bricked;
29 
30     int mDimX;
31     int mDimY;
32     int mDimZ;
33     int m_bricks_dimx;
34     int m_bricks_dimy;
35     int m_bricks_dimz;
36     Volume mVolume;
37     int mBrickCnt = 0;
38 
39     Allocation mBrick_allocation;
40 
41     public final static int BSIZE = 32;
42 
43     public static final byte TYPE_BYTE = 1;
44     public static final byte TYPE_SHORT = 1;
45     public static final byte TYPE_INT = 2;
46 
RsBrickedBitMask(VrState state)47     public RsBrickedBitMask(VrState state) {
48 
49         mVolume = state.mVolume;
50         mDimX = mVolume.mDimx;
51         mDimY = mVolume.mDimy;
52         mDimZ = mVolume.mDimz;
53         m_bricks_dimx = (mDimX + 31) / 32;
54         m_bricks_dimy = (mDimY + 31) / 32;
55         m_bricks_dimz = (mDimZ + 31) / 32;
56         int maxBrick = m_bricks_dimx * m_bricks_dimy * m_bricks_dimz;
57         int size = maxBrick * 32 * 32; // divide by 4 because we will try U32_4
58 
59         Type.Builder b = new Type.Builder(state.mRs, android.renderscript.Element.U32(state.mRs));
60         b.setX(size);
61         mBrick_allocation = Allocation.createTyped(state.mRs, b.create(), Allocation.USAGE_SCRIPT);
62 
63         scriptC_bricked = new ScriptC_bricked(state.mRs);
64 
65         scriptC_bricked.set_volume(mVolume.mVolumeAllocation);
66         scriptC_bricked.set_brick_dimx(m_bricks_dimx);
67         scriptC_bricked.set_brick_dimy(m_bricks_dimy);
68         scriptC_bricked.set_brick_dimz(m_bricks_dimz);
69         scriptC_bricked.set_opacity(state.mMaterial.getOpacityAllocation(state.mRs));
70         state.mRs.finish();
71 
72         scriptC_bricked.forEach_pack_chunk(mBrick_allocation);
73 
74         Allocation tmp = Allocation.createTyped(state.mRs, b.create(), Allocation.USAGE_SCRIPT);
75         scriptC_bricked.set_bricks(mBrick_allocation);
76         scriptC_bricked.forEach_dilate(mBrick_allocation, tmp);
77 
78         mBrick_allocation.destroy();
79         mBrick_allocation = tmp;
80     }
81 
createChunkAllocation(RenderScript rs)82     Allocation createChunkAllocation(RenderScript rs) {
83         Type.Builder b = new Type.Builder(rs, android.renderscript.Element.U32(rs));
84         b.setX(mDimX / 8);
85         b.setY(mDimY);
86         b.setZ(32);
87         return Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT);
88     }
89 
createBitChunkAllocation(RenderScript rs)90     Allocation createBitChunkAllocation(RenderScript rs) {
91         Type.Builder b = new Type.Builder(rs, android.renderscript.Element.U8(rs));
92         b.setX(mDimX / 8);
93         b.setY(mDimY);
94         b.setZ(32);
95         return Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT);
96     }
97 }
98