Home | History | Annotate | Download | only in engine
      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 
     17 package com.example.android.rs.vr.engine;
     18 
     19 import android.util.Log;
     20 
     21 /**
     22  * Base implementation of a rendering pipeline Simply renders a box
     23  */
     24 public class BasicPipeline implements Pipeline {
     25     boolean mCancel = false;
     26     private static final String LOGTAG = "BasicPipeline";
     27     ScriptC_rasterize scriptC_rasterize;
     28 
     29     @Override
     30     public void cancel() {
     31         mCancel = true;
     32     }
     33 
     34     @Override
     35     public boolean isCancel() {
     36         return mCancel;
     37     }
     38 
     39     @Override
     40     public void initBuffers(VrState state) {
     41         mCancel = false;
     42     }
     43 
     44     @Override
     45     public void setupTriangles(VrState state) {
     46         Matrix m = state.mTransform.getMatrix(Transform.VOLUME_SPACE, Transform.SCREEN_SPACE);
     47         state.mCubeVolume.transform(m, state.mCubeScreen);
     48     }
     49 
     50     @Override
     51     public void rasterizeTriangles(VrState state) {
     52         if (scriptC_rasterize == null) {
     53             scriptC_rasterize = new ScriptC_rasterize(state.mRs);
     54         }
     55         scriptC_rasterize.set_index(state.mCubeScreen.mIndex);
     56         scriptC_rasterize.set_vert(state.mCubeScreen.mVert);
     57         long start = System.nanoTime();
     58         scriptC_rasterize.invoke_setup_triangles(state.mImgWidth, state.mImgHeight);
     59         if (mCancel) return;
     60         scriptC_rasterize.forEach_render_z(state.mzRangeFullAllocation);
     61         state.mRs.finish();
     62         Log.v(LOGTAG,"render triangles "+((System.nanoTime()-start)/1E6f)+" ms");
     63     }
     64 
     65     @Override
     66     public void raycast(VrState state) {
     67         scriptC_rasterize.set_z_range_buff(state.mzRangeFullAllocation);
     68         scriptC_rasterize.forEach_draw_z_buffer(state.mzRangeFullAllocation, state.mScrAllocation);
     69     }
     70 }
     71