ProgramRaster.java revision 06d69de78845659e6904ae4964e606a7f1a6a4a8
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 17package android.renderscript; 18 19 20import android.util.Config; 21import android.util.Log; 22 23 24/** 25 * @hide 26 * 27 **/ 28public class ProgramRaster extends BaseObj { 29 30 public enum CullMode { 31 BACK (0), 32 FRONT (1), 33 NONE (2); 34 35 int mID; 36 CullMode(int id) { 37 mID = id; 38 } 39 } 40 41 boolean mPointSmooth; 42 boolean mLineSmooth; 43 boolean mPointSprite; 44 float mLineWidth; 45 CullMode mCullMode; 46 47 ProgramRaster(int id, RenderScript rs) { 48 super(id, rs); 49 50 mLineWidth = 1.0f; 51 mPointSmooth = false; 52 mLineSmooth = false; 53 mPointSprite = false; 54 55 mCullMode = CullMode.BACK; 56 } 57 58 void setLineWidth(float w) { 59 mRS.validate(); 60 mLineWidth = w; 61 mRS.nProgramRasterSetLineWidth(getID(), w); 62 } 63 64 void setCullMode(CullMode m) { 65 mRS.validate(); 66 mCullMode = m; 67 mRS.nProgramRasterSetCullMode(getID(), m.mID); 68 } 69 70 public static ProgramRaster CULL_BACK(RenderScript rs) { 71 if(rs.mProgramRaster_CULL_BACK == null) { 72 ProgramRaster.Builder builder = new ProgramRaster.Builder(rs); 73 builder.setCullMode(CullMode.BACK); 74 rs.mProgramRaster_CULL_BACK = builder.create(); 75 } 76 return rs.mProgramRaster_CULL_BACK; 77 } 78 79 public static ProgramRaster CULL_FRONT(RenderScript rs) { 80 if(rs.mProgramRaster_CULL_FRONT == null) { 81 ProgramRaster.Builder builder = new ProgramRaster.Builder(rs); 82 builder.setCullMode(CullMode.FRONT); 83 rs.mProgramRaster_CULL_FRONT = builder.create(); 84 } 85 return rs.mProgramRaster_CULL_FRONT; 86 } 87 88 public static ProgramRaster CULL_NONE(RenderScript rs) { 89 if(rs.mProgramRaster_CULL_NONE == null) { 90 ProgramRaster.Builder builder = new ProgramRaster.Builder(rs); 91 builder.setCullMode(CullMode.NONE); 92 rs.mProgramRaster_CULL_NONE = builder.create(); 93 } 94 return rs.mProgramRaster_CULL_NONE; 95 } 96 97 public static class Builder { 98 RenderScript mRS; 99 boolean mPointSprite; 100 boolean mPointSmooth; 101 boolean mLineSmooth; 102 CullMode mCullMode; 103 104 public Builder(RenderScript rs) { 105 mRS = rs; 106 mPointSmooth = false; 107 mLineSmooth = false; 108 mPointSprite = false; 109 mCullMode = CullMode.BACK; 110 } 111 112 public Builder setPointSpriteEnable(boolean enable) { 113 mPointSprite = enable; 114 return this; 115 } 116 117 public Builder setPointSmoothEnable(boolean enable) { 118 mPointSmooth = enable; 119 return this; 120 } 121 122 public Builder setLineSmoothEnable(boolean enable) { 123 mLineSmooth = enable; 124 return this; 125 } 126 127 public Builder setCullMode(CullMode m) { 128 mCullMode = m; 129 return this; 130 } 131 132 static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) { 133 int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite); 134 ProgramRaster pr = new ProgramRaster(id, rs); 135 pr.setCullMode(b.mCullMode); 136 return pr; 137 } 138 139 public ProgramRaster create() { 140 mRS.validate(); 141 return internalCreate(mRS, this); 142 } 143 } 144 145} 146 147 148 149 150 151 152