Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 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.Config; |
| 21 | import android.util.Log; |
| 22 | |
| 23 | |
| 24 | /** |
Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 25 | * <p>ProgramStore contains a set of parameters that control how |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 26 | * the graphics hardware handles writes to the framebuffer. |
Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 27 | * It could be used to:</p> |
| 28 | * <ul> |
| 29 | * <li>enable/disable depth testing</li> |
| 30 | * <li>specify wheather depth writes are performed</li> |
| 31 | * <li>setup various blending modes for use in effects like |
| 32 | * transparency</li> |
| 33 | * <li>define write masks for color components written into the |
| 34 | * framebuffer</li> |
| 35 | * </ul> |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 36 | * |
| 37 | **/ |
| 38 | public class ProgramStore extends BaseObj { |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 39 | /** |
| 40 | * Specifies the function used to determine whether a fragment |
| 41 | * will be drawn during the depth testing stage in the rendering |
| 42 | * pipeline by comparing its value with that already in the depth |
| 43 | * buffer. DepthFunc is only valid when depth buffer is present |
| 44 | * and depth testing is enabled |
| 45 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 46 | public enum DepthFunc { |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Always drawn |
| 50 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 51 | ALWAYS (0), |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 52 | /** |
| 53 | * Drawn if the incoming depth value is less than that in the |
| 54 | * depth buffer |
| 55 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 56 | LESS (1), |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 57 | /** |
| 58 | * Drawn if the incoming depth value is less or equal to that in |
| 59 | * the depth buffer |
| 60 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 61 | LESS_OR_EQUAL (2), |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 62 | /** |
| 63 | * Drawn if the incoming depth value is greater than that in the |
| 64 | * depth buffer |
| 65 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 66 | GREATER (3), |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 67 | /** |
| 68 | * Drawn if the incoming depth value is greater or equal to that |
| 69 | * in the depth buffer |
| 70 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 71 | GREATER_OR_EQUAL (4), |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 72 | /** |
| 73 | * Drawn if the incoming depth value is equal to that in the |
| 74 | * depth buffer |
| 75 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 76 | EQUAL (5), |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Drawn if the incoming depth value is not equal to that in the |
| 79 | * depth buffer |
| 80 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 81 | NOT_EQUAL (6); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 82 | |
| 83 | int mID; |
| 84 | DepthFunc(int id) { |
| 85 | mID = id; |
| 86 | } |
| 87 | } |
| 88 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 89 | /** |
| 90 | * Specifies the functions used to combine incoming pixels with |
| 91 | * those already in the frame buffer. |
| 92 | * |
| 93 | * BlendSrcFunc describes how the coefficient used to scale the |
| 94 | * source pixels during the blending operation is computed |
| 95 | * |
| 96 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 97 | public enum BlendSrcFunc { |
| 98 | ZERO (0), |
| 99 | ONE (1), |
| 100 | DST_COLOR (2), |
| 101 | ONE_MINUS_DST_COLOR (3), |
| 102 | SRC_ALPHA (4), |
| 103 | ONE_MINUS_SRC_ALPHA (5), |
| 104 | DST_ALPHA (6), |
Jason Sams | eab4c75 | 2009-10-28 17:40:13 -0700 | [diff] [blame] | 105 | ONE_MINUS_DST_ALPHA (7), |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 106 | SRC_ALPHA_SATURATE (8); |
| 107 | |
| 108 | int mID; |
| 109 | BlendSrcFunc(int id) { |
| 110 | mID = id; |
| 111 | } |
| 112 | } |
| 113 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 114 | /** |
| 115 | * Specifies the functions used to combine incoming pixels with |
| 116 | * those already in the frame buffer. |
| 117 | * |
| 118 | * BlendDstFunc describes how the coefficient used to scale the |
| 119 | * pixels already in the framebuffer is computed during the |
| 120 | * blending operation |
| 121 | * |
| 122 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 123 | public enum BlendDstFunc { |
| 124 | ZERO (0), |
| 125 | ONE (1), |
| 126 | SRC_COLOR (2), |
| 127 | ONE_MINUS_SRC_COLOR (3), |
| 128 | SRC_ALPHA (4), |
| 129 | ONE_MINUS_SRC_ALPHA (5), |
| 130 | DST_ALPHA (6), |
Jason Sams | eab4c75 | 2009-10-28 17:40:13 -0700 | [diff] [blame] | 131 | ONE_MINUS_DST_ALPHA (7); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 132 | |
| 133 | int mID; |
| 134 | BlendDstFunc(int id) { |
| 135 | mID = id; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | |
| 140 | ProgramStore(int id, RenderScript rs) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 141 | super(id, rs); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 144 | /** |
| 145 | * Returns a pre-defined program store object with the following |
| 146 | * characteristics: |
| 147 | * - incoming pixels are drawn if their depth value is less than |
| 148 | * the stored value in the depth buffer. If the pixel is |
| 149 | * drawn, its value is also stored in the depth buffer |
| 150 | * - incoming pixels override the value stored in the color |
| 151 | * buffer if it passes the depth test |
| 152 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 153 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 154 | **/ |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 155 | public static ProgramStore BLEND_NONE_DEPTH_TEST(RenderScript rs) { |
| 156 | if(rs.mProgramStore_BLEND_NONE_DEPTH_TEST == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 157 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 158 | builder.setDepthFunc(ProgramStore.DepthFunc.LESS); |
| 159 | builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 160 | builder.setDitherEnabled(false); |
| 161 | builder.setDepthMaskEnabled(true); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 162 | rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 163 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 164 | return rs.mProgramStore_BLEND_NONE_DEPTH_TEST; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 165 | } |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 166 | /** |
| 167 | * Returns a pre-defined program store object with the following |
| 168 | * characteristics: |
| 169 | * - incoming pixels always pass the depth test and their value |
| 170 | * is not stored in the depth buffer |
| 171 | * - incoming pixels override the value stored in the color |
| 172 | * buffer |
| 173 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 174 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 175 | **/ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 176 | public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) { |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 177 | if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 178 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 179 | builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 180 | builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 181 | builder.setDitherEnabled(false); |
| 182 | builder.setDepthMaskEnabled(false); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 183 | rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 184 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 185 | return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 186 | } |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 187 | /** |
| 188 | * Returns a pre-defined program store object with the following |
| 189 | * characteristics: |
| 190 | * - incoming pixels are drawn if their depth value is less than |
| 191 | * the stored value in the depth buffer. If the pixel is |
| 192 | * drawn, its value is also stored in the depth buffer |
| 193 | * - if the incoming (Source) pixel passes depth test, its value |
| 194 | * is combined with the stored color (Dest) using the |
| 195 | * following formula |
| 196 | * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A) |
| 197 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 198 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 199 | **/ |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 200 | public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) { |
| 201 | if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 202 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 203 | builder.setDepthFunc(ProgramStore.DepthFunc.LESS); |
| 204 | builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 205 | builder.setDitherEnabled(false); |
| 206 | builder.setDepthMaskEnabled(true); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 207 | rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 208 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 209 | return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 210 | } |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 211 | /** |
| 212 | * Returns a pre-defined program store object with the following |
| 213 | * characteristics: |
| 214 | * - incoming pixels always pass the depth test and their value |
| 215 | * is not stored in the depth buffer |
| 216 | * - incoming pixel's value is combined with the stored color |
| 217 | * (Dest) using the following formula |
| 218 | * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A) |
| 219 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 220 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 221 | **/ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 222 | public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) { |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 223 | if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 224 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 225 | builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 226 | builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 227 | builder.setDitherEnabled(false); |
| 228 | builder.setDepthMaskEnabled(false); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 229 | rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 230 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 231 | return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 232 | } |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 233 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 234 | /** |
| 235 | * Builder class for ProgramStore object. If the builder is left |
| 236 | * empty, the equivalent of BLEND_NONE_DEPTH_NONE would be |
| 237 | * returned |
| 238 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 239 | public static class Builder { |
| 240 | RenderScript mRS; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 241 | DepthFunc mDepthFunc; |
| 242 | boolean mDepthMask; |
| 243 | boolean mColorMaskR; |
| 244 | boolean mColorMaskG; |
| 245 | boolean mColorMaskB; |
| 246 | boolean mColorMaskA; |
| 247 | BlendSrcFunc mBlendSrc; |
| 248 | BlendDstFunc mBlendDst; |
| 249 | boolean mDither; |
| 250 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 251 | public Builder(RenderScript rs) { |
| 252 | mRS = rs; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 253 | mDepthFunc = DepthFunc.ALWAYS; |
| 254 | mDepthMask = false; |
| 255 | mColorMaskR = true; |
| 256 | mColorMaskG = true; |
| 257 | mColorMaskB = true; |
| 258 | mColorMaskA = true; |
| 259 | mBlendSrc = BlendSrcFunc.ONE; |
| 260 | mBlendDst = BlendDstFunc.ZERO; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 263 | /** |
| 264 | * Specifies the depth testing behavior |
| 265 | * |
| 266 | * @param func function used for depth testing |
| 267 | * |
| 268 | * @return this |
| 269 | */ |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 270 | public Builder setDepthFunc(DepthFunc func) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 271 | mDepthFunc = func; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 272 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 275 | /** |
| 276 | * Enables writes into the depth buffer |
| 277 | * |
| 278 | * @param enable specifies whether depth writes are |
| 279 | * enabled or disabled |
| 280 | * |
| 281 | * @return this |
| 282 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 283 | public Builder setDepthMaskEnabled(boolean enable) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 284 | mDepthMask = enable; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 285 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 288 | /** |
| 289 | * Enables writes into the color buffer |
| 290 | * |
| 291 | * @param r specifies whether red channel is written |
| 292 | * @param g specifies whether green channel is written |
| 293 | * @param b specifies whether blue channel is written |
| 294 | * @param a specifies whether alpha channel is written |
| 295 | * |
| 296 | * @return this |
| 297 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 298 | public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 299 | mColorMaskR = r; |
| 300 | mColorMaskG = g; |
| 301 | mColorMaskB = b; |
| 302 | mColorMaskA = a; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 303 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 306 | /** |
| 307 | * Specifies how incoming pixels are combined with the pixels |
| 308 | * stored in the framebuffer |
| 309 | * |
| 310 | * @param src specifies how the source blending factor is |
| 311 | * computed |
| 312 | * @param dst specifies how the destination blending factor is |
| 313 | * computed |
| 314 | * |
| 315 | * @return this |
| 316 | */ |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 317 | public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 318 | mBlendSrc = src; |
| 319 | mBlendDst = dst; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 320 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 323 | /** |
| 324 | * Enables dithering |
| 325 | * |
| 326 | * @param enable specifies whether dithering is enabled or |
| 327 | * disabled |
| 328 | * |
| 329 | * @return this |
| 330 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 331 | public Builder setDitherEnabled(boolean enable) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 332 | mDither = enable; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 333 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 337 | rs.nProgramStoreBegin(0, 0); |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 338 | rs.nProgramStoreDepthFunc(b.mDepthFunc.mID); |
| 339 | rs.nProgramStoreDepthMask(b.mDepthMask); |
| 340 | rs.nProgramStoreColorMask(b.mColorMaskR, |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 341 | b.mColorMaskG, |
| 342 | b.mColorMaskB, |
| 343 | b.mColorMaskA); |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 344 | rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID); |
| 345 | rs.nProgramStoreDither(b.mDither); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 346 | |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 347 | int id = rs.nProgramStoreCreate(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 348 | return new ProgramStore(id, rs); |
| 349 | } |
| 350 | |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 351 | /** |
| 352 | * Creates a program store from the current state of the builder |
| 353 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 354 | public ProgramStore create() { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 355 | mRS.validate(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 356 | return internalCreate(mRS, this); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | } |
| 361 | |
| 362 | |
| 363 | |
| 364 | |