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 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 20 | import android.util.Log; |
| 21 | |
| 22 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 23 | /** |
Tim Murray | a908422 | 2013-04-05 22:06:43 +0000 | [diff] [blame] | 24 | * @hide |
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 { |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 39 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 48 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 49 | * Always drawn |
| 50 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 51 | ALWAYS (0), |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 52 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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), |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 57 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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), |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 62 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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), |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 67 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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), |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 72 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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), |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 77 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 89 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 114 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 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 | |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 139 | DepthFunc mDepthFunc; |
| 140 | boolean mDepthMask; |
| 141 | boolean mColorMaskR; |
| 142 | boolean mColorMaskG; |
| 143 | boolean mColorMaskB; |
| 144 | boolean mColorMaskA; |
| 145 | BlendSrcFunc mBlendSrc; |
| 146 | BlendDstFunc mBlendDst; |
| 147 | boolean mDither; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 148 | |
| 149 | ProgramStore(int id, RenderScript rs) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 150 | super(id, rs); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 153 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 154 | * Returns the function used to test writing into the depth |
| 155 | * buffer |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 156 | * @return depth function |
| 157 | */ |
| 158 | public DepthFunc getDepthFunc() { |
| 159 | return mDepthFunc; |
| 160 | } |
| 161 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 162 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 163 | * Queries whether writes are enabled into the depth buffer |
| 164 | * @return depth mask |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 165 | */ |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 166 | public boolean isDepthMaskEnabled() { |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 167 | return mDepthMask; |
| 168 | } |
| 169 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 170 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 171 | * Queries whether red channel is written |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 172 | * @return red color channel mask |
| 173 | */ |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 174 | public boolean isColorMaskRedEnabled() { |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 175 | return mColorMaskR; |
| 176 | } |
| 177 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 178 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 179 | * Queries whether green channel is written |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 180 | * @return green color channel mask |
| 181 | */ |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 182 | public boolean isColorMaskGreenEnabled() { |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 183 | return mColorMaskG; |
| 184 | } |
| 185 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 186 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 187 | * Queries whether blue channel is written |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 188 | * @return blue color channel mask |
| 189 | */ |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 190 | public boolean isColorMaskBlueEnabled() { |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 191 | return mColorMaskB; |
| 192 | } |
| 193 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 194 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 195 | * Queries whether alpha channel is written |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 196 | * @return alpha channel mask |
| 197 | */ |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 198 | public boolean isColorMaskAlphaEnabled() { |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 199 | return mColorMaskA; |
| 200 | } |
| 201 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 202 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 203 | * Specifies how the source blending factor is computed |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 204 | * @return source blend function |
| 205 | */ |
| 206 | public BlendSrcFunc getBlendSrcFunc() { |
| 207 | return mBlendSrc; |
| 208 | } |
| 209 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 210 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 211 | * Specifies how the destination blending factor is computed |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 212 | * @return destination blend function |
| 213 | */ |
| 214 | public BlendDstFunc getBlendDstFunc() { |
| 215 | return mBlendDst; |
| 216 | } |
| 217 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 218 | /** |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 219 | * Specifies whether colors are dithered before writing into the |
| 220 | * framebuffer |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 221 | * @return whether dither is enabled |
| 222 | */ |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 223 | public boolean isDitherEnabled() { |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 224 | return mDither; |
| 225 | } |
| 226 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 227 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 228 | * Returns a pre-defined program store object with the following |
| 229 | * characteristics: |
| 230 | * - incoming pixels are drawn if their depth value is less than |
| 231 | * the stored value in the depth buffer. If the pixel is |
| 232 | * drawn, its value is also stored in the depth buffer |
| 233 | * - incoming pixels override the value stored in the color |
| 234 | * buffer if it passes the depth test |
| 235 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 236 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 237 | **/ |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 238 | public static ProgramStore BLEND_NONE_DEPTH_TEST(RenderScript rs) { |
| 239 | if(rs.mProgramStore_BLEND_NONE_DEPTH_TEST == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 240 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 241 | builder.setDepthFunc(ProgramStore.DepthFunc.LESS); |
| 242 | builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 243 | builder.setDitherEnabled(false); |
| 244 | builder.setDepthMaskEnabled(true); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 245 | rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 246 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 247 | return rs.mProgramStore_BLEND_NONE_DEPTH_TEST; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 248 | } |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 249 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 250 | * Returns a pre-defined program store object with the following |
| 251 | * characteristics: |
| 252 | * - incoming pixels always pass the depth test and their value |
| 253 | * is not stored in the depth buffer |
| 254 | * - incoming pixels override the value stored in the color |
| 255 | * buffer |
| 256 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 257 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 258 | **/ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 259 | public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) { |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 260 | if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 261 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 262 | builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 263 | builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 264 | builder.setDitherEnabled(false); |
| 265 | builder.setDepthMaskEnabled(false); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 266 | rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 267 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 268 | return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 269 | } |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 270 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 271 | * Returns a pre-defined program store object with the following |
| 272 | * characteristics: |
| 273 | * - incoming pixels are drawn if their depth value is less than |
| 274 | * the stored value in the depth buffer. If the pixel is |
| 275 | * drawn, its value is also stored in the depth buffer |
| 276 | * - if the incoming (Source) pixel passes depth test, its value |
| 277 | * is combined with the stored color (Dest) using the |
| 278 | * following formula |
| 279 | * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A) |
| 280 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 281 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 282 | **/ |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 283 | public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) { |
| 284 | if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 285 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 286 | builder.setDepthFunc(ProgramStore.DepthFunc.LESS); |
| 287 | builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 288 | builder.setDitherEnabled(false); |
| 289 | builder.setDepthMaskEnabled(true); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 290 | rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 291 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 292 | return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 293 | } |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 294 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 295 | * Returns a pre-defined program store object with the following |
| 296 | * characteristics: |
| 297 | * - incoming pixels always pass the depth test and their value |
| 298 | * is not stored in the depth buffer |
| 299 | * - incoming pixel's value is combined with the stored color |
| 300 | * (Dest) using the following formula |
| 301 | * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A) |
| 302 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 303 | * @param rs Context to which the program will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 304 | **/ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 305 | public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) { |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 306 | if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) { |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 307 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 308 | builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 309 | builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 310 | builder.setDitherEnabled(false); |
| 311 | builder.setDepthMaskEnabled(false); |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 312 | rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create(); |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 313 | } |
Alex Sakhartchouk | d36f248 | 2010-08-24 11:37:33 -0700 | [diff] [blame] | 314 | return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 315 | } |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 316 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 317 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 318 | * Builder class for ProgramStore object. If the builder is left |
| 319 | * empty, the equivalent of BLEND_NONE_DEPTH_NONE would be |
| 320 | * returned |
| 321 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 322 | public static class Builder { |
| 323 | RenderScript mRS; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 324 | DepthFunc mDepthFunc; |
| 325 | boolean mDepthMask; |
| 326 | boolean mColorMaskR; |
| 327 | boolean mColorMaskG; |
| 328 | boolean mColorMaskB; |
| 329 | boolean mColorMaskA; |
| 330 | BlendSrcFunc mBlendSrc; |
| 331 | BlendDstFunc mBlendDst; |
| 332 | boolean mDither; |
| 333 | |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 334 | public Builder(RenderScript rs) { |
| 335 | mRS = rs; |
Alex Sakhartchouk | 32e09b5 | 2010-08-23 10:24:10 -0700 | [diff] [blame] | 336 | mDepthFunc = DepthFunc.ALWAYS; |
| 337 | mDepthMask = false; |
| 338 | mColorMaskR = true; |
| 339 | mColorMaskG = true; |
| 340 | mColorMaskB = true; |
| 341 | mColorMaskA = true; |
| 342 | mBlendSrc = BlendSrcFunc.ONE; |
| 343 | mBlendDst = BlendDstFunc.ZERO; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 346 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 347 | * Specifies the depth testing behavior |
| 348 | * |
| 349 | * @param func function used for depth testing |
| 350 | * |
| 351 | * @return this |
| 352 | */ |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 353 | public Builder setDepthFunc(DepthFunc func) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 354 | mDepthFunc = func; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 355 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 358 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 359 | * Enables writes into the depth buffer |
| 360 | * |
| 361 | * @param enable specifies whether depth writes are |
| 362 | * enabled or disabled |
| 363 | * |
| 364 | * @return this |
| 365 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 366 | public Builder setDepthMaskEnabled(boolean enable) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 367 | mDepthMask = enable; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 368 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 371 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 372 | * Enables writes into the color buffer |
| 373 | * |
| 374 | * @param r specifies whether red channel is written |
| 375 | * @param g specifies whether green channel is written |
| 376 | * @param b specifies whether blue channel is written |
| 377 | * @param a specifies whether alpha channel is written |
| 378 | * |
| 379 | * @return this |
| 380 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 381 | public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 382 | mColorMaskR = r; |
| 383 | mColorMaskG = g; |
| 384 | mColorMaskB = b; |
| 385 | mColorMaskA = a; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 386 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 389 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 390 | * Specifies how incoming pixels are combined with the pixels |
| 391 | * stored in the framebuffer |
| 392 | * |
| 393 | * @param src specifies how the source blending factor is |
| 394 | * computed |
| 395 | * @param dst specifies how the destination blending factor is |
| 396 | * computed |
| 397 | * |
| 398 | * @return this |
| 399 | */ |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 400 | public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 401 | mBlendSrc = src; |
| 402 | mBlendDst = dst; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 403 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 406 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 407 | * Enables dithering |
| 408 | * |
| 409 | * @param enable specifies whether dithering is enabled or |
| 410 | * disabled |
| 411 | * |
| 412 | * @return this |
| 413 | */ |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 414 | public Builder setDitherEnabled(boolean enable) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 415 | mDither = enable; |
Jim Shuma | 288c871 | 2010-07-07 14:24:21 -0700 | [diff] [blame] | 416 | return this; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 419 | /** |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 420 | * Creates a program store from the current state of the builder |
| 421 | */ |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 422 | public ProgramStore create() { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 423 | mRS.validate(); |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 424 | int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA, |
| 425 | mDepthMask, mDither, |
| 426 | mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID); |
Alex Sakhartchouk | 7d5f5e7 | 2011-10-18 11:08:31 -0700 | [diff] [blame] | 427 | ProgramStore programStore = new ProgramStore(id, mRS); |
| 428 | programStore.mDepthFunc = mDepthFunc; |
| 429 | programStore.mDepthMask = mDepthMask; |
| 430 | programStore.mColorMaskR = mColorMaskR; |
| 431 | programStore.mColorMaskG = mColorMaskG; |
| 432 | programStore.mColorMaskB = mColorMaskB; |
| 433 | programStore.mColorMaskA = mColorMaskA; |
| 434 | programStore.mBlendSrc = mBlendSrc; |
| 435 | programStore.mBlendDst = mBlendDst; |
| 436 | programStore.mDither = mDither; |
| 437 | return programStore; |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
| 441 | } |
| 442 | |
| 443 | |
| 444 | |
| 445 | |