ProgramStore.java revision a0c2eb27b408660b02fa248943166d6c7e447908
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
17package android.renderscript;
18
19
20import android.util.Log;
21
22
23/** @deprecated renderscript is deprecated in J
24 * <p>ProgramStore contains a set of parameters that control how
25 * the graphics hardware handles writes to the framebuffer.
26 * 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>
35 *
36 **/
37public class ProgramStore extends BaseObj {
38    /** @deprecated renderscript is deprecated in J
39    * 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    */
45    public enum DepthFunc {
46
47        /** @deprecated renderscript is deprecated in J
48        * Always drawn
49        */
50        ALWAYS (0),
51        /** @deprecated renderscript is deprecated in J
52        * Drawn if the incoming depth value is less than that in the
53        * depth buffer
54        */
55        LESS (1),
56        /** @deprecated renderscript is deprecated in J
57        * Drawn if the incoming depth value is less or equal to that in
58        * the depth buffer
59        */
60        LESS_OR_EQUAL (2),
61        /** @deprecated renderscript is deprecated in J
62        * Drawn if the incoming depth value is greater than that in the
63        * depth buffer
64        */
65        GREATER (3),
66        /** @deprecated renderscript is deprecated in J
67        * Drawn if the incoming depth value is greater or equal to that
68        * in the depth buffer
69        */
70        GREATER_OR_EQUAL (4),
71        /** @deprecated renderscript is deprecated in J
72        * Drawn if the incoming depth value is equal to that in the
73        * depth buffer
74        */
75        EQUAL (5),
76        /** @deprecated renderscript is deprecated in J
77        * Drawn if the incoming depth value is not equal to that in the
78        * depth buffer
79        */
80        NOT_EQUAL (6);
81
82        int mID;
83        DepthFunc(int id) {
84            mID = id;
85        }
86    }
87
88    /** @deprecated renderscript is deprecated in J
89    * 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    */
96    public enum BlendSrcFunc {
97        /** @deprecated renderscript is deprecated in J
98        */
99        ZERO (0),
100        /** @deprecated renderscript is deprecated in J
101        */
102        ONE (1),
103        /** @deprecated renderscript is deprecated in J
104        */
105        DST_COLOR (2),
106        /** @deprecated renderscript is deprecated in J
107        */
108        ONE_MINUS_DST_COLOR (3),
109        /** @deprecated renderscript is deprecated in J
110        */
111        SRC_ALPHA (4),
112        /** @deprecated renderscript is deprecated in J
113        */
114        ONE_MINUS_SRC_ALPHA (5),
115        /** @deprecated renderscript is deprecated in J
116        */
117        DST_ALPHA (6),
118        /** @deprecated renderscript is deprecated in J
119        */
120        ONE_MINUS_DST_ALPHA (7),
121        /** @deprecated renderscript is deprecated in J
122        */
123        SRC_ALPHA_SATURATE (8);
124
125        int mID;
126        BlendSrcFunc(int id) {
127            mID = id;
128        }
129    }
130
131    /** @deprecated renderscript is deprecated in J
132    * 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    */
140    public enum BlendDstFunc {
141        /** @deprecated renderscript is deprecated in J
142        */
143        ZERO (0),
144        /** @deprecated renderscript is deprecated in J
145        */
146        ONE (1),
147        /** @deprecated renderscript is deprecated in J
148        */
149        SRC_COLOR (2),
150        /** @deprecated renderscript is deprecated in J
151        */
152        ONE_MINUS_SRC_COLOR (3),
153        /** @deprecated renderscript is deprecated in J
154        */
155        SRC_ALPHA (4),
156        /** @deprecated renderscript is deprecated in J
157        */
158        ONE_MINUS_SRC_ALPHA (5),
159        /** @deprecated renderscript is deprecated in J
160        */
161        DST_ALPHA (6),
162        /** @deprecated renderscript is deprecated in J
163        */
164        ONE_MINUS_DST_ALPHA (7);
165
166        int mID;
167        BlendDstFunc(int id) {
168            mID = id;
169        }
170    }
171
172    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;
181
182    ProgramStore(int id, RenderScript rs) {
183        super(id, rs);
184    }
185
186    /** @hide renderscript is deprecated in J
187    * Returns the function used to test writing into the depth
188    * buffer
189    * @return depth function
190    */
191    public DepthFunc getDepthFunc() {
192        return mDepthFunc;
193    }
194
195    /** @hide renderscript is deprecated in J
196    * Queries whether writes are enabled into the depth buffer
197    * @return depth mask
198    */
199    public boolean isDepthMaskEnabled() {
200        return mDepthMask;
201    }
202
203    /** @hide renderscript is deprecated in J
204    * Queries whether red channel is written
205    * @return red color channel mask
206    */
207    public boolean isColorMaskRedEnabled() {
208        return mColorMaskR;
209    }
210
211    /** @hide renderscript is deprecated in J
212    * Queries whether green channel is written
213    * @return green color channel mask
214    */
215    public boolean isColorMaskGreenEnabled() {
216        return mColorMaskG;
217    }
218
219    /** @hide renderscript is deprecated in J
220    * Queries whether blue channel is written
221    * @return blue color channel mask
222    */
223    public boolean isColorMaskBlueEnabled() {
224        return mColorMaskB;
225    }
226
227    /** @hide renderscript is deprecated in J
228    * Queries whether alpha channel is written
229    * @return alpha channel mask
230    */
231    public boolean isColorMaskAlphaEnabled() {
232        return mColorMaskA;
233    }
234
235    /** @hide renderscript is deprecated in J
236    * Specifies how the source blending factor is computed
237    * @return source blend function
238    */
239    public BlendSrcFunc getBlendSrcFunc() {
240        return mBlendSrc;
241    }
242
243    /** @hide renderscript is deprecated in J
244    * Specifies how the destination blending factor is computed
245    * @return destination blend function
246    */
247    public BlendDstFunc getBlendDstFunc() {
248        return mBlendDst;
249    }
250
251    /** @hide renderscript is deprecated in J
252    * Specifies whether colors are dithered before writing into the
253    * framebuffer
254    * @return whether dither is enabled
255    */
256    public boolean isDitherEnabled() {
257        return mDither;
258    }
259
260    /** @deprecated renderscript is deprecated in J
261    * 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    *
269    *  @param rs Context to which the program will belong.
270    **/
271    public static ProgramStore BLEND_NONE_DEPTH_TEST(RenderScript rs) {
272        if(rs.mProgramStore_BLEND_NONE_DEPTH_TEST == null) {
273            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
274            builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
275            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
276            builder.setDitherEnabled(false);
277            builder.setDepthMaskEnabled(true);
278            rs.mProgramStore_BLEND_NONE_DEPTH_TEST = builder.create();
279        }
280        return rs.mProgramStore_BLEND_NONE_DEPTH_TEST;
281    }
282    /** @deprecated renderscript is deprecated in J
283    * 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    *
290    *  @param rs Context to which the program will belong.
291    **/
292    public static ProgramStore BLEND_NONE_DEPTH_NONE(RenderScript rs) {
293        if(rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH == null) {
294            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
295            builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
296            builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
297            builder.setDitherEnabled(false);
298            builder.setDepthMaskEnabled(false);
299            rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH = builder.create();
300        }
301        return rs.mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH;
302    }
303    /** @deprecated renderscript is deprecated in J
304    * 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    *
314    *  @param rs Context to which the program will belong.
315    **/
316    public static ProgramStore BLEND_ALPHA_DEPTH_TEST(RenderScript rs) {
317        if(rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST == null) {
318            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
319            builder.setDepthFunc(ProgramStore.DepthFunc.LESS);
320            builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
321            builder.setDitherEnabled(false);
322            builder.setDepthMaskEnabled(true);
323            rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST = builder.create();
324        }
325        return rs.mProgramStore_BLEND_ALPHA_DEPTH_TEST;
326    }
327    /** @deprecated renderscript is deprecated in J
328    * 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    *
336    *  @param rs Context to which the program will belong.
337    **/
338    public static ProgramStore BLEND_ALPHA_DEPTH_NONE(RenderScript rs) {
339        if(rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH == null) {
340            ProgramStore.Builder builder = new ProgramStore.Builder(rs);
341            builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
342            builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
343            builder.setDitherEnabled(false);
344            builder.setDepthMaskEnabled(false);
345            rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH = builder.create();
346        }
347        return rs.mProgramStore_BLEND_ALPHA_DEPTH_NO_DEPTH;
348    }
349
350    /** @deprecated renderscript is deprecated in J
351    * Builder class for ProgramStore object. If the builder is left
352    * empty, the equivalent of BLEND_NONE_DEPTH_NONE would be
353    * returned
354    */
355    public static class Builder {
356        RenderScript mRS;
357        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
367        public Builder(RenderScript rs) {
368            mRS = rs;
369            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;
377        }
378
379        /** @deprecated renderscript is deprecated in J
380        * Specifies the depth testing behavior
381        *
382        * @param func function used for depth testing
383        *
384        * @return this
385        */
386        public Builder setDepthFunc(DepthFunc func) {
387            mDepthFunc = func;
388            return this;
389        }
390
391        /** @deprecated renderscript is deprecated in J
392        * Enables writes into the depth buffer
393        *
394        * @param enable specifies whether depth writes are
395        *         enabled or disabled
396        *
397        * @return this
398        */
399        public Builder setDepthMaskEnabled(boolean enable) {
400            mDepthMask = enable;
401            return this;
402        }
403
404        /** @deprecated renderscript is deprecated in J
405        * 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        */
414        public Builder setColorMaskEnabled(boolean r, boolean g, boolean b, boolean a) {
415            mColorMaskR = r;
416            mColorMaskG = g;
417            mColorMaskB = b;
418            mColorMaskA = a;
419            return this;
420        }
421
422        /** @deprecated renderscript is deprecated in J
423        * 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        */
433        public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
434            mBlendSrc = src;
435            mBlendDst = dst;
436            return this;
437        }
438
439        /** @deprecated renderscript is deprecated in J
440        * Enables dithering
441        *
442        * @param enable specifies whether dithering is enabled or
443        *               disabled
444        *
445        * @return this
446        */
447        public Builder setDitherEnabled(boolean enable) {
448            mDither = enable;
449            return this;
450        }
451
452        /** @deprecated renderscript is deprecated in J
453        * Creates a program store from the current state of the builder
454        */
455        public ProgramStore create() {
456            mRS.validate();
457            int id = mRS.nProgramStoreCreate(mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA,
458                                             mDepthMask, mDither,
459                                             mBlendSrc.mID, mBlendDst.mID, mDepthFunc.mID);
460            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;
471        }
472    }
473
474}
475
476
477
478
479