Revision ce154014
Added by Leszek Koltunski about 6 years ago
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
79 | 79 |
|
80 | 80 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
81 | 81 |
|
82 |
// buffers used for postprocessing. |
|
83 |
private DistortedOutputSurface[] mBuffer;
|
|
82 |
// Global buffers used for postprocessing.
|
|
83 |
private static DistortedOutputSurface[] mBuffer = new DistortedOutputSurface[1+EffectQuality.LENGTH];
|
|
84 | 84 |
|
85 | 85 |
private long mTime; |
86 | 86 |
private float mFOV; |
... | ... | |
170 | 170 |
mClearStencil = 0; |
171 | 171 |
mClear = GLES31.GL_DEPTH_BUFFER_BIT | GLES31.GL_COLOR_BUFFER_BIT; |
172 | 172 |
|
173 |
mBuffer = new DistortedOutputSurface[1+EffectQuality.LENGTH]; |
|
174 |
|
|
175 | 173 |
mMipmap = 1.0f; |
176 | 174 |
|
177 | 175 |
createProjection(); |
... | ... | |
289 | 287 |
|
290 | 288 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
291 | 289 |
|
292 |
private void createBuffers()
|
|
290 |
private static void createBuffers(int width, int height, float near)
|
|
293 | 291 |
{ |
294 | 292 |
float mipmap=1.0f; |
295 | 293 |
|
296 | 294 |
for(int j=0; j<EffectQuality.LENGTH; j++) |
297 | 295 |
{ |
298 |
mBuffer[j] = new DistortedFramebuffer(2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) );
|
|
296 |
mBuffer[j] = new DistortedFramebuffer(2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(width*mipmap), (int)(height*mipmap) );
|
|
299 | 297 |
mBuffer[j].mMipmap = mipmap; |
300 |
mBuffer[j].mNear = mNear; // copy mNear as well (for blitting- see PostprocessEffect.apply() )
|
|
298 |
mBuffer[j].mNear = near; // copy mNear as well (for blitting- see PostprocessEffect.apply() )
|
|
301 | 299 |
mBuffer[j].glClearColor(1.0f,1.0f,1.0f,0.0f); |
302 | 300 |
|
303 | 301 |
mipmap *= EffectQuality.MULTIPLIER; |
304 | 302 |
} |
305 | 303 |
|
306 |
mBuffer[EffectQuality.LENGTH] = this; |
|
307 |
|
|
308 | 304 |
DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now. |
309 | 305 |
|
310 | 306 |
GLES31.glStencilMask(0xff); |
... | ... | |
326 | 322 |
|
327 | 323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
328 | 324 |
|
329 |
private void cloneSize(DistortedOutputSurface from)
|
|
325 |
static synchronized void onDestroy()
|
|
330 | 326 |
{ |
331 |
mWidth = from.mWidth; |
|
332 |
mHeight= from.mHeight; |
|
333 |
|
|
334 |
createProjection(); |
|
327 |
for(int j=0; j<=EffectQuality.LENGTH; j++) |
|
328 |
{ |
|
329 |
mBuffer[j] = null; |
|
330 |
} |
|
331 |
} |
|
335 | 332 |
|
336 |
int maxw = mWidth >mRealWidth ? mWidth :mRealWidth ; |
|
337 |
int maxh = mHeight>mRealHeight ? mHeight:mRealHeight; |
|
333 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
338 | 334 |
|
339 |
if( maxw>mRealWidth || maxh>mRealHeight ) |
|
335 |
private static void cloneViewport(DistortedOutputSurface from) |
|
336 |
{ |
|
337 |
if( mBuffer[EffectQuality.LENGTH] != from ) |
|
340 | 338 |
{ |
341 |
mRealWidth = maxw; |
|
342 |
mRealHeight= maxh; |
|
339 |
mBuffer[EffectQuality.LENGTH]=from; |
|
340 |
DistortedOutputSurface surface; |
|
341 |
|
|
342 |
for(int i=0; i<EffectQuality.LENGTH; i++) |
|
343 |
{ |
|
344 |
surface = mBuffer[i]; |
|
345 |
|
|
346 |
surface.mWidth = (int)(from.mWidth *surface.mMipmap); |
|
347 |
surface.mHeight = (int)(from.mHeight*surface.mMipmap); |
|
348 |
|
|
349 |
surface.mNear = from.mNear; // Near plane is independent of the mipmap level |
|
350 |
|
|
351 |
surface.createProjection(); |
|
352 |
|
|
353 |
int maxw = surface.mWidth > surface.mRealWidth ? surface.mWidth : surface.mRealWidth; |
|
354 |
int maxh = surface.mHeight > surface.mRealHeight ? surface.mHeight : surface.mRealHeight; |
|
343 | 355 |
|
344 |
recreateSurface(); |
|
345 |
createSurface(); |
|
356 |
if (maxw > surface.mRealWidth || maxh > surface.mRealHeight) |
|
357 |
{ |
|
358 |
surface.mRealWidth = maxw; |
|
359 |
surface.mRealHeight = maxh; |
|
360 |
|
|
361 |
surface.recreateSurface(); |
|
362 |
surface.createSurface(); |
|
363 |
} |
|
364 |
} |
|
346 | 365 |
} |
347 | 366 |
} |
348 | 367 |
|
... | ... | |
404 | 423 |
if( currBucket==0 ) numRenders += child1.draw(time,this); |
405 | 424 |
else |
406 | 425 |
{ |
407 |
if( mBuffer[0]==null ) createBuffers(); |
|
426 |
if( mBuffer[0]==null ) createBuffers(mWidth,mHeight,mNear);
|
|
408 | 427 |
|
409 | 428 |
if( lastBucket!=currBucket ) |
410 | 429 |
{ |
... | ... | |
423 | 442 |
internalQuality = currQueue.getInternalQuality(); |
424 | 443 |
quality = currQueue.getQuality(); |
425 | 444 |
bucketChange = i; |
445 |
|
|
446 |
cloneViewport(this); |
|
426 | 447 |
} |
427 | 448 |
|
428 | 449 |
child1.draw(time,mBuffer[quality]); |
... | ... | |
565 | 586 |
{ |
566 | 587 |
android.util.Log.d("surface", "id " + mSurfaceID + |
567 | 588 |
(mType == TYPE_USER ? " USER" : (mType == TYPE_SYST ? " SYST" : " TREE")) + |
568 |
"viewport: (" + mWidth + "x" + mHeight + ") last frame: " + (value - mLastValue[mLastIndex]) |
|
589 |
" viewport: (" + mWidth + "x" + mHeight + ") last frame: " + (value - mLastValue[mLastIndex])
|
|
569 | 590 |
+ " avg: " + (mAvgSum/RUNNING_AVERAGE) |
570 | 591 |
); |
571 | 592 |
} |
Also available in: Unified diff
Make the postprocessing buffers static.