blob: f8b59bd8182393ab49fb0e4a89514391b611f672 [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),
52 ONE_MINUS_DST_ALPA (7),
53 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),
69 ONE_MINUS_DST_ALPA (7);
70
71 int mID;
72 BlendDstFunc(int id) {
73 mID = id;
74 }
75 }
76
77
78 ProgramStore(int id, RenderScript rs) {
79 super(rs);
80 mID = id;
81 }
82
83 public void destroy() {
Jason Sams1bada8c2009-08-09 17:01:55 -070084 if(mDestroyed) {
85 throw new IllegalStateException("Object already destroyed.");
86 }
87 mDestroyed = true;
Jason Sams22534172009-08-04 16:58:20 -070088 mRS.nProgramFragmentStoreDestroy(mID);
Jason Sams22534172009-08-04 16:58:20 -070089 }
90
91
92
93 public static class Builder {
94 RenderScript mRS;
95 Element mIn;
96 Element mOut;
97 DepthFunc mDepthFunc;
98 boolean mDepthMask;
99 boolean mColorMaskR;
100 boolean mColorMaskG;
101 boolean mColorMaskB;
102 boolean mColorMaskA;
103 BlendSrcFunc mBlendSrc;
104 BlendDstFunc mBlendDst;
105 boolean mDither;
106
107
108
109 public Builder(RenderScript rs, Element in, Element out) {
110 mRS = rs;
111 mIn = in;
112 mOut = out;
113 mDepthFunc = DepthFunc.ALWAYS;
114 mDepthMask = false;
115 mColorMaskR = true;
116 mColorMaskG = true;
117 mColorMaskB = true;
118 mColorMaskA = true;
119 mBlendSrc = BlendSrcFunc.ONE;
120 mBlendDst = BlendDstFunc.ZERO;
121
122
123 }
124
125 public void setDepthFunc(DepthFunc func) {
126 mDepthFunc = func;
127 }
128
129 public void setDepthMask(boolean enable) {
130 mDepthMask = enable;
131 }
132
133 public void setColorMask(boolean r, boolean g, boolean b, boolean a) {
134 mColorMaskR = r;
135 mColorMaskG = g;
136 mColorMaskB = b;
137 mColorMaskA = a;
138 }
139
140 public void setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
141 mBlendSrc = src;
142 mBlendDst = dst;
143 }
144
145 public void setDitherEnable(boolean enable) {
146 mDither = enable;
147 }
148
149 static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
150 int inID = 0;
151 int outID = 0;
152 if (b.mIn != null) {
153 inID = b.mIn.mID;
154 }
155 if (b.mOut != null) {
156 outID = b.mOut.mID;
157 }
158 rs.nProgramFragmentStoreBegin(inID, outID);
159 rs.nProgramFragmentStoreDepthFunc(b.mDepthFunc.mID);
160 rs.nProgramFragmentStoreDepthMask(b.mDepthMask);
161 rs.nProgramFragmentStoreColorMask(b.mColorMaskR,
162 b.mColorMaskG,
163 b.mColorMaskB,
164 b.mColorMaskA);
165 rs.nProgramFragmentStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
166 rs.nProgramFragmentStoreDither(b.mDither);
167
168 int id = rs.nProgramFragmentStoreCreate();
169 return new ProgramStore(id, rs);
170 }
171
172 public ProgramStore create() {
173 return internalCreate(mRS, this);
174 }
175 }
176
177}
178
179
180
181