blob: 20043f27a0b0b4adac94f7b03f6e57263ef90c9f [file] [log] [blame]
Jason Sams22534172009-08-04 16:58:20 -07001/*
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
Jason Sams22534172009-08-04 16:58:20 -070020import android.util.Log;
21
22
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070023/** @deprecated renderscript is deprecated in J
Robert Ly11518ac2011-02-09 13:57:06 -080024 * <p>ProgramStore contains a set of parameters that control how
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080025 * the graphics hardware handles writes to the framebuffer.
Robert Ly11518ac2011-02-09 13:57:06 -080026 * It could be used to:</p>
27 * <ul>
28 * <li>enable/disable depth testing</li>
29 * <li>specify wheather depth writes are performed</li>
30 * <li>setup various blending modes for use in effects like
31 * transparency</li>
32 * <li>define write masks for color components written into the
33 * framebuffer</li>
34 * </ul>
Jason Sams22534172009-08-04 16:58:20 -070035 *
36 **/
37public class ProgramStore extends BaseObj {
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070038 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080039 * Specifies the function used to determine whether a fragment
40 * will be drawn during the depth testing stage in the rendering
41 * pipeline by comparing its value with that already in the depth
42 * buffer. DepthFunc is only valid when depth buffer is present
43 * and depth testing is enabled
44 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080045 public enum DepthFunc {
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080046
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070047 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080048 * Always drawn
49 */
Jason Sams22534172009-08-04 16:58:20 -070050 ALWAYS (0),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070051 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080052 * Drawn if the incoming depth value is less than that in the
53 * depth buffer
54 */
Jason Sams22534172009-08-04 16:58:20 -070055 LESS (1),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070056 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080057 * Drawn if the incoming depth value is less or equal to that in
58 * the depth buffer
59 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080060 LESS_OR_EQUAL (2),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070061 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080062 * Drawn if the incoming depth value is greater than that in the
63 * depth buffer
64 */
Jason Sams22534172009-08-04 16:58:20 -070065 GREATER (3),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070066 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080067 * Drawn if the incoming depth value is greater or equal to that
68 * in the depth buffer
69 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080070 GREATER_OR_EQUAL (4),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070071 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080072 * Drawn if the incoming depth value is equal to that in the
73 * depth buffer
74 */
Jason Sams22534172009-08-04 16:58:20 -070075 EQUAL (5),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070076 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080077 * Drawn if the incoming depth value is not equal to that in the
78 * depth buffer
79 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080080 NOT_EQUAL (6);
Jason Sams22534172009-08-04 16:58:20 -070081
82 int mID;
83 DepthFunc(int id) {
84 mID = id;
85 }
86 }
87
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070088 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080089 * Specifies the functions used to combine incoming pixels with
90 * those already in the frame buffer.
91 *
92 * BlendSrcFunc describes how the coefficient used to scale the
93 * source pixels during the blending operation is computed
94 *
95 */
Jason Sams22534172009-08-04 16:58:20 -070096 public enum BlendSrcFunc {
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -070097 /** @deprecated renderscript is deprecated in J
98 */
Jason Sams22534172009-08-04 16:58:20 -070099 ZERO (0),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700100 /** @deprecated renderscript is deprecated in J
101 */
Jason Sams22534172009-08-04 16:58:20 -0700102 ONE (1),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700103 /** @deprecated renderscript is deprecated in J
104 */
Jason Sams22534172009-08-04 16:58:20 -0700105 DST_COLOR (2),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700106 /** @deprecated renderscript is deprecated in J
107 */
Jason Sams22534172009-08-04 16:58:20 -0700108 ONE_MINUS_DST_COLOR (3),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700109 /** @deprecated renderscript is deprecated in J
110 */
Jason Sams22534172009-08-04 16:58:20 -0700111 SRC_ALPHA (4),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700112 /** @deprecated renderscript is deprecated in J
113 */
Jason Sams22534172009-08-04 16:58:20 -0700114 ONE_MINUS_SRC_ALPHA (5),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700115 /** @deprecated renderscript is deprecated in J
116 */
Jason Sams22534172009-08-04 16:58:20 -0700117 DST_ALPHA (6),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700118 /** @deprecated renderscript is deprecated in J
119 */
Jason Samseab4c752009-10-28 17:40:13 -0700120 ONE_MINUS_DST_ALPHA (7),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700121 /** @deprecated renderscript is deprecated in J
122 */
Jason Sams22534172009-08-04 16:58:20 -0700123 SRC_ALPHA_SATURATE (8);
124
125 int mID;
126 BlendSrcFunc(int id) {
127 mID = id;
128 }
129 }
130
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700131 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800132 * Specifies the functions used to combine incoming pixels with
133 * those already in the frame buffer.
134 *
135 * BlendDstFunc describes how the coefficient used to scale the
136 * pixels already in the framebuffer is computed during the
137 * blending operation
138 *
139 */
Jason Sams22534172009-08-04 16:58:20 -0700140 public enum BlendDstFunc {
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700141 /** @deprecated renderscript is deprecated in J
142 */
Jason Sams22534172009-08-04 16:58:20 -0700143 ZERO (0),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700144 /** @deprecated renderscript is deprecated in J
145 */
Jason Sams22534172009-08-04 16:58:20 -0700146 ONE (1),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700147 /** @deprecated renderscript is deprecated in J
148 */
Jason Sams22534172009-08-04 16:58:20 -0700149 SRC_COLOR (2),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700150 /** @deprecated renderscript is deprecated in J
151 */
Jason Sams22534172009-08-04 16:58:20 -0700152 ONE_MINUS_SRC_COLOR (3),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700153 /** @deprecated renderscript is deprecated in J
154 */
Jason Sams22534172009-08-04 16:58:20 -0700155 SRC_ALPHA (4),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700156 /** @deprecated renderscript is deprecated in J
157 */
Jason Sams22534172009-08-04 16:58:20 -0700158 ONE_MINUS_SRC_ALPHA (5),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700159 /** @deprecated renderscript is deprecated in J
160 */
Jason Sams22534172009-08-04 16:58:20 -0700161 DST_ALPHA (6),
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700162 /** @deprecated renderscript is deprecated in J
163 */
Jason Samseab4c752009-10-28 17:40:13 -0700164 ONE_MINUS_DST_ALPHA (7);
Jason Sams22534172009-08-04 16:58:20 -0700165
166 int mID;
167 BlendDstFunc(int id) {
168 mID = id;
169 }
170 }
171
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700172 DepthFunc mDepthFunc;
173 boolean mDepthMask;
174 boolean mColorMaskR;
175 boolean mColorMaskG;
176 boolean mColorMaskB;
177 boolean mColorMaskA;
178 BlendSrcFunc mBlendSrc;
179 BlendDstFunc mBlendDst;
180 boolean mDither;
Jason Sams22534172009-08-04 16:58:20 -0700181
182 ProgramStore(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700183 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -0700184 }
185
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700186 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700187 * Returns the function used to test writing into the depth
188 * buffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700189 * @return depth function
190 */
191 public DepthFunc getDepthFunc() {
192 return mDepthFunc;
193 }
194
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700195 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700196 * Queries whether writes are enabled into the depth buffer
197 * @return depth mask
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700198 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700199 public boolean isDepthMaskEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700200 return mDepthMask;
201 }
202
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700203 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700204 * Queries whether red channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700205 * @return red color channel mask
206 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700207 public boolean isColorMaskRedEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700208 return mColorMaskR;
209 }
210
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700211 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700212 * Queries whether green channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700213 * @return green color channel mask
214 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700215 public boolean isColorMaskGreenEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700216 return mColorMaskG;
217 }
218
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700219 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700220 * Queries whether blue channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700221 * @return blue color channel mask
222 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700223 public boolean isColorMaskBlueEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700224 return mColorMaskB;
225 }
226
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700227 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700228 * Queries whether alpha channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700229 * @return alpha channel mask
230 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700231 public boolean isColorMaskAlphaEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700232 return mColorMaskA;
233 }
234
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700235 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700236 * Specifies how the source blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700237 * @return source blend function
238 */
239 public BlendSrcFunc getBlendSrcFunc() {
240 return mBlendSrc;
241 }
242
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700243 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700244 * Specifies how the destination blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700245 * @return destination blend function
246 */
247 public BlendDstFunc getBlendDstFunc() {
248 return mBlendDst;
249 }
250
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700251 /** @hide renderscript is deprecated in J
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700252 * Specifies whether colors are dithered before writing into the
253 * framebuffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700254 * @return whether dither is enabled
255 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700256 public boolean isDitherEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700257 return mDither;
258 }
259
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700260 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800261 * Returns a pre-defined program store object with the following
262 * characteristics:
263 * - incoming pixels are drawn if their depth value is less than
264 * the stored value in the depth buffer. If the pixel is
265 * drawn, its value is also stored in the depth buffer
266 * - incoming pixels override the value stored in the color
267 * buffer if it passes the depth test
268 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800269 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800270 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700271 public static ProgramStore BLEND_NONE_DEPTH_TEST(RenderScript rs) {
272 if(rs.mProgramStore_BLEND_NONE_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700273 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
274 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
275 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800276 builder.setDitherEnabled(false);
277 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700278 rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700279 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700280 return rs.mProgramStore_BLEND_NONE_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700281 }
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700282 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800283 * Returns a pre-defined program store object with the following
284 * characteristics:
285 * - incoming pixels always pass the depth test and their value
286 * is not stored in the depth buffer
287 * - incoming pixels override the value stored in the color
288 * buffer
289 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800290 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800291 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800292 public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700293 if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700294 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
295 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
296 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800297 builder.setDitherEnabled(false);
298 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700299 rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700300 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700301 return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700302 }
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700303 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800304 * Returns a pre-defined program store object with the following
305 * characteristics:
306 * - incoming pixels are drawn if their depth value is less than
307 * the stored value in the depth buffer. If the pixel is
308 * drawn, its value is also stored in the depth buffer
309 * - if the incoming (Source) pixel passes depth test, its value
310 * is combined with the stored color (Dest) using the
311 * following formula
312 * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A)
313 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800314 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800315 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700316 public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) {
317 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700318 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
319 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
320 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800321 builder.setDitherEnabled(false);
322 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700323 rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700324 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700325 return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700326 }
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700327 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800328 * Returns a pre-defined program store object with the following
329 * characteristics:
330 * - incoming pixels always pass the depth test and their value
331 * is not stored in the depth buffer
332 * - incoming pixel's value is combined with the stored color
333 * (Dest) using the following formula
334 * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A)
335 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800336 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800337 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800338 public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700339 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700340 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
341 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
342 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800343 builder.setDitherEnabled(false);
344 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700345 rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700346 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700347 return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700348 }
Jason Sams22534172009-08-04 16:58:20 -0700349
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700350 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800351 * Builder class for ProgramStore object. If the builder is left
352 * empty, the equivalent of BLEND_NONE_DEPTH_NONE would be
353 * returned
354 */
Jason Sams22534172009-08-04 16:58:20 -0700355 public static class Builder {
356 RenderScript mRS;
Jason Sams22534172009-08-04 16:58:20 -0700357 DepthFunc mDepthFunc;
358 boolean mDepthMask;
359 boolean mColorMaskR;
360 boolean mColorMaskG;
361 boolean mColorMaskB;
362 boolean mColorMaskA;
363 BlendSrcFunc mBlendSrc;
364 BlendDstFunc mBlendDst;
365 boolean mDither;
366
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700367 public Builder(RenderScript rs) {
368 mRS = rs;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700369 mDepthFunc = DepthFunc.ALWAYS;
370 mDepthMask = false;
371 mColorMaskR = true;
372 mColorMaskG = true;
373 mColorMaskB = true;
374 mColorMaskA = true;
375 mBlendSrc = BlendSrcFunc.ONE;
376 mBlendDst = BlendDstFunc.ZERO;
Jason Sams22534172009-08-04 16:58:20 -0700377 }
378
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700379 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800380 * Specifies the depth testing behavior
381 *
382 * @param func function used for depth testing
383 *
384 * @return this
385 */
Jim Shuma288c8712010-07-07 14:24:21 -0700386 public Builder setDepthFunc(DepthFunc func) {
Jason Sams22534172009-08-04 16:58:20 -0700387 mDepthFunc = func;
Jim Shuma288c8712010-07-07 14:24:21 -0700388 return this;
Jason Sams22534172009-08-04 16:58:20 -0700389 }
390
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700391 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800392 * Enables writes into the depth buffer
393 *
394 * @param enable specifies whether depth writes are
395 * enabled or disabled
396 *
397 * @return this
398 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800399 public Builder setDepthMaskEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700400 mDepthMask = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700401 return this;
Jason Sams22534172009-08-04 16:58:20 -0700402 }
403
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700404 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800405 * Enables writes into the color buffer
406 *
407 * @param r specifies whether red channel is written
408 * @param g specifies whether green channel is written
409 * @param b specifies whether blue channel is written
410 * @param a specifies whether alpha channel is written
411 *
412 * @return this
413 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800414 public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) {
Jason Sams22534172009-08-04 16:58:20 -0700415 mColorMaskR = r;
416 mColorMaskG = g;
417 mColorMaskB = b;
418 mColorMaskA = a;
Jim Shuma288c8712010-07-07 14:24:21 -0700419 return this;
Jason Sams22534172009-08-04 16:58:20 -0700420 }
421
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700422 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800423 * Specifies how incoming pixels are combined with the pixels
424 * stored in the framebuffer
425 *
426 * @param src specifies how the source blending factor is
427 * computed
428 * @param dst specifies how the destination blending factor is
429 * computed
430 *
431 * @return this
432 */
Jim Shuma288c8712010-07-07 14:24:21 -0700433 public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
Jason Sams22534172009-08-04 16:58:20 -0700434 mBlendSrc = src;
435 mBlendDst = dst;
Jim Shuma288c8712010-07-07 14:24:21 -0700436 return this;
Jason Sams22534172009-08-04 16:58:20 -0700437 }
438
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700439 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800440 * Enables dithering
441 *
442 * @param enable specifies whether dithering is enabled or
443 * disabled
444 *
445 * @return this
446 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800447 public Builder setDitherEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700448 mDither = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700449 return this;
Jason Sams22534172009-08-04 16:58:20 -0700450 }
451
Alex Sakhartchouka0c2eb22012-04-19 16:30:58 -0700452 /** @deprecated renderscript is deprecated in J
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800453 * Creates a program store from the current state of the builder
454 */
Jason Sams22534172009-08-04 16:58:20 -0700455 public ProgramStore create() {
Jason Sams771bebb2009-12-07 12:40:12 -0800456 mRS.validate();
Jason Sams331bf9b2011-04-06 11:23:54 -0700457 int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
458 mDepthMask, mDither,
459 mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700460 ProgramStore programStore = new ProgramStore(id, mRS);
461 programStore.mDepthFunc = mDepthFunc;
462 programStore.mDepthMask = mDepthMask;
463 programStore.mColorMaskR = mColorMaskR;
464 programStore.mColorMaskG = mColorMaskG;
465 programStore.mColorMaskB = mColorMaskB;
466 programStore.mColorMaskA = mColorMaskA;
467 programStore.mBlendSrc = mBlendSrc;
468 programStore.mBlendDst = mBlendDst;
469 programStore.mDither = mDither;
470 return programStore;
Jason Sams22534172009-08-04 16:58:20 -0700471 }
472 }
473
474}
475
476
477
478