blob: cce40643ca2cac2106dccd18f749e4adcd0b1713 [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
20import android.util.Config;
21import android.util.Log;
22
23
24/**
25 * @hide
26 *
27 **/
28public class ProgramStore extends BaseObj {
29 public enum DepthFunc {
30 ALWAYS (0),
31 LESS (1),
32 LEQUAL (2),
33 GREATER (3),
34 GEQUAL (4),
35 EQUAL (5),
36 NOTEQUAL (6);
37
38 int mID;
39 DepthFunc(int id) {
40 mID = id;
41 }
42 }
43
44 public enum BlendSrcFunc {
45 ZERO (0),
46 ONE (1),
47 DST_COLOR (2),
48 ONE_MINUS_DST_COLOR (3),
49 SRC_ALPHA (4),
50 ONE_MINUS_SRC_ALPHA (5),
51 DST_ALPHA (6),
Jason Samseab4c752009-10-28 17:40:13 -070052 ONE_MINUS_DST_ALPHA (7),
Jason Sams22534172009-08-04 16:58:20 -070053 SRC_ALPHA_SATURATE (8);
54
55 int mID;
56 BlendSrcFunc(int id) {
57 mID = id;
58 }
59 }
60
61 public enum BlendDstFunc {
62 ZERO (0),
63 ONE (1),
64 SRC_COLOR (2),
65 ONE_MINUS_SRC_COLOR (3),
66 SRC_ALPHA (4),
67 ONE_MINUS_SRC_ALPHA (5),
68 DST_ALPHA (6),
Jason Samseab4c752009-10-28 17:40:13 -070069 ONE_MINUS_DST_ALPHA (7);
Jason Sams22534172009-08-04 16:58:20 -070070
71 int mID;
72 BlendDstFunc(int id) {
73 mID = id;
74 }
75 }
76
77
78 ProgramStore(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070079 super(id, rs);
Jason Sams22534172009-08-04 16:58:20 -070080 }
81
Jason Sams22534172009-08-04 16:58:20 -070082
83
84 public static class Builder {
85 RenderScript mRS;
86 Element mIn;
87 Element mOut;
88 DepthFunc mDepthFunc;
89 boolean mDepthMask;
90 boolean mColorMaskR;
91 boolean mColorMaskG;
92 boolean mColorMaskB;
93 boolean mColorMaskA;
94 BlendSrcFunc mBlendSrc;
95 BlendDstFunc mBlendDst;
96 boolean mDither;
97
98
99
100 public Builder(RenderScript rs, Element in, Element out) {
101 mRS = rs;
102 mIn = in;
103 mOut = out;
104 mDepthFunc = DepthFunc.ALWAYS;
105 mDepthMask = false;
106 mColorMaskR = true;
107 mColorMaskG = true;
108 mColorMaskB = true;
109 mColorMaskA = true;
110 mBlendSrc = BlendSrcFunc.ONE;
111 mBlendDst = BlendDstFunc.ZERO;
112
113
114 }
115
Jim Shuma288c8712010-07-07 14:24:21 -0700116 public Builder setDepthFunc(DepthFunc func) {
Jason Sams22534172009-08-04 16:58:20 -0700117 mDepthFunc = func;
Jim Shuma288c8712010-07-07 14:24:21 -0700118 return this;
Jason Sams22534172009-08-04 16:58:20 -0700119 }
120
Jim Shuma288c8712010-07-07 14:24:21 -0700121 public Builder setDepthMask(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700122 mDepthMask = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700123 return this;
Jason Sams22534172009-08-04 16:58:20 -0700124 }
125
Jim Shuma288c8712010-07-07 14:24:21 -0700126 public Builder setColorMask(boolean r, boolean g, boolean b, boolean a) {
Jason Sams22534172009-08-04 16:58:20 -0700127 mColorMaskR = r;
128 mColorMaskG = g;
129 mColorMaskB = b;
130 mColorMaskA = a;
Jim Shuma288c8712010-07-07 14:24:21 -0700131 return this;
Jason Sams22534172009-08-04 16:58:20 -0700132 }
133
Jim Shuma288c8712010-07-07 14:24:21 -0700134 public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
Jason Sams22534172009-08-04 16:58:20 -0700135 mBlendSrc = src;
136 mBlendDst = dst;
Jim Shuma288c8712010-07-07 14:24:21 -0700137 return this;
Jason Sams22534172009-08-04 16:58:20 -0700138 }
139
Jim Shuma288c8712010-07-07 14:24:21 -0700140 public Builder setDitherEnable(boolean enable) {
Jason Sams22534172009-08-04 16:58:20 -0700141 mDither = enable;
Jim Shuma288c8712010-07-07 14:24:21 -0700142 return this;
Jason Sams22534172009-08-04 16:58:20 -0700143 }
144
145 static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
146 int inID = 0;
147 int outID = 0;
148 if (b.mIn != null) {
149 inID = b.mIn.mID;
150 }
151 if (b.mOut != null) {
152 outID = b.mOut.mID;
153 }
Jason Sams54db59c2010-05-13 18:30:11 -0700154 rs.nProgramStoreBegin(inID, outID);
155 rs.nProgramStoreDepthFunc(b.mDepthFunc.mID);
156 rs.nProgramStoreDepthMask(b.mDepthMask);
157 rs.nProgramStoreColorMask(b.mColorMaskR,
Jason Sams22534172009-08-04 16:58:20 -0700158 b.mColorMaskG,
159 b.mColorMaskB,
160 b.mColorMaskA);
Jason Sams54db59c2010-05-13 18:30:11 -0700161 rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
162 rs.nProgramStoreDither(b.mDither);
Jason Sams22534172009-08-04 16:58:20 -0700163
Jason Sams54db59c2010-05-13 18:30:11 -0700164 int id = rs.nProgramStoreCreate();
Jason Sams22534172009-08-04 16:58:20 -0700165 return new ProgramStore(id, rs);
166 }
167
168 public ProgramStore create() {
Jason Sams771bebb2009-12-07 12:40:12 -0800169 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700170 return internalCreate(mRS, this);
171 }
172 }
173
174}
175
176
177
178