| 33 |
33 |
// TODO: figure this out dynamically; this assumes 8 bit stencil buffer.
|
| 34 |
34 |
private static final int STENCIL_MASK = (1<<8)-1;
|
| 35 |
35 |
|
| 36 |
|
private static int sColorMaskR, sColorMaskG, sColorMaskB, sColorMaskA; //
|
| 37 |
|
private static int sDepthMask; //
|
| 38 |
|
private static int sStencilMask; //
|
| 39 |
|
private static int sDepthTest; //
|
| 40 |
|
private static int sStencilTest; //
|
| 41 |
|
private static int sStencilFuncFunc, sStencilFuncRef, sStencilFuncMask; // current OpenGL state
|
| 42 |
|
private static int sStencilOpSfail, sStencilOpDpfail, sStencilOpDppass; //
|
| 43 |
|
private static int sDepthFunc; //
|
| 44 |
|
private static int sBlend; //
|
| 45 |
|
private static int sBlendSrc, sBlendDst; //
|
| 46 |
|
|
| 47 |
|
private int mColorMaskR, mColorMaskG, mColorMaskB, mColorMaskA; //
|
| 48 |
|
private int mDepthMask; //
|
| 49 |
|
private int mStencilMask; //
|
| 50 |
|
private int mDepthTest; //
|
| 51 |
|
private int mStencilTest; //
|
| 52 |
|
private int mStencilFuncFunc, mStencilFuncRef, mStencilFuncMask; // The state we want to have
|
| 53 |
|
private int mStencilOpSfail, mStencilOpDpfail, mStencilOpDppass; //
|
| 54 |
|
private int mDepthFunc; //
|
| 55 |
|
private int mBlend; //
|
| 56 |
|
private int mBlendSrc, mBlendDst; //
|
| 57 |
|
private int mClear; // This does not have a 'static' compatriot
|
| 58 |
|
|
| 59 |
|
private static int rStencilTest; //
|
| 60 |
|
private static int rStencilFuncFunc; //
|
| 61 |
|
private static int rStencilFuncRef; // Remember values of Stencil.
|
| 62 |
|
private static int rStencilFuncMask; //
|
| 63 |
|
private static int rStencilMask; //
|
|
36 |
private static class RenderState
|
|
37 |
{
|
|
38 |
private int colorMaskR, colorMaskG, colorMaskB, colorMaskA;
|
|
39 |
private int depthMask;
|
|
40 |
private int stencilMask;
|
|
41 |
private int depthTest;
|
|
42 |
private int stencilTest;
|
|
43 |
private int stencilFuncFunc, stencilFuncRef, stencilFuncMask;
|
|
44 |
private int stencilOpSfail, stencilOpDpfail, stencilOpDppass;
|
|
45 |
private int depthFunc;
|
|
46 |
private int blend;
|
|
47 |
private int blendSrc, blendDst;
|
|
48 |
}
|
|
49 |
|
|
50 |
private RenderState mState; // state the current object wants to have
|
|
51 |
static private RenderState cState = new RenderState(); // current OpenGL Stave
|
|
52 |
static private RenderState sState = new RenderState(); // saved OpenGL state
|
|
53 |
|
|
54 |
private int mClear;
|
| 64 |
55 |
|
| 65 |
56 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 66 |
57 |
// default: color writes on, depth test and writes on, blending on, stencil off.
|
| 67 |
58 |
|
| 68 |
59 |
DistortedRenderState()
|
| 69 |
60 |
{
|
| 70 |
|
mColorMaskR = 1;
|
| 71 |
|
mColorMaskG = 1;
|
| 72 |
|
mColorMaskB = 1;
|
| 73 |
|
mColorMaskA = 1;
|
| 74 |
|
|
| 75 |
|
mDepthTest = 1;
|
| 76 |
|
mDepthMask = 1;
|
| 77 |
|
mDepthFunc = GLES30.GL_LEQUAL;
|
| 78 |
|
|
| 79 |
|
mBlend = 1;
|
| 80 |
|
mBlendSrc = GLES30.GL_SRC_ALPHA;
|
| 81 |
|
mBlendDst = GLES30.GL_ONE_MINUS_SRC_ALPHA;
|
| 82 |
|
|
| 83 |
|
mStencilTest = 0;
|
| 84 |
|
mStencilMask = STENCIL_MASK;
|
| 85 |
|
mStencilFuncFunc = GLES30.GL_NEVER;
|
| 86 |
|
mStencilFuncRef = 0;
|
| 87 |
|
mStencilFuncMask = STENCIL_MASK;
|
| 88 |
|
mStencilOpSfail = GLES30.GL_KEEP;
|
| 89 |
|
mStencilOpDpfail = GLES30.GL_KEEP;
|
| 90 |
|
mStencilOpDppass = GLES30.GL_KEEP;
|
|
61 |
mState = new RenderState();
|
|
62 |
|
|
63 |
mState.colorMaskR = 1;
|
|
64 |
mState.colorMaskG = 1;
|
|
65 |
mState.colorMaskB = 1;
|
|
66 |
mState.colorMaskA = 1;
|
|
67 |
|
|
68 |
mState.depthTest = 1;
|
|
69 |
mState.depthMask = 1;
|
|
70 |
mState.depthFunc = GLES30.GL_LEQUAL;
|
|
71 |
|
|
72 |
mState.blend = 1;
|
|
73 |
mState.blendSrc = GLES30.GL_SRC_ALPHA;
|
|
74 |
mState.blendDst = GLES30.GL_ONE_MINUS_SRC_ALPHA;
|
|
75 |
|
|
76 |
mState.stencilTest = 0;
|
|
77 |
mState.stencilMask = STENCIL_MASK;
|
|
78 |
mState.stencilFuncFunc = GLES30.GL_NEVER;
|
|
79 |
mState.stencilFuncRef = 0;
|
|
80 |
mState.stencilFuncMask = STENCIL_MASK;
|
|
81 |
mState.stencilOpSfail = GLES30.GL_KEEP;
|
|
82 |
mState.stencilOpDpfail = GLES30.GL_KEEP;
|
|
83 |
mState.stencilOpDppass = GLES30.GL_KEEP;
|
| 91 |
84 |
|
| 92 |
85 |
mClear = 0;
|
| 93 |
86 |
}
|
| ... | ... | |
| 97 |
90 |
|
| 98 |
91 |
static void reset()
|
| 99 |
92 |
{
|
| 100 |
|
sColorMaskR = -1;
|
| 101 |
|
sColorMaskG = -1;
|
| 102 |
|
sColorMaskB = -1;
|
| 103 |
|
sColorMaskA = -1;
|
| 104 |
|
|
| 105 |
|
sDepthTest = -1;
|
| 106 |
|
sDepthMask = -1;
|
| 107 |
|
sDepthFunc = -1;
|
| 108 |
|
|
| 109 |
|
sBlend = -1;
|
| 110 |
|
sBlendSrc = -1;
|
| 111 |
|
sBlendDst = -1;
|
| 112 |
|
|
| 113 |
|
sStencilTest = -1;
|
| 114 |
|
sStencilMask = -1;
|
| 115 |
|
sStencilFuncFunc = -1;
|
| 116 |
|
sStencilFuncRef = -1;
|
| 117 |
|
sStencilFuncMask = -1;
|
| 118 |
|
sStencilOpSfail = -1;
|
| 119 |
|
sStencilOpDpfail = -1;
|
| 120 |
|
sStencilOpDppass = -1;
|
|
93 |
cState.colorMaskR = -1;
|
|
94 |
cState.colorMaskG = -1;
|
|
95 |
cState.colorMaskB = -1;
|
|
96 |
cState.colorMaskA = -1;
|
|
97 |
|
|
98 |
cState.depthTest = -1;
|
|
99 |
cState.depthMask = -1;
|
|
100 |
cState.depthFunc = -1;
|
|
101 |
|
|
102 |
cState.blend = -1;
|
|
103 |
cState.blendSrc = -1;
|
|
104 |
cState.blendDst = -1;
|
|
105 |
|
|
106 |
cState.stencilTest = -1;
|
|
107 |
cState.stencilMask = -1;
|
|
108 |
cState.stencilFuncFunc = -1;
|
|
109 |
cState.stencilFuncRef = -1;
|
|
110 |
cState.stencilFuncMask = -1;
|
|
111 |
cState.stencilOpSfail = -1;
|
|
112 |
cState.stencilOpDpfail = -1;
|
|
113 |
cState.stencilOpDppass = -1;
|
| 121 |
114 |
}
|
| 122 |
115 |
|
| 123 |
116 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 124 |
117 |
|
| 125 |
118 |
static void colorDepthStencilOn()
|
| 126 |
119 |
{
|
| 127 |
|
if( sColorMaskR!=1 || sColorMaskG!=1 || sColorMaskB!=1 || sColorMaskA!=1 )
|
|
120 |
if( cState.colorMaskR!=1 || cState.colorMaskG!=1 || cState.colorMaskB!=1 || cState.colorMaskA!=1 )
|
| 128 |
121 |
{
|
| 129 |
|
sColorMaskR = 1;
|
| 130 |
|
sColorMaskG = 1;
|
| 131 |
|
sColorMaskB = 1;
|
| 132 |
|
sColorMaskA = 1;
|
|
122 |
cState.colorMaskR = 1;
|
|
123 |
cState.colorMaskG = 1;
|
|
124 |
cState.colorMaskB = 1;
|
|
125 |
cState.colorMaskA = 1;
|
| 133 |
126 |
GLES30.glColorMask(true,true,true,true);
|
| 134 |
127 |
}
|
| 135 |
|
if( sDepthMask!=1 )
|
|
128 |
if( cState.depthMask!=1 )
|
| 136 |
129 |
{
|
| 137 |
|
sDepthMask = 1;
|
|
130 |
cState.depthMask = 1;
|
| 138 |
131 |
GLES30.glDepthMask(true);
|
| 139 |
132 |
}
|
| 140 |
|
if( sStencilMask!= STENCIL_MASK )
|
|
133 |
if( cState.stencilMask!= STENCIL_MASK )
|
| 141 |
134 |
{
|
| 142 |
|
sStencilMask = STENCIL_MASK;
|
| 143 |
|
GLES30.glStencilMask(sStencilMask);
|
|
135 |
cState.stencilMask = STENCIL_MASK;
|
|
136 |
GLES30.glStencilMask(cState.stencilMask);
|
| 144 |
137 |
}
|
| 145 |
138 |
}
|
| 146 |
139 |
|
| ... | ... | |
| 163 |
156 |
|
| 164 |
157 |
static void setUpStencilMark()
|
| 165 |
158 |
{
|
| 166 |
|
if( sStencilTest!=1 )
|
|
159 |
if( cState.stencilTest!=1 )
|
| 167 |
160 |
{
|
| 168 |
|
sStencilTest = 1;
|
|
161 |
cState.stencilTest = 1;
|
| 169 |
162 |
//android.util.Log.d("State", "stencil test on");
|
| 170 |
163 |
GLES30.glEnable(GLES30.GL_STENCIL_TEST);
|
| 171 |
164 |
}
|
| 172 |
|
if( sStencilFuncFunc!=GLES30.GL_ALWAYS || sStencilFuncRef!=1 || sStencilFuncMask!=STENCIL_MASK )
|
|
165 |
if( cState.stencilFuncFunc!=GLES30.GL_ALWAYS || cState.stencilFuncRef!=1 || cState.stencilFuncMask!=STENCIL_MASK )
|
| 173 |
166 |
{
|
| 174 |
|
sStencilFuncFunc = GLES30.GL_ALWAYS;
|
| 175 |
|
sStencilFuncRef = 1;
|
| 176 |
|
sStencilFuncMask = STENCIL_MASK;
|
|
167 |
cState.stencilFuncFunc = GLES30.GL_ALWAYS;
|
|
168 |
cState.stencilFuncRef = 1;
|
|
169 |
cState.stencilFuncMask = STENCIL_MASK;
|
| 177 |
170 |
//android.util.Log.d("State", "stencil func on");
|
| 178 |
|
GLES30.glStencilFunc(sStencilFuncFunc,sStencilFuncRef,sStencilFuncMask);
|
|
171 |
GLES30.glStencilFunc(cState.stencilFuncFunc,cState.stencilFuncRef,cState.stencilFuncMask);
|
| 179 |
172 |
}
|
| 180 |
|
if( sStencilOpSfail!=GLES30.GL_KEEP || sStencilOpDpfail!=GLES30.GL_KEEP || sStencilOpDppass!=GLES30.GL_REPLACE )
|
|
173 |
if( cState.stencilOpSfail!=GLES30.GL_KEEP || cState.stencilOpDpfail!=GLES30.GL_KEEP || cState.stencilOpDppass!=GLES30.GL_REPLACE )
|
| 181 |
174 |
{
|
| 182 |
|
sStencilOpSfail = GLES30.GL_KEEP;
|
| 183 |
|
sStencilOpDpfail= GLES30.GL_KEEP;
|
| 184 |
|
sStencilOpDppass= GLES30.GL_REPLACE;
|
|
175 |
cState.stencilOpSfail = GLES30.GL_KEEP;
|
|
176 |
cState.stencilOpDpfail= GLES30.GL_KEEP;
|
|
177 |
cState.stencilOpDppass= GLES30.GL_REPLACE;
|
| 185 |
178 |
//android.util.Log.d("State", "stencil op on");
|
| 186 |
|
GLES30.glStencilOp(sStencilOpSfail,sStencilOpDpfail,sStencilOpDppass);
|
|
179 |
GLES30.glStencilOp(cState.stencilOpSfail,cState.stencilOpDpfail,cState.stencilOpDppass);
|
| 187 |
180 |
}
|
| 188 |
|
if( sColorMaskR!=0 || sColorMaskG!=0 || sColorMaskB!=0 || sColorMaskA!=0 )
|
|
181 |
if( cState.colorMaskR!=0 || cState.colorMaskG!=0 || cState.colorMaskB!=0 || cState.colorMaskA!=0 )
|
| 189 |
182 |
{
|
| 190 |
|
sColorMaskR = 0;
|
| 191 |
|
sColorMaskG = 0;
|
| 192 |
|
sColorMaskB = 0;
|
| 193 |
|
sColorMaskA = 0;
|
|
183 |
cState.colorMaskR = 0;
|
|
184 |
cState.colorMaskG = 0;
|
|
185 |
cState.colorMaskB = 0;
|
|
186 |
cState.colorMaskA = 0;
|
| 194 |
187 |
//android.util.Log.d("State", "switch off color writing");
|
| 195 |
188 |
GLES30.glColorMask(false,false,false,false);
|
| 196 |
189 |
}
|
| 197 |
|
if( sDepthMask!=0 )
|
|
190 |
if( cState.depthMask!=0 )
|
| 198 |
191 |
{
|
| 199 |
|
sDepthMask = 0;
|
|
192 |
cState.depthMask = 0;
|
| 200 |
193 |
//android.util.Log.d("State", "switch off depth writing");
|
| 201 |
194 |
GLES30.glDepthMask(false);
|
| 202 |
195 |
}
|
| 203 |
|
if( sStencilMask!= STENCIL_MASK )
|
|
196 |
if( cState.stencilMask!= STENCIL_MASK )
|
| 204 |
197 |
{
|
| 205 |
|
sStencilMask = STENCIL_MASK;
|
|
198 |
cState.stencilMask = STENCIL_MASK;
|
| 206 |
199 |
//android.util.Log.d("State", "stencil mask on");
|
| 207 |
|
GLES30.glStencilMask(sStencilMask);
|
|
200 |
GLES30.glStencilMask(cState.stencilMask);
|
| 208 |
201 |
}
|
| 209 |
202 |
}
|
| 210 |
203 |
|
| ... | ... | |
| 212 |
205 |
|
| 213 |
206 |
static void useStencilMark()
|
| 214 |
207 |
{
|
| 215 |
|
if( sStencilTest!=1 )
|
|
208 |
if( cState.stencilTest!=1 )
|
| 216 |
209 |
{
|
| 217 |
|
rStencilTest = sStencilTest;
|
| 218 |
|
sStencilTest = 1;
|
|
210 |
sState.stencilTest = cState.stencilTest;
|
|
211 |
cState.stencilTest = 1;
|
| 219 |
212 |
GLES30.glEnable(GLES30.GL_STENCIL_TEST);
|
| 220 |
213 |
}
|
| 221 |
|
if( sStencilFuncFunc!=GLES30.GL_EQUAL || sStencilFuncRef!=1 || sStencilFuncMask!=STENCIL_MASK )
|
|
214 |
if( cState.stencilFuncFunc!=GLES30.GL_EQUAL || cState.stencilFuncRef!=1 || cState.stencilFuncMask!=STENCIL_MASK )
|
| 222 |
215 |
{
|
| 223 |
|
rStencilFuncFunc = sStencilFuncFunc;
|
| 224 |
|
rStencilFuncRef = sStencilFuncRef;
|
| 225 |
|
rStencilFuncMask = sStencilFuncMask;
|
| 226 |
|
sStencilFuncFunc = GLES30.GL_EQUAL;
|
| 227 |
|
sStencilFuncRef = 1;
|
| 228 |
|
sStencilFuncMask = STENCIL_MASK;
|
| 229 |
|
GLES30.glStencilFunc(sStencilFuncFunc,sStencilFuncRef,sStencilFuncMask);
|
|
216 |
sState.stencilFuncFunc = cState.stencilFuncFunc;
|
|
217 |
sState.stencilFuncRef = cState.stencilFuncRef;
|
|
218 |
sState.stencilFuncMask = cState.stencilFuncMask;
|
|
219 |
cState.stencilFuncFunc = GLES30.GL_EQUAL;
|
|
220 |
cState.stencilFuncRef = 1;
|
|
221 |
cState.stencilFuncMask = STENCIL_MASK;
|
|
222 |
GLES30.glStencilFunc(cState.stencilFuncFunc,cState.stencilFuncRef,cState.stencilFuncMask);
|
| 230 |
223 |
}
|
| 231 |
224 |
|
| 232 |
225 |
// TODO: Debatable
|
| 233 |
|
if( sStencilMask!= 0x00 )
|
|
226 |
if( cState.stencilMask!= 0x00 )
|
| 234 |
227 |
{
|
| 235 |
|
rStencilMask = sStencilMask;
|
| 236 |
|
sStencilMask = 0x00;
|
| 237 |
|
GLES30.glStencilMask(sStencilMask);
|
|
228 |
sState.stencilMask = cState.stencilMask;
|
|
229 |
cState.stencilMask = 0x00;
|
|
230 |
GLES30.glStencilMask(cState.stencilMask);
|
| 238 |
231 |
}
|
| 239 |
232 |
}
|
| 240 |
233 |
|
| ... | ... | |
| 242 |
235 |
|
| 243 |
236 |
static void unuseStencilMark()
|
| 244 |
237 |
{
|
| 245 |
|
if( rStencilTest!=sStencilTest )
|
|
238 |
if( sState.stencilTest!=cState.stencilTest )
|
| 246 |
239 |
{
|
| 247 |
|
sStencilTest = rStencilTest;
|
|
240 |
cState.stencilTest = sState.stencilTest;
|
| 248 |
241 |
|
| 249 |
|
if (sStencilTest == 0)
|
|
242 |
if (cState.stencilTest == 0)
|
| 250 |
243 |
{
|
| 251 |
244 |
GLES30.glDisable(GLES30.GL_STENCIL_TEST);
|
| 252 |
245 |
}
|
| ... | ... | |
| 256 |
249 |
}
|
| 257 |
250 |
}
|
| 258 |
251 |
|
| 259 |
|
if( rStencilFuncFunc!=sStencilFuncFunc || rStencilFuncRef!=sStencilFuncRef || rStencilFuncMask!=sStencilFuncMask )
|
|
252 |
if( sState.stencilFuncFunc!=cState.stencilFuncFunc || sState.stencilFuncRef!=cState.stencilFuncRef || sState.stencilFuncMask!=cState.stencilFuncMask )
|
| 260 |
253 |
{
|
| 261 |
|
sStencilFuncFunc = rStencilFuncFunc;
|
| 262 |
|
sStencilFuncRef = rStencilFuncRef ;
|
| 263 |
|
sStencilFuncMask = rStencilFuncMask;
|
| 264 |
|
GLES30.glStencilFunc(sStencilFuncFunc,sStencilFuncRef,sStencilFuncMask);
|
|
254 |
cState.stencilFuncFunc = sState.stencilFuncFunc;
|
|
255 |
cState.stencilFuncRef = sState.stencilFuncRef ;
|
|
256 |
cState.stencilFuncMask = sState.stencilFuncMask;
|
|
257 |
GLES30.glStencilFunc(cState.stencilFuncFunc,cState.stencilFuncRef,cState.stencilFuncMask);
|
| 265 |
258 |
}
|
| 266 |
259 |
|
| 267 |
|
if( rStencilMask!=sStencilMask )
|
|
260 |
if( sState.stencilMask!=cState.stencilMask )
|
| 268 |
261 |
{
|
| 269 |
|
sStencilMask = rStencilMask;
|
| 270 |
|
GLES30.glStencilMask(sStencilMask);
|
|
262 |
cState.stencilMask = sState.stencilMask;
|
|
263 |
GLES30.glStencilMask(cState.stencilMask);
|
| 271 |
264 |
}
|
| 272 |
265 |
}
|
| 273 |
266 |
|
| ... | ... | |
| 279 |
272 |
|
| 280 |
273 |
/////////////////////////////////////////////////////
|
| 281 |
274 |
// 1. Write to color buffer?
|
| 282 |
|
if( mColorMaskR!=sColorMaskR || mColorMaskG!=sColorMaskG || mColorMaskB!=sColorMaskB || mColorMaskA!=sColorMaskA)
|
|
275 |
if( mState.colorMaskR!=cState.colorMaskR || mState.colorMaskG!=cState.colorMaskG || mState.colorMaskB!=cState.colorMaskB || mState.colorMaskA!=cState.colorMaskA)
|
| 283 |
276 |
{
|
| 284 |
277 |
//android.util.Log.d("State", "setting color mask");
|
| 285 |
|
sColorMaskR = mColorMaskR;
|
| 286 |
|
sColorMaskG = mColorMaskG;
|
| 287 |
|
sColorMaskB = mColorMaskB;
|
| 288 |
|
sColorMaskA = mColorMaskA;
|
| 289 |
|
GLES30.glColorMask(sColorMaskR==1,sColorMaskG==1,sColorMaskB==1,sColorMaskA==1);
|
|
278 |
cState.colorMaskR = mState.colorMaskR;
|
|
279 |
cState.colorMaskG = mState.colorMaskG;
|
|
280 |
cState.colorMaskB = mState.colorMaskB;
|
|
281 |
cState.colorMaskA = mState.colorMaskA;
|
|
282 |
GLES30.glColorMask(cState.colorMaskR==1,cState.colorMaskG==1,cState.colorMaskB==1,cState.colorMaskA==1);
|
| 290 |
283 |
}
|
| 291 |
284 |
|
| 292 |
285 |
/////////////////////////////////////////////////////
|
| 293 |
286 |
// 2. Enable Depth test?
|
| 294 |
|
if( mDepthTest!=sDepthTest )
|
|
287 |
if( mState.depthTest!=cState.depthTest )
|
| 295 |
288 |
{
|
| 296 |
|
sDepthTest = mDepthTest;
|
|
289 |
cState.depthTest = mState.depthTest;
|
| 297 |
290 |
|
| 298 |
|
if (sDepthTest == 0)
|
|
291 |
if (cState.depthTest == 0)
|
| 299 |
292 |
{
|
| 300 |
293 |
//android.util.Log.d("State", "disabling depth test");
|
| 301 |
294 |
GLES30.glDisable(GLES30.GL_DEPTH_TEST);
|
| ... | ... | |
| 309 |
302 |
|
| 310 |
303 |
/////////////////////////////////////////////////////
|
| 311 |
304 |
// 3. Change Depth Function?
|
| 312 |
|
if( mDepthFunc!=sDepthFunc )
|
|
305 |
if( mState.depthFunc!=cState.depthFunc )
|
| 313 |
306 |
{
|
| 314 |
307 |
//android.util.Log.d("State", "setting depth func");
|
| 315 |
|
sDepthFunc = mDepthFunc;
|
| 316 |
|
GLES30.glDepthFunc(sDepthFunc);
|
|
308 |
cState.depthFunc = mState.depthFunc;
|
|
309 |
GLES30.glDepthFunc(cState.depthFunc);
|
| 317 |
310 |
}
|
| 318 |
311 |
|
| 319 |
312 |
/////////////////////////////////////////////////////
|
| 320 |
313 |
// 4. Write to Depth buffer?
|
| 321 |
|
if( mDepthMask!=sDepthMask )
|
|
314 |
if( mState.depthMask!=cState.depthMask )
|
| 322 |
315 |
{
|
| 323 |
316 |
//android.util.Log.d("State", "setting depth mask");
|
| 324 |
|
sDepthMask = mDepthMask;
|
| 325 |
|
GLES30.glDepthMask(sDepthMask==1);
|
|
317 |
cState.depthMask = mState.depthMask;
|
|
318 |
GLES30.glDepthMask(cState.depthMask==1);
|
| 326 |
319 |
}
|
| 327 |
320 |
|
| 328 |
321 |
/////////////////////////////////////////////////////
|
| 329 |
322 |
// 5. Enable Blending?
|
| 330 |
|
if( mBlend!=sBlend )
|
|
323 |
if( mState.blend!=cState.blend )
|
| 331 |
324 |
{
|
| 332 |
|
sBlend = mBlend;
|
|
325 |
cState.blend = mState.blend;
|
| 333 |
326 |
|
| 334 |
|
if (sBlend == 0)
|
|
327 |
if (cState.blend == 0)
|
| 335 |
328 |
{
|
| 336 |
329 |
//android.util.Log.d("State", "disabling blending");
|
| 337 |
330 |
GLES30.glDisable(GLES30.GL_BLEND);
|
| ... | ... | |
| 345 |
338 |
|
| 346 |
339 |
/////////////////////////////////////////////////////
|
| 347 |
340 |
// 6. Change Blend function?
|
| 348 |
|
if( mBlendSrc!=sBlendSrc || mBlendDst!=sBlendDst )
|
|
341 |
if( mState.blendSrc!=cState.blendSrc || mState.blendDst!=cState.blendDst )
|
| 349 |
342 |
{
|
| 350 |
343 |
//android.util.Log.d("State", "setting blend function");
|
| 351 |
|
sBlendSrc = mBlendSrc;
|
| 352 |
|
sBlendDst = mBlendDst;
|
| 353 |
|
GLES30.glBlendFunc(sBlendSrc,sBlendDst);
|
|
344 |
cState.blendSrc = mState.blendSrc;
|
|
345 |
cState.blendDst = mState.blendDst;
|
|
346 |
GLES30.glBlendFunc(cState.blendSrc,cState.blendDst);
|
| 354 |
347 |
}
|
| 355 |
348 |
|
| 356 |
349 |
/////////////////////////////////////////////////////
|
| 357 |
350 |
// 7. Enable/Disable Stencil Test?
|
| 358 |
|
if( mStencilTest!=sStencilTest )
|
|
351 |
if( mState.stencilTest!=cState.stencilTest )
|
| 359 |
352 |
{
|
| 360 |
|
sStencilTest = mStencilTest;
|
|
353 |
cState.stencilTest = mState.stencilTest;
|
| 361 |
354 |
|
| 362 |
|
if (sStencilTest == 0)
|
|
355 |
if (cState.stencilTest == 0)
|
| 363 |
356 |
{
|
| 364 |
357 |
//android.util.Log.d("State", "disabling stencil test");
|
| 365 |
358 |
GLES30.glDisable(GLES30.GL_STENCIL_TEST);
|
| ... | ... | |
| 373 |
366 |
|
| 374 |
367 |
/////////////////////////////////////////////////////
|
| 375 |
368 |
// 8. Adjust Stencil function?
|
| 376 |
|
if( mStencilFuncFunc!=sStencilFuncFunc || mStencilFuncRef!=sStencilFuncRef || mStencilFuncMask!=sStencilFuncMask )
|
|
369 |
if( mState.stencilFuncFunc!=cState.stencilFuncFunc || mState.stencilFuncRef!=cState.stencilFuncRef || mState.stencilFuncMask!=cState.stencilFuncMask )
|
| 377 |
370 |
{
|
| 378 |
371 |
//android.util.Log.d("State", "setting stencil function");
|
| 379 |
|
sStencilFuncFunc = mStencilFuncFunc;
|
| 380 |
|
sStencilFuncRef = mStencilFuncRef ;
|
| 381 |
|
sStencilFuncMask = mStencilFuncMask;
|
| 382 |
|
GLES30.glStencilFunc(sStencilFuncFunc,sStencilFuncRef,sStencilFuncMask);
|
|
372 |
cState.stencilFuncFunc = mState.stencilFuncFunc;
|
|
373 |
cState.stencilFuncRef = mState.stencilFuncRef ;
|
|
374 |
cState.stencilFuncMask = mState.stencilFuncMask;
|
|
375 |
GLES30.glStencilFunc(cState.stencilFuncFunc,cState.stencilFuncRef,cState.stencilFuncMask);
|
| 383 |
376 |
}
|
| 384 |
377 |
|
| 385 |
378 |
/////////////////////////////////////////////////////
|
| 386 |
379 |
// 9. Adjust Stencil operation?
|
| 387 |
|
if( mStencilOpSfail!=sStencilOpSfail || mStencilOpDpfail!=sStencilOpDpfail || mStencilOpDppass!=sStencilOpDppass )
|
|
380 |
if( mState.stencilOpSfail!=cState.stencilOpSfail || mState.stencilOpDpfail!=cState.stencilOpDpfail || mState.stencilOpDppass!=cState.stencilOpDppass )
|
| 388 |
381 |
{
|
| 389 |
382 |
//android.util.Log.d("State", "setting stencil op");
|
| 390 |
|
sStencilOpSfail = mStencilOpSfail;
|
| 391 |
|
sStencilOpDpfail= mStencilOpDpfail;
|
| 392 |
|
sStencilOpDppass= mStencilOpDppass;
|
| 393 |
|
GLES30.glStencilOp(sStencilOpSfail,sStencilOpDpfail,sStencilOpDppass);
|
|
383 |
cState.stencilOpSfail = mState.stencilOpSfail;
|
|
384 |
cState.stencilOpDpfail= mState.stencilOpDpfail;
|
|
385 |
cState.stencilOpDppass= mState.stencilOpDppass;
|
|
386 |
GLES30.glStencilOp(cState.stencilOpSfail,cState.stencilOpDpfail,cState.stencilOpDppass);
|
| 394 |
387 |
}
|
| 395 |
388 |
|
| 396 |
389 |
/////////////////////////////////////////////////////
|
| 397 |
390 |
// 10. Write to Stencil buffer?
|
| 398 |
|
if( mStencilMask!=sStencilMask )
|
|
391 |
if( mState.stencilMask!=cState.stencilMask )
|
| 399 |
392 |
{
|
| 400 |
393 |
//android.util.Log.d("State", "setting stencil mask");
|
| 401 |
|
sStencilMask = mStencilMask;
|
| 402 |
|
GLES30.glStencilMask(sStencilMask);
|
|
394 |
cState.stencilMask = mState.stencilMask;
|
|
395 |
GLES30.glStencilMask(cState.stencilMask);
|
| 403 |
396 |
}
|
| 404 |
397 |
|
| 405 |
398 |
/////////////////////////////////////////////////////
|
| ... | ... | |
| 415 |
408 |
|
| 416 |
409 |
void glColorMask(boolean r, boolean g, boolean b, boolean a)
|
| 417 |
410 |
{
|
| 418 |
|
mColorMaskR = (r ? 1:0);
|
| 419 |
|
mColorMaskG = (g ? 1:0);
|
| 420 |
|
mColorMaskB = (b ? 1:0);
|
| 421 |
|
mColorMaskA = (a ? 1:0);
|
|
411 |
mState.colorMaskR = (r ? 1:0);
|
|
412 |
mState.colorMaskG = (g ? 1:0);
|
|
413 |
mState.colorMaskB = (b ? 1:0);
|
|
414 |
mState.colorMaskA = (a ? 1:0);
|
| 422 |
415 |
}
|
| 423 |
416 |
|
| 424 |
417 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 425 |
418 |
|
| 426 |
419 |
void glDepthMask(boolean mask)
|
| 427 |
420 |
{
|
| 428 |
|
mDepthMask = (mask ? 1:0);
|
|
421 |
mState.depthMask = (mask ? 1:0);
|
| 429 |
422 |
}
|
| 430 |
423 |
|
| 431 |
424 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 432 |
425 |
|
| 433 |
426 |
void glStencilMask(int mask)
|
| 434 |
427 |
{
|
| 435 |
|
mStencilMask = mask;
|
|
428 |
mState.stencilMask = mask;
|
| 436 |
429 |
}
|
| 437 |
430 |
|
| 438 |
431 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 439 |
432 |
|
| 440 |
433 |
void glEnable(int test)
|
| 441 |
434 |
{
|
| 442 |
|
if( test==GLES30.GL_DEPTH_TEST ) mDepthTest = 1;
|
| 443 |
|
else if( test==GLES30.GL_STENCIL_TEST ) mStencilTest = 1;
|
| 444 |
|
else if( test==GLES30.GL_BLEND ) mBlend = 1;
|
|
435 |
if( test==GLES30.GL_DEPTH_TEST ) mState.depthTest = 1;
|
|
436 |
else if( test==GLES30.GL_STENCIL_TEST ) mState.stencilTest = 1;
|
|
437 |
else if( test==GLES30.GL_BLEND ) mState.blend = 1;
|
| 445 |
438 |
}
|
| 446 |
439 |
|
| 447 |
440 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 448 |
441 |
|
| 449 |
442 |
void glDisable(int test)
|
| 450 |
443 |
{
|
| 451 |
|
if( test==GLES30.GL_DEPTH_TEST ) mDepthTest = 0;
|
| 452 |
|
else if( test==GLES30.GL_STENCIL_TEST ) mStencilTest = 0;
|
| 453 |
|
else if( test==GLES30.GL_BLEND ) mBlend = 0;
|
|
444 |
if( test==GLES30.GL_DEPTH_TEST ) mState.depthTest = 0;
|
|
445 |
else if( test==GLES30.GL_STENCIL_TEST ) mState.stencilTest = 0;
|
|
446 |
else if( test==GLES30.GL_BLEND ) mState.blend = 0;
|
| 454 |
447 |
}
|
| 455 |
448 |
|
| 456 |
449 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 457 |
450 |
|
| 458 |
451 |
void glStencilFunc(int func, int ref, int mask)
|
| 459 |
452 |
{
|
| 460 |
|
mStencilFuncFunc = func;
|
| 461 |
|
mStencilFuncRef = ref;
|
| 462 |
|
mStencilFuncMask = mask;
|
|
453 |
mState.stencilFuncFunc = func;
|
|
454 |
mState.stencilFuncRef = ref;
|
|
455 |
mState.stencilFuncMask = mask;
|
| 463 |
456 |
}
|
| 464 |
457 |
|
| 465 |
458 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 466 |
459 |
|
| 467 |
460 |
void glStencilOp(int sfail, int dpfail, int dppass)
|
| 468 |
461 |
{
|
| 469 |
|
mStencilOpSfail = sfail;
|
| 470 |
|
mStencilOpDpfail= dpfail;
|
| 471 |
|
mStencilOpDppass= dppass;
|
|
462 |
mState.stencilOpSfail = sfail;
|
|
463 |
mState.stencilOpDpfail= dpfail;
|
|
464 |
mState.stencilOpDppass= dppass;
|
| 472 |
465 |
}
|
| 473 |
466 |
|
| 474 |
467 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 475 |
468 |
|
| 476 |
469 |
void glDepthFunc(int func)
|
| 477 |
470 |
{
|
| 478 |
|
mDepthFunc = func;
|
|
471 |
mState.depthFunc = func;
|
| 479 |
472 |
}
|
| 480 |
473 |
|
| 481 |
474 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 482 |
475 |
|
| 483 |
476 |
void glBlendFunc(int src, int dst)
|
| 484 |
477 |
{
|
| 485 |
|
mBlendSrc = src;
|
| 486 |
|
mBlendDst = dst;
|
|
478 |
mState.blendSrc = src;
|
|
479 |
mState.blendDst = dst;
|
| 487 |
480 |
}
|
| 488 |
481 |
|
| 489 |
482 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Some improvements to DistortedRenderState.