Revision 5c83f4b4
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
246 | 246 |
if( depthStencil!= NO_DEPTH_NO_STENCIL && mDepthStencilCreated==DONT_CREATE ) |
247 | 247 |
{ |
248 | 248 |
mDepthStencilCreated = NOT_CREATED_YET; |
249 |
|
|
250 |
if( mBuffer1[0]!=null ) |
|
251 |
for(int i=0; i<EffectQuality.LENGTH; i++) mBuffer1[i].enableDepthStencil(depthStencil); |
|
252 |
|
|
253 | 249 |
markForCreation(); |
254 | 250 |
} |
255 | 251 |
if( depthStencil== NO_DEPTH_NO_STENCIL && mDepthStencilCreated!=DONT_CREATE ) |
256 | 252 |
{ |
257 | 253 |
mDepthStencilCreated = DONT_CREATE; |
258 |
|
|
259 |
if( mBuffer1[0]!=null ) |
|
260 |
for(int i=0; i<EffectQuality.LENGTH; i++) mBuffer1[i].enableDepthStencil(depthStencil); |
|
261 |
|
|
262 | 254 |
markForCreation(); |
263 | 255 |
} |
264 | 256 |
} |
src/main/java/org/distorted/library/DistortedNode.java | ||
---|---|---|
259 | 259 |
|
260 | 260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
261 | 261 |
|
262 |
int markStencilAndDraw(long currTime, DistortedOutputSurface surface, float marginInPixels) |
|
262 |
int markStencilAndDraw(long currTime, DistortedOutputSurface surface, int quality, float marginInPixels)
|
|
263 | 263 |
{ |
264 | 264 |
DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO; |
265 | 265 |
|
266 | 266 |
if( input.setAsInput() ) |
267 | 267 |
{ |
268 |
surface.setAsOutput(currTime); |
|
268 |
DistortedFramebuffer buffer1 = surface.mBuffer1[quality]; |
|
269 |
DistortedFramebuffer buffer2 = surface.mBuffer2[quality]; |
|
270 |
float w = mSurface.getWidth() /2.0f; |
|
271 |
float h = mSurface.getHeight()/2.0f; |
|
269 | 272 |
|
270 | 273 |
// Mark area of our object + marginInPixels pixels around with 1s in Stencil buffer |
274 |
buffer2.setAsOutput(currTime); |
|
271 | 275 |
DistortedRenderState.setUpStencilMark(); |
272 |
mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, marginInPixels);
|
|
276 |
mEffects.drawPriv(w, h, mMesh, buffer2, currTime, marginInPixels);
|
|
273 | 277 |
|
274 | 278 |
// Actually draw our object. |
279 |
buffer1.setAsOutput(currTime); |
|
275 | 280 |
mState.apply(); |
276 |
mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, 0);
|
|
281 |
mEffects.drawPriv(w, h, mMesh, buffer1, currTime, 0);
|
|
277 | 282 |
return 1; |
278 | 283 |
} |
279 | 284 |
return 0; |
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
191 | 191 |
|
192 | 192 |
for(int j=0; j<EffectQuality.LENGTH; j++) |
193 | 193 |
{ |
194 |
mBuffer1[j] = new DistortedFramebuffer(mDepthStencil ,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
|
|
195 |
mBuffer2[j] = new DistortedFramebuffer(NO_DEPTH_NO_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
|
|
194 |
mBuffer1[j] = new DistortedFramebuffer(BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
|
|
195 |
mBuffer2[j] = new DistortedFramebuffer(BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
|
|
196 | 196 |
mBuffer1[j].mMipmap = mipmap; |
197 | 197 |
mipmap *= EffectQuality.MULTIPLIER; |
198 | 198 |
} |
199 | 199 |
DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now. |
200 | 200 |
} |
201 | 201 |
|
202 |
numRenders += child.markStencilAndDraw(time,mBuffer1[currP.getQuality()],50);
|
|
202 |
numRenders += child.markStencilAndDraw(time,this,currP.getQuality(),50);
|
|
203 | 203 |
|
204 | 204 |
if( i==num-1 ) |
205 | 205 |
{ |
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
318 | 318 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
319 | 319 |
|
320 | 320 |
// after each postprocess, clear the STENCIL |
321 |
buffer1.setAsOutput(time);
|
|
321 |
buffer2.setAsOutput(time);
|
|
322 | 322 |
GLES30.glClear(GLES30.GL_STENCIL_BUFFER_BIT); |
323 | 323 |
} |
324 | 324 |
|
Also available in: Unified diff
Progress with Stencil in Postprocessing: stencil during the 1st stage postprocess (buffer1->buffer2) works now, provided quality is HIGHEST.
(lower quality --> render errors, looks like Stencil is not set up correctly then)