| 149 |
149 |
|
| 150 |
150 |
void apply()
|
| 151 |
151 |
{
|
| 152 |
|
// 1. Write to color buffer?
|
|
152 |
//android.util.Log.e("State", "APPLYING STATE");
|
| 153 |
153 |
|
|
154 |
/////////////////////////////////////////////////////
|
|
155 |
// 1. Write to color buffer?
|
| 154 |
156 |
if( mColorMaskR!=sColorMaskR || mColorMaskG!=sColorMaskG || mColorMaskB!=sColorMaskB || mColorMaskA!=sColorMaskA)
|
| 155 |
157 |
{
|
|
158 |
//android.util.Log.d("State", "setting color mask");
|
| 156 |
159 |
sColorMaskR = mColorMaskR;
|
| 157 |
160 |
sColorMaskG = mColorMaskG;
|
| 158 |
161 |
sColorMaskB = mColorMaskB;
|
| ... | ... | |
| 160 |
163 |
GLES30.glColorMask(sColorMaskR==1,sColorMaskG==1,sColorMaskB==1,sColorMaskA==1);
|
| 161 |
164 |
}
|
| 162 |
165 |
|
|
166 |
/////////////////////////////////////////////////////
|
| 163 |
167 |
// 2. Enable Depth test?
|
| 164 |
|
|
| 165 |
168 |
if( mDepthTest!=sDepthTest )
|
| 166 |
169 |
{
|
| 167 |
170 |
sDepthTest = mDepthTest;
|
| 168 |
171 |
|
| 169 |
|
if( sDepthTest==0 ) GLES30.glDisable(GLES30.GL_DEPTH_TEST);
|
|
172 |
if (sDepthTest == 0)
|
|
173 |
{
|
|
174 |
//android.util.Log.d("State", "disabling depth test");
|
|
175 |
GLES30.glDisable(GLES30.GL_DEPTH_TEST);
|
|
176 |
}
|
| 170 |
177 |
else
|
| 171 |
178 |
{
|
| 172 |
|
GLES30.glEnable (GLES30.GL_DEPTH_TEST);
|
| 173 |
|
|
| 174 |
|
if( mDepthFunc!=sDepthFunc )
|
| 175 |
|
{
|
| 176 |
|
sDepthFunc = mDepthFunc;
|
| 177 |
|
GLES30.glDepthFunc(sDepthFunc);
|
| 178 |
|
}
|
|
179 |
//android.util.Log.d("State", "enable depth test");
|
|
180 |
GLES30.glEnable(GLES30.GL_DEPTH_TEST);
|
| 179 |
181 |
}
|
| 180 |
182 |
}
|
| 181 |
183 |
|
| 182 |
|
// 3. Write to Depth buffer?
|
|
184 |
/////////////////////////////////////////////////////
|
|
185 |
// 3. Change Depth Function?
|
|
186 |
if( mDepthFunc!=sDepthFunc )
|
|
187 |
{
|
|
188 |
//android.util.Log.d("State", "setting depth func");
|
|
189 |
sDepthFunc = mDepthFunc;
|
|
190 |
GLES30.glDepthFunc(sDepthFunc);
|
|
191 |
}
|
| 183 |
192 |
|
|
193 |
/////////////////////////////////////////////////////
|
|
194 |
// 4. Write to Depth buffer?
|
| 184 |
195 |
if( mDepthMask!=sDepthMask )
|
| 185 |
196 |
{
|
|
197 |
//android.util.Log.d("State", "setting depth mask");
|
| 186 |
198 |
sDepthMask = mDepthMask;
|
| 187 |
199 |
GLES30.glDepthMask(sDepthMask==1);
|
| 188 |
200 |
}
|
| 189 |
201 |
|
| 190 |
|
// 4. Enable Blending?
|
| 191 |
|
|
|
202 |
/////////////////////////////////////////////////////
|
|
203 |
// 5. Enable Blending?
|
| 192 |
204 |
if( mBlend!=sBlend )
|
| 193 |
205 |
{
|
| 194 |
206 |
sBlend = mBlend;
|
| 195 |
207 |
|
| 196 |
|
if( sBlend==0 ) GLES30.glDisable(GLES30.GL_BLEND);
|
|
208 |
if (sBlend == 0)
|
|
209 |
{
|
|
210 |
//android.util.Log.d("State", "disabling blending");
|
|
211 |
GLES30.glDisable(GLES30.GL_BLEND);
|
|
212 |
}
|
| 197 |
213 |
else
|
| 198 |
214 |
{
|
|
215 |
//android.util.Log.d("State", "enabling blending");
|
| 199 |
216 |
GLES30.glEnable(GLES30.GL_BLEND);
|
| 200 |
|
|
| 201 |
|
if( mBlendSrc!=sBlendSrc || mBlendDst!=sBlendDst )
|
| 202 |
|
{
|
| 203 |
|
sBlendSrc = mBlendSrc;
|
| 204 |
|
sBlendDst = mBlendDst;
|
| 205 |
|
GLES30.glBlendFunc(sBlendSrc,sBlendDst);
|
| 206 |
|
}
|
| 207 |
217 |
}
|
| 208 |
218 |
}
|
| 209 |
219 |
|
| 210 |
|
// 5. Enable Stencil Test?
|
|
220 |
/////////////////////////////////////////////////////
|
|
221 |
// 6. Change Blend function?
|
|
222 |
if( mBlendSrc!=sBlendSrc || mBlendDst!=sBlendDst )
|
|
223 |
{
|
|
224 |
//android.util.Log.d("State", "setting blend function");
|
|
225 |
sBlendSrc = mBlendSrc;
|
|
226 |
sBlendDst = mBlendDst;
|
|
227 |
GLES30.glBlendFunc(sBlendSrc,sBlendDst);
|
|
228 |
}
|
| 211 |
229 |
|
|
230 |
/////////////////////////////////////////////////////
|
|
231 |
// 7. Enable/Disable Stencil Test?
|
| 212 |
232 |
if( mStencilTest!=sStencilTest )
|
| 213 |
233 |
{
|
| 214 |
234 |
sStencilTest = mStencilTest;
|
| 215 |
235 |
|
| 216 |
|
if( sStencilTest==0 ) GLES30.glDisable(GLES30.GL_STENCIL_TEST);
|
|
236 |
if (sStencilTest == 0)
|
|
237 |
{
|
|
238 |
//android.util.Log.d("State", "disabling stencil test");
|
|
239 |
GLES30.glDisable(GLES30.GL_STENCIL_TEST);
|
|
240 |
}
|
| 217 |
241 |
else
|
| 218 |
242 |
{
|
|
243 |
//android.util.Log.d("State", "enabling stencil test");
|
| 219 |
244 |
GLES30.glEnable(GLES30.GL_STENCIL_TEST);
|
| 220 |
|
|
| 221 |
|
if( mStencilFuncFunc!=sStencilFuncFunc || mStencilFuncRef!=sStencilFuncRef || mStencilFuncMask!=sStencilFuncMask )
|
| 222 |
|
{
|
| 223 |
|
sStencilFuncFunc = mStencilFuncFunc;
|
| 224 |
|
sStencilFuncRef = mStencilFuncRef ;
|
| 225 |
|
sStencilFuncMask = mStencilFuncMask;
|
| 226 |
|
GLES30.glStencilFunc(sStencilFuncFunc,sStencilFuncRef,sStencilFuncMask);
|
| 227 |
|
}
|
| 228 |
|
|
| 229 |
|
if( mStencilOpSfail!=sStencilOpSfail || mStencilOpDpfail!=sStencilOpDpfail || mStencilOpDppass!=sStencilOpDppass )
|
| 230 |
|
{
|
| 231 |
|
sStencilOpSfail = mStencilOpSfail;
|
| 232 |
|
sStencilOpDpfail= mStencilOpDpfail;
|
| 233 |
|
sStencilOpDppass= mStencilOpDppass;
|
| 234 |
|
GLES30.glStencilOp(sStencilOpSfail,sStencilOpDpfail,sStencilOpDppass);
|
| 235 |
|
}
|
| 236 |
245 |
}
|
| 237 |
246 |
}
|
| 238 |
247 |
|
| 239 |
|
// 6. Write to Stencil buffer?
|
|
248 |
// android.util.Log.d("State", "mFunc="+mStencilFuncFunc+" sFunc="+sStencilFuncFunc);
|
|
249 |
// android.util.Log.d("State", "GL_ALWAYS="+GLES30.GL_ALWAYS+" GL_EQUAL="+GLES30.GL_EQUAL);
|
|
250 |
|
|
251 |
/////////////////////////////////////////////////////
|
|
252 |
// 8. Adjust Stencil function?
|
|
253 |
if( mStencilFuncFunc!=sStencilFuncFunc || mStencilFuncRef!=sStencilFuncRef || mStencilFuncMask!=sStencilFuncMask )
|
|
254 |
{
|
|
255 |
//android.util.Log.d("State", "setting stencil function");
|
|
256 |
sStencilFuncFunc = mStencilFuncFunc;
|
|
257 |
sStencilFuncRef = mStencilFuncRef ;
|
|
258 |
sStencilFuncMask = mStencilFuncMask;
|
|
259 |
GLES30.glStencilFunc(sStencilFuncFunc,sStencilFuncRef,sStencilFuncMask);
|
|
260 |
}
|
|
261 |
|
|
262 |
/////////////////////////////////////////////////////
|
|
263 |
// 9. Adjust Stencil operation?
|
|
264 |
if( mStencilOpSfail!=sStencilOpSfail || mStencilOpDpfail!=sStencilOpDpfail || mStencilOpDppass!=sStencilOpDppass )
|
|
265 |
{
|
|
266 |
//android.util.Log.d("State", "setting stencil op");
|
|
267 |
sStencilOpSfail = mStencilOpSfail;
|
|
268 |
sStencilOpDpfail= mStencilOpDpfail;
|
|
269 |
sStencilOpDppass= mStencilOpDppass;
|
|
270 |
GLES30.glStencilOp(sStencilOpSfail,sStencilOpDpfail,sStencilOpDppass);
|
|
271 |
}
|
| 240 |
272 |
|
|
273 |
/////////////////////////////////////////////////////
|
|
274 |
// 10. Write to Stencil buffer?
|
| 241 |
275 |
if( mStencilMask!=sStencilMask )
|
| 242 |
276 |
{
|
|
277 |
//android.util.Log.d("State", "setting stencil mask");
|
| 243 |
278 |
sStencilMask = mStencilMask;
|
| 244 |
279 |
GLES30.glStencilMask(sStencilMask);
|
| 245 |
280 |
}
|
| 246 |
281 |
|
| 247 |
|
// 7. Clear buffers?
|
| 248 |
|
|
|
282 |
/////////////////////////////////////////////////////
|
|
283 |
// 11. Clear buffers?
|
| 249 |
284 |
if( mClear!=0 )
|
| 250 |
285 |
{
|
|
286 |
//android.util.Log.d("State", "clearing buffer");
|
| 251 |
287 |
GLES30.glClear(mClear);
|
| 252 |
288 |
}
|
| 253 |
289 |
}
|
1. Correct some bugs in DistortedRenderState
2. Thus make the Stencil App work
3. New icon for it