Project

General

Profile

« Previous | Next » 

Revision f4d6114c

Added by Leszek Koltunski almost 6 years ago

I spoke too soon, the ARM Mali flashing is of course not fixed yet. The previous commit fixed Triblur, but the bug is still reproducible elsewhere (only in the 'postprocessed' apps though).

This commit introduces a circular queue in case of the postprocessing FBOs - with little success though.

View differences:

src/main/java/org/distorted/library/main/DistortedOutputSurface.java
180 180

  
181 181
    for(int j=0; j<EffectQuality.LENGTH; j++)
182 182
      {
183
      mBuffer[j] = new DistortedFramebuffer(2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(width*mipmap), (int)(height*mipmap) );
183
      mBuffer[j] = new DistortedFramebuffer(Distorted.FBO_QUEUE_SIZE,2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(width*mipmap), (int)(height*mipmap) );
184 184
      mBuffer[j].mMipmap = mipmap;
185 185
      mBuffer[j].mNear   = near;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
186 186
      mBuffer[j].glClearColor(1.0f,1.0f,1.0f,0.0f);
......
199 199

  
200 200
    for(int j=0; j<EffectQuality.LENGTH; j++)
201 201
      {
202
      mBuffer[j].setAsOutput();
203
      GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[j].mColorH[1], 0);
204
      GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT);
205
      GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[j].mColorH[0], 0);
206
      GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
202
      for(int k=0; k<Distorted.FBO_QUEUE_SIZE; k++)
203
        {
204
        GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mBuffer[j].mFBOH[k]);
205
        GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[j].mColorH[2*k+1], 0);
206
        GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT | GLES31.GL_DEPTH_BUFFER_BIT | GLES31.GL_STENCIL_BUFFER_BIT);
207
        GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mBuffer[j].mColorH[2*k  ], 0);
208
        GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
209
        }
207 210
      }
211

  
212
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
208 213
    }
209 214

  
210 215
///////////////////////////////////////////////////////////////////////////////////////////////////
......
267 272
  private int blitWithDepth(long currTime, DistortedOutputSurface buffer,int fbo)
268 273
    {
269 274
    GLES31.glViewport(0, 0, mWidth, mHeight);
270
    setAsOutput(currTime,fbo);
275
    setAsOutputFBO(currTime,fbo);
271 276
    GLES31.glActiveTexture(GLES31.GL_TEXTURE0);
272
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[0]);
277
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo]);
273 278
    GLES31.glActiveTexture(GLES31.GL_TEXTURE1);
274
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mDepthStencilH[0]);
279
    GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]);
275 280

  
276 281
    GLES31.glDisable(GLES31.GL_STENCIL_TEST);
277 282
    GLES31.glStencilMask(0x00);
......
290 295
    GLES31.glClearDepthf(1.0f);
291 296
    GLES31.glClearStencil(0);
292 297

  
293
    buffer.setAsOutput();
294
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[1], 0);
298
    buffer.setAsOutputFBO(fbo);
299
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo+1], 0);
295 300
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT);
296
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[0], 0);
301
    GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo  ], 0);
297 302
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
298 303

  
299 304
    return 1;
......
331 336

  
332 337
      if( currBucket==0 )
333 338
        {
334
        setAsOutput(time,fbo);
339
        setAsOutputFBO(time,fbo);
335 340
        numRenders += child1.draw(time,this);
336 341
        }
337 342
      else
......
349 354
            for(int j=bucketChange; j<i; j++)
350 355
              {
351 356
              child2 = children.get(j);
357
              mBuffer[internalQuality].setAsOutputFBO(fbo);
352 358
              numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastQueue);
353 359
              }
354 360

  
355
            numRenders += lastQueue.postprocess(mBuffer);
361
            numRenders += lastQueue.postprocess(mBuffer,fbo);
356 362
            numRenders += blitWithDepth(time, mBuffer[quality],fbo);
357 363

  
358
            mBuffer[quality].setAsOutputAndClear(time);
364
            mBuffer[quality].setAsOutputAndClear(time,fbo);
359 365
            }
360 366

  
361 367
          internalQuality = currQueue.getInternalQuality();
......
363 369
          bucketChange    = i;
364 370
          }
365 371

  
366
        mBuffer[quality].setAsOutput(time);
372
        mBuffer[quality].setAsOutputFBO(time,fbo);
367 373
        child1.drawNoBlend(time,mBuffer[quality]);
368 374

  
369 375
        if( i==numChildren-1 )
......
371 377
          for(int j=bucketChange; j<numChildren; j++)
372 378
            {
373 379
            child2 = children.get(j);
380
            mBuffer[internalQuality].setAsOutputFBO(fbo);
374 381
            numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currQueue);
375 382
            }
376 383

  
377
          numRenders += currQueue.postprocess(mBuffer);
384
          numRenders += currQueue.postprocess(mBuffer,fbo);
378 385
          numRenders += blitWithDepth(time, mBuffer[quality],fbo);
379 386
          }
380 387
        } // end postprocessed child case
......
422 429
 * Useful for drawing to the postprocessing buffer, which must sometimes be cleared multiple times
423 430
 * per frame.
424 431
 */
425

  
426
  private void setAsOutputAndClear(long time)
432
  private void setAsOutputAndClear(long time,int fbo)
427 433
    {
428
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
434
    GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[fbo]);
429 435

  
430
    mTime[0] = time;    // have to do this otherwise on the next setAsOutput() we would clear
436
    mTime[fbo] = time;    // have to do this otherwise on the next setAsOutput() we would clear
431 437
    DistortedRenderState.colorDepthStencilOn();
432 438
    GLES31.glClearColor(mClearR, mClearG, mClearB, mClearA);
433 439
    GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT);
......
436 442

  
437 443
///////////////////////////////////////////////////////////////////////////////////////////////////
438 444

  
439
  private void setAsOutput(long time, int fbo)
445
  private void setAsOutputFBO(long time, int fbo)
440 446
    {
441 447
    if( fbo>=0 && fbo<mNumFBOs )
442 448
      {
......
450 456
      }
451 457
    else
452 458
      {
453
      android.util.Log.e("surface", "error in setAsOutput, fbo="+fbo);
459
      android.util.Log.e("surface", "error in setAsOutput1, fbo="+fbo);
460
      }
461
    }
462

  
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464
/**
465
 * Not part of the Public API.
466
 *
467
 * @y.exclude
468
 */
469
  public void setAsOutputFBO(int fbo)
470
    {
471
    if( fbo>=0 && fbo<mNumFBOs )
472
      {
473
      GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[fbo]);
474
      }
475
    else
476
      {
477
      android.util.Log.e("surface", "error in setAsOutput2, fbo="+fbo);
454 478
      }
455 479
    }
456 480

  

Also available in: Unified diff