15b539461dcc159bd89297443780d635ccc5e3564John Hoford/* 25b539461dcc159bd89297443780d635ccc5e3564John Hoford * Copyright (C) 2015 The Android Open Source Project 35b539461dcc159bd89297443780d635ccc5e3564John Hoford * 45b539461dcc159bd89297443780d635ccc5e3564John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 55b539461dcc159bd89297443780d635ccc5e3564John Hoford * you may not use this file except in compliance with the License. 65b539461dcc159bd89297443780d635ccc5e3564John Hoford * You may obtain a copy of the License at 75b539461dcc159bd89297443780d635ccc5e3564John Hoford * 85b539461dcc159bd89297443780d635ccc5e3564John Hoford * http://www.apache.org/licenses/LICENSE-2.0 95b539461dcc159bd89297443780d635ccc5e3564John Hoford * 105b539461dcc159bd89297443780d635ccc5e3564John Hoford * Unless required by applicable law or agreed to in writing, software 115b539461dcc159bd89297443780d635ccc5e3564John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 125b539461dcc159bd89297443780d635ccc5e3564John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135b539461dcc159bd89297443780d635ccc5e3564John Hoford * See the License for the specific language governing permissions and 145b539461dcc159bd89297443780d635ccc5e3564John Hoford * limitations under the License. 155b539461dcc159bd89297443780d635ccc5e3564John Hoford */ 165b539461dcc159bd89297443780d635ccc5e3564John Hofordpackage com.example.android.rs.vr.engine; 175b539461dcc159bd89297443780d635ccc5e3564John Hoford 185b539461dcc159bd89297443780d635ccc5e3564John Hofordimport android.renderscript.Allocation; 195b539461dcc159bd89297443780d635ccc5e3564John Hofordimport android.renderscript.RenderScript; 205b539461dcc159bd89297443780d635ccc5e3564John Hofordimport android.renderscript.Type; 215b539461dcc159bd89297443780d635ccc5e3564John Hofordimport android.util.Log; 225b539461dcc159bd89297443780d635ccc5e3564John Hoford 235b539461dcc159bd89297443780d635ccc5e3564John Hoford/** 245b539461dcc159bd89297443780d635ccc5e3564John Hoford * create bricked binary representation of the non transparent voxels 255b539461dcc159bd89297443780d635ccc5e3564John Hoford */ 265b539461dcc159bd89297443780d635ccc5e3564John Hofordpublic class RsBrickedBitMask { 275b539461dcc159bd89297443780d635ccc5e3564John Hoford private static final String LOGTAG = "BrickedBitMask"; 285b539461dcc159bd89297443780d635ccc5e3564John Hoford ScriptC_bricked scriptC_bricked; 295b539461dcc159bd89297443780d635ccc5e3564John Hoford 305b539461dcc159bd89297443780d635ccc5e3564John Hoford int mDimX; 315b539461dcc159bd89297443780d635ccc5e3564John Hoford int mDimY; 325b539461dcc159bd89297443780d635ccc5e3564John Hoford int mDimZ; 335b539461dcc159bd89297443780d635ccc5e3564John Hoford int m_bricks_dimx; 345b539461dcc159bd89297443780d635ccc5e3564John Hoford int m_bricks_dimy; 355b539461dcc159bd89297443780d635ccc5e3564John Hoford int m_bricks_dimz; 365b539461dcc159bd89297443780d635ccc5e3564John Hoford Volume mVolume; 375b539461dcc159bd89297443780d635ccc5e3564John Hoford int mBrickCnt = 0; 385b539461dcc159bd89297443780d635ccc5e3564John Hoford 395b539461dcc159bd89297443780d635ccc5e3564John Hoford Allocation mBrick_allocation; 405b539461dcc159bd89297443780d635ccc5e3564John Hoford 415b539461dcc159bd89297443780d635ccc5e3564John Hoford public final static int BSIZE = 32; 425b539461dcc159bd89297443780d635ccc5e3564John Hoford 435b539461dcc159bd89297443780d635ccc5e3564John Hoford public static final byte TYPE_BYTE = 1; 445b539461dcc159bd89297443780d635ccc5e3564John Hoford public static final byte TYPE_SHORT = 1; 455b539461dcc159bd89297443780d635ccc5e3564John Hoford public static final byte TYPE_INT = 2; 465b539461dcc159bd89297443780d635ccc5e3564John Hoford 475b539461dcc159bd89297443780d635ccc5e3564John Hoford public RsBrickedBitMask(VrState state) { 485b539461dcc159bd89297443780d635ccc5e3564John Hoford 495b539461dcc159bd89297443780d635ccc5e3564John Hoford mVolume = state.mVolume; 505b539461dcc159bd89297443780d635ccc5e3564John Hoford mDimX = mVolume.mDimx; 515b539461dcc159bd89297443780d635ccc5e3564John Hoford mDimY = mVolume.mDimy; 525b539461dcc159bd89297443780d635ccc5e3564John Hoford mDimZ = mVolume.mDimz; 535b539461dcc159bd89297443780d635ccc5e3564John Hoford m_bricks_dimx = (mDimX + 31) / 32; 545b539461dcc159bd89297443780d635ccc5e3564John Hoford m_bricks_dimy = (mDimY + 31) / 32; 555b539461dcc159bd89297443780d635ccc5e3564John Hoford m_bricks_dimz = (mDimZ + 31) / 32; 565b539461dcc159bd89297443780d635ccc5e3564John Hoford int maxBrick = m_bricks_dimx * m_bricks_dimy * m_bricks_dimz; 575b539461dcc159bd89297443780d635ccc5e3564John Hoford int size = maxBrick * 32 * 32; // divide by 4 because we will try U32_4 585b539461dcc159bd89297443780d635ccc5e3564John Hoford 595b539461dcc159bd89297443780d635ccc5e3564John Hoford Type.Builder b = new Type.Builder(state.mRs, android.renderscript.Element.U32(state.mRs)); 605b539461dcc159bd89297443780d635ccc5e3564John Hoford b.setX(size); 615b539461dcc159bd89297443780d635ccc5e3564John Hoford mBrick_allocation = Allocation.createTyped(state.mRs, b.create(), Allocation.USAGE_SCRIPT); 625b539461dcc159bd89297443780d635ccc5e3564John Hoford 635b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked = new ScriptC_bricked(state.mRs); 645b539461dcc159bd89297443780d635ccc5e3564John Hoford 655b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.set_volume(mVolume.mVolumeAllocation); 665b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.set_brick_dimx(m_bricks_dimx); 675b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.set_brick_dimy(m_bricks_dimy); 685b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.set_brick_dimz(m_bricks_dimz); 695b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.set_opacity(state.mMaterial.getOpacityAllocation(state.mRs)); 705b539461dcc159bd89297443780d635ccc5e3564John Hoford state.mRs.finish(); 715b539461dcc159bd89297443780d635ccc5e3564John Hoford 725b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.forEach_pack_chunk(mBrick_allocation); 735b539461dcc159bd89297443780d635ccc5e3564John Hoford 745b539461dcc159bd89297443780d635ccc5e3564John Hoford Allocation tmp = Allocation.createTyped(state.mRs, b.create(), Allocation.USAGE_SCRIPT); 755b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.set_bricks(mBrick_allocation); 765b539461dcc159bd89297443780d635ccc5e3564John Hoford scriptC_bricked.forEach_dilate(mBrick_allocation, tmp); 775b539461dcc159bd89297443780d635ccc5e3564John Hoford 785b539461dcc159bd89297443780d635ccc5e3564John Hoford mBrick_allocation.destroy(); 795b539461dcc159bd89297443780d635ccc5e3564John Hoford mBrick_allocation = tmp; 805b539461dcc159bd89297443780d635ccc5e3564John Hoford } 815b539461dcc159bd89297443780d635ccc5e3564John Hoford 825b539461dcc159bd89297443780d635ccc5e3564John Hoford Allocation createChunkAllocation(RenderScript rs) { 835b539461dcc159bd89297443780d635ccc5e3564John Hoford Type.Builder b = new Type.Builder(rs, android.renderscript.Element.U32(rs)); 845b539461dcc159bd89297443780d635ccc5e3564John Hoford b.setX(mDimX / 8); 855b539461dcc159bd89297443780d635ccc5e3564John Hoford b.setY(mDimY); 865b539461dcc159bd89297443780d635ccc5e3564John Hoford b.setZ(32); 875b539461dcc159bd89297443780d635ccc5e3564John Hoford return Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT); 885b539461dcc159bd89297443780d635ccc5e3564John Hoford } 895b539461dcc159bd89297443780d635ccc5e3564John Hoford 905b539461dcc159bd89297443780d635ccc5e3564John Hoford Allocation createBitChunkAllocation(RenderScript rs) { 915b539461dcc159bd89297443780d635ccc5e3564John Hoford Type.Builder b = new Type.Builder(rs, android.renderscript.Element.U8(rs)); 925b539461dcc159bd89297443780d635ccc5e3564John Hoford b.setX(mDimX / 8); 935b539461dcc159bd89297443780d635ccc5e3564John Hoford b.setY(mDimY); 945b539461dcc159bd89297443780d635ccc5e3564John Hoford b.setZ(32); 955b539461dcc159bd89297443780d635ccc5e3564John Hoford return Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT); 965b539461dcc159bd89297443780d635ccc5e3564John Hoford } 975b539461dcc159bd89297443780d635ccc5e3564John Hoford} 98