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