Revision 23eecbd9
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
|---|---|---|
| 183 | 183 |
* @param width Width of the COLOR attachment. |
| 184 | 184 |
* @param height Height of the COLOR attachment. |
| 185 | 185 |
* @param depthStencil Add DEPTH or STENCIL attachment? |
| 186 |
* Valid values: NO_DEPTH_STENCIL, DEPTH_NO_STENCIL, BOTH_DEPTH_STENCIL. |
|
| 186 |
* Valid values: NO_DEPTH_NO_STENCIL, DEPTH_NO_STENCIL, BOTH_DEPTH_STENCIL.
|
|
| 187 | 187 |
*/ |
| 188 | 188 |
@SuppressWarnings("unused")
|
| 189 | 189 |
public DistortedFramebuffer(int width, int height, int depthStencil) |
| ... | ... | |
| 202 | 202 |
@SuppressWarnings("unused")
|
| 203 | 203 |
public DistortedFramebuffer(int width, int height) |
| 204 | 204 |
{
|
| 205 |
super(width,height,NOT_CREATED_YET,NO_DEPTH_STENCIL,NOT_CREATED_YET,TYPE_USER);
|
|
| 205 |
super(width,height,NOT_CREATED_YET, NO_DEPTH_NO_STENCIL,NOT_CREATED_YET,TYPE_USER);
|
|
| 206 | 206 |
} |
| 207 | 207 |
|
| 208 | 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 227 | 227 |
/** |
| 228 | 228 |
* Enable.disable DEPTH and STENCIL buffers. |
| 229 | 229 |
* |
| 230 |
* @param depthStencil Valid values: NO_DEPTH_STENCIL, DEPTH_NO_STENCIL, BOTH_DEPTH_STENCIL. |
|
| 230 |
* @param depthStencil Valid values: NO_DEPTH_NO_STENCIL, DEPTH_NO_STENCIL, BOTH_DEPTH_STENCIL.
|
|
| 231 | 231 |
*/ |
| 232 | 232 |
public void enableDepthStencil(int depthStencil) |
| 233 | 233 |
{
|
| 234 |
if( depthStencil!=NO_DEPTH_STENCIL && mDepthStencilCreated==DONT_CREATE )
|
|
| 234 |
if( depthStencil!= NO_DEPTH_NO_STENCIL && mDepthStencilCreated==DONT_CREATE )
|
|
| 235 | 235 |
{
|
| 236 | 236 |
mDepthStencilCreated = NOT_CREATED_YET; |
| 237 | 237 |
mDepthStencil = depthStencil; |
| ... | ... | |
| 243 | 243 |
|
| 244 | 244 |
markForCreation(); |
| 245 | 245 |
} |
| 246 |
if( depthStencil==NO_DEPTH_STENCIL && mDepthStencilCreated!=DONT_CREATE )
|
|
| 246 |
if( depthStencil== NO_DEPTH_NO_STENCIL && mDepthStencilCreated!=DONT_CREATE )
|
|
| 247 | 247 |
{
|
| 248 | 248 |
mDepthStencilCreated = DONT_CREATE; |
| 249 | 249 |
mDepthStencil = depthStencil; |
| src/main/java/org/distorted/library/DistortedNode.java | ||
|---|---|---|
| 71 | 71 |
private DistortedInputSurface mSurface; |
| 72 | 72 |
private DistortedRenderState mState; |
| 73 | 73 |
private NodeData mData; |
| 74 |
private int mFboW, mFboH, mFboDepthStencil; |
|
| 74 | 75 |
|
| 75 | 76 |
private class NodeData |
| 76 | 77 |
{
|
| ... | ... | |
| 245 | 246 |
} |
| 246 | 247 |
else if( createNewFBO ) |
| 247 | 248 |
{
|
| 248 |
newData.mFBO = new DistortedFramebuffer(DistortedFramebuffer.DEPTH_NO_STENCIL, DistortedSurface.TYPE_TREE, mSurface.getWidth(),mSurface.getHeight()); |
|
| 249 |
int width = mFboW <= 0 ? mSurface.getWidth() : mFboW; |
|
| 250 |
int height = mFboH <= 0 ? mSurface.getHeight() : mFboH; |
|
| 251 |
newData.mFBO = new DistortedFramebuffer(mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height); |
|
| 249 | 252 |
//android.util.Log.d("NODE", "creating new FBO "+newData.mFBO.getID() );
|
| 250 | 253 |
} |
| 251 | 254 |
|
| ... | ... | |
| 289 | 292 |
|
| 290 | 293 |
if( mData.mFBO==null ) |
| 291 | 294 |
{
|
| 292 |
mData.mFBO = new DistortedFramebuffer(DistortedFramebuffer.DEPTH_NO_STENCIL, DistortedSurface.TYPE_TREE, mSurface.getWidth(),mSurface.getHeight()); |
|
| 295 |
int width = mFboW <= 0 ? mSurface.getWidth() : mFboW; |
|
| 296 |
int height = mFboH <= 0 ? mSurface.getHeight() : mFboH; |
|
| 297 |
mData.mFBO = new DistortedFramebuffer(mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height); |
|
| 293 | 298 |
} |
| 294 | 299 |
|
| 295 | 300 |
mData.mFBO.setAsOutput(currTime); |
| ... | ... | |
| 351 | 356 |
mParent = null; |
| 352 | 357 |
mSurfaceParent = null; |
| 353 | 358 |
|
| 359 |
mFboW = 0; // i.e. take this from |
|
| 360 |
mFboH = 0; // mSurface's dimensions |
|
| 361 |
mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL; |
|
| 362 |
|
|
| 354 | 363 |
ArrayList<Long> list = new ArrayList<>(); |
| 355 | 364 |
list.add(mSurface.getID()); |
| 356 | 365 |
list.add(-mEffects.getID()); |
| ... | ... | |
| 387 | 396 |
mParent = null; |
| 388 | 397 |
mSurfaceParent= null; |
| 389 | 398 |
|
| 399 |
mFboW = node.mFboW; |
|
| 400 |
mFboH = node.mFboH; |
|
| 401 |
mFboDepthStencil = node.mFboDepthStencil; |
|
| 402 |
|
|
| 390 | 403 |
if( (flags & Distorted.CLONE_SURFACE) != 0 ) |
| 391 | 404 |
{
|
| 392 | 405 |
mSurface = node.mSurface; |
| ... | ... | |
| 402 | 415 |
} |
| 403 | 416 |
else if( node.mSurface instanceof DistortedFramebuffer ) |
| 404 | 417 |
{
|
| 405 |
int depthStencil = DistortedFramebuffer.NO_DEPTH_STENCIL; |
|
| 418 |
int depthStencil = DistortedFramebuffer.NO_DEPTH_NO_STENCIL;
|
|
| 406 | 419 |
|
| 407 | 420 |
if( ((DistortedFramebuffer) node.mSurface).hasDepth() ) |
| 408 | 421 |
{
|
| ... | ... | |
| 683 | 696 |
|
| 684 | 697 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 685 | 698 |
/** |
| 686 |
* Returns the DistortedFramebuffer object that's in the Node. |
|
| 687 |
* |
|
| 688 |
* @return The DistortedFramebuffer contained in the Node. |
|
| 699 |
* Resizes the DistortedFramebuffer object that we render this Node to. |
|
| 689 | 700 |
*/ |
| 690 |
public DistortedFramebuffer getFramebuffer()
|
|
| 701 |
public void resize(int width, int height)
|
|
| 691 | 702 |
{
|
| 692 |
return mData.mFBO; |
|
| 703 |
mFboW = width; |
|
| 704 |
mFboH = height; |
|
| 705 |
|
|
| 706 |
if ( mData.mFBO !=null ) |
|
| 707 |
{
|
|
| 708 |
// TODO: potentially allocate a new NodeData if we have to |
|
| 709 |
mData.mFBO.resize(width,height); |
|
| 710 |
} |
|
| 711 |
} |
|
| 712 |
|
|
| 713 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 714 |
/** |
|
| 715 |
* Enables/disables DEPTH and STENCIL buffers in the Framebuffer object that we render this Node to. |
|
| 716 |
*/ |
|
| 717 |
public void enableDepthStencil(int depthStencil) |
|
| 718 |
{
|
|
| 719 |
mFboDepthStencil = depthStencil; |
|
| 720 |
|
|
| 721 |
if ( mData.mFBO !=null ) |
|
| 722 |
{
|
|
| 723 |
// TODO: potentially allocate a new NodeData if we have to |
|
| 724 |
mData.mFBO.enableDepthStencil(depthStencil); |
|
| 725 |
} |
|
| 693 | 726 |
} |
| 694 | 727 |
|
| 695 | 728 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
|---|---|---|
| 30 | 30 |
/** |
| 31 | 31 |
* Do not create DEPTH or STENCIL attachment |
| 32 | 32 |
*/ |
| 33 |
public static final int NO_DEPTH_STENCIL = 0; |
|
| 33 |
public static final int NO_DEPTH_NO_STENCIL = 0;
|
|
| 34 | 34 |
/** |
| 35 | 35 |
* Create DEPTH, but not STENCIL |
| 36 | 36 |
*/ |
| 37 |
public static final int DEPTH_NO_STENCIL = 1; |
|
| 37 |
public static final int DEPTH_NO_STENCIL = 1;
|
|
| 38 | 38 |
/** |
| 39 | 39 |
* Create both DEPTH and STENCIL |
| 40 | 40 |
*/ |
| 41 |
public static final int BOTH_DEPTH_STENCIL= 2; |
|
| 41 |
public static final int BOTH_DEPTH_STENCIL = 2;
|
|
| 42 | 42 |
|
| 43 | 43 |
private static final int ATTACH = 0; |
| 44 | 44 |
private static final int DETACH = 1; |
| ... | ... | |
| 78 | 78 |
|
| 79 | 79 |
private float mClearR, mClearG, mClearB, mClearA; |
| 80 | 80 |
private float mClearDepth; |
| 81 |
private int mClearStencil; |
|
| 81 | 82 |
private int mClear; |
| 82 | 83 |
|
| 83 | 84 |
//private String sNew="", sOld=""; |
| ... | ... | |
| 95 | 96 |
mFOV = 60.0f; |
| 96 | 97 |
mNear= 0.5f; |
| 97 | 98 |
|
| 98 |
mDepthStencilCreated= (depthStencil==NO_DEPTH_STENCIL ? DONT_CREATE:NOT_CREATED_YET);
|
|
| 99 |
mDepthStencilCreated= (depthStencil== NO_DEPTH_NO_STENCIL ? DONT_CREATE:NOT_CREATED_YET);
|
|
| 99 | 100 |
mDepthStencil = depthStencil; |
| 100 | 101 |
|
| 101 | 102 |
mFBOH[0] = fbo; |
| ... | ... | |
| 109 | 110 |
mClearA = 0.0f; |
| 110 | 111 |
|
| 111 | 112 |
mClearDepth = 1.0f; |
| 113 |
mClearStencil = 0; |
|
| 112 | 114 |
mClear = GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT; |
| 113 | 115 |
|
| 114 | 116 |
mBuffer1 = new DistortedFramebuffer[EffectQuality.LENGTH]; |
| ... | ... | |
| 196 | 198 |
|
| 197 | 199 |
for(int j=0; j<EffectQuality.LENGTH; j++) |
| 198 | 200 |
{
|
| 199 |
mBuffer1[j] = new DistortedFramebuffer( mDepthStencil , DistortedObject.TYPE_SYST, |
|
| 201 |
mBuffer1[j] = new DistortedFramebuffer( mDepthStencil , DistortedObject.TYPE_SYST,
|
|
| 200 | 202 |
(int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
| 201 |
mBuffer2[j] = new DistortedFramebuffer( NO_DEPTH_STENCIL, DistortedObject.TYPE_SYST,
|
|
| 203 |
mBuffer2[j] = new DistortedFramebuffer(NO_DEPTH_NO_STENCIL, DistortedObject.TYPE_SYST,
|
|
| 202 | 204 |
(int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
| 203 | 205 |
mBuffer1[j].mMipmap = mipmap; |
| 204 | 206 |
mipmap *= EffectQuality.MULTIPLIER; |
| ... | ... | |
| 310 | 312 |
if( mTime!=time ) |
| 311 | 313 |
{
|
| 312 | 314 |
mTime = time; |
| 313 |
DistortedRenderState.colorDepthOn(); |
|
| 315 |
DistortedRenderState.colorDepthStencilOn();
|
|
| 314 | 316 |
GLES30.glClearColor(mClearR, mClearG, mClearB, mClearA); |
| 315 | 317 |
GLES30.glClearDepthf(mClearDepth); |
| 318 |
GLES30.glClearStencil(mClearStencil); |
|
| 316 | 319 |
GLES30.glClear(mClear); |
| 317 | 320 |
} |
| 318 | 321 |
} |
| ... | ... | |
| 361 | 364 |
|
| 362 | 365 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 363 | 366 |
/** |
| 364 |
* Set the Depth value of GLES30.glClearDepthf() to set up depth with which to clear
|
|
| 365 |
* the Depth buffer of Surface at the beginning of each frame. |
|
| 367 |
* Uses glClearDepthf() to set up a value with which to clear
|
|
| 368 |
* the Depth buffer of our Surface at the beginning of each frame.
|
|
| 366 | 369 |
* |
| 367 | 370 |
* @param d the Depth. Default: 1.0f |
| 368 | 371 |
*/ |
| ... | ... | |
| 371 | 374 |
mClearDepth = d; |
| 372 | 375 |
} |
| 373 | 376 |
|
| 377 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 378 |
/** |
|
| 379 |
* Uses glClearStencil() to set up a value with which to clear the |
|
| 380 |
* Stencil buffer of our Surface at the beginning of each frame. |
|
| 381 |
* |
|
| 382 |
* @param s the Stencil. Default: 0 |
|
| 383 |
*/ |
|
| 384 |
public void glClearStencil(int s) |
|
| 385 |
{
|
|
| 386 |
mClearStencil = s; |
|
| 387 |
} |
|
| 388 |
|
|
| 374 | 389 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 375 | 390 |
/** |
| 376 | 391 |
* Which buffers to Clear at the beginning of each frame? |
| src/main/java/org/distorted/library/DistortedRenderState.java | ||
|---|---|---|
| 30 | 30 |
*/ |
| 31 | 31 |
class DistortedRenderState |
| 32 | 32 |
{
|
| 33 |
// TODO: figure this out dynamically; this assumes 8 bit stencil buffer. |
|
| 34 |
private static final int STENCIL_MASK = (1<<8)-1; |
|
| 35 |
|
|
| 33 | 36 |
private static int sColorMaskR, sColorMaskG, sColorMaskB, sColorMaskA; // |
| 34 | 37 |
private static int sDepthMask; // |
| 35 | 38 |
private static int sStencilMask; // |
| ... | ... | |
| 72 | 75 |
mBlendDst = GLES30.GL_ONE_MINUS_SRC_ALPHA; |
| 73 | 76 |
|
| 74 | 77 |
mStencilTest = 0; |
| 75 |
mStencilMask = 0x11111111;
|
|
| 78 |
mStencilMask = STENCIL_MASK;
|
|
| 76 | 79 |
mStencilFuncFunc = GLES30.GL_NEVER; |
| 77 | 80 |
mStencilFuncRef = 0; |
| 78 |
mStencilFuncMask = 0x11111111;
|
|
| 81 |
mStencilFuncMask = STENCIL_MASK;
|
|
| 79 | 82 |
mStencilOpSfail = GLES30.GL_KEEP; |
| 80 | 83 |
mStencilOpDpfail = GLES30.GL_KEEP; |
| 81 | 84 |
mStencilOpDppass = GLES30.GL_KEEP; |
| ... | ... | |
| 113 | 116 |
|
| 114 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 115 | 118 |
|
| 116 |
static void colorDepthOn() |
|
| 119 |
static void colorDepthStencilOn()
|
|
| 117 | 120 |
{
|
| 118 | 121 |
if( sColorMaskR!=1 || sColorMaskG!=1 || sColorMaskB!=1 || sColorMaskA!=1 ) |
| 119 | 122 |
{
|
| ... | ... | |
| 128 | 131 |
sDepthMask = 1; |
| 129 | 132 |
GLES30.glDepthMask(true); |
| 130 | 133 |
} |
| 134 |
if( sStencilMask!= STENCIL_MASK ) |
|
| 135 |
{
|
|
| 136 |
sStencilMask = STENCIL_MASK; |
|
| 137 |
GLES30.glStencilMask(sStencilMask); |
|
| 138 |
} |
|
| 131 | 139 |
} |
| 132 | 140 |
|
| 133 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Progress with Stencil app. Rendering through an intermediate FBO still doesn't quite work.