blob: 969cc2568eda2d0ef44f1fa99b04a51b60774c75 [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
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070023/**
Tim Murraya9084222013-04-05 22:06:43 +000024 * @hide
Robert Ly11518ac2011-02-09 13:57:06 -080025 * <p>ProgramStore contains a set of parameters that control how
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080026 * the graphics hardware handles writes to the framebuffer.
Robert Ly11518ac2011-02-09 13:57:06 -080027 * 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 Sams22534172009-08-04 16:58:20 -070036 *
37 **/
38public class ProgramStore extends BaseObj {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070039 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080040 * 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -080046 public enum DepthFunc {
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080047
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070048 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080049 * Always drawn
50 */
Jason Sams22534172009-08-04 16:58:20 -070051 ALWAYS (0),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070052 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080053 * Drawn if the incoming depth value is less than that in the
54 * depth buffer
55 */
Jason Sams22534172009-08-04 16:58:20 -070056 LESS (1),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070057 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080058 * Drawn if the incoming depth value is less or equal to that in
59 * the depth buffer
60 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080061 LESS_OR_EQUAL (2),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070062 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080063 * Drawn if the incoming depth value is greater than that in the
64 * depth buffer
65 */
Jason Sams22534172009-08-04 16:58:20 -070066 GREATER (3),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070067 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080068 * Drawn if the incoming depth value is greater or equal to that
69 * in the depth buffer
70 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080071 GREATER_OR_EQUAL (4),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070072 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080073 * Drawn if the incoming depth value is equal to that in the
74 * depth buffer
75 */
Jason Sams22534172009-08-04 16:58:20 -070076 EQUAL (5),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070077 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080078 * Drawn if the incoming depth value is not equal to that in the
79 * depth buffer
80 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -080081 NOT_EQUAL (6);
Jason Sams22534172009-08-04 16:58:20 -070082
83 int mID;
84 DepthFunc(int id) {
85 mID = id;
86 }
87 }
88
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070089 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080090 * 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 Sams22534172009-08-04 16:58:20 -070097 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 Samseab4c752009-10-28 17:40:13 -0700105 ONE_MINUS_DST_ALPHA (7),
Jason Sams22534172009-08-04 16:58:20 -0700106 SRC_ALPHA_SATURATE (8);
107
108 int mID;
109 BlendSrcFunc(int id) {
110 mID = id;
111 }
112 }
113
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700114 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800115 * 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 Sams22534172009-08-04 16:58:20 -0700123 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 Samseab4c752009-10-28 17:40:13 -0700131 ONE_MINUS_DST_ALPHA (7);
Jason Sams22534172009-08-04 16:58:20 -0700132
133 int mID;
134 BlendDstFunc(int id) {
135 mID = id;
136 }
137 }
138
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700139 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 Sams22534172009-08-04 16:58:20 -0700148
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000149 ProgramStore(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700150 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -0700151 }
152
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700153 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700154 * Returns the function used to test writing into the depth
155 * buffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700156 * @return depth function
157 */
158 public DepthFunc getDepthFunc() {
159 return mDepthFunc;
160 }
161
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700162 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700163 * Queries whether writes are enabled into the depth buffer
164 * @return depth mask
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700165 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700166 public boolean isDepthMaskEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700167 return mDepthMask;
168 }
169
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700170 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700171 * Queries whether red channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700172 * @return red color channel mask
173 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700174 public boolean isColorMaskRedEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700175 return mColorMaskR;
176 }
177
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700178 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700179 * Queries whether green channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700180 * @return green color channel mask
181 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700182 public boolean isColorMaskGreenEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700183 return mColorMaskG;
184 }
185
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700186 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700187 * Queries whether blue channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700188 * @return blue color channel mask
189 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700190 public boolean isColorMaskBlueEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700191 return mColorMaskB;
192 }
193
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700194 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700195 * Queries whether alpha channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700196 * @return alpha channel mask
197 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700198 public boolean isColorMaskAlphaEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700199 return mColorMaskA;
200 }
201
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700202 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700203 * Specifies how the source blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700204 * @return source blend function
205 */
206 public BlendSrcFunc getBlendSrcFunc() {
207 return mBlendSrc;
208 }
209
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700210 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700211 * Specifies how the destination blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700212 * @return destination blend function
213 */
214 public BlendDstFunc getBlendDstFunc() {
215 return mBlendDst;
216 }
217
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700218 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700219 * Specifies whether colors are dithered before writing into the
220 * framebuffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700221 * @return whether dither is enabled
222 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700223 public boolean isDitherEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700224 return mDither;
225 }
226
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700227 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800228 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800236 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800237 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700238 public static ProgramStore BLEND_NONE_DEPTH_TEST(RenderScript rs) {
239 if(rs.mProgramStore_BLEND_NONE_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700240 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
241 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
242 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800243 builder.setDitherEnabled(false);
244 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700245 rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700246 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700247 return rs.mProgramStore_BLEND_NONE_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700248 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700249 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800250 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800257 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800258 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800259 public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700260 if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700261 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
262 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
263 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800264 builder.setDitherEnabled(false);
265 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700266 rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700267 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700268 return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700269 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700270 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800271 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800281 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800282 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700283 public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) {
284 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700285 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800288 builder.setDitherEnabled(false);
289 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700290 rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700291 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700292 return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700293 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700294 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800295 * 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 Sakhartchoukf5c876e2011-01-13 14:53:43 -0800303 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800304 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800305 public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700306 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700307 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800310 builder.setDitherEnabled(false);
311 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700312 rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700313 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700314 return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700315 }
Jason Sams22534172009-08-04 16:58:20 -0700316
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700317 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800318 * 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 Sams22534172009-08-04 16:58:20 -0700322 public static class Builder {
323 RenderScript mRS;
Jason Sams22534172009-08-04 16:58:20 -0700324 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 Sakhartchouk32e09b52010-08-23 10:24:10 -0700334 public Builder(RenderScript rs) {
335 mRS = rs;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700336 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 Sams22534172009-08-04 16:58:20 -0700344 }
345
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700346 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800347 * Specifies the depth testing behavior
348 *
349 * @param func function used for depth testing
350 *
351 * @return this
352 */
Jim Shuma288c8712010-07-07 14:24:21 -0700353 public Builder setDepthFunc(DepthFunc func) {
Jason Sams22534172009-08-04 16:58:20 -0700354 mDepthFunc = func;
Jim Shuma288c8712010-07-07 14:24:21 -0700355 return this;
Jason Sams22534172009-08-04 16:58:20 -0700356 }
357
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700358 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800359 * 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800366 public Builder setDepthMaskEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700367 mDepthMask = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700368 return this;
Jason Sams22534172009-08-04 16:58:20 -0700369 }
370
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700371 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800372 * 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 Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800381 public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) {
Jason Sams22534172009-08-04 16:58:20 -0700382 mColorMaskR = r;
383 mColorMaskG = g;
384 mColorMaskB = b;
385 mColorMaskA = a;
Jim Shuma288c8712010-07-07 14:24:21 -0700386 return this;
Jason Sams22534172009-08-04 16:58:20 -0700387 }
388
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700389 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800390 * 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 Shuma288c8712010-07-07 14:24:21 -0700400 public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
Jason Sams22534172009-08-04 16:58:20 -0700401 mBlendSrc = src;
402 mBlendDst = dst;
Jim Shuma288c8712010-07-07 14:24:21 -0700403 return this;
Jason Sams22534172009-08-04 16:58:20 -0700404 }
405
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700406 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800407 * Enables dithering
408 *
409 * @param enable specifies whether dithering is enabled or
410 * disabled
411 *
412 * @return this
413 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800414 public Builder setDitherEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700415 mDither = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700416 return this;
Jason Sams22534172009-08-04 16:58:20 -0700417 }
418
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700419 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800420 * Creates a program store from the current state of the builder
421 */
Jason Sams22534172009-08-04 16:58:20 -0700422 public ProgramStore create() {
Jason Sams771bebb2009-12-07 12:40:12 -0800423 mRS.validate();
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000424 long id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -0700425 mDepthMask, mDither,
426 mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700427 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 Sams22534172009-08-04 16:58:20 -0700438 }
439 }
440
441}
442
443
444
445