Home | History | Annotate | Download | only in renderscript
      1 /*
      2  * Copyright (C) 2008 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 android.renderscript;
     18 
     19 
     20 import android.util.Log;
     21 
     22 
     23 /**
     24  * Program raster is primarily used to specify whether point sprites are enabled and to control
     25  * the culling mode. By default, back faces are culled.
     26  **/
     27 public class ProgramRaster extends BaseObj {
     28 
     29     public enum CullMode {
     30         BACK (0),
     31         FRONT (1),
     32         NONE (2);
     33 
     34         int mID;
     35         CullMode(int id) {
     36             mID = id;
     37         }
     38     }
     39 
     40     boolean mPointSprite;
     41     CullMode mCullMode;
     42 
     43     ProgramRaster(int id, RenderScript rs) {
     44         super(id, rs);
     45 
     46         mPointSprite = false;
     47         mCullMode = CullMode.BACK;
     48     }
     49 
     50     /**
     51      * @hide
     52      * @return whether point sprites are enabled
     53      */
     54     public boolean getPointSpriteEnabled() {
     55         return mPointSprite;
     56     }
     57 
     58     /**
     59      * @hide
     60      * @return cull mode
     61      */
     62     public CullMode getCullMode() {
     63         return mCullMode;
     64     }
     65 
     66     public static ProgramRaster CULL_BACK(RenderScript rs) {
     67         if(rs.mProgramRaster_CULL_BACK == null) {
     68             ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
     69             builder.setCullMode(CullMode.BACK);
     70             rs.mProgramRaster_CULL_BACK = builder.create();
     71         }
     72         return rs.mProgramRaster_CULL_BACK;
     73     }
     74 
     75     public static ProgramRaster CULL_FRONT(RenderScript rs) {
     76         if(rs.mProgramRaster_CULL_FRONT == null) {
     77             ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
     78             builder.setCullMode(CullMode.FRONT);
     79             rs.mProgramRaster_CULL_FRONT = builder.create();
     80         }
     81         return rs.mProgramRaster_CULL_FRONT;
     82     }
     83 
     84     public static ProgramRaster CULL_NONE(RenderScript rs) {
     85         if(rs.mProgramRaster_CULL_NONE == null) {
     86             ProgramRaster.Builder builder = new ProgramRaster.Builder(rs);
     87             builder.setCullMode(CullMode.NONE);
     88             rs.mProgramRaster_CULL_NONE = builder.create();
     89         }
     90         return rs.mProgramRaster_CULL_NONE;
     91     }
     92 
     93     public static class Builder {
     94         RenderScript mRS;
     95         boolean mPointSprite;
     96         CullMode mCullMode;
     97 
     98         public Builder(RenderScript rs) {
     99             mRS = rs;
    100             mPointSprite = false;
    101             mCullMode = CullMode.BACK;
    102         }
    103 
    104         public Builder setPointSpriteEnabled(boolean enable) {
    105             mPointSprite = enable;
    106             return this;
    107         }
    108 
    109         public Builder setCullMode(CullMode m) {
    110             mCullMode = m;
    111             return this;
    112         }
    113 
    114         public ProgramRaster create() {
    115             mRS.validate();
    116             int id = mRS.nProgramRasterCreate(mPointSprite, mCullMode.mID);
    117             ProgramRaster programRaster = new ProgramRaster(id, mRS);
    118             programRaster.mPointSprite = mPointSprite;
    119             programRaster.mCullMode = mCullMode;
    120             return programRaster;
    121         }
    122     }
    123 
    124 }
    125 
    126 
    127 
    128 
    129 
    130 
    131