blob: d0fd6e5184f863b92d4dd69ecee3c888bade1239 [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/**
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 {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070038 /**
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
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070047 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -080048 * Always drawn
49 */
Jason Sams22534172009-08-04 16:58:20 -070050 ALWAYS (0),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070051 /**
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),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070056 /**
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),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070061 /**
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),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070066 /**
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),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070071 /**
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),
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070076 /**
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
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070088 /**
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 {
97 ZERO (0),
98 ONE (1),
99 DST_COLOR (2),
100 ONE_MINUS_DST_COLOR (3),
101 SRC_ALPHA (4),
102 ONE_MINUS_SRC_ALPHA (5),
103 DST_ALPHA (6),
Jason Samseab4c752009-10-28 17:40:13 -0700104 ONE_MINUS_DST_ALPHA (7),
Jason Sams22534172009-08-04 16:58:20 -0700105 SRC_ALPHA_SATURATE (8);
106
107 int mID;
108 BlendSrcFunc(int id) {
109 mID = id;
110 }
111 }
112
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700113 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800114 * Specifies the functions used to combine incoming pixels with
115 * those already in the frame buffer.
116 *
117 * BlendDstFunc describes how the coefficient used to scale the
118 * pixels already in the framebuffer is computed during the
119 * blending operation
120 *
121 */
Jason Sams22534172009-08-04 16:58:20 -0700122 public enum BlendDstFunc {
123 ZERO (0),
124 ONE (1),
125 SRC_COLOR (2),
126 ONE_MINUS_SRC_COLOR (3),
127 SRC_ALPHA (4),
128 ONE_MINUS_SRC_ALPHA (5),
129 DST_ALPHA (6),
Jason Samseab4c752009-10-28 17:40:13 -0700130 ONE_MINUS_DST_ALPHA (7);
Jason Sams22534172009-08-04 16:58:20 -0700131
132 int mID;
133 BlendDstFunc(int id) {
134 mID = id;
135 }
136 }
137
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700138 DepthFunc mDepthFunc;
139 boolean mDepthMask;
140 boolean mColorMaskR;
141 boolean mColorMaskG;
142 boolean mColorMaskB;
143 boolean mColorMaskA;
144 BlendSrcFunc mBlendSrc;
145 BlendDstFunc mBlendDst;
146 boolean mDither;
Jason Sams22534172009-08-04 16:58:20 -0700147
148 ProgramStore(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700149 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -0700150 }
151
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700152 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700153 * Returns the function used to test writing into the depth
154 * buffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700155 * @return depth function
156 */
157 public DepthFunc getDepthFunc() {
158 return mDepthFunc;
159 }
160
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700161 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700162 * Queries whether writes are enabled into the depth buffer
163 * @return depth mask
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700164 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700165 public boolean isDepthMaskEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700166 return mDepthMask;
167 }
168
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700169 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700170 * Queries whether red channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700171 * @return red color channel mask
172 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700173 public boolean isColorMaskRedEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700174 return mColorMaskR;
175 }
176
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700177 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700178 * Queries whether green channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700179 * @return green color channel mask
180 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700181 public boolean isColorMaskGreenEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700182 return mColorMaskG;
183 }
184
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700185 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700186 * Queries whether blue channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700187 * @return blue color channel mask
188 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700189 public boolean isColorMaskBlueEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700190 return mColorMaskB;
191 }
192
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700193 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700194 * Queries whether alpha channel is written
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700195 * @return alpha channel mask
196 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700197 public boolean isColorMaskAlphaEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700198 return mColorMaskA;
199 }
200
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700201 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700202 * Specifies how the source blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700203 * @return source blend function
204 */
205 public BlendSrcFunc getBlendSrcFunc() {
206 return mBlendSrc;
207 }
208
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700209 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700210 * Specifies how the destination blending factor is computed
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700211 * @return destination blend function
212 */
213 public BlendDstFunc getBlendDstFunc() {
214 return mBlendDst;
215 }
216
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700217 /**
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700218 * Specifies whether colors are dithered before writing into the
219 * framebuffer
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700220 * @return whether dither is enabled
221 */
Alex Sakhartchouk918e8402012-04-11 14:04:23 -0700222 public boolean isDitherEnabled() {
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700223 return mDither;
224 }
225
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700226 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800227 * Returns a pre-defined program store object with the following
228 * characteristics:
229 * - incoming pixels are drawn if their depth value is less than
230 * the stored value in the depth buffer. If the pixel is
231 * drawn, its value is also stored in the depth buffer
232 * - incoming pixels override the value stored in the color
233 * buffer if it passes the depth test
234 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800235 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800236 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700237 public static ProgramStore BLEND_NONE_DEPTH_TEST(RenderScript rs) {
238 if(rs.mProgramStore_BLEND_NONE_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700239 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
240 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
241 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800242 builder.setDitherEnabled(false);
243 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700244 rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700245 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700246 return rs.mProgramStore_BLEND_NONE_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700247 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700248 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800249 * Returns a pre-defined program store object with the following
250 * characteristics:
251 * - incoming pixels always pass the depth test and their value
252 * is not stored in the depth buffer
253 * - incoming pixels override the value stored in the color
254 * buffer
255 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800256 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800257 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800258 public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700259 if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700260 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
261 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
262 builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800263 builder.setDitherEnabled(false);
264 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700265 rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700266 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700267 return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700268 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700269 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800270 * Returns a pre-defined program store object with the following
271 * characteristics:
272 * - incoming pixels are drawn if their depth value is less than
273 * the stored value in the depth buffer. If the pixel is
274 * drawn, its value is also stored in the depth buffer
275 * - if the incoming (Source) pixel passes depth test, its value
276 * is combined with the stored color (Dest) using the
277 * following formula
278 * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A)
279 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800280 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800281 **/
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700282 public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) {
283 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700284 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
285 builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
286 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800287 builder.setDitherEnabled(false);
288 builder.setDepthMaskEnabled(true);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700289 rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700290 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700291 return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700292 }
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700293 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800294 * Returns a pre-defined program store object with the following
295 * characteristics:
296 * - incoming pixels always pass the depth test and their value
297 * is not stored in the depth buffer
298 * - incoming pixel's value is combined with the stored color
299 * (Dest) using the following formula
300 * Final.RGB = Source.RGB * Source.A + Dest.RGB * (1 - Source.A)
301 *
Alex Sakhartchoukf5c876e2011-01-13 14:53:43 -0800302 * @param rs Context to which the program will belong.
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800303 **/
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800304 public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) {
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700305 if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) {
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700306 ProgramStore.Builder builder = new ProgramStore.Builder(rs);
307 builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
308 builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800309 builder.setDitherEnabled(false);
310 builder.setDepthMaskEnabled(false);
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700311 rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create();
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700312 }
Alex Sakhartchoukd36f2482010-08-24 11:37:33 -0700313 return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700314 }
Jason Sams22534172009-08-04 16:58:20 -0700315
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700316 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800317 * Builder class for ProgramStore object. If the builder is left
318 * empty, the equivalent of BLEND_NONE_DEPTH_NONE would be
319 * returned
320 */
Jason Sams22534172009-08-04 16:58:20 -0700321 public static class Builder {
322 RenderScript mRS;
Jason Sams22534172009-08-04 16:58:20 -0700323 DepthFunc mDepthFunc;
324 boolean mDepthMask;
325 boolean mColorMaskR;
326 boolean mColorMaskG;
327 boolean mColorMaskB;
328 boolean mColorMaskA;
329 BlendSrcFunc mBlendSrc;
330 BlendDstFunc mBlendDst;
331 boolean mDither;
332
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700333 public Builder(RenderScript rs) {
334 mRS = rs;
Alex Sakhartchouk32e09b52010-08-23 10:24:10 -0700335 mDepthFunc = DepthFunc.ALWAYS;
336 mDepthMask = false;
337 mColorMaskR = true;
338 mColorMaskG = true;
339 mColorMaskB = true;
340 mColorMaskA = true;
341 mBlendSrc = BlendSrcFunc.ONE;
342 mBlendDst = BlendDstFunc.ZERO;
Jason Sams22534172009-08-04 16:58:20 -0700343 }
344
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700345 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800346 * Specifies the depth testing behavior
347 *
348 * @param func function used for depth testing
349 *
350 * @return this
351 */
Jim Shuma288c8712010-07-07 14:24:21 -0700352 public Builder setDepthFunc(DepthFunc func) {
Jason Sams22534172009-08-04 16:58:20 -0700353 mDepthFunc = func;
Jim Shuma288c8712010-07-07 14:24:21 -0700354 return this;
Jason Sams22534172009-08-04 16:58:20 -0700355 }
356
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700357 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800358 * Enables writes into the depth buffer
359 *
360 * @param enable specifies whether depth writes are
361 * enabled or disabled
362 *
363 * @return this
364 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800365 public Builder setDepthMaskEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700366 mDepthMask = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700367 return this;
Jason Sams22534172009-08-04 16:58:20 -0700368 }
369
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700370 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800371 * Enables writes into the color buffer
372 *
373 * @param r specifies whether red channel is written
374 * @param g specifies whether green channel is written
375 * @param b specifies whether blue channel is written
376 * @param a specifies whether alpha channel is written
377 *
378 * @return this
379 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800380 public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) {
Jason Sams22534172009-08-04 16:58:20 -0700381 mColorMaskR = r;
382 mColorMaskG = g;
383 mColorMaskB = b;
384 mColorMaskA = a;
Jim Shuma288c8712010-07-07 14:24:21 -0700385 return this;
Jason Sams22534172009-08-04 16:58:20 -0700386 }
387
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700388 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800389 * Specifies how incoming pixels are combined with the pixels
390 * stored in the framebuffer
391 *
392 * @param src specifies how the source blending factor is
393 * computed
394 * @param dst specifies how the destination blending factor is
395 * computed
396 *
397 * @return this
398 */
Jim Shuma288c8712010-07-07 14:24:21 -0700399 public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
Jason Sams22534172009-08-04 16:58:20 -0700400 mBlendSrc = src;
401 mBlendDst = dst;
Jim Shuma288c8712010-07-07 14:24:21 -0700402 return this;
Jason Sams22534172009-08-04 16:58:20 -0700403 }
404
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700405 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800406 * Enables dithering
407 *
408 * @param enable specifies whether dithering is enabled or
409 * disabled
410 *
411 * @return this
412 */
Alex Sakhartchoukb4d7bb62010-12-21 14:42:26 -0800413 public Builder setDitherEnabled(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700414 mDither = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700415 return this;
Jason Sams22534172009-08-04 16:58:20 -0700416 }
417
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700418 /**
Alex Sakhartchouk623c54d2011-01-12 17:32:36 -0800419 * Creates a program store from the current state of the builder
420 */
Jason Sams22534172009-08-04 16:58:20 -0700421 public ProgramStore create() {
Jason Sams771bebb2009-12-07 12:40:12 -0800422 mRS.validate();
Jason Sams331bf9b2011-04-06 11:23:54 -0700423 int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
424 mDepthMask, mDither,
425 mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700426 ProgramStore programStore = new ProgramStore(id, mRS);
427 programStore.mDepthFunc = mDepthFunc;
428 programStore.mDepthMask = mDepthMask;
429 programStore.mColorMaskR = mColorMaskR;
430 programStore.mColorMaskG = mColorMaskG;
431 programStore.mColorMaskB = mColorMaskB;
432 programStore.mColorMaskA = mColorMaskA;
433 programStore.mBlendSrc = mBlendSrc;
434 programStore.mBlendDst = mBlendDst;
435 programStore.mDither = mDither;
436 return programStore;
Jason Sams22534172009-08-04 16:58:20 -0700437 }
438 }
439
440}
441
442
443
444