Revision b3120b1b
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/DistortedEffects.java | ||
|---|---|---|
| 256 | 256 |
GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
| 257 | 257 |
|
| 258 | 258 |
mMainProgram.useProgram(); |
| 259 |
surface.setAsOutput(currTime); |
|
| 260 | 259 |
GLES30.glUniform1i(mMainTextureH, 0); |
| 261 | 260 |
|
| 262 | 261 |
if( Distorted.GLSL >= 300 ) |
| src/main/java/org/distorted/library/DistortedNode.java | ||
|---|---|---|
| 265 | 265 |
|
| 266 | 266 |
if( input.setAsInput() ) |
| 267 | 267 |
{
|
| 268 |
surface.setAsOutput(currTime); |
|
| 269 |
|
|
| 268 | 270 |
// Mark area of our object + marginInPixels pixels around with 1s in Stencil buffer |
| 269 | 271 |
DistortedRenderState.setUpStencilMark(); |
| 270 | 272 |
mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, marginInPixels); |
| ... | ... | |
| 286 | 288 |
|
| 287 | 289 |
if( input.setAsInput() ) |
| 288 | 290 |
{
|
| 291 |
surface.setAsOutput(currTime); |
|
| 289 | 292 |
mState.apply(); |
| 290 | 293 |
mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, 0); |
| 291 | 294 |
return 1; |
| src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
|---|---|---|
| 194 | 194 |
mBuffer1[j] = new DistortedFramebuffer(mDepthStencil ,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
| 195 | 195 |
mBuffer2[j] = new DistortedFramebuffer(NO_DEPTH_NO_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
| 196 | 196 |
mBuffer1[j].mMipmap = mipmap; |
| 197 |
mBuffer1[j].glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT); |
|
| 198 | 197 |
mipmap *= EffectQuality.MULTIPLIER; |
| 199 | 198 |
} |
| 200 | 199 |
DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now. |
| 201 | 200 |
} |
| 202 | 201 |
|
| 203 |
numRenders += child.markStencilAndDraw(time,mBuffer1[currP.getQuality()],20);
|
|
| 202 |
numRenders += child.markStencilAndDraw(time,mBuffer1[currP.getQuality()],50);
|
|
| 204 | 203 |
|
| 205 | 204 |
if( i==num-1 ) |
| 206 | 205 |
{
|
| src/main/java/org/distorted/library/DistortedRenderState.java | ||
|---|---|---|
| 166 | 166 |
if( sStencilTest!=1 ) |
| 167 | 167 |
{
|
| 168 | 168 |
sStencilTest = 1; |
| 169 |
//android.util.Log.d("State", "stencil test on");
|
|
| 169 | 170 |
GLES30.glEnable(GLES30.GL_STENCIL_TEST); |
| 170 | 171 |
} |
| 171 | 172 |
if( sStencilFuncFunc!=GLES30.GL_ALWAYS || sStencilFuncRef!=1 || sStencilFuncMask!=STENCIL_MASK ) |
| ... | ... | |
| 173 | 174 |
sStencilFuncFunc = GLES30.GL_ALWAYS; |
| 174 | 175 |
sStencilFuncRef = 1; |
| 175 | 176 |
sStencilFuncMask = STENCIL_MASK; |
| 177 |
//android.util.Log.d("State", "stencil func on");
|
|
| 176 | 178 |
GLES30.glStencilFunc(sStencilFuncFunc,sStencilFuncRef,sStencilFuncMask); |
| 177 | 179 |
} |
| 178 | 180 |
if( sStencilOpSfail!=GLES30.GL_KEEP || sStencilOpDpfail!=GLES30.GL_KEEP || sStencilOpDppass!=GLES30.GL_REPLACE ) |
| ... | ... | |
| 180 | 182 |
sStencilOpSfail = GLES30.GL_KEEP; |
| 181 | 183 |
sStencilOpDpfail= GLES30.GL_KEEP; |
| 182 | 184 |
sStencilOpDppass= GLES30.GL_REPLACE; |
| 185 |
//android.util.Log.d("State", "stencil op on");
|
|
| 183 | 186 |
GLES30.glStencilOp(sStencilOpSfail,sStencilOpDpfail,sStencilOpDppass); |
| 184 | 187 |
} |
| 185 | 188 |
if( sColorMaskR!=0 || sColorMaskG!=0 || sColorMaskB!=0 || sColorMaskA!=0 ) |
| ... | ... | |
| 188 | 191 |
sColorMaskG = 0; |
| 189 | 192 |
sColorMaskB = 0; |
| 190 | 193 |
sColorMaskA = 0; |
| 194 |
//android.util.Log.d("State", "switch off color writing");
|
|
| 191 | 195 |
GLES30.glColorMask(false,false,false,false); |
| 192 | 196 |
} |
| 193 | 197 |
if( sDepthMask!=0 ) |
| 194 | 198 |
{
|
| 195 | 199 |
sDepthMask = 0; |
| 200 |
//android.util.Log.d("State", "switch off depth writing");
|
|
| 196 | 201 |
GLES30.glDepthMask(false); |
| 197 | 202 |
} |
| 198 | 203 |
if( sStencilMask!= STENCIL_MASK ) |
| 199 | 204 |
{
|
| 200 | 205 |
sStencilMask = STENCIL_MASK; |
| 206 |
//android.util.Log.d("State", "stencil mask on");
|
|
| 201 | 207 |
GLES30.glStencilMask(sStencilMask); |
| 202 | 208 |
} |
| 203 | 209 |
} |
| ... | ... | |
| 234 | 240 |
|
| 235 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 236 | 242 |
|
| 237 |
static void restoreStencilMark()
|
|
| 243 |
static void unuseStencilMark()
|
|
| 238 | 244 |
{
|
| 239 | 245 |
if( rStencilTest!=sStencilTest ) |
| 240 | 246 |
{
|
| src/main/java/org/distorted/library/EffectQueueMatrix.java | ||
|---|---|---|
| 197 | 197 |
|
| 198 | 198 |
scale = 1.0f + marginInPixels/( xlen>ylen ? ylen:xlen ); |
| 199 | 199 |
|
| 200 |
// android.util.Log.d("scale", "scale= "+scale+" xlen="+xlen+" ylen="+ylen);
|
|
| 200 |
//android.util.Log.d("scale", ""+marginInPixels+" scale= "+scale+" xlen="+xlen+" ylen="+ylen);
|
|
| 201 | 201 |
|
| 202 | 202 |
Matrix.scaleM(mViewMatrix, 0, scale, scale, scale); |
| 203 | 203 |
} |
| src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
|---|---|---|
| 294 | 294 |
GLES30.glUniform1fv( mOffsets1H ,radius+1, mOffsets,0); |
| 295 | 295 |
GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
| 296 | 296 |
GLES30.glVertexAttribPointer(mBlur1Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
| 297 |
|
|
| 298 |
DistortedRenderState.useStencilMark(); |
|
| 297 | 299 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
| 300 |
DistortedRenderState.unuseStencilMark(); |
|
| 298 | 301 |
|
| 299 | 302 |
// vertical blur |
| 300 | 303 |
GLES30.glViewport(0, 0, (int)w2, (int)h2); |
| ... | ... | |
| 313 | 316 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
| 314 | 317 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
| 315 | 318 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
| 319 |
|
|
| 320 |
// after each postprocess, clear the STENCIL |
|
| 321 |
buffer1.setAsOutput(time); |
|
| 322 |
GLES30.glClear(GLES30.GL_STENCIL_BUFFER_BIT); |
|
| 316 | 323 |
} |
| 317 | 324 |
|
| 318 | 325 |
return mNumEffects; |
Also available in: Unified diff
Progress with Stencil in Postprocessing (doesn't work still)