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 Hoford
175b539461dcc159bd89297443780d635ccc5e3564John Hofordpackage com.example.android.rs.vr.engine;
185b539461dcc159bd89297443780d635ccc5e3564John Hoford
195b539461dcc159bd89297443780d635ccc5e3564John Hofordimport android.util.Log;
205b539461dcc159bd89297443780d635ccc5e3564John Hoford
215b539461dcc159bd89297443780d635ccc5e3564John Hoford/**
225b539461dcc159bd89297443780d635ccc5e3564John Hoford * Base implementation of a rendering pipeline Simply renders a box
235b539461dcc159bd89297443780d635ccc5e3564John Hoford */
245b539461dcc159bd89297443780d635ccc5e3564John Hofordpublic class BasicPipeline implements Pipeline {
255b539461dcc159bd89297443780d635ccc5e3564John Hoford    boolean mCancel = false;
265b539461dcc159bd89297443780d635ccc5e3564John Hoford    private static final String LOGTAG = "BasicPipeline";
275b539461dcc159bd89297443780d635ccc5e3564John Hoford    ScriptC_rasterize scriptC_rasterize;
285b539461dcc159bd89297443780d635ccc5e3564John Hoford
295b539461dcc159bd89297443780d635ccc5e3564John Hoford    @Override
305b539461dcc159bd89297443780d635ccc5e3564John Hoford    public void cancel() {
315b539461dcc159bd89297443780d635ccc5e3564John Hoford        mCancel = true;
325b539461dcc159bd89297443780d635ccc5e3564John Hoford    }
335b539461dcc159bd89297443780d635ccc5e3564John Hoford
345b539461dcc159bd89297443780d635ccc5e3564John Hoford    @Override
355b539461dcc159bd89297443780d635ccc5e3564John Hoford    public boolean isCancel() {
365b539461dcc159bd89297443780d635ccc5e3564John Hoford        return mCancel;
375b539461dcc159bd89297443780d635ccc5e3564John Hoford    }
385b539461dcc159bd89297443780d635ccc5e3564John Hoford
395b539461dcc159bd89297443780d635ccc5e3564John Hoford    @Override
405b539461dcc159bd89297443780d635ccc5e3564John Hoford    public void initBuffers(VrState state) {
415b539461dcc159bd89297443780d635ccc5e3564John Hoford        mCancel = false;
425b539461dcc159bd89297443780d635ccc5e3564John Hoford    }
435b539461dcc159bd89297443780d635ccc5e3564John Hoford
445b539461dcc159bd89297443780d635ccc5e3564John Hoford    @Override
455b539461dcc159bd89297443780d635ccc5e3564John Hoford    public void setupTriangles(VrState state) {
465b539461dcc159bd89297443780d635ccc5e3564John Hoford        Matrix m = state.mTransform.getMatrix(Transform.VOLUME_SPACE, Transform.SCREEN_SPACE);
475b539461dcc159bd89297443780d635ccc5e3564John Hoford        state.mCubeVolume.transform(m, state.mCubeScreen);
485b539461dcc159bd89297443780d635ccc5e3564John Hoford    }
495b539461dcc159bd89297443780d635ccc5e3564John Hoford
505b539461dcc159bd89297443780d635ccc5e3564John Hoford    @Override
515b539461dcc159bd89297443780d635ccc5e3564John Hoford    public void rasterizeTriangles(VrState state) {
525b539461dcc159bd89297443780d635ccc5e3564John Hoford        if (scriptC_rasterize == null) {
535b539461dcc159bd89297443780d635ccc5e3564John Hoford            scriptC_rasterize = new ScriptC_rasterize(state.mRs);
545b539461dcc159bd89297443780d635ccc5e3564John Hoford        }
555b539461dcc159bd89297443780d635ccc5e3564John Hoford        scriptC_rasterize.set_index(state.mCubeScreen.mIndex);
565b539461dcc159bd89297443780d635ccc5e3564John Hoford        scriptC_rasterize.set_vert(state.mCubeScreen.mVert);
575b539461dcc159bd89297443780d635ccc5e3564John Hoford        long start = System.nanoTime();
585b539461dcc159bd89297443780d635ccc5e3564John Hoford        scriptC_rasterize.invoke_setup_triangles(state.mImgWidth, state.mImgHeight);
595b539461dcc159bd89297443780d635ccc5e3564John Hoford        if (mCancel) return;
605b539461dcc159bd89297443780d635ccc5e3564John Hoford        scriptC_rasterize.forEach_render_z(state.mzRangeFullAllocation);
615b539461dcc159bd89297443780d635ccc5e3564John Hoford        state.mRs.finish();
625b539461dcc159bd89297443780d635ccc5e3564John Hoford        Log.v(LOGTAG,"render triangles "+((System.nanoTime()-start)/1E6f)+" ms");
635b539461dcc159bd89297443780d635ccc5e3564John Hoford    }
645b539461dcc159bd89297443780d635ccc5e3564John Hoford
655b539461dcc159bd89297443780d635ccc5e3564John Hoford    @Override
665b539461dcc159bd89297443780d635ccc5e3564John Hoford    public void raycast(VrState state) {
675b539461dcc159bd89297443780d635ccc5e3564John Hoford        scriptC_rasterize.set_z_range_buff(state.mzRangeFullAllocation);
685b539461dcc159bd89297443780d635ccc5e3564John Hoford        scriptC_rasterize.forEach_draw_z_buffer(state.mzRangeFullAllocation, state.mScrAllocation);
695b539461dcc159bd89297443780d635ccc5e3564John Hoford    }
705b539461dcc159bd89297443780d635ccc5e3564John Hoford}
71