Revision baa3989b
Added by Leszek Koltunski almost 6 years ago
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
69 | 69 |
|
70 | 70 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
71 | 71 |
|
72 |
// Global buffers used for postprocessing. MipmapLevels x PING_PONG of each for postprocessing ping-pong. |
|
73 |
private static final int PING_PONG = 2; |
|
74 |
private static DistortedOutputSurface[][] mBuffer = null; |
|
72 |
// Global buffers used for postprocessing. |
|
73 |
private static DistortedOutputSurface[] mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH]; |
|
75 | 74 |
|
76 | 75 |
private long mTime; |
77 | 76 |
private float mFOV; |
... | ... | |
172 | 171 |
|
173 | 172 |
private static void createPostprocessingBuffers(int width, int height, float near) |
174 | 173 |
{ |
175 |
mBuffer = new DistortedOutputSurface[EffectQuality.LENGTH][PING_PONG]; |
|
176 | 174 |
float mipmap=1.0f; |
177 | 175 |
|
178 |
for (int i=0; i<EffectQuality.LENGTH; i++)
|
|
176 |
for (int j=0; j<EffectQuality.LENGTH; j++)
|
|
179 | 177 |
{ |
180 |
mBuffer[i][0] = new DistortedFramebuffer(1, BOTH_DEPTH_STENCIL, TYPE_SYST, (int) (width * mipmap), (int) (height * mipmap)); |
|
181 |
mBuffer[i][0].mMipmap = mipmap; |
|
182 |
mBuffer[i][0].mNear = near; // copy mNear as well (for blitting- see PostprocessEffect.apply() ) |
|
183 |
mBuffer[i][0].glClearColor(1.0f, 1.0f, 1.0f, 0.0f); |
|
184 |
|
|
185 |
for(int j=1; j<PING_PONG; j++) |
|
186 |
{ |
|
187 |
mBuffer[i][j] = new DistortedFramebuffer(1, NO_DEPTH_NO_STENCIL, TYPE_SYST, (int) (width * mipmap), (int) (height * mipmap)); |
|
188 |
mBuffer[i][j].mMipmap = mipmap; |
|
189 |
mBuffer[i][j].mNear = near; |
|
190 |
mBuffer[i][j].glClearColor(1.0f, 1.0f, 1.0f, 0.0f); |
|
191 |
} |
|
178 |
mBuffer[j] = new DistortedFramebuffer(2, BOTH_DEPTH_STENCIL, TYPE_SYST, (int) (width * mipmap), (int) (height * mipmap)); |
|
179 |
mBuffer[j].mMipmap = mipmap; |
|
180 |
mBuffer[j].mNear = near; // copy mNear as well (for blitting- see PostprocessEffect.apply() ) |
|
181 |
mBuffer[j].glClearColor(1.0f, 1.0f, 1.0f, 0.0f); |
|
192 | 182 |
|
193 | 183 |
mipmap *= EffectQuality.MULTIPLIER; |
194 | 184 |
} |
195 | 185 |
|
196 | 186 |
DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now. |
197 | 187 |
|
198 |
for (int i=0; i<EffectQuality.LENGTH; i++) |
|
199 |
{ |
|
200 |
for(int j=1; j<PING_PONG; j++) |
|
201 |
{ |
|
202 |
( (DistortedFramebuffer)mBuffer[i][j]).copyDepthAndStencil( (DistortedFramebuffer)mBuffer[i][0] ); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 | 188 |
GLES31.glStencilMask(0xff); |
207 | 189 |
GLES31.glDepthMask(true); |
208 | 190 |
GLES31.glColorMask(true, true, true, true); |
... | ... | |
210 | 192 |
GLES31.glClearDepthf(1.0f); |
211 | 193 |
GLES31.glClearStencil(0); |
212 | 194 |
|
213 |
for (int i=0; i<EffectQuality.LENGTH; i++)
|
|
195 |
for (int j=0; j<EffectQuality.LENGTH; j++)
|
|
214 | 196 |
{ |
215 |
mBuffer[i][0].setAsOutput(); |
|
197 |
mBuffer[j].setAsOutput(); |
|
198 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[j].mColorH[1], 0); |
|
216 | 199 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT | GLES31.GL_DEPTH_BUFFER_BIT | GLES31.GL_STENCIL_BUFFER_BIT); |
217 |
|
|
218 |
for(int j=1; j<PING_PONG; j++) |
|
219 |
{ |
|
220 |
mBuffer[i][j].setAsOutput(); |
|
221 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT); |
|
222 |
} |
|
200 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[j].mColorH[0], 0); |
|
201 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT); |
|
223 | 202 |
} |
224 | 203 |
} |
225 | 204 |
|
... | ... | |
227 | 206 |
|
228 | 207 |
static synchronized void onDestroy() |
229 | 208 |
{ |
230 |
if( mBuffer!=null )
|
|
209 |
for(int j=0; j<EffectQuality.LENGTH; j++)
|
|
231 | 210 |
{ |
232 |
for (int i=0; i<EffectQuality.LENGTH; i++) |
|
233 |
{ |
|
234 |
for (int j=1; j<PING_PONG; j++) |
|
235 |
{ |
|
236 |
mBuffer[i][j] = null; |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
mBuffer = null; |
|
211 |
mBuffer[j] = null; |
|
241 | 212 |
} |
242 | 213 |
} |
243 | 214 |
|
... | ... | |
249 | 220 |
|
250 | 221 |
private static void clonePostprocessingViewport(DistortedOutputSurface from) |
251 | 222 |
{ |
252 |
if( mBuffer[0][0].mWidth != from.mWidth || mBuffer[0][0].mHeight != from.mHeight )
|
|
223 |
if( mBuffer[0].mWidth != from.mWidth || mBuffer[0].mHeight != from.mHeight )
|
|
253 | 224 |
{ |
254 | 225 |
DistortedOutputSurface surface; |
255 | 226 |
|
256 | 227 |
for(int i=0; i<EffectQuality.LENGTH; i++) |
257 | 228 |
{ |
258 |
for(int j=0; j<PING_PONG; j++) |
|
259 |
{ |
|
260 |
surface = mBuffer[i][j]; |
|
229 |
surface = mBuffer[i]; |
|
261 | 230 |
|
262 |
surface.mWidth = (int) (from.mWidth * surface.mMipmap);
|
|
263 |
surface.mHeight = (int) (from.mHeight * surface.mMipmap);
|
|
231 |
surface.mWidth = (int)(from.mWidth *surface.mMipmap);
|
|
232 |
surface.mHeight = (int)(from.mHeight*surface.mMipmap);
|
|
264 | 233 |
|
265 |
surface.mNear = from.mNear; // Near plane is independent of the mipmap level
|
|
234 |
surface.mNear = from.mNear; // Near plane is independent of the mipmap level
|
|
266 | 235 |
|
267 |
//android.util.Log.e("surface", "viewport "+i+" to ("+from.mWidth+"x"+from.mHeight+")");
|
|
236 |
//android.util.Log.e("surface", "viewport "+i+" to ("+from.mWidth+"x"+from.mHeight+")"); |
|
268 | 237 |
|
269 |
surface.createProjection();
|
|
238 |
surface.createProjection(); |
|
270 | 239 |
|
271 |
int maxw = surface.mWidth > surface.mRealWidth ? surface.mWidth : surface.mRealWidth;
|
|
272 |
int maxh = surface.mHeight > surface.mRealHeight ? surface.mHeight : surface.mRealHeight;
|
|
240 |
int maxw = surface.mWidth > surface.mRealWidth ? surface.mWidth : surface.mRealWidth; |
|
241 |
int maxh = surface.mHeight > surface.mRealHeight ? surface.mHeight : surface.mRealHeight; |
|
273 | 242 |
|
274 |
if (maxw > surface.mRealWidth || maxh > surface.mRealHeight)
|
|
275 |
{
|
|
276 |
surface.mRealWidth = maxw;
|
|
277 |
surface.mRealHeight = maxh;
|
|
243 |
if (maxw > surface.mRealWidth || maxh > surface.mRealHeight) |
|
244 |
{ |
|
245 |
surface.mRealWidth = maxw; |
|
246 |
surface.mRealHeight = maxh; |
|
278 | 247 |
|
279 |
surface.recreate(); |
|
280 |
surface.create(); |
|
281 |
} |
|
248 |
surface.recreate(); |
|
249 |
surface.create(); |
|
282 | 250 |
} |
283 | 251 |
} |
284 | 252 |
} |
... | ... | |
320 | 288 |
} |
321 | 289 |
|
322 | 290 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
323 |
// two phases: 1. collapse the SSBO 2. blend the SSBO's color
|
|
291 |
// two phases: 1. collapse the SSBO 2. blend the ssbo's color
|
|
324 | 292 |
|
325 | 293 |
private int oitRender(long currTime) |
326 | 294 |
{ |
... | ... | |
350 | 318 |
|
351 | 319 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
352 | 320 |
|
353 |
private static void clearPostprocessingBuffer(int quality)
|
|
321 |
private static void clearBuffer(DistortedOutputSurface buffer)
|
|
354 | 322 |
{ |
355 | 323 |
GLES31.glStencilMask(0xff); |
356 | 324 |
GLES31.glDepthMask(true); |
... | ... | |
359 | 327 |
GLES31.glClearDepthf(1.0f); |
360 | 328 |
GLES31.glClearStencil(0); |
361 | 329 |
|
362 |
mBuffer[quality][0].setAsOutput(); |
|
330 |
buffer.setAsOutput(); |
|
331 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[buffer.mNumColors-1], 0); |
|
363 | 332 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT); |
364 | 333 |
|
365 |
for(int j=1; j<PING_PONG; j++)
|
|
334 |
for(int i=buffer.mNumColors-2; i>=0; i--)
|
|
366 | 335 |
{ |
367 |
mBuffer[quality][j].setAsOutput();
|
|
336 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[i], 0);
|
|
368 | 337 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT); |
369 | 338 |
} |
370 | 339 |
} |
... | ... | |
406 | 375 |
} |
407 | 376 |
else |
408 | 377 |
{ |
409 |
if( mBuffer==null ) createPostprocessingBuffers(mWidth,mHeight,mNear); |
|
378 |
if( mBuffer[0]==null ) createPostprocessingBuffers(mWidth,mHeight,mNear);
|
|
410 | 379 |
|
411 | 380 |
if( lastBucket!=currBucket ) |
412 | 381 |
{ |
... | ... | |
420 | 389 |
for(int j=bucketChange; j<i; j++) |
421 | 390 |
{ |
422 | 391 |
child2 = children.get(j); |
423 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality][0],lastQueue);
|
|
392 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastQueue); |
|
424 | 393 |
} |
425 | 394 |
|
426 | 395 |
numRenders += lastQueue.postprocess(mBuffer); |
427 |
numRenders += oitBuild(mBuffer[quality][0]);
|
|
396 |
numRenders += oitBuild(mBuffer[quality]); |
|
428 | 397 |
GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT|GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT); |
429 |
clearPostprocessingBuffer(quality);
|
|
398 |
clearBuffer(mBuffer[quality]);
|
|
430 | 399 |
} |
431 | 400 |
|
432 | 401 |
internalQuality = currQueue.getInternalQuality(); |
... | ... | |
434 | 403 |
bucketChange = i; |
435 | 404 |
} |
436 | 405 |
|
437 |
mBuffer[quality][0].setAsOutput(time);
|
|
438 |
child1.drawNoBlend(time,mBuffer[quality][0]);
|
|
406 |
mBuffer[quality].setAsOutput(time); |
|
407 |
child1.drawNoBlend(time,mBuffer[quality]); |
|
439 | 408 |
|
440 | 409 |
if( i==numChildren-1 ) |
441 | 410 |
{ |
442 | 411 |
for(int j=bucketChange; j<numChildren; j++) |
443 | 412 |
{ |
444 | 413 |
child2 = children.get(j); |
445 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality][0],currQueue);
|
|
414 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currQueue); |
|
446 | 415 |
} |
447 | 416 |
|
448 | 417 |
numRenders += currQueue.postprocess(mBuffer); |
449 |
numRenders += oitBuild(mBuffer[quality][0]);
|
|
418 |
numRenders += oitBuild(mBuffer[quality]); |
|
450 | 419 |
GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT|GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT); |
451 | 420 |
numRenders += oitRender(time); // merge the OIT linked list |
452 |
clearPostprocessingBuffer(quality);
|
|
421 |
clearBuffer(mBuffer[quality]);
|
|
453 | 422 |
} |
454 | 423 |
} // end else (postprocessed child) |
455 | 424 |
|
Also available in: Unified diff
Revert last changes to the postprocessing FBO.
This reverts commit 2dbed690bdbee80d9bfb22c800073855eb5d0946.