blob: c0fa9c45fb53f71e612b10815b33a61324cdd8a6 [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
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070020/**
Tim Murraya9084222013-04-05 22:06:43 +000021 * @hide
Robert Ly11518ac2011-02-09 13:57:06 -080022 * <p>ProgramStore contains a set of parameters that control how
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080023 * the graphics hardware handles writes to the framebuffer.
Robert Ly11518ac2011-02-09 13:57:06 -080024 * 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 Sams22534172009-08-04 16:58:20 -070033 *
34 **/
35public class ProgramStore extends BaseObj {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070036 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080037 * 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -080043 public enum DepthFunc {
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080044
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070045 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080046 * Always drawn
47 */
Jason Sams22534172009-08-04 16:58:20 -070048 ALWAYS (0),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070049 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080050 * Drawn if the incoming depth value is less than that in the
51 * depth buffer
52 */
Jason Sams22534172009-08-04 16:58:20 -070053 LESS (1),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070054 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080055 * Drawn if the incoming depth value is less or equal to that in
56 * the depth buffer
57 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080058 LESS_OR_EQUAL (2),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070059 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080060 * Drawn if the incoming depth value is greater than that in the
61 * depth buffer
62 */
Jason Sams22534172009-08-04 16:58:20 -070063 GREATER (3),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070064 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080065 * Drawn if the incoming depth value is greater or equal to that
66 * in the depth buffer
67 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080068 GREATER_OR_EQUAL (4),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070069 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080070 * Drawn if the incoming depth value is equal to that in the
71 * depth buffer
72 */
Jason Sams22534172009-08-04 16:58:20 -070073 EQUAL (5),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070074 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080075 * Drawn if the incoming depth value is not equal to that in the
76 * depth buffer
77 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080078 NOT_EQUAL (6);
Jason Sams22534172009-08-04 16:58:20 -070079
80 int mID;
81 DepthFunc(int id) {
82 mID = id;
83 }
84 }
85
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070086 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080087 * 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 Sams22534172009-08-04 16:58:20 -070094 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 Samseab4c752009-10-28 17:40:13 -0700102 ONE_MINUS_DST_ALPHA (7),
Jason Sams22534172009-08-04 16:58:20 -0700103 SRC_ALPHA_SATURATE (8);
104
105 int mID;
106 BlendSrcFunc(int id) {
107 mID = id;
108 }
109 }
110
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700111 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800112 * 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 Sams22534172009-08-04 16:58:20 -0700120 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 Samseab4c752009-10-28 17:40:13 -0700128 ONE_MINUS_DST_ALPHA (7);
Jason Sams22534172009-08-04 16:58:20 -0700129
130 int mID;
131 BlendDstFunc(int id) {
132 mID = id;
133 }
134 }
135
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700136 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 Sams22534172009-08-04 16:58:20 -0700145
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000146 ProgramStore(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700147 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -0700148 }
149
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700150 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700151 * Returns the function used to test writing into the depth
152 * buffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700153 * @return depth function
154 */
155 public DepthFunc getDepthFunc() {
156 return mDepthFunc;
157 }
158
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700159 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700160 * Queries whether writes are enabled into the depth buffer
161 * @return depth mask
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700162 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700163 public boolean isDepthMaskEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700164 return mDepthMask;
165 }
166
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700167 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700168 * Queries whether red channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700169 * @return red color channel mask
170 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700171 public boolean isColorMaskRedEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700172 return mColorMaskR;
173 }
174
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700175 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700176 * Queries whether green channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700177 * @return green color channel mask
178 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700179 public boolean isColorMaskGreenEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700180 return mColorMaskG;
181 }
182
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700183 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700184 * Queries whether blue channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700185 * @return blue color channel mask
186 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700187 public boolean isColorMaskBlueEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700188 return mColorMaskB;
189 }
190
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700191 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700192 * Queries whether alpha channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700193 * @return alpha channel mask
194 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700195 public boolean isColorMaskAlphaEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700196 return mColorMaskA;
197 }
198
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700199 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700200 * Specifies how the source blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700201 * @return source blend function
202 */
203 public BlendSrcFunc getBlendSrcFunc() {
204 return mBlendSrc;
205 }
206
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700207 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700208 * Specifies how the destination blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700209 * @return destination blend function
210 */
211 public BlendDstFunc getBlendDstFunc() {
212 return mBlendDst;
213 }
214
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700215 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700216 * Specifies whether colors are dithered before writing into the
217 * framebuffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700218 * @return whether dither is enabled
219 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700220 public boolean isDitherEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700221 return mDither;
222 }
223
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700224 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800225 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800233 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800234 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700235 public static ProgramStore BLEND_NONE_DEPTH_TEST(RenderScript rs) {
236 if(rs.mProgramStore_BLEND_NONE_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700237 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
238 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
239 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800240 builder.setDitherEnabled(false);
241 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700242 rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700243 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700244 return rs.mProgramStore_BLEND_NONE_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700245 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700246 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800247 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800254 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800255 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800256 public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700257 if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700258 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
259 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
260 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800261 builder.setDitherEnabled(false);
262 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700263 rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700264 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700265 return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700266 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700267 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800268 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800278 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800279 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700280 public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) {
281 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700282 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800285 builder.setDitherEnabled(false);
286 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700287 rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700288 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700289 return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700290 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700291 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800292 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800300 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800301 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800302 public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700303 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700304 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800307 builder.setDitherEnabled(false);
308 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700309 rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700310 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700311 return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700312 }
Jason Sams22534172009-08-04 16:58:20 -0700313
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700314 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800315 * 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 Sams22534172009-08-04 16:58:20 -0700319 public static class Builder {
320 RenderScript mRS;
Jason Sams22534172009-08-04 16:58:20 -0700321 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 Sakhartchouk32e09b52010-08-23 10:24:10 -0700331 public Builder(RenderScript rs) {
332 mRS = rs;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700333 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 Sams22534172009-08-04 16:58:20 -0700341 }
342
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700343 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800344 * Specifies the depth testing behavior
345 *
346 * @param func function used for depth testing
347 *
348 * @return this
349 */
Jim Shuma288c8712010-07-07 14:24:21 -0700350 public Builder setDepthFunc(DepthFunc func) {
Jason Sams22534172009-08-04 16:58:20 -0700351 mDepthFunc = func;
Jim Shuma288c8712010-07-07 14:24:21 -0700352 return this;
Jason Sams22534172009-08-04 16:58:20 -0700353 }
354
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700355 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800356 * 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800363 public Builder setDepthMaskEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700364 mDepthMask = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700365 return this;
Jason Sams22534172009-08-04 16:58:20 -0700366 }
367
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700368 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800369 * 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800378 public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) {
Jason Sams22534172009-08-04 16:58:20 -0700379 mColorMaskR = r;
380 mColorMaskG = g;
381 mColorMaskB = b;
382 mColorMaskA = a;
Jim Shuma288c8712010-07-07 14:24:21 -0700383 return this;
Jason Sams22534172009-08-04 16:58:20 -0700384 }
385
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700386 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800387 * 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 Shuma288c8712010-07-07 14:24:21 -0700397 public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
Jason Sams22534172009-08-04 16:58:20 -0700398 mBlendSrc = src;
399 mBlendDst = dst;
Jim Shuma288c8712010-07-07 14:24:21 -0700400 return this;
Jason Sams22534172009-08-04 16:58:20 -0700401 }
402
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700403 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800404 * Enables dithering
405 *
406 * @param enable specifies whether dithering is enabled or
407 * disabled
408 *
409 * @return this
410 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800411 public Builder setDitherEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700412 mDither = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700413 return this;
Jason Sams22534172009-08-04 16:58:20 -0700414 }
415
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700416 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800417 * Creates a program store from the current state of the builder
418 */
Jason Sams22534172009-08-04 16:58:20 -0700419 public ProgramStore create() {
Jason Sams771bebb2009-12-07 12:40:12 -0800420 mRS.validate();
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000421 long id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -0700422 mDepthMask, mDither,
423 mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700424 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 Sams22534172009-08-04 16:58:20 -0700435 }
436 }
437
438}
439
440
441
442