Revision 040cd18c
Added by Leszek Koltunski almost 6 years ago
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
public abstract class DistortedOutputSurface extends DistortedSurface implements DistortedMaster.Slave |
36 | 36 |
{ |
37 |
//////////// DEBUG FLAGS ///////////////////////////////////////////// |
|
38 |
/** |
|
39 |
* When rendering a Screen, show FPS in the upper-left corner? |
|
40 |
*/ |
|
41 |
public static final int DEBUG_FPS = 1; |
|
42 |
//////////// END DEBUG FLAGS ///////////////////////////////////////// |
|
43 |
|
|
44 | 37 |
/** |
45 | 38 |
* Do not create DEPTH or STENCIL attachment |
46 | 39 |
*/ |
... | ... | |
77 | 70 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
78 | 71 |
|
79 | 72 |
// Global buffers used for postprocessing. |
80 |
private static DistortedOutputSurface[] mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH];
|
|
73 |
private static DistortedOutputSurface[] mBuffer = null;
|
|
81 | 74 |
|
82 | 75 |
private long mTime; |
83 | 76 |
private float mFOV; |
... | ... | |
95 | 88 |
private int mClear; |
96 | 89 |
float mMipmap; |
97 | 90 |
|
98 |
private int mDebugLevel; |
|
99 |
|
|
100 | 91 |
int mRealWidth; // the Surface can be backed up with a texture that is |
101 | 92 |
int mRealHeight; // larger than the viewport we have to it. |
102 | 93 |
// mWidth,mHeight are the sizes of the Viewport, those - |
103 | 94 |
// sizes of the backing up texture. |
104 | 95 |
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
abstract void prepareDebug(long time); |
|
108 |
abstract void renderDebug(long time); |
|
109 |
|
|
110 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
111 | 97 |
|
112 | 98 |
DistortedOutputSurface(int width, int height, int createColor, int numcolors, int depthStencil, int fbo, int type) |
... | ... | |
128 | 114 |
mDepthStencilH[0]= 0; |
129 | 115 |
|
130 | 116 |
mTime = 0; |
131 |
mDebugLevel = 0; |
|
132 | 117 |
|
133 | 118 |
mClearR = 0.0f; |
134 | 119 |
mClearG = 0.0f; |
... | ... | |
184 | 169 |
|
185 | 170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
186 | 171 |
|
187 |
private static void createBuffers(int width, int height, float near) |
|
172 |
private static void createPostprocessingBuffers(int width, int height, float near)
|
|
188 | 173 |
{ |
174 |
mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH]; |
|
189 | 175 |
float mipmap=1.0f; |
190 | 176 |
|
191 | 177 |
for(int j=0; j<EffectQuality.LENGTH; j++) |
... | ... | |
221 | 207 |
|
222 | 208 |
static synchronized void onDestroy() |
223 | 209 |
{ |
224 |
for(int j=0; j<EffectQuality.LENGTH; j++)
|
|
210 |
if( mBuffer!=null )
|
|
225 | 211 |
{ |
226 |
mBuffer[j] = null; |
|
212 |
for (int i=0; i<EffectQuality.LENGTH; i++) |
|
213 |
{ |
|
214 |
mBuffer[i] = null; |
|
215 |
} |
|
216 |
|
|
217 |
mBuffer = null; |
|
227 | 218 |
} |
228 | 219 |
} |
229 | 220 |
|
230 | 221 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
231 | 222 |
// The postprocessing buffers mBuffer[] are generally speaking too large (there's just one static |
232 |
// set of them) so before we use them for output, we need to adjust the Vieport as if they were |
|
223 |
// set of them) so before we use them for output, we need to adjust the Viewport as if they were
|
|
233 | 224 |
// smaller. That takes care of outputting pixels to them. When we use them as input, we have to |
234 | 225 |
// adjust the texture coords - see the get{Width|Height}Correction functions. |
235 | 226 |
|
236 |
private static void cloneViewport(DistortedOutputSurface from) |
|
227 |
private static void clonePostprocessingViewport(DistortedOutputSurface from)
|
|
237 | 228 |
{ |
238 |
if( mBuffer[0].mWidth != from.mWidth ) |
|
229 |
if( mBuffer[0].mWidth != from.mWidth || mBuffer[0].mHeight != from.mHeight )
|
|
239 | 230 |
{ |
240 | 231 |
DistortedOutputSurface surface; |
241 | 232 |
|
... | ... | |
304 | 295 |
return 1; |
305 | 296 |
} |
306 | 297 |
|
298 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
299 |
|
|
300 |
void clear() |
|
301 |
{ |
|
302 |
DistortedRenderState.colorDepthStencilOn(); |
|
303 |
GLES31.glClearColor(mClearR, mClearG, mClearB, mClearA); |
|
304 |
GLES31.glClearDepthf(mClearDepth); |
|
305 |
GLES31.glClearStencil(mClearStencil); |
|
306 |
GLES31.glClear(mClear); |
|
307 |
DistortedRenderState.colorDepthStencilRestore(); |
|
308 |
} |
|
309 |
|
|
307 | 310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
308 | 311 |
// Render all children, one by one. If there are no postprocessing effects, just render to THIS. |
309 | 312 |
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing |
... | ... | |
322 | 325 |
currQueue = child1.getPostprocessQueue(); |
323 | 326 |
currBucket= currQueue.getID(); |
324 | 327 |
|
325 |
if( currBucket==0 ) numRenders += child1.draw(time,this); |
|
328 |
if( currBucket==0 ) |
|
329 |
{ |
|
330 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]); |
|
331 |
numRenders += child1.draw(time,this); |
|
332 |
} |
|
326 | 333 |
else |
327 | 334 |
{ |
328 |
if( mBuffer[0]==null ) createBuffers(mWidth,mHeight,mNear);
|
|
335 |
if( mBuffer==null ) createPostprocessingBuffers(mWidth,mHeight,mNear);
|
|
329 | 336 |
|
330 | 337 |
if( lastBucket!=currBucket ) |
331 | 338 |
{ |
332 |
if( lastBucket!=0 ) |
|
339 |
if( lastBucket==0 ) |
|
340 |
{ |
|
341 |
clonePostprocessingViewport(this); |
|
342 |
} |
|
343 |
else |
|
333 | 344 |
{ |
334 | 345 |
for(int j=bucketChange; j<i; j++) |
335 | 346 |
{ |
... | ... | |
346 | 357 |
internalQuality = currQueue.getInternalQuality(); |
347 | 358 |
quality = currQueue.getQuality(); |
348 | 359 |
bucketChange = i; |
349 |
|
|
350 |
cloneViewport(this); |
|
351 | 360 |
} |
352 | 361 |
|
362 |
mBuffer[quality].setAsOutput(time); |
|
353 | 363 |
child1.drawNoBlend(time,mBuffer[quality]); |
354 | 364 |
|
355 | 365 |
if( i==numChildren-1 ) |
... | ... | |
363 | 373 |
numRenders += currQueue.postprocess(mBuffer); |
364 | 374 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
365 | 375 |
} |
366 |
} |
|
376 |
} // end postprocessed child case
|
|
367 | 377 |
|
368 | 378 |
lastQueue = currQueue; |
369 | 379 |
lastBucket= currBucket; |
370 |
} |
|
380 |
} // end main for loop
|
|
371 | 381 |
|
372 | 382 |
return numRenders; |
373 | 383 |
} |
... | ... | |
423 | 433 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
424 | 434 |
// PUBLIC API |
425 | 435 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
426 |
/** |
|
427 |
* Make the library show various debugging information. |
|
428 |
* <p> |
|
429 |
* Currently only DEBUG_FPS - show FPS in the upper-left corner of every Screen - is defined. |
|
430 |
* |
|
431 |
* @param bitmask 0, or a bitmask of DEBUG_** flags to enable (currently only DEBUG_FPS defined) |
|
432 |
*/ |
|
433 |
public void setDebug(int bitmask) |
|
434 |
{ |
|
435 |
if( this instanceof DistortedScreen ) |
|
436 |
mDebugLevel = bitmask; |
|
437 |
} |
|
438 |
|
|
439 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
440 | 436 |
|
441 | 437 |
/** |
442 | 438 |
* Draws all the attached children to this OutputSurface. |
... | ... | |
448 | 444 |
*/ |
449 | 445 |
public int render(long time) |
450 | 446 |
{ |
451 |
if( mDebugLevel!=0 ) prepareDebug(time); |
|
452 |
|
|
453 | 447 |
// change tree topology (attach and detach children) |
454 | 448 |
/* |
455 | 449 |
boolean changed1 = |
... | ... | |
494 | 488 |
setAsOutput(time); |
495 | 489 |
numRenders += renderChildren(time,mNumChildren,mChildren); |
496 | 490 |
|
497 |
if( mDebugLevel != 0 ) renderDebug(time); |
|
498 |
|
|
499 | 491 |
return numRenders; |
500 | 492 |
} |
501 | 493 |
|
... | ... | |
515 | 507 |
if( mTime!=time ) |
516 | 508 |
{ |
517 | 509 |
mTime = time; |
518 |
DistortedRenderState.colorDepthStencilOn(); |
|
519 |
GLES31.glClearColor(mClearR, mClearG, mClearB, mClearA); |
|
520 |
GLES31.glClearDepthf(mClearDepth); |
|
521 |
GLES31.glClearStencil(mClearStencil); |
|
522 |
GLES31.glClear(mClear); |
|
523 |
DistortedRenderState.colorDepthStencilRestore(); |
|
524 |
/* |
|
525 |
if( mSSBO[0]>=0 ) |
|
526 |
{ |
|
527 |
// yes, this DOES keep on working when 'value' overflows into negative territory. |
|
528 |
int value = mIntBuffer.get(FRAME_DELAY*mSurfaceID+mLastIndex); |
|
529 |
|
|
530 |
if( value-mLastValue[mLastIndex]!=mLastDiff ) |
|
531 |
{ |
|
532 |
android.util.Log.d("surface", "id " + mSurfaceID + |
|
533 |
(mType == TYPE_USER ? " USER" : (mType == TYPE_SYST ? " SYST" : " TREE")) + |
|
534 |
" viewport: (" + mWidth + "x" + mHeight + ") last frame: " + (value - mLastValue[mLastIndex]) |
|
535 |
+ " avg: " + (mAvgSum/RUNNING_AVERAGE) |
|
536 |
); |
|
537 |
} |
|
538 |
|
|
539 |
mLastDiff = value-mLastValue[mLastIndex]; |
|
540 |
mLastValue[mLastIndex] = value; |
|
541 |
|
|
542 |
mAvgSum += (mLastDiff-mRunningAvg[mAvgIndex]); |
|
543 |
mRunningAvg[mAvgIndex] = mLastDiff; |
|
544 |
if( ++mAvgIndex>=RUNNING_AVERAGE ) mAvgIndex =0; |
|
545 |
} |
|
546 |
|
|
547 |
if( ++mLastIndex >= FRAME_DELAY ) mLastIndex=0; |
|
548 |
*/ |
|
510 |
clear(); |
|
549 | 511 |
} |
550 | 512 |
} |
551 | 513 |
|
... | ... | |
683 | 645 |
mNear=0.99f; |
684 | 646 |
} |
685 | 647 |
|
686 |
if( mBuffer[0]!=null )
|
|
648 |
if( mBuffer!=null ) |
|
687 | 649 |
{ |
688 | 650 |
for(int j=0; j<EffectQuality.LENGTH; j++) mBuffer[j].mNear = mNear; |
689 | 651 |
} |
... | ... | |
874 | 836 |
{ |
875 | 837 |
case ATTACH: if( mChildren==null ) mChildren = new ArrayList<>(2); |
876 | 838 |
job.node.setSurfaceParent(this); |
877 |
DistortedMaster.addSorted(mChildren,job.node);
|
|
839 |
DistortedMaster.addSortingByBuckets(mChildren,job.node);
|
|
878 | 840 |
mNumChildren++; |
879 | 841 |
break; |
880 | 842 |
case DETACH: if( mNumChildren>0 && mChildren.remove(job.node) ) |
... | ... | |
897 | 859 |
} |
898 | 860 |
break; |
899 | 861 |
case SORT : mChildren.remove(job.node); |
900 |
DistortedMaster.addSorted(mChildren,job.node);
|
|
862 |
DistortedMaster.addSortingByBuckets(mChildren,job.node);
|
|
901 | 863 |
break; |
902 | 864 |
} |
903 | 865 |
} |
Also available in: Unified diff
Port all the 'non-controversial' changes from order-independent-transparency branch.